Beispiel #1
0
        private void btnAcquisisceMisure_Click(object sender, EventArgs e)
        {
            List <UploadMeasuresElementRequest> measures = new List <UploadMeasuresElementRequest>();
            UploadMeasuresElementRequest        e1       = new UploadMeasuresElementRequest();

            e1.Material = txtMaterial1.Text;
            e1.Measure  = nMeasure1.Value;
            if (!String.IsNullOrEmpty(txtMaterial1.Text))
            {
                measures.Add(e1);
            }

            UploadMeasuresElementRequest e2 = new UploadMeasuresElementRequest();

            e2.Material = txtMaterial2.Text;
            e2.Measure  = nMeasure2.Value;
            if (!String.IsNullOrEmpty(txtMaterial2.Text))
            {
                measures.Add(e2);
            }

            UploadMeasuresElementRequest e3 = new UploadMeasuresElementRequest();

            e3.Material = txtMaterial3.Text;
            e3.Measure  = nMeasure3.Value;
            if (!String.IsNullOrEmpty(txtMaterial3.Text))
            {
                measures.Add(e3);
            }

            string json = JSonSerializer.Serialize <List <UploadMeasuresElementRequest> >(measures);

            CertixWS.CertixServicesSoapClient client = new CertixWS.CertixServicesSoapClient();
            txtMessaggio.Text = client.UploadMeasures((int)nIdMeasure.Value, json);
        }
        public void CreateAndSendAggregatedStatusRequestMessage(cRoadSideObject RoadSideObject)
        {
            RSMP_Messages.AggregatedStatusRequest AggregatedStatusRequest;

            string sSendBuffer;

            try
            {
                AggregatedStatusRequest = new RSMP_Messages.AggregatedStatusRequest();

                AggregatedStatusRequest.mType = "rSMsg";
                AggregatedStatusRequest.type  = "AggregatedStatusRequest";
                AggregatedStatusRequest.mId   = System.Guid.NewGuid().ToString();

                AggregatedStatusRequest.ntsOId = RoadSideObject.sNTSObjectId;
                AggregatedStatusRequest.xNId   = RoadSideObject.sExternalNTSId;
                AggregatedStatusRequest.cId    = RoadSideObject.sComponentId;

                sSendBuffer = JSonSerializer.SerializeObject(AggregatedStatusRequest);

                RSMPGS.JSon.SendJSonPacket(AggregatedStatusRequest.type, AggregatedStatusRequest.mId, sSendBuffer, true);

                if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false)
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent AggregatedStatusRequest message, ntsOId: " + RoadSideObject.sNTSObjectId + ", cId: " + RoadSideObject.sComponentId + ", MsgId: " + AggregatedStatusRequest.mId);
                }
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to create AggregatedStatusRequest message: {0}", e.Message);
            }
        }
        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));
        }
        private string CreaUploadMeasuresResponse(string Status, string messaggioErrore)
        {
            UploadMeasuresResponse response = new UploadMeasuresResponse();

            response.Status = Status;
            response.Error  = messaggioErrore;

            return(JSonSerializer.Serialize <UploadMeasuresResponse>(response));
        }
