Beispiel #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);
        }