Exemple #1
0
        /// <summary>
        /// Loads records from xml file.
        /// </summary>
        /// <param name="stream">Current stream.</param>
        /// <returns>Count loaded records.</returns>
        internal int LoadFromXml(StreamReader stream)
        {
            FileCabinetRecordXmlReader reader = new FileCabinetRecordXmlReader(stream);

            this.records = reader.ReadAll().ToArray();
            return(this.records.Length);
        }
        /// <summary>
        /// Loads the records from xml file.
        /// </summary>
        /// <param name="reader">Xml reader.</param>
        /// <returns>List of imported records.</returns>
        public IList <FileCabinetRecord> LoadFromXml(StreamReader reader)
        {
            XmlReader xmlReader = XmlReader.Create(reader);
            FileCabinetRecordXmlReader fileXmlReader = new FileCabinetRecordXmlReader(xmlReader);
            IList <FileCabinetRecord>  records       = fileXmlReader.ReadAll();

            return(records);
        }
Exemple #3
0
        /// <summary>
        /// Loads record from XML-file.
        /// </summary>
        /// <param name="reader">Stream to read.</param>
        /// <returns>Count of records.</returns>
        public int LoadFromXml(StreamReader reader)
        {
            var xmlReader = new FileCabinetRecordXmlReader(reader);

            this.records = xmlReader.ReadAll();

            return(this.records.Count);
        }
Exemple #4
0
        /// <summary>
        /// Метод выгрузки из xml.
        /// </summary>
        /// <param name="fs">Экзмепляр Filestream.</param>
        public void LoadFromXml(FileStream fs)
        {
            StreamReader reader = new StreamReader(fs);
            FileCabinetRecordXmlReader xmlReader = new FileCabinetRecordXmlReader(reader);
            List <FileCabinetRecord>   list      = new List <FileCabinetRecord>(xmlReader.ReadAll());

            this.records = list.ToArray();
        }
        /// <summary>
        /// Gets records from xml.
        /// </summary>
        /// <param name="xmlReader">Xml reader to get records.</param>
        public void LoadFromXml(XmlReader xmlReader)
        {
            FileCabinetRecordXmlReader fileXmlReader = new FileCabinetRecordXmlReader(xmlReader);

            try
            {
                this.records = fileXmlReader.ReadAll().ToArray();
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine(Configurator.GetConstantString("InvalidDeserialize"));
            }
        }
Exemple #6
0
        /// <summary>Loads records from XML file.</summary>
        /// <param name="reader">Reader.</param>
        /// <param name="validator">Validator.</param>
        /// <exception cref="ArgumentNullException">Thrown when reader or validator is null.</exception>
        public void LoadFromXml(XmlReader reader, IRecordValidator validator)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            if (validator == null)
            {
                throw new ArgumentNullException(nameof(validator));
            }

            var xmlReader = new FileCabinetRecordXmlReader(reader);
            IList <FileCabinetRecord> records;

            try
            {
                records = xmlReader.ReadAll();
            }
            catch (InvalidOperationException)
            {
                throw;
            }

            UnverifiedData unverifiedData;

            foreach (var record in records)
            {
                unverifiedData = new UnverifiedData(record);
                try
                {
                    validator.ValidateParameters(unverifiedData);
                }
                catch (ArgumentException ex)
                {
                    this.invalidRecords.Add(new Tuple <FileCabinetRecord, string>(record, ex.Message));
                    continue;
                }

                this.records.Add(record);
            }
        }
Exemple #7
0
        /// <summary>
        /// This Methods load from file in xml-format.
        /// </summary>
        /// <param name="streamReader">Represents characters read.</param>
        /// <returns>List records.</returns>
        public IList <FileCabinetRecord> LoadFromXml(StreamReader streamReader)
        {
            FileCabinetRecordXmlReader xmlReader = new FileCabinetRecordXmlReader(streamReader);

            return(xmlReader.ReadAll());
        }
Exemple #8
0
        /// <summary>
        /// Load records from xml file.
        /// </summary>
        /// <param name="reader">Stream Reader.</param>
        public void LoadFromXml(StreamReader reader)
        {
            FileCabinetRecordXmlReader xmlReader = new FileCabinetRecordXmlReader(reader);

            this.records = xmlReader.ReadAll().ToArray();
        }