Beispiel #5
0
        public RSMP_Messages.AggregatedStatus CreateAndSendAggregatedStatusMessage(cRoadSideObject RoadSideObject, bool bCreateMessageOnly, out string sSendBuffer)
        {
            sSendBuffer = "";

            RSMP_Messages.AggregatedStatus AggregatedStatusMessage = new RSMP_Messages.AggregatedStatus();

            AggregatedStatusMessage.mType  = "rSMsg";
            AggregatedStatusMessage.type   = "AggregatedStatus";
            AggregatedStatusMessage.mId    = System.Guid.NewGuid().ToString();
            AggregatedStatusMessage.ntsOId = RoadSideObject.sNTSObjectId;
            AggregatedStatusMessage.xNId   = RoadSideObject.sExternalNTSId;
            AggregatedStatusMessage.cId    = RoadSideObject.sComponentId;

            if (RoadSideObject.dtLastChangedAggregatedStatus == DateTime.MinValue)
            {
                RoadSideObject.dtLastChangedAggregatedStatus = DateTime.Now;
            }

            AggregatedStatusMessage.aSTS = CreateISO8601UTCTimeStamp(RoadSideObject.dtLastChangedAggregatedStatus);

            AggregatedStatusMessage.fP = RoadSideObject.sFunctionalPosition.Length > 0 ? RoadSideObject.sFunctionalPosition : null;
            AggregatedStatusMessage.fS = RoadSideObject.sFunctionalState.Length > 0 ? RoadSideObject.sFunctionalState : null;

            AggregatedStatusMessage.se = (bool[])RoadSideObject.bBitStatus.Clone();

            for (int iIndex = 0; iIndex < RoadSideObject.bBitStatus.GetLength(0); iIndex++)
            {
                AggregatedStatusMessage.se[iIndex] = RoadSideObject.bBitStatus[iIndex];
            }

            sSendBuffer = JSonSerializer.SerializeObject(AggregatedStatusMessage);

            if (bCreateMessageOnly)
            {
                return(AggregatedStatusMessage);
            }

            if (RSMPGS.JSon.SendJSonPacket(AggregatedStatusMessage.type, AggregatedStatusMessage.mId, sSendBuffer, true))
            {
                if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false)
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent aggregated status message, ntsOId: " + AggregatedStatusMessage.ntsOId + ", Type: " + AggregatedStatusMessage.type + ", MsgId: " + AggregatedStatusMessage.mId);
                }
            }
            else
            {
                if (cHelper.IsSettingChecked("BufferAndSendAggregatedStatusWhenConnect"))
                {
                    cBufferedMessage BufferedMessage = new cBufferedMessage(cBufferedMessage.eMessageType.AggregatedStatus, AggregatedStatusMessage.type, AggregatedStatusMessage.mId, sSendBuffer);
                    RSMPGS.MainForm.AddBufferedMessageToListAndListView(BufferedMessage);
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Warning, "Buffered aggregated status message, ntsOId: " + AggregatedStatusMessage.ntsOId + ", Type: " + AggregatedStatusMessage.type + ", MsgId: " + AggregatedStatusMessage.mId);
                }
            }

            return(AggregatedStatusMessage);
        }
        public async Task SerializeElementAsJson()
        {
            var store = await StoreBuilder.New().CreateAsync();

            await store.Schemas.New <LibraryDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            Library lib;

            using (var session = store.BeginSession())
            {
                lib      = new Library(domain);
                lib.Name = "Lib1";
                for (int i = 0; i < 3; i++)
                {
                    var b = new Book(domain);
                    b.Title  = "Book \"book\" " + i.ToString();
                    b.Copies = i + 1;
                    lib.Books.Add(b);

                    var m = new Member(domain);
                    m.Name = "Book " + i.ToString();
                    lib.Members.Add(m);
                }
                session.AcceptChanges();
            }

            var txt = JSonSerializer.Serialize(lib, JSonSerializationOption.Hyperstore);

            Assert.True(!String.IsNullOrEmpty(txt));

            var json = JSonSerializer.Serialize(lib, JSonSerializationOption.Json);

            Assert.True(!String.IsNullOrEmpty(json));

            var newton = Newtonsoft.Json.JsonConvert.SerializeObject(lib, new Newtonsoft.Json.JsonSerializerSettings {
                PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects
            });

            store.DomainModels.Unload(domain);
            domain = await store.DomainModels.New().CreateAsync("Test");

            using (var session = store.BeginSession(new SessionConfiguration {
                DefaultDomainModel = domain, Mode = SessionMode.Loading
            }))
            {
                Newtonsoft.Json.JsonConvert.DeserializeObject <Library>(json);
                session.AcceptChanges();
            }
            lib = domain.GetEntities <Library>().FirstOrDefault();
            Assert.NotNull(lib);
            Assert.Equal(3, lib.Books.Count());
        }
        private string CreaUploadCodeResponsePerErrore(string messaggioErrore)
        {
            UploadCodeResponse response = new UploadCodeResponse();

            response.Status    = Status.ERRORE;
            response.Error     = messaggioErrore;
            response.IdMeasure = -1;
            response.Materials = new List <string>();

            return(JSonSerializer.Serialize <UploadCodeResponse>(response));
        }
        public void CreateAndSendAlarmMessage(cAlarmObject AlarmObject, AlarmSpecialisation alarmSpecialisation)
        {
            RSMP_Messages.AlarmHeader AlarmHeader;
            cAlarmEvent AlarmEvent = null;
            string      sSendBuffer;

            try
            {
                AlarmHeader = new RSMP_Messages.AlarmHeader();

                AlarmHeader.mType = "rSMsg";
                AlarmHeader.type  = "Alarm";
                AlarmHeader.mId   = System.Guid.NewGuid().ToString();

                AlarmHeader.ntsOId = AlarmObject.RoadSideObject.sNTSObjectId;
                AlarmHeader.xNId   = AlarmObject.RoadSideObject.sExternalNTSId;
                AlarmHeader.cId    = AlarmObject.RoadSideObject.sComponentId;
                AlarmHeader.aCId   = AlarmObject.sAlarmCodeId;
                AlarmHeader.xACId  = AlarmObject.sExternalAlarmCodeId;
                AlarmHeader.xNACId = AlarmObject.sExternalNTSAlarmCodeId;

                AlarmHeader.aSp = alarmSpecialisation.ToString();

                sSendBuffer = JSonSerializer.SerializeObject(AlarmHeader);

                AlarmEvent              = new cAlarmEvent();
                AlarmEvent.AlarmObject  = AlarmObject;
                AlarmEvent.sDirection   = "Sent";
                AlarmEvent.sTimeStamp   = CreateLocalTimeStamp();
                AlarmEvent.sMessageId   = AlarmHeader.mId;
                AlarmEvent.sAlarmCodeId = AlarmHeader.aCId;
                AlarmEvent.sEvent       = AlarmHeader.aSp;

                RSMPGS.MainForm.AddAlarmEventToAlarmObjectAndToList(AlarmObject, AlarmEvent);
                RSMPGS.MainForm.UpdateAlarmListView(AlarmObject);

                /*
                 * if (RSMPGS_Main.bWriteEventsContinous)
                 * {
                 * RSMPGS.SysLog.EventLog("Alarm;{0}\tMId: {1}\tComponentId: {2}\tAlarmCodeId: {3}\tEvent: {4}",
                 *    AlarmEvent.sTimeStamp, AlarmEvent.sMessageId, AlarmHeader.cId, AlarmEvent.sAlarmCodeId, AlarmEvent.sEvent);
                 * }
                 */
                RSMPGS.JSon.SendJSonPacket(AlarmHeader.type, AlarmHeader.mId, sSendBuffer, true);
                if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false)
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent alarm message, AlarmCode: " + AlarmObject.sAlarmCodeId + ", Type: " + AlarmHeader.type + "/" + AlarmHeader.aSp + ", MsgId: " + AlarmHeader.mId);
                }
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to create alarm message: {0}", e.Message);
            }
        }
        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);
        }
