private void Send(string api, Packet packet, DateTime time) { try { Uri uri = new Uri(this.GetUrl(api)); byte[] data = Encoding.ASCII.GetBytes(packet.ToString()); WebClient wc = new WebClient(); wc.UploadDataCompleted += (object sender, UploadDataCompletedEventArgs e) => { if (e.Error != null) { return; } Packet p = (Packet)e.UserState; if (p != null) { string result = Encoding.ASCII.GetString(e.Result); // TODO: with result } }; wc.UploadDataAsync(uri, Post, data, packet); } catch (Exception e) { } }
public void Commit(Packet packet) { byte[] data = ASCIIEncoding.UTF8.GetBytes(packet.ToString()); this.Send("data/commit", data); }
internal void SendReplyPacket(Packet p, DateTime time) { string s = p.ToString(); // this.Send(Encoding.ASCII.GetBytes(s)); }
/// <summary> /// Upload Data Implements /// </summary> /// <param name="api"></param> /// <param name="packet"></param> /// <param name="time"></param> private void Send(string api, Packet packet, DateTime time) { try { Uri uri = new Uri(api); byte[] data = Encoding.ASCII.GetBytes(packet.ToString()); using (WebClient wc = new WebClient()) { wc.UploadDataCompleted += (object sender, UploadDataCompletedEventArgs e) => { if (e.Error != null) { this.NotifyEvent(this, NotifyEvents.SendDataOK, new Notify() { DeviceKey = packet.DeviceKey, Message = e.Error.Message }); this.HandleWebException(e.Error); return; } Packet p = (Packet)e.UserState; if (p != null) { string result = Encoding.ASCII.GetString(e.Result); result = result.Trim(); if (!string.IsNullOrEmpty(result)) { this.NotifyEvent(this, NotifyEvents.SendDataOK, new Notify() { DeviceKey = packet.DeviceKey, Message = result }); } } }; wc.UploadDataAsync(uri, "POST", data, packet); } } catch (Exception e) { } }