private bool handleReply(String strReply) { JMessage reply = null; JEnterDataLineReply dataReply = null; try { reply = Newtonsoft.Json.JsonConvert.DeserializeObject <JMessage>(strReply); dataReply = Newtonsoft.Json.JsonConvert.DeserializeObject <JEnterDataLineReply>(reply.InnerMessage); } catch (Exception ex) { DataClient.logEntry(System.Diagnostics.EventLogEntryType.Error, "ProductionFile.handleReply failed: " + ex.Message); throw new DataException.DataFormatException(); } if (dataReply != null) { DataClient.logEntry(System.Diagnostics.EventLogEntryType.Information, "ProductionFile.handleReply: DataReply with error " + dataReply.ErrorCode + " " + dataReply.ErrorText); if (!dataReply.Success) { Console.WriteLine("DataReply with error " + dataReply.ErrorCode + " " + dataReply.ErrorText); handleDataReplyError(dataReply.ErrorCode); } } return(true); }
public JEnterDataLineReply handleProductionDataLine(JMessage request) { SqlConnection conn = new SqlConnection(connStringBuilder.ConnectionString); JEnterProductionDataLineRequest prodLine = JsonConvert.DeserializeObject <JEnterProductionDataLineRequest>(request.InnerMessage); JEnterDataLineReply reply = new JEnterDataLineReply(); reply.ErrorCode = 0; reply.Success = true; reply.ErrorText = "OK"; try { for (int i = 0; i < prodLine.DataColumns.Count; i++) { JDataValue dataValue = prodLine.DataColumns[i]; if (!rowExists(request, prodLine, dataValue, conn)) { if (!insertRow(request, prodLine, dataValue, conn)) { reply.Success = false; reply.ErrorCode = 300; reply.ErrorText = "Could not insert line"; break; } } else { Receiver.LogEntry(System.Diagnostics.EventLogEntryType.Warning, "DataBaseDriver.handleProductionLine Entry already exists for value " + prodLine.SourceFile + " Line " + prodLine.LineNumber + " value " + dataValue.Value.ToString()); Console.WriteLine("Entry already exists for " + prodLine.SourceFile + " Line " + prodLine.LineNumber + " value " + dataValue.Value.ToString()); } } } catch (Exception ex) { Receiver.LogEntry(System.Diagnostics.EventLogEntryType.Error, "DataBaseDriver.handleProductionLine failed: " + ex.Message); reply.Success = false; reply.ErrorCode = 301; reply.ErrorText = "DB Error"; } finally { conn.Close(); } if (reply.Success) { Receiver.LogEntry(System.Diagnostics.EventLogEntryType.SuccessAudit, "DataBaseDriver.handleProductionLineRequest success for " + prodLine.SourceFile + " Line " + prodLine.LineNumber); Console.WriteLine("Success for " + prodLine.SourceFile + " Line " + prodLine.LineNumber); } return(reply); }
private String handleDataMessage(String message) { JMessage request = JsonConvert.DeserializeObject <JMessage>(message); JMessage replyMessage = new JMessage(); replyMessage.Sender = "DataManagerService"; // String to set to the InnerMessage String strInnerMessage = String.Empty; try { switch (request.Function) { case "JEnterProductionDataLineRequest": replyMessage.Function = "JEnterDataLineReply"; strInnerMessage = JsonConvert.SerializeObject(dbDriver.handleProductionDataLine(request)); break; case "JEnterPowerUsageDataLineRequest": replyMessage.Function = "JEnterDataLineReply"; strInnerMessage = JsonConvert.SerializeObject(dbDriver.handlePowerUsageLine(request)); break; case "JSetAliveRequest": replyMessage.Function = "JSetAliveResponse"; strInnerMessage = JsonConvert.SerializeObject(dbDriver.handleAliveMessage(request)); break; default: replyMessage.Function = "JEnterDataLineReply"; JEnterDataLineReply reply = new JEnterDataLineReply() { ErrorCode = 1, ErrorText = "Unvalid format", Success = false }; strInnerMessage = JsonConvert.SerializeObject(reply); break; } } catch (Exception ex) { replyMessage.Function = "JEnterDataLineReply"; JEnterDataLineReply reply = new JEnterDataLineReply() { ErrorCode = 1, ErrorText = "Unvalid format", Success = false }; strInnerMessage = JsonConvert.SerializeObject(reply); LogEntry(System.Diagnostics.EventLogEntryType.Error, "Receiver.handleDataMessage failed: " + ex.Message); } replyMessage.InnerMessage = strInnerMessage; return(JsonConvert.SerializeObject(replyMessage)); }