Beispiel #10
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));
        }
Beispiel #11
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 void CreateAndSendSubscriptionMessage_upto_3_1_4(cRoadSideObject RoadSideObject, List <RSMP_Messages.StatusSubscribe_Status_Over_3_1_4> StatusSubscribeValues)
        {
            RSMP_Messages.StatusSubscribe_UpTo_3_1_4 StatusSubscribe;

            string sSendBuffer;

            try
            {
                StatusSubscribe = new RSMP_Messages.StatusSubscribe_UpTo_3_1_4();

                StatusSubscribe.mType = "rSMsg";
                StatusSubscribe.type  = "StatusSubscribe";
                StatusSubscribe.mId   = System.Guid.NewGuid().ToString();

                StatusSubscribe.ntsOId = RoadSideObject.sNTSObjectId;
                StatusSubscribe.xNId   = RoadSideObject.sExternalNTSId;
                StatusSubscribe.cId    = RoadSideObject.sComponentId;
                StatusSubscribe.sS     = new List <RSMP_Messages.StatusSubscribe_Status_UpTo_3_1_4>();

                foreach (RSMP_Messages.StatusSubscribe_Status_Over_3_1_4 StatusSubscriptionValue in StatusSubscribeValues)
                {
                    RSMP_Messages.StatusSubscribe_Status_UpTo_3_1_4 StatusSubscribeValue = new RSMP_Messages.StatusSubscribe_Status_UpTo_3_1_4();

                    StatusSubscribeValue.n   = StatusSubscriptionValue.n;
                    StatusSubscribeValue.sCI = StatusSubscriptionValue.sCI;
                    StatusSubscribeValue.uRt = StatusSubscriptionValue.uRt;

                    StatusSubscribe.sS.Add(StatusSubscribeValue);

                    AddSubscriptionMessageEvent(RoadSideObject, StatusSubscribe.mId, StatusSubscribe.cId, StatusSubscriptionValue);
                }

                sSendBuffer = JSonSerializer.SerializeObject(StatusSubscribe);
                if (RSMPGS.JSon.SendJSonPacket(StatusSubscribe.type, StatusSubscribe.mId, sSendBuffer, true))
                {
                    if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false)
                    {
                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent subscription message, ComponentId: " + StatusSubscribe.cId + " , MsgId: " + StatusSubscribe.mId);
                    }
                }
                else
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to send subscription message, ComponentId: " + StatusSubscribe.cId + " , MsgId: " + StatusSubscribe.mId);
                }
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to create subscription message: {0}", e.Message);
            }
        }
        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);
        }
