Beispiel #1
0
        public string Parse(string packetXml)
        {
            trace.Write(TraceLevel.Info, "COPSPacket::Parse");

            string resultado = string.Empty;

            try
            {
                if (string.IsNullOrEmpty(packetXml?.Trim()))
                {
                    throw new ArgumentNullException(nameof(packetXml));
                }

                XmlDocument xml = CreateWrappedXmlFromInput(packetXml);

                ExtractRootAttributesFromXml(xml);
                ExtractMessagesFromXml(xml);

                return(resultado);
            }
            catch (Exception error)
            {
                trace.Write(TraceLevel.Error, error.ToLogString());
                throw;
            }

            return(resultado);
        }
        private void btnCompute_Click(object sender, System.EventArgs e)
        {
            if (!IsEntradaRegistroSelectionValid())
            {
                MessageBox.Show("Register entry selection must can't be null");
                return;
            }

            if (!IsTextoEntradaValid())
            {
                MessageBox.Show("Input message must can't be null");
                return;
            }

            this.Cursor = Cursors.WaitCursor;

            int returnValue = Compute(loggerManager);

            logger.Write(PDMHelpers.TraceLevel.Info, $"El valor devuelto por la funcion es {returnValue}");
            MessageBox.Show($"El valor devuelto por la funcion es {returnValue}");

            if (returnValue != C_RES_OK)
            {
                MessageBox.Show("Error processing Input message");
            }

            logger.Write(PDMHelpers.TraceLevel.Info, $"==== APP FINISH =====");

            this.Cursor = Cursors.Default;
        }
        /// <summary>
        /// Load application params from xml file specified by filepath
        /// </summary>
        /// <param name="filepath">Xml file path </param>
        /// <returns>Bool with the result</returns>
        public virtual bool LoadParams(string filepath)
        {
            bool result = true;

            try
            {
                if (string.IsNullOrEmpty(filepath))
                {
                    throw new ArgumentException("ParamLoader filepath is null or empty", nameof(filepath));
                }

                if (!File.Exists(filepath))
                {
                    throw new FileNotFoundException("File not found", filepath);
                }

                XmlDocument xmlDocument = LoadXmlFile(filepath);
                List <KeyValuePair <string, string> > parameters = ParseXmlToParams(xmlDocument);
                parameters.ForEach(p => InsertUpdateValue(p.Key, p.Value));

                _trace.Write(TraceLevel.Debug, $"LoadParams result is  : {result}");

                result = true;
            }
            catch (Exception error)
            {
                _trace.Write(TraceLevel.Error, error.ToLogString());
                result = false;
                throw;
            }

            return(result);
        }
        public bool Open(string connectionString)
        {
            bool bReturn = true;

            try
            {
                Connection = new OracleConnection(connectionString);
                Connection.Open();

                if (!IsOpened())
                {
                    bReturn = false;
                }
                else
                {
                    trace.Write(TraceLevel.Info, $"Database connection is already open");
                }
            }
            catch (Exception error)
            {
                trace.Write(TraceLevel.Error, $"Error opening database connection");
                trace.Write(TraceLevel.Error, error.ToLogString());
                bReturn = false;
            }

            return(bReturn);
        }
Beispiel #5
0
        public COPSMsg(ILoggerManager loggerManager, XmlNode xmlMessage) : this(loggerManager)
        {
            m_strName = xmlMessage.Name;
            m_pTrace.Write(TraceLevel.Info, $"Element: {m_strName }");

            SetMessageType();

            ExtractAttributesFromXmlNode(xmlMessage);
            ExtractElementsFromXmlNode(xmlMessage);
        }
