public string UploadMeasures(int IdMeasure, string JSON)
        {
            ScriviMessaggioInLog("*************  UploadMeasures Richiamato");
            bool IsTest = Properties.Settings.Default.IsTest;

            try
            {
                List <UploadMeasuresElementRequest> UploadMeasuresElements = JSonSerializer.Deserialize <List <UploadMeasuresElementRequest> >(JSON);

                CertixBLL bll = new CertixBLL();
                bll.RegistraMisure(IdMeasure, UploadMeasuresElements, Properties.Settings.Default.IsTest);
            }
            catch (ArgumentException ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("********** ERRORE IN UPLOADCODE");
                ScriviErroreGestitoInLog(ex, sb.ToString());
                return(CreaUploadMeasuresResponse(Status.ERRORE, ex.Message));
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("********** ERRORE IN UPLOADCODE");
                sb.AppendLine(string.Format(" IdMeasure: {0}  ", IdMeasure));
                sb.AppendLine(string.Format("JSON: {0}  ", JSON));
                ScriviEccezioneInLog(ex, sb.ToString());
                return(CreaUploadMeasuresResponse(Status.ERRORE, "Errore non recuperabile."));
            }
            return(CreaUploadMeasuresResponse(Status.OK, string.Empty));
        }
예제 #2
0
        private bool DecodeAndParseAggregatedStatusMessage(RSMP_Messages.Header packetHeader, string sJSon, bool bUseStrictProtocolAnalysis, bool bUseCaseSensitiveIds, ref bool bHasSentAckOrNack, ref string sError)
        {
            StringComparison sc = bUseCaseSensitiveIds ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            bool bSuccess = false;

            try
            {
                RSMP_Messages.AggregatedStatus AggregatedStatus = JSonSerializer.Deserialize <RSMP_Messages.AggregatedStatus>(sJSon);

                cRoadSideObject RoadSideObject = cHelper.FindRoadSideObject(AggregatedStatus.ntsOId, AggregatedStatus.cId, bUseCaseSensitiveIds);

                if (RoadSideObject != null)
                {
                    RoadSideObject.bBitStatus          = AggregatedStatus.se;
                    RoadSideObject.sFunctionalPosition = AggregatedStatus.fP;
                    RoadSideObject.sFunctionalState    = AggregatedStatus.fS;
                    cAggregatedStatusEvent AggregatedStatusEvent = new cAggregatedStatusEvent();
                    AggregatedStatusEvent.sTimeStamp          = UnpackISO8601UTCTimeStamp(AggregatedStatus.aSTS);
                    AggregatedStatusEvent.sMessageId          = AggregatedStatus.mId;
                    AggregatedStatusEvent.sFunctionalPosition = AggregatedStatus.fP;
                    AggregatedStatusEvent.sFunctionalState    = AggregatedStatus.fS;

                    for (int i = 1; i < AggregatedStatus.se.Length + 1; i++)
                    {
                        AggregatedStatusEvent.sBitStatus += "B" + i + ": " + AggregatedStatus.se[i - 1] + " | ";
                    }
                    AggregatedStatusEvent.sBitStatus.Trim();

                    if (RSMPGS_Main.bWriteEventsContinous)
                    {
                        RSMPGS.SysLog.EventLog("AggregatedStatus;{0}\tMId: {1}\tComponentId: {2}\tBitStatus: {3}\tFuncPos: {4}\tFunkState: {5}",
                                               AggregatedStatusEvent.sTimeStamp, AggregatedStatusEvent.sMessageId, AggregatedStatus.cId, AggregatedStatusEvent.sBitStatus,
                                               AggregatedStatusEvent.sFunctionalPosition, AggregatedStatusEvent.sFunctionalState);
                    }

                    RoadSideObject.AggregatedStatusEvents.Add(AggregatedStatusEvent);
                    RSMPGS.MainForm.HandleAggregatedStatusListUpdate(RoadSideObject, AggregatedStatusEvent);
                    bSuccess = true;
                }
                if (bSuccess == false)
                {
                    sError = "Failed to update AggregatedStatus, could not find object, ntsOId: '" + AggregatedStatus.ntsOId + "', cId: '" + AggregatedStatus.cId + "'";
                }
            }
            catch (Exception e)
            {
                sError   = "Failed to deserialize packet: " + e.Message;
                bSuccess = false;
            }

            return(bSuccess);
        }
예제 #3
0
        public ActionResult AggiornaMaster(int IdSPMaster, string Codice, string Descrizione, string Task, string AreaProduzione, string Lista)
        {
            Codice         = Codice.ToUpper();
            Descrizione    = Descrizione.ToUpper();
            Task           = Task.ToUpper();
            AreaProduzione = AreaProduzione.ToUpper();

            ElementoMaster[] elementiLista = JSonSerializer.Deserialize <ElementoMaster[]>(Lista);

            string messaggio = MPIntranet.Business.SchedeProcesso.SPMaster.SalvaMaster(IdSPMaster, Codice, Descrizione, AreaProduzione, Task, elementiLista, ConnectedUser.ToUpper());

            return(Content(messaggio));
        }
예제 #4
0
        public ActionResult AggiornaControllo(int IdSPControllo, string Codice, string Descrizione, string Tipo, string Lista)
        {
            Codice      = Codice.ToUpper();
            Descrizione = Descrizione.ToUpper();
            Tipo        = Tipo.ToUpper();


            ElementoLista[] elementiLista = JSonSerializer.Deserialize <ElementoLista[]>(Lista);

            string messaggio = SPControllo.SalvaControllo(IdSPControllo, Codice, Descrizione, Tipo, 0, 0, 0, elementiLista, ConnectedUser.ToUpper());

            return(Content(messaggio));
        }
        public string GetToken(string user, string password, string url)
        {
            string            method = @"topfinish-tmr-api/auth/login";
            string            StatusDescription;
            Uri               uri  = new Uri(url + method);
            AuthenticationDto adto = new AuthenticationDto();

            adto.password = password;
            adto.username = user;
            string   Json       = JSonSerializer.Serialize <AuthenticationDto>(adto);
            object   jsonObject = executeCall(uri, Json, out StatusDescription);
            string   result     = jsonObject as string;
            TokenDto o          = JSonSerializer.Deserialize <TokenDto>(jsonObject as string);

            return(o.value);
        }