Beispiel #14
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 string AssociazioneTelaio(string odl, string prodotto, string telaio, int qta, int stato, string url, string token)
        {
            string method = @"topfinish-tmr-api/custom/productionLot/createProductionLot";
            string StatusDescription;
            Uri    uri = new Uri(url + method);
            AssociazioneTelaioDto adto = new AssociazioneTelaioDto();

            adto.odl      = odl;
            adto.prodotto = prodotto;
            adto.telaio   = telaio;
            adto.qty      = qta;
            adto.stato    = stato;
            string Json       = JSonSerializer.Serialize <AssociazioneTelaioDto>(adto);
            object jsonObject = executeCall(uri, Json, token, out StatusDescription);
            string result     = jsonObject as string;

            return(result);
        }
Beispiel #16
0
        public RSMP_Messages.StatusUpdate CreateAndSendStatusUpdateMessage(cRoadSideObject RoadSideObject, List <RSMP_Messages.Status_VTQ> sS, bool bCreateMessageOnly, out string sSendBuffer)
        {
            sSendBuffer = "";

            RSMP_Messages.StatusUpdate StatusUpdateMessage = new RSMP_Messages.StatusUpdate();

            StatusUpdateMessage.mType = "rSMsg";
            StatusUpdateMessage.type  = "StatusUpdate";
            StatusUpdateMessage.mId   = System.Guid.NewGuid().ToString();

            StatusUpdateMessage.ntsOId = RoadSideObject.sNTSObjectId;
            StatusUpdateMessage.xNId   = RoadSideObject.sExternalNTSId;
            StatusUpdateMessage.cId    = RoadSideObject.sComponentId;

            StatusUpdateMessage.sTs = CreateISO8601UTCTimeStamp();

            StatusUpdateMessage.sS = sS;

            sSendBuffer = JSonSerializer.SerializeObject(StatusUpdateMessage);

            if (bCreateMessageOnly)
            {
                return(StatusUpdateMessage);
            }

            if (RSMPGS.JSon.SendJSonPacket(StatusUpdateMessage.type, StatusUpdateMessage.mId, sSendBuffer, true))
            {
                if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false)
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent Status Update message, Type: " + StatusUpdateMessage.type + ", MsgId: " + StatusUpdateMessage.mId);
                }
            }
            else
            {
                if (cHelper.IsSettingChecked("BufferAndSendStatusUpdatesWhenConnect"))
                {
                    cBufferedMessage BufferedMessage = new cBufferedMessage(cBufferedMessage.eMessageType.Status, StatusUpdateMessage.type, StatusUpdateMessage.mId, sSendBuffer);
                    RSMPGS.MainForm.AddBufferedMessageToListAndListView(BufferedMessage);
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Warning, "Buffered Status Update message, Type: " + StatusUpdateMessage.type + ", MsgId: " + StatusUpdateMessage.mId);
                }
            }

            return(StatusUpdateMessage);
        }
 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;
         }
     }
 }
