Exemplo n.º 1
0
        /// <summary>
        /// Gets a list of invalid exception items.
        /// </summary>
        /// <param name="meterTables">The table structure for the meter.</param>
        /// <param name="programTables">The table structure for the program.</param>
        /// <returns>The list of invalid items.</returns>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ -------------------------------------------
        //  07/08/10 AF  2.42.03        Created
        //  03/06/12 AF  2.53.48 193820 We can no longer assume that the meter and program items will
        //                              be in the same order. We have to search both lists for mismatches
        //
        protected virtual List <ProgramValidationItem> GetInvalidExceptionItems(GatewayTables meterTables, GatewayTables programTables)
        {
            List <ProgramValidationItem> InvalidItems   = new List <ProgramValidationItem>();
            ProgramValidationItem        ValidationItem = null;

            object objMeterValue;
            object objProgramValue;

            ushort usMeterHosts;
            ushort usProgramHosts;
            ushort usMeterEvents;
            ushort usProgramEvents;

            ushort usMaxHosts;
            ushort usMaxEvents;

            // We shouldn't validate this if Table 123 is not cached in the program.
            if (programTables.IsAllCached(123))
            {
                // Get the number of exception hosts
                meterTables.GetValue(StdTableEnum.STDTBL121_NBR_EXCEPTION_HOSTS, null, out objMeterValue);
                programTables.GetValue(StdTableEnum.STDTBL121_NBR_EXCEPTION_HOSTS, null, out objProgramValue);

                usMeterHosts   = (ushort)objMeterValue;
                usProgramHosts = (ushort)objProgramValue;

                // Get the number of exception events
                meterTables.GetValue(StdTableEnum.STDTBL121_NBR_EXCEPTION_EVENTS, null, out objMeterValue);
                programTables.GetValue(StdTableEnum.STDTBL121_NBR_EXCEPTION_EVENTS, null, out objProgramValue);

                usMeterEvents   = (ushort)objMeterValue;
                usProgramEvents = (ushort)objProgramValue;

                // Determine the maximum values.
                if (usMeterHosts >= usProgramHosts)
                {
                    usMaxHosts = usMeterHosts;
                }
                else
                {
                    usMaxHosts = usProgramHosts;
                }

                if (usMeterEvents >= usProgramEvents)
                {
                    usMaxEvents = usMeterEvents;
                }
                else
                {
                    usMaxEvents = usProgramEvents;
                }

                // Verify each of the hosts
                for (int iHost = 0; iHost < usMaxHosts; iHost++)
                {
                    bool meterValidHost   = iHost < usMeterHosts;
                    bool programValidHost = iHost < usProgramHosts;

                    List <ushort> meterEventsList         = new List <ushort>();
                    List <ushort> programEventsList       = new List <ushort>();
                    List <ushort> invalidMeterItemsList   = new List <ushort>();
                    List <ushort> invalidProgramItemsList = new List <ushort>();
                    // the event number is just an index used for labeling the invalid item
                    int iEventNumber = 1;

                    int[]  iIndexer    = { iHost };
                    string strCategory = "Exception Host " + (iHost + 1).ToString(CultureInfo.CurrentCulture);

                    ValidationItem = ValidateItem(new EDLValidationItem((long)StdTableEnum.STDTBL123_APTITLE_NOTIFY, iIndexer, "Exception Host Aptitle", strCategory),
                                                  meterTables, programTables);

                    if (ValidationItem != null)
                    {
                        InvalidItems.Add(ValidationItem);
                    }

                    ValidationItem = ValidateItem(new EDLValidationItem((long)StdTableEnum.STDTBL123_MAX_NUMBER_OF_RETRIES, iIndexer, "Max Number of Retries", strCategory),
                                                  meterTables, programTables);

                    if (ValidationItem != null)
                    {
                        InvalidItems.Add(ValidationItem);
                    }

                    ValidationItem = ValidateItem(new EDLValidationItem((long)StdTableEnum.STDTBL123_RETRY_DELAY, iIndexer, "Retry Delay", strCategory),
                                                  meterTables, programTables);

                    if (ValidationItem != null)
                    {
                        InvalidItems.Add(ValidationItem);
                    }

                    ValidationItem = ValidateItem(new EDLValidationItem((long)StdTableEnum.STDTBL123_EXCLUSION_PERIOD, iIndexer, "Exclusion Period", strCategory),
                                                  meterTables, programTables);

                    if (ValidationItem != null)
                    {
                        InvalidItems.Add(ValidationItem);
                    }

                    if (meterValidHost == true)
                    {
                        for (int iEvent = 0; iEvent < usMeterEvents; iEvent++)
                        {
                            meterTables.GetValue(StdTableEnum.STDTBL123_EVENT_REPORTED, new int[] { iHost, iEvent }, out objMeterValue);
                            meterEventsList.Add((ushort)objMeterValue);
                        }
                    }

                    if (programValidHost == true)
                    {
                        for (int iEvent = 0; iEvent < usProgramEvents; iEvent++)
                        {
                            programTables.GetValue(StdTableEnum.STDTBL123_EVENT_REPORTED, new int[] { iHost, iEvent }, out objProgramValue);
                            programEventsList.Add((ushort)objProgramValue);
                        }
                    }

                    foreach (ushort item in meterEventsList)
                    {
                        if (!programEventsList.Contains(item))
                        {
                            invalidMeterItemsList.Add(item);
                        }
                    }

                    foreach (ushort item in invalidMeterItemsList)
                    {
                        string strMeterException = "";

                        if (EventDescriptions.TryGetValue((int)item, out strMeterException) == false)
                        {
                            // The TryGetValue failed so say it is an unknown event.
                            strMeterException = "Unknown Event " + item.ToString(CultureInfo.InvariantCulture);
                        }

                        // We don't know which program item this belongs with so just make the program item blank
                        InvalidItems.Add(new ProgramValidationItem(strCategory, "Event " + iEventNumber.ToString(CultureInfo.CurrentCulture),
                                                                   "", strMeterException));

                        iEventNumber++;
                    }

                    foreach (ushort item in programEventsList)
                    {
                        if (!meterEventsList.Contains(item))
                        {
                            invalidProgramItemsList.Add(item);
                        }
                    }

                    foreach (ushort item in invalidProgramItemsList)
                    {
                        string strProgramException = "";

                        if (EventDescriptions.TryGetValue((int)item, out strProgramException) == false)
                        {
                            // The TryGetValue failed so say it is an unknown event.
                            strProgramException = "Unknown Event " + item.ToString(CultureInfo.InvariantCulture);
                        }

                        // We don't know which meter item this belongs with so just make the meter item blank
                        InvalidItems.Add(new ProgramValidationItem(strCategory, "Event " + iEventNumber.ToString(CultureInfo.CurrentCulture),
                                                                   strProgramException, ""));

                        iEventNumber++;
                    }
                }
            }

            return(InvalidItems);
        }