예제 #6
0
        public ActionResult AggiornaSchedaProcesso(int IdSPScheda, int IdSPMaster, string Codice, string Descrizione, string Task, string AreaProduzione, string Anagrafica, string Controlli, string Obbligatori)
        {
            Codice         = Codice.ToUpper();
            Descrizione    = Descrizione.ToUpper();
            Task           = Task.ToUpper();
            AreaProduzione = AreaProduzione.ToUpper();
            Anagrafica     = Anagrafica.ToUpper();

            ElementoScheda[] elementiScheda            = JSonSerializer.Deserialize <ElementoScheda[]>(Controlli);
            ElementoScheda[] elementiObbligatoriScheda = JSonSerializer.Deserialize <ElementoScheda[]>(Obbligatori);
            //if (!Item.VerificaEsistenzaItem(Anagrafica))
            //    return Content("Scheda non salvata - Anagrafica non presente in Business Central");

            string messaggio = SpScheda.SalvaScheda(IdSPScheda, IdSPMaster, Anagrafica, Codice, Descrizione, AreaProduzione, Task, elementiScheda.ToList(), elementiObbligatoriScheda.ToList(), ConnectedUser.ToUpper());

            return(Content(messaggio));
        }
 public void SalvaConsuntivo(string Inizio, string Fine, int Barre, string Fermi, string UIDUSER)
 {
     FermiJsonModel[] fermiJson = JSonSerializer.Deserialize <FermiJsonModel[]>(Fermi);
     using (GalvanicaBusiness bGalvanica = new GalvanicaBusiness())
     {
         try
         {
             long idConsuntivo = bGalvanica.GetID();
             bGalvanica.SalvaConsuntivo(idConsuntivo, Inizio, Fine, Barre, UIDUSER);
             foreach (FermiJsonModel f in fermiJson)
             {
                 bGalvanica.SalvaFermo(idConsuntivo, f.Tipo, f.Ora, f.Durata, f.Motivo, UIDUSER);
             }
         }
         catch
         {
             bGalvanica.Rollback();
             throw;
         }
     }
 }
예제 #8
0
        private bool DecodeAndParseAggregatedStatusRequestMessage(RSMP_Messages.Header packetHeader, string sJSon, bool bUseStrictProtocolAnalysis, bool bUseCaseSensitiveIds, ref bool bHasSentAckOrNack, ref string sError)
        {
            bool bPacketWasProperlyHandled = false;

            StringComparison sc = bUseCaseSensitiveIds ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            try
            {
                RSMP_Messages.AggregatedStatusRequest AggregatedStatusRequest = JSonSerializer.Deserialize <RSMP_Messages.AggregatedStatusRequest>(sJSon);

                cRoadSideObject RoadSideObject = cHelper.FindRoadSideObject(AggregatedStatusRequest.ntsOId, AggregatedStatusRequest.cId, bUseStrictProtocolAnalysis);

                if (RoadSideObject != null)
                {
                    if (cHelper.IsSettingChecked("AllowRequestsOfAlarmsAndAggStatus"))
                    {
                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Request of aggregated status, ntsOId: {0}, cId: {1}", AggregatedStatusRequest.ntsOId, AggregatedStatusRequest.cId);
                        bHasSentAckOrNack = SendPacketAck(true, packetHeader.mId, "");
                        CreateAndSendAggregatedStatusMessage(RoadSideObject);
                    }
                    else
                    {
                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Warning, "Request of aggregated status, ntsOId: {0}, cId: {1}. RSMP settings prevent us from answering.", AggregatedStatusRequest.ntsOId, AggregatedStatusRequest.cId);
                        bHasSentAckOrNack = SendPacketAck(false, packetHeader.mId, "Invalid packet type: " + packetHeader.type);
                    }
                    bPacketWasProperlyHandled = true;
                }
                else
                {
                    sError = "Failed to handle AggregatedStatusRequest message, ntsOId: " + AggregatedStatusRequest.ntsOId + "/ cId: " + AggregatedStatusRequest.cId + " could not be found)";
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "{0}", sError);
                }
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to deserialize packet: {0}", e.Message);
            }

            return(bPacketWasProperlyHandled);
        }
예제 #9
0
        public void SalvaApprovvigionamenti(string approvigionamenti, string Modello)
        {
            ApprovvigionamentoMagazzino[] Approvvigionamenti = JSonSerializer.Deserialize <ApprovvigionamentoMagazzino[]>(approvigionamenti);

            using (MagazzinoBusiness bMagazzino = new MagazzinoBusiness())
            {
                MagazzinoDS ds = new MagazzinoDS();
                bMagazzino.FillMONITOR_APPROVVIGIONAMENTO(ds);

                foreach (string idMagazz in Approvvigionamenti.Where(x => !x.Checked).Select(x => x.IDMAGAZZ))
                {
                    MagazzinoDS.MONITOR_APPROVVIGIONAMENTORow approvvigionamentoDaCancellare = ds.MONITOR_APPROVVIGIONAMENTO.Where(x => x.RowState != System.Data.DataRowState.Deleted && x.IDMAGAZZ == idMagazz).FirstOrDefault();
                    if (approvvigionamentoDaCancellare != null)
                    {
                        approvvigionamentoDaCancellare.Delete();
                    }
                }

                foreach (ApprovvigionamentoMagazzino approv in Approvvigionamenti.Where(x => x.Checked))
                {
                    MagazzinoDS.MONITOR_APPROVVIGIONAMENTORow approvvigionamento = ds.MONITOR_APPROVVIGIONAMENTO.Where(x => x.RowState != System.Data.DataRowState.Deleted && x.IDMAGAZZ == approv.IDMAGAZZ).FirstOrDefault();
                    if (approvvigionamento == null)
                    {
                        approvvigionamento              = ds.MONITOR_APPROVVIGIONAMENTO.NewMONITOR_APPROVVIGIONAMENTORow();
                        approvvigionamento.IDMAGAZZ     = approv.IDMAGAZZ;
                        approvvigionamento.NOTA         = approv.Nota;
                        approvvigionamento.DATASCADENZA = DateTime.Parse(approv.DataScadenza);
                        ds.MONITOR_APPROVVIGIONAMENTO.AddMONITOR_APPROVVIGIONAMENTORow(approvvigionamento);
                    }
                    else
                    {
                        approvvigionamento.NOTA         = approv.Nota;
                        approvvigionamento.DATASCADENZA = DateTime.Parse(approv.DataScadenza);
                    }
                }

                bMagazzino.UpdateMONITOR_APPROVVIGIONAMENTO(ds);
            }
        }