Beispiel #18
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);
        }
Beispiel #19
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);
            }
        }
Beispiel #20
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");
            }
        }
Beispiel #21
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);
            }
        }
        public string UploadCode(int IdLine, string Code)
        {
            ScriviMessaggioInLog("*************  UploadCode Richiamato");

            try
            {
                CertixBLL bll = new CertixBLL();

                List <string> Measures;
                int           IdMeasure = bll.CreateIdMeasureFromCodeAndIdLine(IdLine, Code, Properties.Settings.Default.IsTest, out Measures);

                UploadCodeResponse response = new UploadCodeResponse();
                response.Status    = Status.OK;
                response.Error     = string.Empty;
                response.IdMeasure = IdMeasure;
                response.Materials = Measures;

                return(JSonSerializer.Serialize <UploadCodeResponse>(response));
            }
            catch (ArgumentException ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("********** ERRORE IN UPLOADCODE");
                ScriviErroreGestitoInLog(ex, sb.ToString());
                return(CreaUploadCodeResponsePerErrore(ex.Message));
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("********** ERRORE IN UPLOADCODE");
                sb.AppendLine(string.Format(" IdLine: {0}  ", IdLine));
                sb.AppendLine(string.Format("Code: {0}  ", Code));
                ScriviEccezioneInLog(ex, sb.ToString());
                return(CreaUploadCodeResponsePerErrore("Errore non recuperabile."));
            }
        }
