Exemplo n.º 1
0
        /// <summary>
        /// Creates an EDL file with the specified sections.
        /// </summary>
        /// <param name="FileName">Path to the file where the EDL file will be written.</param>
        /// <param name="IncludedSections">The sections to include in the EDL file.</param>
        /// <returns>CreateEDLResult Code.</returns>
        // Revision History
        // MM/DD/YY who Version Issue# Description
        // -------- --- ------- ------ ---------------------------------------
        // 07/06/10 AF  2.42.02         Created
        //
        public override CreateEDLResult CreateEDLFromMeter(string FileName, EDLSections IncludedSections)
        {
            GatewayTables MeterTables = new GatewayTables();

            List <ushort>   TablesToRead;
            int             iFileNameStart;
            string          strDirectory;
            CreateEDLResult Result     = CreateEDLResult.SUCCESS;
            PSEMResponse    PSEMResult = PSEMResponse.Ok;

            // First check to make sure we can create the file
            iFileNameStart = FileName.LastIndexOf(@"\", StringComparison.Ordinal);

            if (iFileNameStart > 0)
            {
                strDirectory = FileName.Substring(0, iFileNameStart);

                if (Directory.Exists(strDirectory) == false)
                {
                    Result = CreateEDLResult.INVALID_PATH;
                }
            }

            // Make sure we will be able to write to the file
            if (Result == CreateEDLResult.SUCCESS && File.Exists(FileName) == true)
            {
                FileInfo OutputFile = new FileInfo(FileName);

                if ((OutputFile.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    Result = CreateEDLResult.INVALID_PATH;
                }
            }

            if (Result == CreateEDLResult.SUCCESS)
            {
                // Read the data from the meter
                TablesToRead = GetTablesToRead(IncludedSections);

                OnShowProgress(new ShowProgressEventArgs(1, TablesToRead.Count, "Creating EDL file...", "Creating EDL file..."));

                foreach (ushort TableID in TablesToRead)
                {
                    if (PSEMResult == PSEMResponse.Ok)
                    {
                        // Read the table if it exists
                        if ((Table00.IsTableUsed(TableID) == true))
                        {
                            if (MeterTables.GetTableDependencies(TableID).Contains(TableID) || MeterTables.GetTableLength(TableID) > 0)
                            {
                                PSEMResult = ReadTable(TableID, ref MeterTables);

                                if (PSEMResult == PSEMResponse.Bsy ||
                                    PSEMResult == PSEMResponse.Dnr ||
                                    PSEMResult == PSEMResponse.Iar ||
                                    PSEMResult == PSEMResponse.Onp ||
                                    PSEMResult == PSEMResponse.Err)
                                {
                                    // We can't read the table but we should be able to continue we just need to
                                    // clear out anything that is there.
                                    MeterTables.ClearTable(TableID);
                                    PSEMResult = PSEMResponse.Ok;
                                }
                            }
                        }

                        OnStepProgress(new ProgressEventArgs());
                    }
                }

                if (PSEMResult == PSEMResponse.Isc)
                {
                    Result = CreateEDLResult.SECURITY_ERROR;
                }
                else if (PSEMResult != PSEMResponse.Ok)
                {
                    Result = CreateEDLResult.PROTOCOL_ERROR;
                }
            }

#if (WindowsCE)
            //The saving of the EDL file on the handheld can take over 6 seconds so we need
            //to send a wait before.
            m_PSEM.Wait(CPSEM.MAX_WAIT_TIME);
#endif

            // Generate the EDL file
            if (Result == CreateEDLResult.SUCCESS)
            {
                XmlWriterSettings WriterSettings = new XmlWriterSettings();
                WriterSettings.Encoding        = Encoding.ASCII;
                WriterSettings.Indent          = true;
                WriterSettings.CheckCharacters = false;

                XmlWriter EDLWriter = XmlWriter.Create(FileName, WriterSettings);

                MeterTables.SaveEDLFile(EDLWriter, null, AllowTableExport, AllowFieldExport);
            }

            OnHideProgress(new EventArgs());

            return(Result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a list of items that are not consistent between the configuration
        /// of the program and the device.
        /// </summary>
        /// <param name="strProgramName">The name of the program to validate against.</param>
        /// <returns>
        /// A list of items that failed the validation. Returns an empty list if
        /// all items match.
        /// </returns>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ -------------------------------------------
        //  07/08/10 AF  2.42.03        Created
        //
        public override List <ProgramValidationItem> ValidateProgram(string strProgramName)
        {
            PSEMResponse Response = PSEMResponse.Ok;

            List <ProgramValidationItem> InvalidItemsList = new List <ProgramValidationItem>();
            List <EDLValidationItem>     ItemsToValidate  = GetValidationList();
            List <ushort> ValidationTablesToRead          = GetValidationTablesToRead();

            FileStream    EDLFileStream = new FileStream(strProgramName, FileMode.Open, FileAccess.Read, FileShare.Read);
            XmlTextReader EDLReader     = new XmlTextReader(EDLFileStream);

            GatewayTables ProgramTables = new GatewayTables();
            GatewayTables MeterTables   = new GatewayTables();

            OnShowProgress(new ShowProgressEventArgs(1, ValidationTablesToRead.Count));

            // Read the data from the meter.
            // NOTE: ReadTable is defined in M2_Gateway_ICreateEDL so this will not compile if
            //       that file is not included. We may want to move this method eventually, but
            //       we are keeping Interfaces separate in case we wish to support OpenWay in HH-Pro
            foreach (ushort TableID in ValidationTablesToRead)
            {
                OnStepProgress(new ProgressEventArgs());

                if (Response == PSEMResponse.Ok)
                {
                    if (MeterTables.IsTableKnown(TableID) && Table00.IsTableUsed(TableID) && (TableID == 0 || MeterTables.GetTableLength(TableID) > 0))
                    {
                        Response = ReadTable(TableID, ref MeterTables);
                    }
                }
            }

            if (Response != PSEMResponse.Ok)
            {
                throw new PSEMException(PSEMException.PSEMCommands.PSEM_READ, Response, "Error reading device for validation.");
            }
            else
            {
                // Load the EDL file.
                ProgramTables.LoadEDLFile(EDLReader);

                // Compare the values
                foreach (EDLValidationItem Item in ItemsToValidate)
                {
                    ProgramValidationItem InvalidItem;

                    // Only compare items where the meter's FW version is greater than or equal to
                    // the minimum required for that item and the FW version is less than
                    // the version in which it became obsolete.  Max set to high for active items.
                    if ((VersionChecker.CompareTo(FWRevision, Item.MinFWVersion) >= 0) &&
                        (VersionChecker.CompareTo(FWRevision, Item.MaxFWVersion) < 0))
                    {
                        // We need to handle the display items differently than the rest of the items since
                        // there can be a different number of Normal and Test items.
                        if (RequiresSpecialHandling(Item.Item) == false)
                        {
                            InvalidItem = ValidateItem(Item, MeterTables, ProgramTables);

                            // Only add the item if it does not match.
                            if (null != InvalidItem)
                            {
                                InvalidItemsList.Add(InvalidItem);
                            }
                        }
                        else
                        {
                            InvalidItemsList.AddRange(HandleSpecialCases(Item.Item, MeterTables, ProgramTables));
                        }
                    }
                }
            }

            return(InvalidItemsList);
        }