示例#1
0
        /// <summary>
        /// Reads the Contents.xml file to look for the AcquiredTime entry
        /// </summary>
        /// <param name="strFolderPath"></param>
        /// <param name="datasetFileInfo"></param>
        /// <returns>True if the file exists and the AcquiredTime entry was successfully parsed; otherwise false</returns>
        /// <remarks></remarks>
        private bool ProcessContentsXMLFile(string strFolderPath, clsDatasetFileInfo datasetFileInfo)
        {
            var blnSuccess = false;

            try
            {
                // Open the Contents.xml file
                var strFilePath = Path.Combine(strFolderPath, AGILENT_XML_CONTENTS_FILE);

                using (var srReader = new System.Xml.XmlTextReader(new FileStream(strFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
                {
                    while (!srReader.EOF)
                    {
                        srReader.Read();

                        switch (srReader.NodeType)
                        {
                        case System.Xml.XmlNodeType.Element:

                            if (srReader.Name == "AcquiredTime")
                            {
                                try
                                {
                                    var dtAcquisitionStartTime = srReader.ReadElementContentAsDateTime();

                                    // Convert from Universal time to Local time
                                    var dtAcquisitionTime = dtAcquisitionStartTime.ToLocalTime();

                                    // There have been some cases where the acquisition start time is several years before the file modification time,
                                    // for example XG_A83CapiHSSWash1.d where the time in the Contents.xml file is 3/20/2005 while the file modification time is 2010
                                    // Thus, we use a sanity check of a maximum run time of 24 hours

                                    if (datasetFileInfo.AcqTimeEnd.Subtract(dtAcquisitionTime).TotalDays < 1)
                                    {
                                        datasetFileInfo.AcqTimeStart = dtAcquisitionStartTime.ToLocalTime();
                                        blnSuccess = true;
                                    }
                                }
                                catch (Exception)
                                {
                                    // Ignore errors here
                                }
                            }

                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Exception reading file
                OnErrorEvent("Exception reading " + AGILENT_XML_CONTENTS_FILE + ": " + ex.Message, ex);
                blnSuccess = false;
            }

            return(blnSuccess);
        }