Beispiel #23
0
        public RSMP_Messages.AlarmHeaderAndBody CreateAndSendAlarmMessage(cAlarmObject AlarmObject, AlarmSpecialisation alarmSpecialisation, bool bCreateMessageOnly, out string sSendBuffer, out cAlarmEvent AlarmEvent)
        {
            sSendBuffer = "";

            RSMP_Messages.AlarmHeaderAndBody AlarmHeaderAndBody;
            //      RSMP_Messages.AlarmHeader AlarmHeader;


            AlarmHeaderAndBody = new RSMP_Messages.AlarmHeaderAndBody();

            AlarmEvent = new cAlarmEvent();

            try
            {
                AlarmHeaderAndBody.mType  = "rSMsg";
                AlarmHeaderAndBody.type   = "Alarm";
                AlarmHeaderAndBody.mId    = System.Guid.NewGuid().ToString();
                AlarmHeaderAndBody.ntsOId = AlarmObject.RoadSideObject.sNTSObjectId;
                AlarmHeaderAndBody.xNId   = AlarmObject.RoadSideObject.sExternalNTSId;
                AlarmHeaderAndBody.cId    = AlarmObject.RoadSideObject.sComponentId;
                AlarmHeaderAndBody.aCId   = AlarmObject.sAlarmCodeId;
                AlarmHeaderAndBody.xACId  = AlarmObject.sExternalAlarmCodeId;
                AlarmHeaderAndBody.xNACId = AlarmObject.sExternalNTSAlarmCodeId;
                AlarmHeaderAndBody.rvs    = new List <RSMP_Messages.AlarmReturnValue>();


                AlarmEvent.AlarmObject = AlarmObject;

                AlarmHeaderAndBody.ack = AlarmObject.bAcknowledged ? "Acknowledged" : "notAcknowledged";
                AlarmHeaderAndBody.aS  = AlarmObject.bActive ? "Active" : "inActive";
                AlarmHeaderAndBody.sS  = AlarmObject.bSuspended ? "Suspended" : "notSuspended";

                switch (alarmSpecialisation)
                {
                case AlarmSpecialisation.Issue:
                    AlarmHeaderAndBody.aSp = "Issue";
                    AlarmEvent.sEvent      = AlarmHeaderAndBody.aSp + " / " + AlarmHeaderAndBody.aS;
                    break;

                case AlarmSpecialisation.Acknowledge:
                    AlarmHeaderAndBody.aSp = "Acknowledge";
                    AlarmEvent.sEvent      = AlarmHeaderAndBody.aSp + " / " + AlarmHeaderAndBody.ack;
                    break;

                case AlarmSpecialisation.Suspend:
                    AlarmHeaderAndBody.aSp = "Suspend";
                    AlarmEvent.sEvent      = AlarmHeaderAndBody.aSp + " / " + AlarmHeaderAndBody.sS;
                    break;
                }

                if (AlarmObject.bActive == false && AlarmObject.bAcknowledged)
                {
                    AlarmObject.AlarmCount = 0;
                }

                if (AlarmObject.dtLastChangedAlarmStatus == DateTime.MinValue)
                {
                    AlarmObject.dtLastChangedAlarmStatus = DateTime.Now;
                }

                AlarmHeaderAndBody.aTs = CreateISO8601UTCTimeStamp(AlarmObject.dtLastChangedAlarmStatus);
                AlarmHeaderAndBody.cat = AlarmObject.sCategory;
                AlarmHeaderAndBody.pri = AlarmObject.sPriority;

                AlarmEvent.sAlarmCodeId = AlarmObject.sAlarmCodeId;
                AlarmEvent.sDirection   = "Sent";
                AlarmEvent.sTimeStamp   = UnpackISO8601UTCTimeStamp(AlarmHeaderAndBody.aTs); // String.Format("{0:yyyy-MM-dd}T{0:HH:mm:ss.fff}", UnpackISO8601UTCTimeStamp(AlarmHeaderAndBody.aTs));
                AlarmEvent.sMessageId   = AlarmHeaderAndBody.mId;

                foreach (cAlarmReturnValue AlarmReturnValue in AlarmObject.AlarmReturnValues)
                {
                    RSMP_Messages.AlarmReturnValue rv = new RSMP_Messages.AlarmReturnValue();
                    rv.n = AlarmReturnValue.sName;
                    rv.v = AlarmReturnValue.Value.GetValue();
                    AlarmHeaderAndBody.rvs.Add(rv);
                    AlarmEvent.AlarmEventReturnValues.Add(new nsRSMPGS.cAlarmEventReturnValue(rv.n, rv.v));
                }

                sSendBuffer = JSonSerializer.SerializeObject(AlarmHeaderAndBody);

                if (bCreateMessageOnly)
                {
                    return(AlarmHeaderAndBody);
                }

                if (RSMPGS.JSon.SendJSonPacket(AlarmHeaderAndBody.type, AlarmHeaderAndBody.mId, sSendBuffer, true))
                {
                    if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false)
                    {
                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent alarm message, AlarmCode: " + AlarmObject.sAlarmCodeId + ", Type: " + AlarmHeaderAndBody.type + "/" + AlarmHeaderAndBody.aSp + "/" + AlarmHeaderAndBody.aS + ", MsgId: " + AlarmHeaderAndBody.mId);//, SequenceNumber: " + AlarmHeaderAndBody.sNr);
                    }
                }
                else
                {
                    if (cHelper.IsSettingChecked("BufferAndSendAlarmsWhenConnect"))
                    {
                        cBufferedMessage BufferedMessage = new cBufferedMessage(cBufferedMessage.eMessageType.Alarm, AlarmHeaderAndBody.type, AlarmHeaderAndBody.mId, sSendBuffer);
                        RSMPGS.MainForm.AddBufferedMessageToListAndListView(BufferedMessage);
                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Warning, "Buffered alarm message, AlarmCode: " + AlarmObject.sAlarmCodeId + ", Type: " + AlarmHeaderAndBody.type + "/" + AlarmHeaderAndBody.aSp + "/" + AlarmHeaderAndBody.aS + ", MsgId: " + AlarmHeaderAndBody.mId);// + ", SequenceNumber: " + AlarmHeaderAndBody.sNr);
                    }
                }

                //        RSMPGS.ProcessImage.SequenceNumber_Alarm++;
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to create alarm message: {0}", e.Message);
                AlarmEvent = null;
            }

            return(AlarmHeaderAndBody);
        }