예제 #10
0
        public string SalvaTrasferimento(string barcode, string odlJSON)
        {
            string[] odls = JSonSerializer.Deserialize <string[]>(odlJSON);
            if (barcode.Substring(0, 3) != "RSF")
            {
                return("NON RISORSA FISICA");
            }


            if (!VerificaEsistenzaTrasferimento(barcode))
            {
                return("ESISTE GIA' UN TRASFERIMENTO ATTIVO PER QUESTO OPERATORE");
            }
            else
            {
                foreach (string odl in odls)
                {
                    CaricaODL(odl, 1);
                }
                CreaTrasferimento(barcode);
                return("OK");
            }
        }
예제 #11
0
        public void SalvaGiacenze(string giacenze, string Modello)
        {
            GiacenzaMagazzino[] Giacenze = JSonSerializer.Deserialize <GiacenzaMagazzino[]>(giacenze);

            using (MagazzinoBusiness bMagazzino = new MagazzinoBusiness())
            {
                MagazzinoDS ds = new MagazzinoDS();
                bMagazzino.FillMONITOR_GIACENZA(ds);

                foreach (string idMagazz in Giacenze.Where(x => !x.Checked).Select(x => x.IDMAGAZZ))
                {
                    MagazzinoDS.MONITOR_GIACENZARow giacenzaDaCancellare = ds.MONITOR_GIACENZA.Where(x => x.RowState != System.Data.DataRowState.Deleted && x.IDMAGAZZ == idMagazz).FirstOrDefault();
                    if (giacenzaDaCancellare != null)
                    {
                        giacenzaDaCancellare.Delete();
                    }
                }

                foreach (GiacenzaMagazzino giac in Giacenze.Where(x => x.Checked))
                {
                    MagazzinoDS.MONITOR_GIACENZARow giacenza = ds.MONITOR_GIACENZA.Where(x => x.RowState != System.Data.DataRowState.Deleted && x.IDMAGAZZ == giac.IDMAGAZZ).FirstOrDefault();
                    if (giacenza == null)
                    {
                        giacenza          = ds.MONITOR_GIACENZA.NewMONITOR_GIACENZARow();
                        giacenza.IDMAGAZZ = giac.IDMAGAZZ;
                        giacenza.GIACENZA = giac.Giacenza;
                        ds.MONITOR_GIACENZA.AddMONITOR_GIACENZARow(giacenza);
                    }
                    else
                    {
                        giacenza.GIACENZA = giac.Giacenza;
                    }
                }

                bMagazzino.UpdateMONITOR_GIACENZA(ds);
            }
        }
예제 #12
0
        private bool DecodeAndParseStatusMessage(RSMP_Messages.Header packetHeader, StatusMsgType statusMsgType, string sJSon, bool bUseStrictProtocolAnalysis, bool bUseCaseSensitiveIds, ref bool bHasSentAckOrNack, ref string sError)
        {
            StringComparison sc = bUseCaseSensitiveIds ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            bool bSuccess = true;

            // Values to return
            List <RSMP_Messages.Status_VTQ> sS = new List <RSMP_Messages.Status_VTQ>();

            try
            {
                // StatusSubscribe, StatusUnsubscribe and StatusRequest are very much alike, differns by the uRt property only
                RSMP_Messages.StatusSubscribe_Over_3_1_4 StatusSubscribe = JSonSerializer.Deserialize <RSMP_Messages.StatusSubscribe_Over_3_1_4>(sJSon);

                foreach (RSMP_Messages.StatusSubscribe_Status_Over_3_1_4 StatusSubscribe_Status in StatusSubscribe.sS)
                {
                    if (StatusSubscribe_Status.sCI == null)
                    {
                        sError = "StatusCode Id (sCI) in " + packetHeader.type + " is missing";
                        return(false);
                    }
                }

                cRoadSideObject RoadSideObject = cHelper.FindRoadSideObject(StatusSubscribe.ntsOId, StatusSubscribe.cId, bUseCaseSensitiveIds);

                if (RoadSideObject != null)
                {
                    foreach (RSMP_Messages.StatusSubscribe_Status_Over_3_1_4 StatusSubscribe_Status in StatusSubscribe.sS)
                    {
                        RSMP_Messages.Status_VTQ s = new RSMP_Messages.Status_VTQ();
                        s.sCI = StatusSubscribe_Status.sCI;
                        s.n   = StatusSubscribe_Status.n;
                        s.s   = null;
                        // 3.1.1 = unknown
                        //s.q = "unknown";
                        // 3.1.2 = undefined ??
                        s.q = "undefined";
                        // Find status in object
                        cStatusObject      StatusObject      = RoadSideObject.StatusObjects.Find(x => x.sStatusCodeId.Equals(StatusSubscribe_Status.sCI, sc));
                        cStatusReturnValue StatusReturnValue = null;
                        if (StatusObject != null)
                        {
                            StatusReturnValue = StatusObject.StatusReturnValues.Find(x => x.sName.Equals(StatusSubscribe_Status.n, sc));
                        }
                        if (StatusReturnValue != null)
                        {
                            RSMPGS.ProcessImage.UpdateStatusValue(ref s, StatusReturnValue.Value.GetValueType(), StatusReturnValue.Value.GetValue());
                            switch (statusMsgType)
                            {
                            case StatusMsgType.Request:
                                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Got status request (NTSObjectId: {0}, ComponentId: {1}, StatusCodeId: {2}, Name: {3}, Status: {4})", StatusSubscribe.ntsOId, StatusSubscribe.cId, StatusObject.sStatusCodeId, StatusReturnValue.sName, StatusReturnValue.Value.GetValue());
                                break;

                            case StatusMsgType.UnSubscribe:
                            case StatusMsgType.Subscribe:
                                // Delete subscription if it already exists
                                foreach (cSubscription Subscription in RoadSideObject.Subscriptions)
                                {
                                    if (Subscription.StatusReturnValue == StatusReturnValue)
                                    {
                                        RoadSideObject.Subscriptions.Remove(Subscription);
                                        break;
                                    }
                                }
                                if (statusMsgType == StatusMsgType.Subscribe)
                                {
                                    string sUpdateRate = StatusSubscribe_Status.uRt;
                                    float  fUpdateRate = 0;
                                    float.TryParse(StatusSubscribe_Status.uRt, out fUpdateRate);
                                    if (fUpdateRate == 0)
                                    {
                                        float.TryParse(StatusSubscribe_Status.uRt.Replace('.', ','), out fUpdateRate);
                                    }
                                    bool bAlwaysSendOnChange = StatusSubscribe_Status.sOc;
                                    RoadSideObject.Subscriptions.Add(new cSubscription(StatusObject, StatusReturnValue, fUpdateRate, bAlwaysSendOnChange));
                                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Got status subscribe (NTSObjectId: {0}, ComponentId: {1}. StatusCodeId: {2}, Name: {3}, Status: {4})", StatusSubscribe.ntsOId, StatusSubscribe.cId, StatusObject.sStatusCodeId, StatusReturnValue.sName, StatusReturnValue.Value.GetValue());
                                }
                                else
                                {
                                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Got status unsubscribe, removed subscription (NTSObjectId: {0}, ComponentId: {1}. StatusCodeId: {2}, Name: {3}, Status: {4})", StatusSubscribe.ntsOId, StatusSubscribe.cId, StatusObject.sStatusCodeId, StatusReturnValue.sName, StatusReturnValue.Value.GetValue());
                                }
                                break;
                            }
                        }
                        if (s.s == null)
                        {
                            RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Got status request/subscribe, failed to update StatusCodeId or Object (could be unknown value) (NTSObjectId: {0}, ComponentId: {1}, StatusCodeId: {2}))", StatusSubscribe.ntsOId, StatusSubscribe.cId, StatusSubscribe_Status.sCI);
                        }

                        sS.Add(s);
                    }
                }
                else
                {
                    // Failed, fill return list with 'unknown'
                    foreach (RSMP_Messages.StatusSubscribe_Status_Over_3_1_4 StatusSubscribe_Status in StatusSubscribe.sS)
                    {
                        RSMP_Messages.Status_VTQ s = new RSMP_Messages.Status_VTQ();
                        s.sCI = StatusSubscribe_Status.sCI;
                        s.n   = StatusSubscribe_Status.n;
                        s.s   = null;
                        // 3.1.1 = unknown
                        //s.q = "unknown";
                        // 3.1.2 = undefined ??
                        s.q = "undefined";
                        sS.Add(s);
                    }
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Got status message, failed to find object (NTSObjectId: {0}, ComponentId: {1})", StatusSubscribe.ntsOId, StatusSubscribe.cId);
                }

                if (statusMsgType != StatusMsgType.UnSubscribe)
                {
                    // Response message
                    RSMP_Messages.StatusResponse StatusResponse = new RSMP_Messages.StatusResponse();
                    // Send response to client
                    StatusResponse.mType  = "rSMsg";
                    StatusResponse.type   = (statusMsgType == StatusMsgType.Subscribe) ? "StatusUpdate" : "StatusResponse";
                    StatusResponse.mId    = System.Guid.NewGuid().ToString();
                    StatusResponse.ntsOId = StatusSubscribe.ntsOId;
                    StatusResponse.xNId   = StatusSubscribe.xNId;
                    StatusResponse.cId    = StatusSubscribe.cId;
                    StatusResponse.sTs    = CreateISO8601UTCTimeStamp();
                    StatusResponse.sS     = sS;
                    string sSendBuffer = JSonSerializer.SerializeObject(StatusResponse);
                    if (bHasSentAckOrNack == false)
                    {
                        bHasSentAckOrNack = SendPacketAck(true, packetHeader.mId, "");
                    }
                    RSMPGS.JSon.SendJSonPacket(StatusResponse.type, StatusResponse.mId, sSendBuffer, true);
                    if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false)
                    {
                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent StatusResponse message, Type: " + StatusResponse.type + ", MsgId: " + StatusResponse.mId);
                    }
                }
            }
            catch (Exception e)
            {
                sError   = "Failed to deserialize packet: " + e.Message;
                bSuccess = false;
            }

            return(bSuccess);
        }
