/// <summary> /// 处理接收信息 /// </summary> /// <param name="client"></param> /// <param name="message"></param> private void receiveMessage(IWebSocketConnection client, string message) { WSProtocol wsp = default; this.LogModule.Debug($"接收到网络命令:{client.ConnectionInfo.ClientIpAddress} 内容:{message}"); try { wsp = WSProtocol.FromJson(message); } catch (Exception ex) { this.LogModule.Error($"接收到无法解析的内容: {message}"); return; } if (wsp == null || wsp?.Header == null || wsp?.Body == null) { this.LogModule.Error($"接收到无法解析的内容: {message}"); return; } switch (wsp.Header.Ver) { case "1.0": // default: this.procWSPDefault(wsp); break; } }
/// <summary> /// 根据文件名获取ws包 /// </summary> /// <param name="fileName"></param> /// <returns></returns> public static WSProtocol GetUploadPicWSP(string fileName) { FileInfo fileInfo = new FileInfo(fileName); FileStream fs = new FileStream(fileName, FileMode.Open); byte[] data = new byte[fs.Length]; fs.Read(data, 0, data.Length); fs.Close(); string base64 = Convert.ToBase64String(data); WSProtocol wsp = new WSProtocol(); WSPHeader header = new WSPHeader() { BodyType = BodyType.UploadEvent, Time = DateTime.Now.ToString(), Ver = "1.0", SN = "1" }; wsp.Header = header; WSEventUpload body = new WSEventUpload() { EventType = WSEventDefine.FaceImg, Module = WSDefine.VideoModule }; WSEvent_FileUpload f = new WSEvent_FileUpload() { FileType = fileInfo.Extension, FileData_Base64 = base64 }; body.Params = f; wsp.Body = body; return(wsp); }
/// <summary> /// 处理请求 /// </summary> /// <param name="wsp"></param> private void procRequest(WSProtocol wsp) { //WSRequest wSRequest = JsonConvert.DeserializeObject<WSRequest>(wsp.Body); var wSRequest = JsonConvert.DeserializeObject <WSRequest>(wsp.Body.ToString()); this.Manager.WebSocketRequestProc(wSRequest); }
private void Button_Click(object sender, RoutedEventArgs e) { WSProtocol wsp = new WSProtocol() { Header = new WSPHeader() { BodyType = BodyType.Request, SN = "1", Time = DateTime.Now.ToString(), Ver = "1.0" }, }; WSRequest request = new WSRequest() { Command = WSVideoRequest.OpenWindow, Module = WSDefine.VideoModule, RequestSN = "1", Sync = true }; WSVideoRequest_OpenWindow req = new WSVideoRequest_OpenWindow() { LayoutName = "16", Height = 600, Width = 800, LocationX = 0, LocationY = 0, PanelID = "1", ScreenID = 0, ShowVCTitle = true, ShowWindowBorder = true, TopMost = true }; request.Params = req; wsp.Body = request; this.ricktextbox.AppendText($"{JsonConvert.SerializeObject(wsp)}\n"); }
public WSConfig (WSConfig parent, object context) { if (parent == null) return; protocols = parent.protocols; wsdlHelpPage = parent.wsdlHelpPage; if (wsdlHelpPage != null) filePath = parent.filePath; else filePath = context as string; }
/// <summary> /// 处理网络请求 /// </summary> /// <param name="wsp"></param> private void procWSPDefault(WSProtocol wsp) { switch (wsp.Header.BodyType) { case BodyType.Request: this.procRequest(wsp); break; case BodyType.Response: break; case BodyType.UploadEvent: break; default: break; } }
public WSConfig(WSConfig parent, object context) { if (parent == null) { return; } protocols = parent.protocols; wsdlHelpPage = parent.wsdlHelpPage; if (wsdlHelpPage != null) { filePath = parent.filePath; } else { filePath = context as string; } }
public bool RemoveProtocol(string protoName, out string error) { if (protoName == "All") { error = "Invalid protocol name"; return(false); } WSProtocol proto = ParseProtocol(protoName, out error); if (error != null) { return(false); } protocols &= ~proto; return(true); }
private void Button_Click_2(object sender, RoutedEventArgs e) { WSProtocol wsp = new WSProtocol() { Header = new WSPHeader() { BodyType = BodyType.Request, SN = "1", Time = DateTime.Now.ToString(), Ver = "1.0" }, }; WSRequest request = new WSRequest() { Command = WSVideoRequest.StartPlayback, Module = WSDefine.VideoModule, RequestSN = "1", Sync = true }; WSVideoRequest_StartPlayback req = new WSVideoRequest_StartPlayback() { CameraCode = "", CameraID = "1", CameraName = "测试", PanelID = "1", VCIndex = 0, SourceID = "1", SourceIP = "192.168.0.1", SourceName = "海康8200", SourcePort = 9000, SourceType = 200, SourcePassword = "******", SourceUser = "******", StartTime = DateTime.Now.AddHours(-1), EndTime = DateTime.Now }; request.Params = req; wsp.Body = request; this.ricktextbox.AppendText($"{JsonConvert.SerializeObject(wsp)}\n"); }
// Methods to query/get configuration public static bool IsSupported (WSProtocol proto) { return ((Instance.protocols & proto) == proto && (proto != 0) && (proto != WSProtocol.All)); }
public void ClearProtocol () { protocols = 0; }
public bool RemoveProtocol (string protoName, out string error) { if (protoName == "All") { error = "Invalid protocol name"; return false; } WSProtocol proto = ParseProtocol (protoName, out error); if (error != null) return false; protocols &= ~proto; return true; }
/// <summary> /// 事件上报处理 /// </summary> /// <param name="wsp"></param> public void EventUploadProc(WSProtocol wsp) { this.WebsocketHelper.SendEvent(wsp); }
// Methods to query/get configuration public static bool IsSupported(WSProtocol proto) { return((Instance.protocols & proto) == proto && (proto != 0) && (proto != WSProtocol.All)); }
public void ClearProtocol() { protocols = 0; }
/// <summary> /// 发送事件 /// </summary> /// <param name="wsp"></param> public void SendEvent(WSProtocol wsp) { this.SendMessage(JsonConvert.SerializeObject(wsp)); }