protected override void OnStop() { try { if (log.IsDebugEnabled) { log.Debug ($"Shutdown {this.ServiceName}..."); } websocketclientToServer.Disconnect(); WebsocketserverMain.Shutdown(); if (log.IsDebugEnabled) { log.Debug($" {this.ServiceName} was shutdown successfully."); } } catch (Exception exception) { if (log.IsDebugEnabled) { string[] message = { exception.Message, "\r\n", exception.Source, "\r\n", exception.StackTrace }; log.Error(string.Concat(message)); } } }
private void WebsocketserverMain_OnDataIn(object sender, WebsocketserverDataInEventArgs ex) { try { try { log.Info("Received Data From :" + ex.ConnectionId + ";Data: " + ex.Text); var dataObj = JObject.Parse(ex.Text); string inspexIQConnectionId = (string)dataObj["inspexIQConnectionId"]; //need to query server for the PI IPaddress if (string.IsNullOrEmpty(inspexIQConnectionId)) { 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"]; var message = new { serviceType = serviceType, sellingMethod = sellingMethod, vinCode = vinCode, vehicleId = vehicleId, autoInspexID = autoInspexID, uuid = uuid, imageType = imageType, sequenceNo = sequenceNo, inspexIQConnectionId = ex.ConnectionId, }; var json = JsonConvert.SerializeObject(message); foreach (var c in WebsocketserverMain.Connections.Values) { WebsocketserverMain.SendText(c.ConnectionId, json); } } else { WebsocketserverMain.SendText(inspexIQConnectionId, ex.Text); } } catch (Exception e) { } } catch (Exception ext) { log.Error(ext.Message, ext); } }
private void WebsocketserverMain_OnConnected(object sender, WebsocketserverConnectedEventArgs e) { log.Info("Client Connected. ConnectionID: " + e.ConnectionId); WebsocketserverMain.SendText(e.ConnectionId, "hell you are connected."); }