예제 #13
0
        private bool DecodeAndParseCommandMessage(RSMP_Messages.Header packetHeader, string sJSon, bool bUseStrictProtocolAnalysis, bool bUseCaseSensitiveIds, ref bool bHasSentAckOrNack, ref string sError)
        {
            StringComparison sc = bUseCaseSensitiveIds ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            bool bSuccess = false;

            // Values to return
            List <RSMP_Messages.CommandResponse_Value> rvs = new List <RSMP_Messages.CommandResponse_Value>();

            //Dictionary<cRoadSideObject, cRoadSideObject> UpdatedRoadSideObjects = new Dictionary<cRoadSideObject, cRoadSideObject>();

            try
            {
                RSMP_Messages.CommandRequest CommandRequest = JSonSerializer.Deserialize <RSMP_Messages.CommandRequest>(sJSon);

                // Response message
                RSMP_Messages.CommandResponse CommandResponse = new RSMP_Messages.CommandResponse();

                bool bSomeValueWasBad = false;

                // Scan through each value to set
                foreach (RSMP_Messages.CommandRequest_Value CommandRequest_Value in CommandRequest.arg)
                {
                    // Create return value for each value to be set
                    RSMP_Messages.CommandResponse_Value rv = new RSMP_Messages.CommandResponse_Value();
                    rv.v   = null;
                    rv.n   = CommandRequest_Value.n;
                    rv.age = "undefined";

                    bool bFoundCommand = false;

                    cRoadSideObject RoadSideObject = cHelper.FindRoadSideObject(CommandRequest.ntsOId, CommandRequest.cId, bUseStrictProtocolAnalysis);

                    if (RoadSideObject != null)
                    {
                        // Find command in object
                        foreach (cCommandObject CommandObject in RoadSideObject.CommandObjects)
                        {
                            bool bDone = false;
                            // Find command name in command
                            foreach (cCommandReturnValue CommandReturnValue in CommandObject.CommandReturnValues)
                            {
                                if (CommandReturnValue.sName.Equals(CommandRequest_Value.n, sc) &&
                                    CommandReturnValue.sCommand.Equals(CommandRequest_Value.cO, sc))
                                {
                                    // Do some validation
                                    if (ValidateTypeAndRange(CommandReturnValue.Value.GetValueType(), CommandRequest_Value.v))
                                    {
                                        if (CommandReturnValue.Value.GetValueType().Equals("base64", StringComparison.OrdinalIgnoreCase))
                                        {
                                            if (RSMPGS.MainForm.ToolStripMenuItem_StoreBase64Updates.Checked)
                                            {
                                                CommandReturnValue.Value.SetValue(RSMPGS.SysLog.StoreBase64DebugData(CommandRequest_Value.v));
                                            }
                                        }
                                        else
                                        {
                                            CommandReturnValue.Value.SetValue(CommandRequest_Value.v);
                                        }
                                        rv.v   = CommandRequest_Value.v;
                                        rv.cCI = CommandRequest_Value.cCI;
                                        rv.age = "recent";
                                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Got Command, updated NTSObjectId: {0}, ComponentId: {1}, CommandCodeId: {2}, Name: {3}, Command: {4}, Value: {5}", CommandRequest.ntsOId, CommandRequest.cId, CommandRequest_Value.cCI, CommandRequest_Value.n, CommandRequest_Value.cO, CommandRequest_Value.v);
                                        RSMPGS.MainForm.HandleCommandListUpdate(RoadSideObject, CommandObject, CommandReturnValue);
                                    }
                                    else
                                    {
                                        rv.v   = null;
                                        rv.cCI = CommandRequest_Value.cCI;
                                        rv.age = "unknown";
                                        sError = "Value and/or type is out of range or invalid for this RSMP protocol version, type: " + CommandReturnValue.Value.GetValueType() + ", value: " + ((CommandRequest_Value.v.Length < 10) ? CommandRequest_Value.v : CommandRequest_Value.v.Substring(0, 9) + "...");
                                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "{0}", sError);
                                        bSomeValueWasBad = true;
                                    }

                                    /*
                                     * // Found at least one value
                                     * if (UpdatedRoadSideObjects.ContainsKey(RoadSideObject) == false)
                                     * {
                                     * UpdatedRoadSideObjects.Add(RoadSideObject, RoadSideObject);
                                     * }
                                     */
                                    bDone         = true;
                                    bFoundCommand = true;
                                    break;
                                }
                            }
                            if (bDone)
                            {
                                break;
                            }
                        }
                    }
                    rvs.Add(rv);
                    if (bFoundCommand == false)
                    {
                        sError = "Got Command, failed to find object/command/name (NTSObjectId: " + CommandRequest.ntsOId + ", ComponentId: " + CommandRequest.cId + ", CommandCodeId: " + CommandRequest_Value.cCI + ", Name: " + CommandRequest_Value.n + ", Command: " + CommandRequest_Value.cO + ", Value: " + CommandRequest_Value.v + ")";
                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "{0}", sError);
                        bSomeValueWasBad = true;
                    }
                }

                //cRoadSideObject UpdatedRoadSideObject = null;

                /*
                 * foreach (cRoadSideObject UpdatedRoadSideObject in UpdatedRoadSideObjects.Values)
                 * {
                 * RSMPGS.MainForm.HandleCommandListUpdate(UpdatedRoadSideObject);
                 * }
                 */

                bSuccess = bSomeValueWasBad == false ? true : false;

                // Send response to client
                CommandResponse.mType  = "rSMsg";
                CommandResponse.type   = "CommandResponse";
                CommandResponse.mId    = System.Guid.NewGuid().ToString();
                CommandResponse.ntsOId = CommandRequest.ntsOId;
                CommandResponse.xNId   = CommandRequest.xNId;
                CommandResponse.cId    = CommandRequest.cId;
                //CommandResponse.cCI = CommandRequest.cCI;
                CommandResponse.cTS = CreateISO8601UTCTimeStamp();
                CommandResponse.rvs = rvs;

                if (bHasSentAckOrNack == false)
                {
                    bHasSentAckOrNack = SendPacketAck(bSuccess, packetHeader.mId, "");
                }

                string sSendBuffer = JSonSerializer.SerializeObject(CommandResponse);
                RSMPGS.JSon.SendJSonPacket(CommandResponse.type, CommandResponse.mId, sSendBuffer, true);

                if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false)
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent CommandResponse message, Type: " + CommandResponse.type + ", MsgId: " + CommandResponse.mId);
                }
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to deserialize packet: {0}", e.Message);
            }

            return(bSuccess);
        }
