private async void websocketclientToServer_OnDataIn(object sender, nsoftware.IPWorksWS.WebsocketclientDataInEventArgs e) { try { log.Info("Received Data From AutoPix backend server:" + e.Text); var AutoInspexID = ConfigurationManager.AppSettings["AutoInspexID"] + ""; var AutoInspexWebServiceUrl = ConfigurationManager.AppSettings["AutoInspexWebServiceUrl"] + ""; List <int> camerasSequecences = null; var dataObj = JObject.Parse(e.Text); var sequenceNums = (string)dataObj["sequenceNo"]; if (sequenceNums.ToLower() == "all") { camerasSequecences = Enumerable.Range(1, 72).ToList(); } else { var sequenceNoArray = sequenceNums.Split(','); var list = new List <int>(); foreach (var i in sequenceNoArray) { try { list.Add(Convert.ToInt32(i)); } catch (Exception ext) { log.Error(ext.Message, ext); } } camerasSequecences = list; } if (dataObj != null && (string)dataObj["autoInspexID"] == AutoInspexID) { string serviceType = (string)dataObj["serviceType"]; string sellingMethod = (string)dataObj["sellingMethod"]; string vinCode = (string)dataObj["vinCode"]; string vehicleId = (string)dataObj["vehicleId"]; string autoInspexID = (string)dataObj["autoInspexID"]; string uuid = (string)dataObj["uuid"]; string imageType = (string)dataObj["imageType"]; string sequenceNo = (string)dataObj["sequenceNo"]; string inspexIQConnectionId = (string)dataObj["inspexIQConnectionId"]; var client = new RestClient(AutoInspexWebServiceUrl); var request = new RestRequest("/api/PICameras/" + autoInspexID, DataFormat.Json); var piCameras = await client.GetAsync <List <PICamera> >(request); int countCamera = 0; if (piCameras != null && piCameras.Any()) { foreach (var p in piCameras.Where(p => camerasSequecences.Contains(Convert.ToInt32(p.RingPosition)))) { countCamera++; try { string piIPAddress = (string)dataObj["piIPAddress"]; this.components = new System.ComponentModel.Container(); var websocketclient = new nsoftware.IPWorksWS.Websocketclient(this.components); websocketclient.Firewall.Port = 1080; websocketclient.OnLog += Websocketclient_OnLog; websocketclient.Firewall.FirewallType = nsoftware.IPWorksWS.FirewallTypes.fwNone; websocketclient.OnDataIn += new nsoftware.IPWorksWS.Websocketclient.OnDataInHandler(this.websocketclient_OnDataIn); websocketclient.OnConnected += Websocketclient_OnConnected; websocketclient.OnError += Websocketclient_OnError; websocketclient.Connect($"ws://{p.IPAddress}:5001"); var message = new { serviceType = serviceType, sellingMethod = sellingMethod, vinCode = vinCode, vehicleId = vehicleId, autoInspexID = autoInspexID, uuid = uuid, imageType = imageType, sequenceNo = p.RingPosition, inspexIQConnectionId = inspexIQConnectionId, }; var json = JsonConvert.SerializeObject(message); websocketclient.DataToSend = json; websocketclient.Timeout = 120; } catch (IPWorksWSException ipwse) { log.Error(ipwse.Message + "\r\n" + ipwse.StackTrace); var message = new { serviceType = serviceType, sellingMethod = sellingMethod, vinCode = vinCode, vehicleId = vehicleId, autoInspexID = autoInspexID, uuid = uuid, imageType = imageType, sequenceNo = sequenceNo, inspexIQConnectionId = inspexIQConnectionId, error = "Unable to connect to the camera at postion " + p.RingPosition }; var json = JsonConvert.SerializeObject(message); this.websocketclientToServer.SendText(json); } catch (Exception ext) { log.Error(ext.Message, ext); } } if (countCamera == 0) { log.Error("countCamera=0"); var message = new { serviceType = serviceType, sellingMethod = sellingMethod, vinCode = vinCode, vehicleId = vehicleId, autoInspexID = autoInspexID, uuid = uuid, imageType = imageType, sequenceNo = sequenceNo, inspexIQConnectionId = inspexIQConnectionId, error = "No camera found to take pictures. Please check the sequenceNo" }; var json = JsonConvert.SerializeObject(message); this.websocketclientToServer.SendText(json); } } else { var message = new { serviceType = serviceType, sellingMethod = sellingMethod, vinCode = vinCode, vehicleId = vehicleId, autoInspexID = autoInspexID, uuid = uuid, imageType = imageType, sequenceNo = sequenceNo, inspexIQConnectionId = inspexIQConnectionId, error = "No camera configured for autoInspexID" + autoInspexID }; var json = JsonConvert.SerializeObject(message); this.websocketclientToServer.SendText(json); } } } catch (Exception ext) { log.Error(ext.Message, ext); } }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(websocketclientDemo)); this.websocketclient1 = new nsoftware.IPWorksWS.Websocketclient(this.components); this.Label1 = new System.Windows.Forms.Label(); this.lNotice = new System.Windows.Forms.Label(); this.bSend = new System.Windows.Forms.Button(); this.tbEcho = new System.Windows.Forms.TextBox(); this.lServer = new System.Windows.Forms.Label(); this.bConnect = new System.Windows.Forms.Button(); this.tbServer = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.textBox1 = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // websocketclient1 // this.websocketclient1.About = "IPWorks WebSockets 2020 [Build 7525]"; this.websocketclient1.Firewall.Port = 1080; this.websocketclient1.OnConnected += new nsoftware.IPWorksWS.Websocketclient.OnConnectedHandler(this.websocketclient1_OnConnected); this.websocketclient1.OnDataIn += new nsoftware.IPWorksWS.Websocketclient.OnDataInHandler(this.websocketclient1_OnDataIn); this.websocketclient1.OnDisconnected += new nsoftware.IPWorksWS.Websocketclient.OnDisconnectedHandler(this.websocketclient1_OnDisconnected); this.websocketclient1.OnSSLServerAuthentication += new nsoftware.IPWorksWS.Websocketclient.OnSSLServerAuthenticationHandler(this.websocketclient1_OnSSLServerAuthentication); // // Label1 // this.Label1.Location = new System.Drawing.Point(8, 104); this.Label1.Name = "Label1"; this.Label1.Size = new System.Drawing.Size(144, 16); this.Label1.TabIndex = 24; this.Label1.Text = "Data received from server:"; // // lNotice // this.lNotice.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lNotice.ForeColor = System.Drawing.SystemColors.Highlight; this.lNotice.Location = new System.Drawing.Point(8, 5); this.lNotice.Name = "lNotice"; this.lNotice.Size = new System.Drawing.Size(1231, 45); this.lNotice.TabIndex = 17; this.lNotice.Text = resources.GetString("lNotice.Text"); // // bSend // this.bSend.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.bSend.Location = new System.Drawing.Point(1143, 82); this.bSend.Name = "bSend"; this.bSend.Size = new System.Drawing.Size(75, 23); this.bSend.TabIndex = 22; this.bSend.Text = "Retake"; this.bSend.Click += new System.EventHandler(this.bSend_Click); // // tbEcho // this.tbEcho.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tbEcho.Location = new System.Drawing.Point(11, 123); this.tbEcho.Multiline = true; this.tbEcho.Name = "tbEcho"; this.tbEcho.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.tbEcho.Size = new System.Drawing.Size(1101, 760); this.tbEcho.TabIndex = 21; // // lServer // this.lServer.Location = new System.Drawing.Point(12, 57); this.lServer.Name = "lServer"; this.lServer.Size = new System.Drawing.Size(80, 23); this.lServer.TabIndex = 15; this.lServer.Text = "Echo Server:"; // // bConnect // this.bConnect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.bConnect.Location = new System.Drawing.Point(1143, 53); this.bConnect.Name = "bConnect"; this.bConnect.Size = new System.Drawing.Size(75, 23); this.bConnect.TabIndex = 23; this.bConnect.Tag = "disconnected"; this.bConnect.Text = "Connect"; this.bConnect.Click += new System.EventHandler(this.bConnect_Click); // // tbServer // this.tbServer.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tbServer.Location = new System.Drawing.Point(143, 55); this.tbServer.Name = "tbServer"; this.tbServer.Size = new System.Drawing.Size(523, 20); this.tbServer.TabIndex = 19; this.tbServer.Text = "ws://localhost:8801"; // // button1 // this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.button1.Location = new System.Drawing.Point(1143, 121); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 25; this.button1.Text = "Take 72 "; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.button2.Location = new System.Drawing.Point(1143, 295); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 23); this.button2.TabIndex = 26; this.button2.Text = "Clear"; this.button2.Click += new System.EventHandler(this.button2_Click); // // textBox1 // this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.textBox1.Location = new System.Drawing.Point(143, 81); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(523, 20); this.textBox1.TabIndex = 27; // // label2 // this.label2.Location = new System.Drawing.Point(10, 80); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(122, 23); this.label2.TabIndex = 28; this.label2.Text = "Sequence Numbers:"; // // label3 // this.label3.Location = new System.Drawing.Point(672, 78); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(158, 23); this.label3.TabIndex = 29; this.label3.Text = "(Example: all or 12,34,56)"; // // websocketclientDemo // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(1247, 892); this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.textBox1); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Controls.Add(this.Label1); this.Controls.Add(this.lNotice); this.Controls.Add(this.bSend); this.Controls.Add(this.tbEcho); this.Controls.Add(this.lServer); this.Controls.Add(this.bConnect); this.Controls.Add(this.tbServer); this.Name = "websocketclientDemo"; this.Text = "WebSocketClient"; this.ResumeLayout(false); this.PerformLayout(); }