Beispiel #6
0
        public void LoadData(IDbConnection connection)
        {
            trace.Write(TraceLevel.Info, "LoadData");

            inMemoryTables = new Dictionary <MemoryDatabaseTables, IInMemoryTable>
            {
                { MemoryDatabaseTables.DB_VERSION, new IMT_TablesVersion(loggerManager, connection) },
                { MemoryDatabaseTables.Groups, new IMT_Groups(loggerManager, connection) },
                { MemoryDatabaseTables.GroupsChilds, new IMT_GroupsChilds(loggerManager, connection) },
                { MemoryDatabaseTables.Articles, new IMT_Articles(loggerManager, connection) },
                { MemoryDatabaseTables.ArticlesRules, new IMT_ArticlesRules(loggerManager, connection) },
                { MemoryDatabaseTables.Days, new IMT_Days(loggerManager, connection) },
                { MemoryDatabaseTables.DaysDef, new IMT_DaysDef(loggerManager, new DaysDefRepository(connection)) },
                { MemoryDatabaseTables.TimeTables, new IMT_TimeTables(loggerManager, connection) },
                { MemoryDatabaseTables.Constraints, new IMT_Constraints(loggerManager, new ConstraintsRepository(connection)) },
                { MemoryDatabaseTables.Tariffs, new IMT_Tariffs(loggerManager, new TariffsRepository(connection)) },
                { MemoryDatabaseTables.Status, new IMT_Status(loggerManager, new StatusRepository(connection)) },
                { MemoryDatabaseTables.Intervals, new IMT_Intervals(loggerManager, new IntervalsRepository(connection)) }
            };

            foreach (KeyValuePair <MemoryDatabaseTables, IInMemoryTable> table in inMemoryTables)
            {
                if (table.Key != MemoryDatabaseTables.DB_VERSION)
                {
                    table.Value.Version = GetTable <IMT_TablesVersion>(MemoryDatabaseTables.DB_VERSION).GetTableVersion((long)table.Key);
                }
                table.Value.LoadData();
                table.Value.SetTracerEnabled(trace.Enabled);

                trace.Write(TraceLevel.Info, $"Loaded table {Enum.GetName(typeof(MemoryDatabaseTables), table.Key)} Version {table.Value.Version} Count {table.Value.GetNum()}");
            }

            trace.Write(TraceLevel.Info, "LoadData finished");
        }
        public bool Copy(CM1Group pSrcGroup)
        {
            trace?.Write(TraceLevel.Debug, "CM1Group::Copy");
            bool fnResult = true;

            try
            {
                trace     = pSrcGroup.trace;
                m_lId     = pSrcGroup.m_lId;
                m_lTypeId = pSrcGroup.m_lTypeId;
                m_dtLast  = pSrcGroup.m_dtLast.Copy();
                m_lState  = pSrcGroup.m_lState;
                //M1ComputeEx0 Attributes
                m_lAccumMoney   = pSrcGroup.m_lAccumMoney;
                m_lAccumMinutes = pSrcGroup.m_lAccumMinutes;
                //M1ComputeEx1 Attributes
                m_lEfecAccumMoney   = pSrcGroup.m_lEfecAccumMoney;
                m_lEfecAccumMinutes = pSrcGroup.m_lEfecAccumMinutes;
                m_lRealAccumMoney   = pSrcGroup.m_lRealAccumMoney;
                m_lRealAccumMinutes = pSrcGroup.m_lRealAccumMinutes;

                int i = 0;
                for (i = 0; i < CM1Constraint.CNSTR_NUM; i++)
                {
                    m_Cnstr[i].Copy(pSrcGroup.m_Cnstr[i]);
                }
            }
            catch (Exception error)
            {
                trace?.Write(TraceLevel.Error, error.ToLogString());
                fnResult = false;
            }

            return(fnResult);
        }
        public bool SetTelegram(string telegram, Int64 telegramLen)
        {
            m_pTrace.Write(TraceLevel.Info, "CPDMMessage::SetTelegram");
            bool fnResult = false;

            lock (this)
            {
                try
                {
                    if (String.IsNullOrWhiteSpace(telegram))
                    {
                        throw new ArgumentNullException(nameof(telegram), "Telegram parameter == NULL");
                    }

                    if (telegramLen <= 0)
                    {
                        throw new ArgumentOutOfRangeException(nameof(telegramLen), "telegramLen <= 0");
                    }

                    m_szBuffer = string.Empty;
                    m_szBuffer = telegram.Clone() as string;

                    m_iSize = m_szBuffer.Length;

                    m_iTelDev  = C_DEVICE_CC;
                    m_iTelType = C_TYPE_CC;

                    fnResult = true;
                }
                catch (Exception error)
                {
                    m_pTrace.Write(TraceLevel.Error, error.ToLogString());
                    fnResult = false;
                }
            }

            return(fnResult);
        }
        public bool Copy(CM1GroupsTree pSrcTree)
        {
            trace?.Write(TraceLevel.Debug, "CM1GroupsTree::Copy");
            bool fnResult = true;

            try
            {
                trace       = pSrcTree.trace;
                m_nNodeNum  = pSrcTree.m_nNodeNum;
                m_nGroupNum = pSrcTree.m_nGroupNum;

                int i = 0;
                for (i = 0; i < m_nGroupNum; i++)
                {
                    m_Groups[i].Init();
                    m_Groups[i].Copy(pSrcTree.m_Groups[i]);
                }

                long lGrpId;
                for (i = 0; i < m_nNodeNum; i++)
                {
                    m_Nodes[i].Init();
                    m_Nodes[i].Copy(pSrcTree.m_Nodes[i]);
                    if (pSrcTree.m_Nodes[i].Grp != null)
                    {
                        lGrpId         = pSrcTree.m_Nodes[i].Grp.GetGrpId();
                        m_Nodes[i].Grp = GetGroupFromGrpId(lGrpId);
                    }
                    if (pSrcTree.m_Nodes[i].GrpChild != null)
                    {
                        lGrpId = pSrcTree.m_Nodes[i].GrpChild.GetGrpId();
                        m_Nodes[i].GrpChild = GetGroupFromGrpId(lGrpId);
                    }
                }
            }
            catch (Exception error)
            {
                trace?.Write(TraceLevel.Error, error.ToLogString());
                fnResult = false;
            }

            return(fnResult);
        }
        public virtual void Clear()
        {
            trace.Write(TraceLevel.Debug, "CDatM::Clear");

            try
            {
                m_bLookingForType = false;
                m_strIDMsg        = "";
                // Header
                m_dwTelID = 0;
                // Message Attributtes
                m_iIdentifier = GlobalDefs.DEF_UNDEFINED_VALUE;
                m_iRet        = GlobalDefs.DEF_UNDEFINED_VALUE;
                m_iPriority   = GlobalDefs.DEF_UNDEFINED_VALUE;
                m_iInUnit     = GlobalDefs.DEF_UNDEFINED_VALUE;

                m_iTelType = DEF_TELTYPE_UNKNOW;
                m_iMxType  = DEF_MTYPE_MUNKNOW;
                m_iNbError = 0;
                m_bTagAtt  = false;

                m_dtHdDate?.SetStatus(COPSDateStatus.Null);

                m_szHdSrc    = string.Empty;
                m_szDst      = string.Empty;
                m_szTagValue = string.Empty;
                m_szTagName  = string.Empty;

                m_iSent            = 0;
                m_pStatColl        = null;
                m_iSendingPriority = (int)Priority.PRIORITY_MEDIUM;
            }
            catch (Exception error)
            {
                trace.Write(TraceLevel.Error, error.ToLogString());
            }
        }
        public int fnM1(string pStrIn, string pRegEntry, ref string pStrOut, ref string pStrOutM50, int nSize, bool bApplyHistory, bool bUseDefaultArticleDef)
        {
            int nRes = 1;

            try
            {
                Guard.IsNullOrEmptyString(pStrIn, nameof(pStrIn));

                LoadParams(pRegEntry);
                trace.Write(TraceLevel.Debug, $"GeneralParams.UnitId loaded  {GeneralParams.UnitId}");

                CDatM1     m1        = new CDatM1(loggerManager);
                CDatM1     m1Return  = new CDatM1(loggerManager);
                CDatM1     m1Amp     = new CDatM1(loggerManager);
                COPSPacket opsPacket = new COPSPacket(loggerManager);
                bool       exitCurrentOperationInOtherGroup = false;

                trace.Write(TraceLevel.Info, "Waiting For Unlock .....");

                //TODO : Añadir en lock toda la seccion
                trace.Write(TraceLevel.Info, "Inside Lock .....");

                if (!OpenDatabase())
                {
                    throw new InvalidOperationException("Open database has failed");
                }

                if (!InitComputeM1())
                {
                    throw new InvalidOperationException("Compute1 initialization has failed");
                }

                tariffCalculator.SetDBB(database);

                opsPacket.Parse(pStrIn);
                if (opsPacket.GetMsg(0) == null)
                {
                    throw new InvalidOperationException("OPSPacket doesn't conatin any message");
                }

                if (!m1.SetData(opsPacket.GetMsg(0)))
                {
                    throw new InvalidOperationException("M1 Extracting data from OPSPacket");
                }

                if (m1.GetInArticleDef() == GlobalDefs.DEF_UNDEFINED_VALUE)
                {
                    trace.Write(TraceLevel.Debug, $"Set M1 InArticleDef from parameters");
                    m1.SetInArticleDef(defaultArticleDef);
                }

                if (tariffCalculator == null)
                {
                    throw new InvalidOperationException("TariffCalculator is NULL");
                }

                trace.Write(TraceLevel.Info, "FnM1 ");
                m1.Trace();

                if (!database.IsOpened())
                {
                    trace.Write(TraceLevel.Info, "Database is not connected");

                    if (!database.Close())
                    {
                        trace.Write(TraceLevel.Error, "ERROR Closing Database");
                    }

                    if (!OpenDatabase())
                    {
                        throw new InvalidOperationException("Open database has failed");
                    }
                }

                if (m1.GetInOperType() == OperationDat.DEF_OPERTYPE_RETN)
                {
                    if (!m1Return.SetData(opsPacket.GetMsg(0)))
                    {
                        throw new InvalidOperationException("M1RETURN Extracting data from OPSPacket");
                    }

                    if (m1Return.GetInArticleDef() == GlobalDefs.DEF_UNDEFINED_VALUE)
                    {
                        trace.Write(TraceLevel.Debug, $"Set M1RETURN InArticleDef from parameters");
                        m1.SetInArticleDef(defaultArticleDef);
                    }

                    if (!ComputeReturn(m1Return, m1))
                    {
                        trace.Write(TraceLevel.Info, $"ERROR: Computing Return");
                    }
                }
                else
                {
                    bool isVIP      = false;
                    bool isResident = false;

                    if (!bUseDefaultArticleDef)
                    {
                        if (!IsVehicleIdVIP(m1, ref isVIP))
                        {
                            trace.Write(TraceLevel.Error, "ERROR : IsVehicleIdVIP");
                        }

                        if (!isVIP)
                        {
                            if (!IsVehicleIdResident(m1, ref isResident))
                            {
                                trace.Write(TraceLevel.Error, "ERROR : IsVehicleIdResident");
                            }
                        }
                    }

                    // Modify tariffs for abonos in Zumarraga
                    trace.Write(TraceLevel.Info, "System ID %1", GeneralParams.SystemId.ToString());
                    if (GeneralParams.SystemId == SYSTEM_IDENTIFIER_ZUMARRAGA)
                    {
                        if (m1.GetInArticleDef() >= 102 && m1.GetInArticleDef() <= 113)
                        {
                            trace.Write(TraceLevel.Info, "Modifying tariffs for Zumarraga");
                            COPSPlate strVehicleId = m1.GetInVehicleID();

                            if (!database.SetTariffDates(tariffCalculator.GetTree(), m1.GetInArticleDef(), strVehicleId))
                            {
                                throw new InvalidOperationException("Setting tariff dates before calling M1");
                            }
                        }
                    }

                    bool bM1Plus      = false;
                    int  nMaxQuantity = (int)m1.GetOutIntAcumul();

                    if (!tariffCalculator.GetM1(m1, bM1Plus, nMaxQuantity, bApplyHistory))
                    {
                        trace.Write(TraceLevel.Info, "ERROR : GetM1");
                    }

                    m1AppliedHistory  = (tariffCalculator.GetApplyVehicleHistory()) ? 1: 0;
                    m1RealCurrMinutes = (int)tariffCalculator.GetRealCurrMinutes();

                    if (lookOtherGroups)
                    {
                        m1Amp = new CDatM1(loggerManager);
                        if (m1Amp == null)
                        {
                            throw new InvalidOperationException("ERROR : pM1 is NULL");
                        }

                        if (!m1Amp.SetData(opsPacket.GetMsg(0)))
                        {
                            throw new InvalidOperationException("ERROR : pM1 Extracting data from OPSPacket");
                        }

                        if (m1Amp.GetInArticleDef() == GlobalDefs.DEF_UNDEFINED_VALUE)
                        {
                            m1Amp.SetInArticleDef(defaultArticleDef);
                        }


                        if (!ComputeAmpliation(m1Amp, ref exitCurrentOperationInOtherGroup))
                        {
                            trace.Write(TraceLevel.Info, "ERROR : Computing Ampliation");
                        }
                    }
                }

                m1.Trace();

                string szOutMessage;
                string szOutMessageM50;

                //// Format Result Message
                szOutMessage = FormatOutMessage(m1, true, "A");
                if (exitCurrentOperationInOtherGroup && m1Amp != null)
                {
                    szOutMessage = FormatOutMessage(m1Amp, false, "B");
                }

                szOutMessageM50 = FormatOutMessageM50(m1);

                trace.Write(TraceLevel.Info, $"Message {szOutMessage}");
                trace.Write(TraceLevel.Info, $"Message 50 {szOutMessageM50}");

                pStrOut    = szOutMessage;
                pStrOutM50 = szOutMessageM50;

                ////// Format Result Message
                //XmlDocument xmlMessage = FormatOutMessage(m1, true, "A");
                //if (exitCurrentOperationInOtherGroup && m1Amp != null)
                //{
                //    xmlMessage = FormatOutMessage(m1Amp, false, "B", xmlMessage);
                //}

                //szOutMessage = xmlMessage.InnerXml;
                //xmlMessage.RemoveAll();

                //xmlMessage = FormatOutMessageM50(m1);
                //szOutMessageM50 = xmlMessage.InnerXml;

                //trace.Write(TraceLevel.Info, $"Message {szOutMessage}");
                //trace.Write(TraceLevel.Info, $"Message 50 {szOutMessageM50}");

                //pStrOut = szOutMessage;
                //pStrOutM50 = szOutMessageM50;
            }
            catch (LoadParametersException error)
            {
                trace.Write(TraceLevel.Error, error.ToLogString());
                nRes = -3;
            }
            catch (Exception error)
            {
                trace.Write(TraceLevel.Error, error.ToLogString());
                nRes = -1;
            }
            finally
            {
                if (!database.Close())
                {
                    trace.Write(TraceLevel.Error, "ERROR Closing Database");
                }
            }

            return(nRes);
        }
        public bool AmpliationIsAllowed(long groupId, ref bool ampliationIsAllowed)
        {
            trace.Write(TraceLevel.Debug, "CM1GroupsTree::AmpliationIsAllowed");
            bool fnResult = true;

            try
            {
                CM1Group group     = GetGroupFromGrpId(groupId);
                float    isAllowed = GlobalDefs.DEF_UNDEFINED_VALUE;
                group.GetConstraint(CM1Constraint.CNSTR_AMP_ALLOW, ref isAllowed);

                if (isAllowed == CM1Constraint.CNSTR_UNDEFINED)
                {
                    isAllowed = 1;
                }

                ampliationIsAllowed = isAllowed != 0;
            }
            catch (Exception error)
            {
                trace.Write(TraceLevel.Error, error.ToLogString());
                fnResult = false;
            }

            return(fnResult);
        }
        public bool Reset()
        {
            trace?.Write(TraceLevel.Debug, "CM1GroupsTree::Reset");
            bool fnResult = true;

            try
            {
                m_nNodeNum  = 0;
                m_nGroupNum = 0;
            }
            catch (Exception error)
            {
                trace?.Write(TraceLevel.Error, error.ToLogString());
                fnResult = false;
            }

            return(fnResult);
        }