예제 #14
0
        private bool DecodeAndParseAlarmMessage(RSMP_Messages.Header packetHeader, string sJSon, bool bUseStrictProtocolAnalysis, bool bUseCaseSensitiveIds, ref bool bHasSentAckOrNack, ref string sError)
        {
            StringComparison sc = bUseCaseSensitiveIds ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            bool bPacketWasProperlyHandled = false;

            try
            {
                RSMP_Messages.AlarmHeader AlarmHeader = JSonSerializer.Deserialize <RSMP_Messages.AlarmHeader>(sJSon);

                cRoadSideObject RoadSideObject = cHelper.FindRoadSideObject(AlarmHeader.ntsOId, AlarmHeader.cId, bUseStrictProtocolAnalysis);

                if (RoadSideObject != null)
                {
                    foreach (cAlarmObject AlarmObject in RoadSideObject.AlarmObjects)
                    {
                        if (AlarmObject.sAlarmCodeId.Equals(AlarmHeader.aCId, sc))
                        {
                            cAlarmEvent AlarmEvent = new cAlarmEvent();
                            AlarmEvent.AlarmObject  = AlarmObject;
                            AlarmEvent.sDirection   = "Received";
                            AlarmEvent.sTimeStamp   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                            AlarmEvent.sMessageId   = AlarmHeader.mId;
                            AlarmEvent.sAlarmCodeId = AlarmHeader.aCId;
                            AlarmEvent.sEvent       = AlarmHeader.aSp;

                            AlarmSpecialisation alarmSpecialisation = cJSon.AlarmSpecialisation.Unknown;

                            switch (AlarmHeader.aSp.ToLower())
                            {
                            case "acknowledge":
                                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Ack of alarm, AlarmCodeId: {0}", AlarmHeader.aCId);
                                AlarmObject.bAcknowledged = true;
                                alarmSpecialisation       = cJSon.AlarmSpecialisation.Acknowledge;
                                break;

                            case "suspend":
                                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Suspend of alarm, AlarmCodeId: {0}", AlarmHeader.aCId);
                                AlarmObject.bSuspended = true;
                                alarmSpecialisation    = cJSon.AlarmSpecialisation.Suspend;
                                break;

                            case "resume":
                                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Resume of alarm, AlarmCodeId: {0}", AlarmHeader.aCId);
                                AlarmObject.bSuspended = false;
                                alarmSpecialisation    = cJSon.AlarmSpecialisation.Suspend;
                                break;

                            case "request":
                                if (cHelper.IsSettingChecked("AllowRequestsOfAlarmsAndAggStatus"))
                                {
                                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Request of alarm status, AlarmCodeId: {0}", AlarmHeader.aCId);
                                    alarmSpecialisation = cJSon.AlarmSpecialisation.Issue;
                                }
                                else
                                {
                                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Warning, "Request of alarm status, AlarmCodeId: {0}. RSMP settings prevent us from answering.", AlarmHeader.aCId);
                                }
                                break;
                            }

                            if (bHasSentAckOrNack == false)
                            {
                                if (alarmSpecialisation == AlarmSpecialisation.Unknown)
                                {
                                    bHasSentAckOrNack = SendPacketAck(false, packetHeader.mId, "Unknown Alarm Specialisation: " + AlarmHeader.aSp);
                                }
                                else
                                {
                                    bHasSentAckOrNack = SendPacketAck(true, packetHeader.mId, "");
                                }
                            }

                            bPacketWasProperlyHandled = true;

                            if (alarmSpecialisation != AlarmSpecialisation.Unknown)
                            {
                                if (AlarmObject.bActive == false && AlarmObject.bAcknowledged && alarmSpecialisation != AlarmSpecialisation.Unknown)
                                {
                                    AlarmObject.AlarmCount = 0;
                                }

                                if (AlarmHeader.aSp.ToLower() != "request")
                                {
                                    AlarmObject.dtLastChangedAlarmStatus = DateTime.Now;
                                }

                                CreateAndSendAlarmMessage(AlarmObject, alarmSpecialisation);

                                RSMPGS.MainForm.AddAlarmEventToAlarmObjectAndToList(AlarmObject, AlarmEvent);

                                RSMPGS.MainForm.UpdateAlarmListView(AlarmObject);
                            }
                        }
                    }
                }
                if (bPacketWasProperlyHandled == false)
                {
                    sError = "Failed to handle alarm message, AlarmCodeId " + AlarmHeader.aCId + " could not be found)";
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "{0}", sError);
                }
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to deserialize packet: {0}", e.Message);
            }

            return(bPacketWasProperlyHandled);
        }