Beispiel #24
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);
        }
        public void CreateAndSendCommandMessage(cRoadSideObject RoadSideObject, List <cCommandReturnValue> ReturnValues, bool bUseCaseSensitiveIds)
        {
            StringComparison sc = bUseCaseSensitiveIds ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            RSMP_Messages.CommandRequest       CommandRequest;
            RSMP_Messages.CommandRequest_Value CommandRequest_Value;
            string sSendBuffer;

            try
            {
                CommandRequest = new RSMP_Messages.CommandRequest();

                CommandRequest.mType = "rSMsg";
                CommandRequest.type  = "CommandRequest";
                CommandRequest.mId   = System.Guid.NewGuid().ToString();

                CommandRequest.ntsOId = RoadSideObject.sNTSObjectId;
                CommandRequest.xNId   = RoadSideObject.sExternalNTSId;
                CommandRequest.cId    = RoadSideObject.sComponentId;
                CommandRequest.arg    = new List <RSMP_Messages.CommandRequest_Value>();
                foreach (cCommandReturnValue CommandReturnValue in ReturnValues)
                {
                    CommandRequest_Value     = new RSMP_Messages.CommandRequest_Value();
                    CommandRequest_Value.cCI = CommandReturnValue.CommandObject.sCommandCodeId;
                    CommandRequest_Value.n   = CommandReturnValue.sName;
                    CommandRequest_Value.cO  = CommandReturnValue.sCommand;

                    if (CommandReturnValue.Value.GetValueType().Equals("base64", StringComparison.OrdinalIgnoreCase))
                    {
                        // Path?
                        if (CommandReturnValue.Value.GetValue().Contains("\\"))
                        {
                            try
                            {
                                byte[] Base64Bytes = null;
                                // Open file for reading
                                System.IO.FileStream   fsBase64 = new System.IO.FileStream(CommandReturnValue.Value.GetValue(), System.IO.FileMode.Open, System.IO.FileAccess.Read);
                                System.IO.BinaryReader brBase64 = new System.IO.BinaryReader(fsBase64);
                                long lBytes = new System.IO.FileInfo(CommandReturnValue.Value.GetValue()).Length;
                                Base64Bytes = brBase64.ReadBytes((Int32)lBytes);
                                fsBase64.Close();
                                fsBase64.Dispose();
                                brBase64.Close();
                                CommandRequest_Value.v = Convert.ToBase64String(Base64Bytes);
                                if (CommandRequest_Value.v.Length > (cTcpSocketClientThread.BUFLENGTH - 100))
                                {
                                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Base64 encoded packet is too big (" + Base64Bytes.GetLength(0).ToString() + " bytes), max buffer length is " + cTcpSocketClientThread.BUFLENGTH.ToString() + " bytes");
                                    CommandRequest_Value.v = null;
                                }
                            }
                            catch (Exception e)
                            {
                                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Could not base64-encode and send file '{0}', error {1}", CommandReturnValue.Value.GetValue(), e.Message);
                                CommandRequest_Value.v = null;
                            }
                        }
                    }
                    else
                    {
                        CommandRequest_Value.v = CommandReturnValue.Value.GetValue();
                    }
                    CommandRequest.arg.Add(CommandRequest_Value);

                    cCommandEvent CommandEvent = new cCommandEvent();
                    CommandEvent.sTimeStamp     = CreateLocalTimeStamp();
                    CommandEvent.sMessageId     = CommandRequest.mId;
                    CommandEvent.sEvent         = "Sent Command";
                    CommandEvent.sCommandCodeId = CommandReturnValue.CommandObject.sCommandCodeId;
                    CommandEvent.sName          = CommandReturnValue.sName;
                    CommandEvent.sCommand       = CommandReturnValue.sCommand;
                    CommandEvent.sValue         = CommandReturnValue.Value.GetValue();
                    RoadSideObject.CommandEvents.Add(CommandEvent);
                    RSMPGS.MainForm.HandleCommandListUpdate(RoadSideObject, CommandRequest.ntsOId, CommandRequest.cId, CommandEvent, true, bUseCaseSensitiveIds);

                    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, CommandRequest.cId, CommandEvent.sCommandCodeId,
                                               CommandEvent.sName, CommandEvent.sCommand, CommandEvent.sValue, CommandEvent.sAge, CommandEvent.sEvent);
                    }
                }

                sSendBuffer = JSonSerializer.SerializeObject(CommandRequest);

                if (RSMPGS.JSon.SendJSonPacket(CommandRequest.type, CommandRequest.mId, sSendBuffer, true))
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent command message, MsgId: " + CommandRequest.mId);
                }
                else
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to send command message, MsgId: " + CommandRequest.mId);
                }
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to create command message: {0}", e.Message);
            }
        }
