Example #1
0
        public static void ReadElements <TItem>(this XmlReader reader, List <TItem> list,
                                                params IXmlElementHelper <TItem>[] helpers)
        {
            IXmlElementHelper <TItem> helper;

            while ((helper = reader.FindHelper(helpers)) != null)
            {
                list.Add(helper.Deserialize(reader));
            }
        }
Example #2
0
        public void ReadXml(XmlReader reader)
        {
            bool isEmpty = reader.IsEmptyElement;

            // Read past the property element
            reader.Read();

            // For empty lists in Settings.Default
            if (isEmpty)
            {
                return;
            }

            if (reader.IsStartElement(EL.revision))
            {
                RevisionIndex = reader.GetIntAttribute(ATTR.index);
                reader.Read();  // Consume tag
            }
            var helpers = GetXmlElementHelpers();
            var helper  = reader.FindHelper(helpers);

            // Read list items
            List <TValue> list = new List <TValue>();

            if (helper != null)
            {
                reader.ReadElements(list, helpers);
            }
            else
            {
                // Support for v0.1 format
                if (reader.IsEmptyElement)
                {
                    reader.Read();
                }
                else
                {
                    // Try to get through the elements with whatever
                    // names they were given, based on class names.
                    helper = new XmlElementHelper <TValue>();
                    reader.ReadStartElement();  // <ArrayOfType
                    while (reader.IsStartElement())
                    {
                        list.Add(helper.Deserialize(reader));   // <Type
                    }
                    reader.ReadEndElement();
                }
            }
            Clear();
            AddRange(list);

            // Perform final list specific updates
            ValidateLoad();
        }
Example #3
0
        public override void ReadXml(XmlReader reader)
        {
            // Read tag attributes
            base.ReadXml(reader);
            UseForRetentionTimeFilter = reader.GetBoolAttribute(ATTR.use_for_retention_time_prediction, false);
            AnalyteConcentration      = reader.GetNullableDoubleAttribute(ATTR.analyte_concentration);
            SampleType = SampleType.FromName(reader.GetAttribute(ATTR.sample_type));
            // Consume tag
            reader.Read();

            // Check if there is an optimization function element, and read
            // if if there is.
            IXmlElementHelper <OptimizableRegression> helper =
                reader.FindHelper(OPTIMIZATION_HELPERS);

            if (helper != null)
            {
                OptimizationFunction = helper.Deserialize(reader);
            }

            var chromFileInfos = new List <ChromFileInfo>();
            var fileLoadIds    = new List <string>();

            while (reader.IsStartElement(EL.sample_file) ||
                   reader.IsStartElement(EL.replicate_file) ||
                   reader.IsStartElement(EL.chromatogram_file))
            {
                // Note that the file path is actually be a URI that encodes things like lockmass correction as well as filename
                ChromFileInfo chromFileInfo = new ChromFileInfo(MsDataFileUri.Parse(reader.GetAttribute(ATTR.file_path)));
                chromFileInfo = chromFileInfo.ChangeHasMidasSpectra(reader.GetBoolAttribute(ATTR.has_midas_spectra, false));
                chromFileInfos.Add(chromFileInfo);

                string id = reader.GetAttribute(ATTR.id) ?? GetOrdinalSaveId(fileLoadIds.Count);
                fileLoadIds.Add(id);
                reader.Read();
                if (reader.IsStartElement(EL.instrument_info_list))
                {
                    reader.Skip();
                    reader.Read();
                }
            }
            Annotations = SrmDocument.ReadAnnotations(reader);

            MSDataFileInfos = chromFileInfos;
            _fileLoadIds    = fileLoadIds.ToArray();

            // Consume end tag
            reader.ReadEndElement();
        }
Example #4
0
        public override void ReadXml(XmlReader reader)
        {
            // Read tag attributes
            base.ReadXml(reader);
            UseForRetentionTimeFilter = reader.GetBoolAttribute(ATTR.use_for_retention_time_prediction, false);
            AnalyteConcentration = reader.GetNullableDoubleAttribute(ATTR.analyte_concentration);
            SampleType = SampleType.FromName(reader.GetAttribute(ATTR.sample_type));
            // Consume tag
            reader.Read();

            // Check if there is an optimization function element, and read
            // if if there is.
            IXmlElementHelper<OptimizableRegression> helper =
                reader.FindHelper(OPTIMIZATION_HELPERS);
            if (helper != null)
                OptimizationFunction = helper.Deserialize(reader);

            var msDataFilePaths = new List<MsDataFileUri>();
            var fileLoadIds = new List<string>();
            while (reader.IsStartElement(EL.sample_file) ||
                    reader.IsStartElement(EL.replicate_file) ||
                    reader.IsStartElement(EL.chromatogram_file))
            {
                // Note that the file path is actually be a URI that encodes things like lockmass correction as well as filename
                msDataFilePaths.Add(MsDataFileUri.Parse(reader.GetAttribute(ATTR.file_path)));
                string id = reader.GetAttribute(ATTR.id) ?? GetOrdinalSaveId(fileLoadIds.Count);
                fileLoadIds.Add(id);
                reader.Read();
                if (reader.IsStartElement(EL.instrument_info_list))
                {
                    reader.Skip();
                    reader.Read();
                }
            }
            Annotations = SrmDocument.ReadAnnotations(reader);

            MSDataFileInfos = msDataFilePaths.ConvertAll(path => new ChromFileInfo(path));
            _fileLoadIds = fileLoadIds.ToArray();

            // Consume end tag
            reader.ReadEndElement();
        }
Example #5
0
 public void ReadXml(XmlReader reader)
 {
     // Consume tag
     if (reader.IsEmptyElement)
         reader.Read();
     else
     {
         reader.ReadStartElement();
         // Read child element
         var helperSpec = reader.FindHelper(PEAK_SCORING_MODEL_SPEC_HELPERS);
         if (helperSpec != null)
             PeakScoringModel = helperSpec.Deserialize(reader);
         reader.ReadEndElement();
     }
 }
Example #6
0
        public void ReadXml(XmlReader reader)
        {
            Pick = reader.GetEnumAttribute(ATTR.pick, PeptidePick.library);
            PeptideCount = reader.GetNullableIntAttribute(ATTR.peptide_count);
            HasDocumentLibrary = reader.GetBoolAttribute(ATTR.document_library);

            _rankIdName = reader.GetAttribute(ATTR.rank_type);

            var list = new List<XmlNamedElement>();

            // Consume tag
            if (reader.IsEmptyElement)
                reader.Read();
            else
            {
                reader.ReadStartElement();
                // Read child elements
                IXmlElementHelper<Library> helperLib;
                IXmlElementHelper<LibrarySpec> helperSpec = null;
                while ((helperLib = reader.FindHelper(LIBRARY_HELPERS)) != null ||
                        (helperSpec = reader.FindHelper(LIBRARY_SPEC_HELPERS)) != null)
                {
                    if (helperLib != null)
                        list.Add(helperLib.Deserialize(reader));
                    else
                        list.Add(helperSpec.Deserialize(reader));

                }
                reader.ReadEndElement();
            }

            var libraries = new Library[list.Count];
            var librarySpecs = new LibrarySpec[list.Count];
            for (int i = 0; i < list.Count; i++)
            {
                var library = list[i] as Library;
                if (library != null)
                    libraries[i] = library;
                else
                    librarySpecs[i] = (LibrarySpec) list[i];
            }
            Libraries = libraries;
            LibrarySpecs = librarySpecs;

            DoValidate();
        }