예제 #15
0
        private bool DecodeAndParseStatusMessage(RSMP_Messages.Header packetHeader, string sJSon, bool bUseStrictProtocolAnalysis, bool bUseCaseSensitiveIds, ref bool bHasSentAckOrNack, ref string sError)
        {
            StringComparison sc = bUseCaseSensitiveIds ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            bool bSuccess = false;

            try
            {
                RSMP_Messages.StatusResponse StatusResponse = JSonSerializer.Deserialize <RSMP_Messages.StatusResponse>(sJSon);

                cRoadSideObject RoadSideObject = cHelper.FindRoadSideObject(StatusResponse.ntsOId, StatusResponse.cId, bUseCaseSensitiveIds);

                foreach (RSMP_Messages.Status_VTQ Reply in StatusResponse.sS)
                {
                    cStatusObject StatusObject = RoadSideObject.StatusObjects.Find(x => x.sStatusCodeId.Equals(Reply.sCI, sc));

                    if (StatusObject == null)
                    {
                        continue;
                    }

                    cStatusReturnValue StatusReturnValue = StatusObject.StatusReturnValues.Find(x => x.sName.Equals(Reply.n, sc));

                    if (StatusReturnValue == null)
                    {
                        continue;
                    }

                    if (StatusReturnValue.Value.GetValueType().Equals("base64", StringComparison.OrdinalIgnoreCase))
                    {
                        if (RSMPGS.MainForm.ToolStripMenuItem_StoreBase64Updates.Checked)
                        {
                            StatusReturnValue.Value.SetValue(RSMPGS.SysLog.StoreBase64DebugData(Reply.s));
                        }
                        else
                        {
                            StatusReturnValue.Value.SetValue("base64");
                        }
                    }
                    else
                    {
                        StatusReturnValue.Value.SetValue(Reply.s);
                    }
                    StatusReturnValue.sQuality = Reply.q;

                    if (ValidateTypeAndRange(StatusReturnValue.Value.GetValueType(), Reply.s))
                    {
                        bSuccess = true;
                    }
                    else
                    {
                        string sStatusValue;
                        if (Reply.s == null)
                        {
                            sStatusValue = "(null)";
                        }
                        else
                        {
                            sStatusValue = (Reply.s.Length < 10) ? Reply.s : Reply.s.Substring(0, 9) + "...";
                        }
                        sError = "Value and/or type is out of range or invalid for this RSMP protocol version, type: " + StatusReturnValue.Value.GetValueType() + ", quality: " + StatusReturnValue.sQuality + ", statusvalue: " + sStatusValue;
                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, sError);
                    }

                    cStatusEvent StatusEvent = new cStatusEvent();
                    StatusEvent.sTimeStamp       = UnpackISO8601UTCTimeStamp(StatusResponse.sTs);
                    StatusEvent.sMessageId       = StatusResponse.mId;
                    StatusEvent.sEvent           = "Received status";
                    StatusEvent.sStatusCommandId = Reply.sCI;
                    StatusEvent.sName            = Reply.n;
                    if (StatusReturnValue.Value.GetValueType().Equals("base64", StringComparison.OrdinalIgnoreCase))
                    {
                        StatusEvent.sStatus = "base64";
                    }
                    else
                    {
                        StatusEvent.sStatus = Reply.s;
                    }
                    StatusEvent.sQuality = Reply.q;
                    if (RSMPGS_Main.bWriteEventsContinous)
                    {
                        RSMPGS.SysLog.EventLog("Status;{0}\tMId: {1}\tComponentId: {2}\tStatusCommandId: {3}\tName: {4}\tStatus: {5}\tQuality: {6}\tUpdateRate: {7}\tUpdateOnChange: {8}\tEvent: {9}",
                                               StatusEvent.sTimeStamp, StatusEvent.sMessageId, StatusResponse.cId, StatusEvent.sStatusCommandId,
                                               StatusEvent.sName, StatusEvent.sStatus, StatusEvent.sQuality, StatusEvent.sUpdateRate, StatusEvent.bUpdateOnChange, StatusEvent.sEvent);
                    }
                    RoadSideObject.StatusEvents.Add(StatusEvent);
                    RSMPGS.MainForm.HandleStatusListUpdate(RoadSideObject, StatusEvent, false);
                }
            }
            catch (Exception e)
            {
                sError   = "Failed to deserialize packet: " + e.Message;
                bSuccess = false;
            }
            return(bSuccess);
        }