Beispiel #26
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);
        }
Beispiel #27
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);
        }
        public void CreateAndSendStatusMessage(cRoadSideObject RoadSideObject, List <RSMP_Messages.StatusSubscribe_Status_Over_3_1_4> StatusSubscribeValues, string statusType)
        {
            RSMP_Messages.StatusRequest        StatusRequest;
            RSMP_Messages.StatusRequest_Status StatusRequest_Status;
            cStatusEvent StatusEvent = null;
            string       sSendBuffer;

            try
            {
                StatusRequest = new RSMP_Messages.StatusRequest();

                StatusRequest.mType = "rSMsg";
                StatusRequest.type  = statusType;
                StatusRequest.mId   = System.Guid.NewGuid().ToString();

                StatusRequest.ntsOId = RoadSideObject.sNTSObjectId;
                StatusRequest.xNId   = RoadSideObject.sExternalNTSId;
                StatusRequest.cId    = RoadSideObject.sComponentId;
                StatusRequest.sS     = new List <RSMP_Messages.StatusRequest_Status>();

                foreach (RSMP_Messages.StatusSubscribe_Status_Over_3_1_4 StatusSubscribeValue in StatusSubscribeValues)
                {
                    StatusRequest_Status     = new RSMP_Messages.StatusRequest_Status();
                    StatusRequest_Status.sCI = StatusSubscribeValue.sCI;
                    StatusRequest_Status.n   = StatusSubscribeValue.n;
                    StatusRequest.sS.Add(StatusRequest_Status);

                    StatusEvent                  = new cStatusEvent();
                    StatusEvent.sTimeStamp       = CreateLocalTimeStamp();
                    StatusEvent.sMessageId       = StatusRequest.mId;
                    StatusEvent.sStatusCommandId = StatusRequest_Status.sCI;
                    StatusEvent.sName            = StatusRequest_Status.n;
                    if (statusType.ToLower() == "statusunsubscribe")
                    {
                        StatusEvent.sEvent = "Sent unsubscription";
                        //StatusReturnValue.sLastUpdateRate = null;
                    }
                    else
                    {
                        StatusEvent.sEvent = "Sent status request";
                    }

                    if (RSMPGS_Main.bWriteEventsContinous)
                    {
                        RSMPGS.SysLog.EventLog("Status;{0}\tMId: {1}\tComponentId: {2}\tStatusCommandId: {3}\tName: {4}\tStatus: {5}\tQuality: {6}\tUpdateRate: {7}\tEvent: {8}",
                                               StatusEvent.sTimeStamp, StatusEvent.sMessageId, StatusRequest.cId, StatusEvent.sStatusCommandId,
                                               StatusEvent.sName, StatusEvent.sStatus, StatusEvent.sQuality, StatusEvent.sUpdateRate, StatusEvent.sEvent);
                    }

                    RoadSideObject.StatusEvents.Add(StatusEvent);
                    RSMPGS.MainForm.HandleStatusListUpdate(RoadSideObject, StatusEvent, true);
                }

                sSendBuffer = JSonSerializer.SerializeObject(StatusRequest);

                RSMPGS.JSon.SendJSonPacket(StatusRequest.type, StatusRequest.mId, sSendBuffer, true);
                if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false)
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent status message, ComponentId: " + StatusRequest.cId + " , MsgId: " + StatusRequest.mId);
                }
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to create status message: {0}", e.Message);
            }
        }
        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);
        }
Beispiel #30
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);
        }