Exemplo n.º 2
0
        protected ProgramValidationItem ValidateItem(EDLValidationItem item, GatewayTables meterTables, GatewayTables programTables)
        {
            bool bItemsMatch = false;

            string strDisplayMeterValue   = "";
            string strDisplayProgramValue = "";

            object objMeterValue;
            object objProgramValue;

            ProgramValidationItem InvalidItem = null;

            // Get the values
            objMeterValue = GetTableValue(item, meterTables);

            objProgramValue = GetTableValue(item, programTables);

            switch (item.Item)
            {
            case (long)StdTableEnum.STDTBL34_SEC_DISP_SOURCES:
            {
                if (objMeterValue != null)
                {
                    if (String.Compare(objMeterValue.ToString(), "3", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        strDisplayMeterValue = "No Display Item";
                    }
                    else
                    {
                        int iIndex = Convert.ToInt32(objMeterValue.ToString(), CultureInfo.InvariantCulture);
                        strDisplayMeterValue = "Comm. Status Field " + (iIndex + 1).ToString(CultureInfo.InvariantCulture);
                    }
                }
                if (objProgramValue != null)
                {
                    if (String.Compare(objProgramValue.ToString(), "3", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        strDisplayProgramValue = "No Display Item";
                    }
                    else
                    {
                        int iIndex = Convert.ToInt32(objProgramValue.ToString(), CultureInfo.InvariantCulture);
                        strDisplayProgramValue = "Comm. Status Field " + (iIndex + 1).ToString(CultureInfo.InvariantCulture);
                    }
                }
                if (strDisplayMeterValue.Equals(strDisplayProgramValue))
                {
                    bItemsMatch = true;
                }
                break;
            }

            case (long)StdTableEnum.STDTBL123_APTITLE_NOTIFY:
            {
                if (objMeterValue != null)
                {
                    strDisplayMeterValue = ESNConverter.Decode((byte[])objMeterValue);
                }

                if (objProgramValue != null)
                {
                    strDisplayProgramValue = ESNConverter.Decode((byte[])objProgramValue);
                }

                if (strDisplayMeterValue.Equals(strDisplayProgramValue))
                {
                    bItemsMatch = true;
                }

                break;
            }

            case (long)StdTableEnum.STDTBL53_TIME_ZONE_OFFSET:
            {
                TimeSpan tsOffset;
                short    sOffset;

                if (objMeterValue != null)
                {
                    sOffset              = (short)objMeterValue;
                    tsOffset             = TimeSpan.FromMinutes((double)sOffset);
                    strDisplayMeterValue = "GMT " + tsOffset.Hours + ":00";
                }

                if (objProgramValue != null)
                {
                    sOffset  = (short)objProgramValue;
                    tsOffset = TimeSpan.FromMinutes((double)sOffset);
                    strDisplayProgramValue = "GMT " + tsOffset.Hours + ":00";
                }

                // Compare the values
                if (strDisplayMeterValue == strDisplayProgramValue)
                {
                    bItemsMatch = true;
                }

                break;
            }

            case (long)GatewayTblEnum.MFGTBL145_EXCEPTION_SECURITY_MODEL:
            {
                OpenWayMFGTable2193.SecurityFormat MeterValue   = OpenWayMFGTable2193.SecurityFormat.None;
                OpenWayMFGTable2193.SecurityFormat ProgramValue = OpenWayMFGTable2193.SecurityFormat.None;

                if (objMeterValue != null)
                {
                    MeterValue           = (OpenWayMFGTable2193.SecurityFormat)(byte) objMeterValue;
                    strDisplayMeterValue = OpenWayMFGTable2193.GetSecurityFormatString(MeterValue);
                }

                if (objProgramValue != null)
                {
                    ProgramValue           = (OpenWayMFGTable2193.SecurityFormat)(byte) objProgramValue;
                    strDisplayProgramValue = OpenWayMFGTable2193.GetSecurityFormatString(ProgramValue);
                }

                bItemsMatch = ProgramValue == MeterValue;

                break;
            }

            case (long)GatewayTblEnum.MfgTbl145C1218OverZigBee:
            {
                bool bMeterValue   = false;
                bool bProgramValue = false;

                strDisplayProgramValue = null;

                if (objMeterValue != null)
                {
                    // We need to use the value of the bit
                    bMeterValue = (bool)objMeterValue;
                }

                strDisplayMeterValue = bMeterValue.ToString(CultureInfo.CurrentCulture);

                if (objProgramValue != null)
                {
                    bProgramValue          = (bool)objProgramValue;
                    strDisplayProgramValue = bProgramValue.ToString(CultureInfo.CurrentCulture);
                }

                bItemsMatch = strDisplayMeterValue.Equals(strDisplayProgramValue);
                break;
            }

            case (long)GatewayTblEnum.MFGTBL145_REQUIRE_ENHANCED_SECURITY:
            {
                strDisplayProgramValue = null;

                if (objMeterValue != null)
                {
                    strDisplayMeterValue = ((bool)objMeterValue).ToString(CultureInfo.CurrentCulture);
                }

                if (objProgramValue != null)
                {
                    strDisplayProgramValue = ((bool)objProgramValue).ToString(CultureInfo.CurrentCulture);
                }

                bItemsMatch = strDisplayMeterValue.Equals(strDisplayProgramValue);

                break;
            }

            case (long)GatewayTblEnum.MfgTbl58SecurityMode:
            {
                byte bySecurityMode;
                byte byDeviceAuthMode;
                byte byCBKEMode;

                // Get the Meter value
                if (objMeterValue != null && meterTables.IsCached((long)GatewayTblEnum.MfgTbl58DeviceAuthMode, null) &&
                    meterTables.IsCached((long)GatewayTblEnum.MfgTbl58CbkeMode, null))
                {
                    // We have already retrieved the Security Mode
                    bySecurityMode = (byte)objMeterValue;

                    // Get the other two modes
                    meterTables.GetValue(GatewayTblEnum.MfgTbl58DeviceAuthMode, null, out objMeterValue);
                    byDeviceAuthMode = (byte)objMeterValue;

                    meterTables.GetValue(GatewayTblEnum.MfgTbl58CbkeMode, null, out objMeterValue);
                    byCBKEMode = (byte)objMeterValue;

                    // Get the HAN Profile Name
                    strDisplayMeterValue = CHANMfgTable2106.GetHANSecurityProfile(bySecurityMode, byDeviceAuthMode, byCBKEMode);
                }

                // Get the Program value
                if (objProgramValue != null && programTables.IsCached((long)GatewayTblEnum.MfgTbl58DeviceAuthMode, null) &&
                    programTables.IsCached((long)GatewayTblEnum.MfgTbl58CbkeMode, null))
                {
                    // We have already retrieved the Security Mode
                    bySecurityMode = (byte)objProgramValue;

                    // Get the other two modes
                    programTables.GetValue(GatewayTblEnum.MfgTbl58DeviceAuthMode, null, out objProgramValue);
                    byDeviceAuthMode = (byte)objProgramValue;

                    programTables.GetValue(GatewayTblEnum.MfgTbl58CbkeMode, null, out objProgramValue);
                    byCBKEMode = (byte)objProgramValue;

                    // Get the HAN Profile Name
                    strDisplayProgramValue = CHANMfgTable2106.GetHANSecurityProfile(bySecurityMode, byDeviceAuthMode, byCBKEMode);
                }

                bItemsMatch = strDisplayMeterValue.Equals(strDisplayProgramValue);

                break;
            }

            case (long)GatewayTblEnum.MfgTbl58InterPanMode:
            {
                bool blnSkipComparison = false;

                // Get the Meter value
                if (objMeterValue != null)
                {
                    // Get the Inter PAN Mode description
                    strDisplayMeterValue = CHANMfgTable2106.GetInterPANMode((byte)objMeterValue);
                }

                // Get the Program value
                if (objProgramValue != null)
                {
                    // Get the Inter PAN Mode description
                    strDisplayProgramValue = CHANMfgTable2106.GetInterPANMode((byte)objProgramValue);
                }
                else if (programTables.IsCached((long)GatewayTblEnum.MFGTBL2045_CE_VERSION_NUMBER, null))
                {
                    object objValue = null;
                    programTables.GetValue(GatewayTblEnum.MFGTBL2045_CE_VERSION_NUMBER, null, out objValue);

                    string   strValue      = objValue as string;
                    string[] astrCEVersion = strValue.Split(new char[] { ' ', '.', '-' });
                    float    fltCEVersion  = Convert.ToSingle(astrCEVersion[0] + "." + astrCEVersion[1]);

                    if (0 <= VersionChecker.CompareTo(fltCEVersion, CE_VERSION_LITHIUM_3_9))
                    {
                        //Only skipping comparison if program value is null and program's CE version is Lithium or greater
                        blnSkipComparison = true;
                    }
                }

                if (true == blnSkipComparison)
                {
                    bItemsMatch = true;
                }
                else
                {
                    bItemsMatch = strDisplayMeterValue.Equals(strDisplayProgramValue);
                }

                break;
            }

            default:
            {
                // The GatewayTables object may return null so make sure we don't
                // cause an exception first.
                if (objMeterValue != null)
                {
                    // Trim spaces and null characters so that they will display and validate correctly
                    strDisplayMeterValue = objMeterValue.ToString().Trim(new char[] { ' ', '\0' });
                }

                if (objProgramValue != null)
                {
                    // Trim spaces and null characters so that they will display and validate correctly
                    strDisplayProgramValue = objProgramValue.ToString().Trim(new char[] { ' ', '\0' });
                }

                // Compare the values
                if (strDisplayMeterValue == strDisplayProgramValue)
                {
                    bItemsMatch = true;
                }

                break;
            }
            }

            if (bItemsMatch == false)
            {
                // There is a mismatch so add the item.
                InvalidItem = new ProgramValidationItem(item.Category, item.Name, strDisplayProgramValue, strDisplayMeterValue);
            }

            return(InvalidItem);
        }