using System;
using System.Collections.Concurrent;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using TeamAAS.Communication.Attributes;
using TeamAAS.Communication.Base;
using TeamAAS.Communication.Interfaces;
namespace TeamAAS.Communication.Devices
{
///
/// Web 通讯(HTTP 客户端)。ReadValue(address) 为 GET 请求,
/// WriteValue(address, value) 为 POST 请求,address 为相对路径。
///
[Communication("Web", "基础通讯", "HTTP/WebApi 客户端")]
public class WebCommunication : BindableCommunicationBase
{
[JsonIgnore]
private static readonly HttpClient _http = new HttpClient();
[JsonIgnore]
private readonly ConcurrentQueue _received = new ConcurrentQueue();
[JsonIgnore]
private bool _connected;
private string _baseUrl = "http://127.0.0.1:8000";
public string BaseUrl
{
get { return _baseUrl; }
set { SetProperty(ref _baseUrl, value); }
}
public override string EndpointUrl
{
get { return BaseUrl; }
set
{
if (!string.IsNullOrWhiteSpace(value))
BaseUrl = value.TrimEnd('/');
}
}
public override bool IsConnected
{
get { return _connected; }
}
public override event Action