예제 #16
0
        private bool DecodeAndParseAlarmMessage(RSMP_Messages.Header packetHeader, string sJSon, bool bUseStrictProtocolAnalysis, bool bUseCaseSensitiveIds, ref bool bHasSentAckOrNack, ref string sError)
        {
            StringComparison sc = bUseCaseSensitiveIds ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            bool bPacketWasProperlyHandled = false;

            try
            {
                RSMP_Messages.AlarmHeaderAndBody AlarmHeader = JSonSerializer.Deserialize <RSMP_Messages.AlarmHeaderAndBody>(sJSon);

                if (AlarmHeader.cat != null && AlarmHeader.cat != "")
                {
                    cRoadSideObject RoadSideObject = cHelper.FindRoadSideObject(AlarmHeader.ntsOId, AlarmHeader.cId, bUseCaseSensitiveIds);
                    if (RoadSideObject != null)
                    {
                        foreach (cAlarmObject AlarmObject in RoadSideObject.AlarmObjects)
                        {
                            if (AlarmObject.sAlarmCodeId.Equals(AlarmHeader.aCId, sc))
                            {
                                cAlarmEvent AlarmEvent = new cAlarmEvent();
                                AlarmEvent.AlarmObject  = AlarmObject;
                                AlarmEvent.sDirection   = "Received";
                                AlarmEvent.sTimeStamp   = UnpackISO8601UTCTimeStamp(AlarmHeader.aTs);
                                AlarmEvent.sMessageId   = AlarmHeader.mId;
                                AlarmEvent.sAlarmCodeId = AlarmHeader.aCId;

                                //foreach (cAlarmReturnValue AlarmReturnValue in AlarmHeader.rvs)
                                if (AlarmHeader.rvs != null)
                                {
                                    foreach (RSMP_Messages.AlarmReturnValue AlarmReturnValue in AlarmHeader.rvs)
                                    {
                                        AlarmEvent.AlarmEventReturnValues.Add(new cAlarmEventReturnValue(AlarmReturnValue.n, AlarmReturnValue.v));
                                    }
                                }
                                switch (AlarmHeader.aSp.ToLower())
                                {
                                case "issue":
                                    AlarmEvent.sEvent = AlarmHeader.aSp + " / " + AlarmHeader.aS;
                                    if (AlarmHeader.aS.Equals("active", StringComparison.OrdinalIgnoreCase))
                                    {
                                        AlarmObject.AlarmCount++;
                                    }
                                    bPacketWasProperlyHandled = true;
                                    break;

                                case "acknowledge":
                                    AlarmEvent.sEvent         = AlarmHeader.aSp + " / " + AlarmHeader.ack;
                                    bPacketWasProperlyHandled = true;
                                    break;

                                case "suspend":
                                    AlarmEvent.sEvent         = AlarmHeader.aSp + " / " + AlarmHeader.sS;
                                    bPacketWasProperlyHandled = true;
                                    break;

                                default:
                                    AlarmEvent.sEvent = "(unknown: " + AlarmHeader.aSp + ")";
                                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Warning, "Could not parse correct alarm state {0} (corresponding MsgId {1}) ", AlarmHeader.aSp, AlarmHeader.mId);
                                    break;
                                }

                                if (bPacketWasProperlyHandled)
                                {
                                    AlarmObject.bActive = AlarmHeader.aS.Equals("active", StringComparison.OrdinalIgnoreCase)
                      ? true : false;
                                    AlarmObject.bAcknowledged = AlarmHeader.ack.Equals("acknowledged", StringComparison.OrdinalIgnoreCase)
                      ? true : false;
                                    AlarmObject.bSuspended = AlarmHeader.sS.Equals("suspended", StringComparison.OrdinalIgnoreCase)
                      ? true : false;
                                    if (AlarmObject.bActive == false && AlarmObject.bAcknowledged)
                                    {
                                        AlarmObject.AlarmCount = 0;
                                    }
                                }
                                RSMPGS.MainForm.AddAlarmEventToAlarmObjectAndToList(AlarmObject, AlarmEvent);
                                RSMPGS.MainForm.UpdateAlarmListView(AlarmObject);
                                break;
                            }
                        }
                    }
                    if (bPacketWasProperlyHandled == false)
                    {
                        sError = "Failed to handle Alarm message, could not find object, ntsOId: '" + AlarmHeader.ntsOId + "', cId: '" + AlarmHeader.cId + "', aCId: '" + AlarmHeader.aCId + "'";
                    }
                }
                else
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Got alarm message from SCADA, aSp: {0} (corresponding MsgId {1}) ", AlarmHeader.aSp, AlarmHeader.mId);
                }
            }
            catch (Exception e)
            {
                sError = "Failed to deserialize packet: " + e.Message;
                bPacketWasProperlyHandled = false;
            }

            return(bPacketWasProperlyHandled);
        }
