public override SendDataInfo SendData(SendDataInfo data) { data.SendTimes += 1; try { if (connectionState) { if (networkStream.CanWrite && !string.IsNullOrEmpty(data.Content)) { byte[] buff = Encoding.UTF8.GetBytes(data.Content); networkStream.Write(buff, 0, buff.Length); networkStream.Flush(); return(null); } } else { client.BeginConnect(host, port, new AsyncCallback(AsynConnect), client); } return(data); } catch (Exception ex) { OnError?.Invoke(ex); return(null); } }
/// <summary> /// 数据发送结果 /// </summary> /// <param name="data"></param> public override void OnSendResult(SendDataInfo data) { if (data.SendTimes < config.ReCount) { SendData(data); } }
/// <summary> /// 发送数据 /// </summary> /// <param name="content"></param> private void SendData(string content) { SendDataInfo info = new SendDataInfo(); info.DataId = Guid.NewGuid().ToString(); info.Content = content; messageArray.Add(info); }
/// <summary> /// 消息发送任务 /// </summary> /// <param name="state"></param> private void MessageCallBack(object state) { if (messageArray.Count > 0) { SendDataInfo info = messageArray.FirstOrDefault(); if (null != info) { OnDataSend.Invoke(info); } messageArray.Remove(info); } }
private void SendData(SendDataInfo info) { if (sendTextEnable) { //AcceptText += "【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】发送数据:" + info.Content; logger.Info("【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】发送数据:" + info.Content); SendDataInfo res = communication.SendData(info); if (null != res) { protocol.OnSendResult(res); } } }
public static void Update(UserConfiguration userConfig, List <Data.DeviceInfo> deviceInfos) { if (ApiConfiguration.DataApiHost.ToString() != ApiConfiguration.LOCAL_API_HOST) // Remote { var json = Data.DeviceInfo.ListToJson(deviceInfos); if (json != null) { var values = new NameValueCollection(); if (userConfig != null) { values["token"] = userConfig.SessionToken; } values["sender_id"] = UserManagement.SenderId.Get(); values["devices"] = json; string url = new Uri(ApiConfiguration.DataApiHost, "data/update/index.php").ToString(); var info = new SendDataInfo(url, values); ThreadPool.QueueUserWorkItem(new WaitCallback(SendData), info); } } else // Local { var json = Data.DeviceInfo.ListToJson(deviceInfos); if (json != null) { var values = new NameValueCollection(); values["devices"] = json; string url = new Uri(ApiConfiguration.DataApiHost, "data/update/index.php").ToString(); // Send to local server var info = new SendDataInfo(url, values); ThreadPool.QueueUserWorkItem(new WaitCallback(SendData), info); if (userConfig != null) { values["token"] = userConfig.SessionToken; values["sender_id"] = UserManagement.SenderId.Get(); // Send to TrakHound Cloud (for Mobile App) var cloudUri = new Uri(ApiConfiguration.CLOUD_API_HOST); url = new Uri(cloudUri, "data/update/index.php").ToString(); var cloudInfo = new SendDataInfo(url, values); ThreadPool.QueueUserWorkItem(new WaitCallback(SendData), cloudInfo); } } } }
public static void Update(UserConfiguration userConfig, List<Data.DeviceInfo> deviceInfos) { if (ApiConfiguration.DataApiHost.ToString() != ApiConfiguration.LOCAL_API_HOST) // Remote { var json = Data.DeviceInfo.ListToJson(deviceInfos); if (json != null) { var values = new NameValueCollection(); if (userConfig != null) values["token"] = userConfig.SessionToken; values["sender_id"] = UserManagement.SenderId.Get(); values["devices"] = json; string url = new Uri(ApiConfiguration.DataApiHost, "data/update/index.php").ToString(); var info = new SendDataInfo(url, values); ThreadPool.QueueUserWorkItem(new WaitCallback(SendData), info); } } else // Local { var json = Data.DeviceInfo.ListToJson(deviceInfos); if (json != null) { var values = new NameValueCollection(); values["devices"] = json; string url = new Uri(ApiConfiguration.DataApiHost, "data/update/index.php").ToString(); // Send to local server var info = new SendDataInfo(url, values); ThreadPool.QueueUserWorkItem(new WaitCallback(SendData), info); if (userConfig != null) { values["token"] = userConfig.SessionToken; values["sender_id"] = UserManagement.SenderId.Get(); // Send to TrakHound Cloud (for Mobile App) var cloudUri = new Uri(ApiConfiguration.CLOUD_API_HOST); url = new Uri(cloudUri, "data/update/index.php").ToString(); var cloudInfo = new SendDataInfo(url, values); ThreadPool.QueueUserWorkItem(new WaitCallback(SendData), cloudInfo); } } } }
public void GetSentData(EventData data) { Dispatcher.BeginInvoke(new Action(UpdateCurrentDate), System.Windows.Threading.DispatcherPriority.Background, new object[] { }); Dispatcher.BeginInvoke(new Action <EventData>(UpdateLoggedInChanged), System.Windows.Threading.DispatcherPriority.Normal, new object[] { data }); Dispatcher.BeginInvoke(new Action <EventData>(UpdateDevicesLoading), System.Windows.Threading.DispatcherPriority.Normal, new object[] { data }); Dispatcher.BeginInvoke(new Action <EventData>(UpdateDeviceAdded), System.Windows.Threading.DispatcherPriority.DataBind, new object[] { data }); Dispatcher.BeginInvoke(new Action <EventData>(UpdateDeviceUpdated), System.Windows.Threading.DispatcherPriority.DataBind, new object[] { data }); Dispatcher.BeginInvoke(new Action <EventData>(UpdateDeviceRemoved), System.Windows.Threading.DispatcherPriority.DataBind, new object[] { data }); if (Plugins != null) { foreach (IClientPlugin plugin in Plugins) { var sendDataInfo = new SendDataInfo(plugin, data); ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessSendData), sendDataInfo); } } }
/// <summary> /// Plugin has sent a DataEvent_Data object to other plugins /// </summary> /// <param name="de_d"></param> private void Plugin_SendData(EventData data) { foreach (var config in PluginConfigurations) { if (config.Enabled) { var plugin = Plugins.Find(x => x.Title == config.Name && x.ParentPlugin == config.Parent && x.ParentPluginCategory == config.Category ); if (plugin != null && plugin != data.Sender) { var sendDataInfo = new SendDataInfo(plugin, data); ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessSendData), sendDataInfo); } } } SendEventData(data); }
/// <summary> /// 发送数据 /// </summary> /// <param name="data"></param> /// <returns></returns> public abstract SendDataInfo SendData(SendDataInfo data);
public void GetSentData(EventData data) { Dispatcher.BeginInvoke(new Action(UpdateCurrentDate), System.Windows.Threading.DispatcherPriority.Background, new object[] { }); Dispatcher.BeginInvoke(new Action<EventData>(UpdateLoggedInChanged), System.Windows.Threading.DispatcherPriority.Normal, new object[] { data }); Dispatcher.BeginInvoke(new Action<EventData>(UpdateDevicesLoading), System.Windows.Threading.DispatcherPriority.Normal, new object[] { data }); Dispatcher.BeginInvoke(new Action<EventData>(UpdateDeviceAdded), System.Windows.Threading.DispatcherPriority.DataBind, new object[] { data }); Dispatcher.BeginInvoke(new Action<EventData>(UpdateDeviceUpdated), System.Windows.Threading.DispatcherPriority.DataBind, new object[] { data }); Dispatcher.BeginInvoke(new Action<EventData>(UpdateDeviceRemoved), System.Windows.Threading.DispatcherPriority.DataBind, new object[] { data }); if (Plugins != null) { foreach (IClientPlugin plugin in Plugins) { var sendDataInfo = new SendDataInfo(plugin, data); ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessSendData), sendDataInfo); } } }
/// <summary> /// 数据发送结果 /// </summary> public abstract void OnSendResult(SendDataInfo data);
/// <summary> /// 发送数据 /// </summary> /// <param name="data"></param> private void SendData(SendDataInfo info) { messageArray.Add(info); }