예제 #17
0
        public string SalvaProcesso(decimal idArticolo, decimal idImpianto, decimal idProcesso, decimal idTelaio, string descrizione, string vascheJSON, string utente)
        {
            string messaggio = string.Empty;
            bool   esito     = true;

            SalvaProcessoJson[] vasche = JSonSerializer.Deserialize <SalvaProcessoJson[]>(vascheJSON);
            foreach (SalvaProcessoJson vasca in vasche)
            {
                decimal aux;
                if (string.IsNullOrEmpty(vasca.Durata))
                {
                    esito = false;
                }
            }

            if (!esito)
            {
                messaggio = "Valorizzare la durata delle vasche";
                return(messaggio);
            }

            ArticoloDS.PROCESSIRow processo;

            using (ArticoloBusiness bArticolo = new ArticoloBusiness())
            {
                bArticolo.FillProcessi(_ds, idArticolo, true);
                bArticolo.FillFasiProcesso(_ds, idArticolo, true);

                processo = _ds.PROCESSI.Where(x => x.IDPROCESSO == idProcesso).FirstOrDefault();
                if (processo != null)
                {
                    processo.DESCRIZIONE = descrizione;

                    processo.IDTELAIO = idTelaio;
                    if (idTelaio == ElementiVuoti.TelaioVuoto)
                    {
                        processo.SetIDTELAIONull();
                    }

                    List <ArticoloDS.FASIPROCESSORow> fasi = _ds.FASIPROCESSO.Where(x => x.IDPROCESSO == idProcesso).ToList();
                    List <decimal> idFaseProcesso          = vasche.Select(x => x.IdFaseProcesso).ToList();

                    foreach (ArticoloDS.FASIPROCESSORow faseDaCancellare in fasi.Where(x => !idFaseProcesso.Contains(x.IDFASEPROCESSO)))
                    {
                        faseDaCancellare.CANCELLATO     = SiNo.Si;
                        faseDaCancellare.DATAMODIFICA   = DateTime.Now;
                        faseDaCancellare.UTENTEMODIFICA = utente;
                    }

                    for (int i = 0; i < vasche.Length; i++)
                    {
                        SalvaProcessoJson vasca            = vasche[i];
                        decimal           corrente         = decimal.Parse(vasca.Corrente.Replace(".", ","));
                        decimal           spessoreMinimo   = decimal.Parse(vasca.SpessoreMinimo.Replace(".", ","));
                        decimal           spessoreMassimo  = decimal.Parse(vasca.SpessoreMassimo.Replace(".", ","));
                        decimal           spessoreNominale = decimal.Parse(vasca.SpessoreNominale.Replace(".", ","));

                        ArticoloDS.FASIPROCESSORow fase = fasi.Where(x => x.IDFASEPROCESSO == vasca.IdFaseProcesso).FirstOrDefault();
                        if (fase == null)
                        {
                            fase                  = _ds.FASIPROCESSO.NewFASIPROCESSORow();
                            fase.CANCELLATO       = SiNo.No;
                            fase.CORRENTE         = corrente;
                            fase.SPESSOREMASSIMO  = spessoreMassimo;
                            fase.SPESSORENOMINALE = spessoreNominale;
                            fase.SPESSOREMINIMO   = spessoreMinimo;
                            fase.DURATA           = vasca.Durata;
                            fase.DATAMODIFICA     = DateTime.Now;
                            fase.IDPROCESSO       = idProcesso;
                            fase.IDVASCA          = vasca.IdVasca;
                            fase.SEQUENZA         = i;
                            fase.UTENTEMODIFICA   = utente;
                            _ds.FASIPROCESSO.AddFASIPROCESSORow(fase);
                        }
                        else
                        {
                            fase.CORRENTE         = corrente;
                            fase.DURATA           = vasca.Durata;
                            fase.SPESSOREMASSIMO  = spessoreMassimo;
                            fase.SPESSORENOMINALE = spessoreNominale;
                            fase.SPESSOREMINIMO   = spessoreMinimo;
                            fase.DATAMODIFICA     = DateTime.Now;
                            fase.SEQUENZA         = i;
                            fase.UTENTEMODIFICA   = utente;
                        }
                    }

                    bArticolo.UpdateTable(_ds.FASIPROCESSO.TableName, _ds);
                    bArticolo.UpdateTable(_ds.PROCESSI.TableName, _ds);
                    messaggio = "Salvataggio riuscito";
                }
            }

            return(messaggio);
        }
예제 #18
0
        private bool DecodeAndParseCommandMessage(RSMP_Messages.Header packetHeader, string sJSon, bool bUseStrictProtocolAnalysis, bool bUseCaseSensitiveIds, ref bool bHasSentAckOrNack, ref string sError)
        {
            StringComparison sc = bUseCaseSensitiveIds ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            bool bSuccess = false;

            try
            {
                RSMP_Messages.CommandResponse CommandResponse = JSonSerializer.Deserialize <RSMP_Messages.CommandResponse>(sJSon);

                if (CommandResponse.type.Equals("commandresponse", StringComparison.OrdinalIgnoreCase))
                {
                    cRoadSideObject RoadSideObject = cHelper.FindRoadSideObject(CommandResponse.ntsOId, CommandResponse.cId, bUseCaseSensitiveIds);

                    if (RoadSideObject != null)
                    {
                        foreach (RSMP_Messages.CommandResponse_Value Reply in CommandResponse.rvs)
                        {
                            foreach (cCommandObject CommandObject in RoadSideObject.CommandObjects)
                            {
                                bool bDone = false;
                                foreach (cCommandReturnValue CommandReturnValue in CommandObject.CommandReturnValues)
                                {
                                    if (CommandReturnValue.sName.Equals(Reply.n, sc) &&
                                        CommandObject.sCommandCodeId.Equals(Reply.cCI, sc))
                                    {
                                        cCommandEvent CommandEvent = new cCommandEvent();
                                        CommandEvent.sTimeStamp     = UnpackISO8601UTCTimeStamp(CommandResponse.cTS);
                                        CommandEvent.sMessageId     = CommandResponse.mId;
                                        CommandEvent.sEvent         = "Received command";
                                        CommandEvent.sCommandCodeId = Reply.cCI;
                                        CommandEvent.sName          = Reply.n;

                                        if (CommandReturnValue.Value.GetValueType().Equals("base64", StringComparison.OrdinalIgnoreCase))
                                        {
                                            if (RSMPGS.MainForm.ToolStripMenuItem_StoreBase64Updates.Checked)
                                            {
                                                RSMPGS.SysLog.StoreBase64DebugData(Reply.v);
                                            }
                                            CommandEvent.sValue = "base64";
                                        }
                                        else
                                        {
                                            CommandEvent.sValue = Reply.v;
                                        }

                                        CommandEvent.sAge = Reply.age;

                                        CommandReturnValue.sLastRecValue = Reply.v;
                                        CommandReturnValue.sLastRecAge   = Reply.age;

                                        if (ValidateTypeAndRange(CommandReturnValue.Value.GetValueType(), Reply.v))
                                        {
                                            bSuccess = true;
                                        }
                                        else
                                        {
                                            sError = "Value and/or type is out of range or invalid for this RSMP protocol version, type: " + CommandReturnValue.Value.GetValueType() + ", value: " + ((Reply.v.Length < 10) ? Reply.v : Reply.v.Substring(0, 9) + "...");
                                            RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, sError);
                                        }

                                        if (RSMPGS_Main.bWriteEventsContinous)
                                        {
                                            RSMPGS.SysLog.EventLog("Command;{0}\tMId: {1}\tComponentId: {2}\tCommandCodeId: {3}\tName: {4}\tCommand: {5}\tValue: {6}\t Age: {7}\tEvent: {8}",
                                                                   CommandEvent.sTimeStamp, CommandEvent.sMessageId, CommandResponse.cId, CommandEvent.sCommandCodeId,
                                                                   CommandEvent.sName, CommandEvent.sCommand, CommandEvent.sValue, CommandEvent.sAge, CommandEvent.sEvent);
                                        }

                                        RoadSideObject.CommandEvents.Add(CommandEvent);
                                        RSMPGS.MainForm.HandleCommandListUpdate(RoadSideObject, CommandResponse.ntsOId, CommandResponse.cId, CommandEvent, false, bUseCaseSensitiveIds);
                                        bDone = true;
                                        break;
                                    }
                                }
                                if (bDone)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Got commandrequest message from SCADA, (corresponding MsgId {0}) ", CommandResponse.mId);
                }
            }
            catch (Exception e)
            {
                sError   = "Failed to deserialize packet: " + e.Message;
                bSuccess = false;
            }

            return(bSuccess);
        }