コード例 #1
0
 private void FixupFromDto(TimeSeriesDatabaseDto dto)
 {
     this.Title     = dto.Title;
     this.StartTime = dto.StartTime;
     FixupArchiveTemplatesFromDto(dto);
     FixupDataSourcesFromDto(dto);
 }
コード例 #2
0
        public TimeSeriesDatabaseDto Read()
        {
            Debug.Assert(this.reader == null);

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;
            settings.IgnoreComments   = true;

            TimeSeriesDatabaseDto dto = new TimeSeriesDatabaseDto();

            using (this.reader = XmlReader.Create(this.filename, settings))
            {
                this.reader.MoveToContent();
                this.reader.ReadStartElement("TimeSeriesDatabase");

                // Title
                this.reader.ReadStartElement("Title");
                dto.Title = this.reader.ReadString();
                this.reader.ReadEndElement();

                // Start time
                this.reader.ReadStartElement("StartTime");
                dto.StartTime = this.reader.ReadContentAsDateTime();
                this.reader.ReadEndElement();

                dto.ArchiveTemplates = ReadArchiveTemplates();
                dto.DataSources      = ReadDataSources();

                this.reader.Close();
            }

            return(dto);
        }
コード例 #3
0
        /// <summary>
        /// Import the database state from a previously exported XML file
        /// </summary>
        /// <param name="importFile">File name to import from</param>
        public static TimeSeriesDatabase Import(string databaseFile, string importFile)
        {
            XmlFileTimeSeriesDatabaseDao xmlImporter = new XmlFileTimeSeriesDatabaseDao(importFile);

            try
            {
                TimeSeriesDatabaseDto dto = xmlImporter.Read();

                TimeSeriesDatabase newDatabase = new TimeSeriesDatabase(databaseFile);

                // Create the database from the DTO
                try
                {
                    newDatabase.Create(dto);
                }
                catch (IOException e)
                {
                    throw new TimeTagException(e.Message, e);
                }

                return(newDatabase);
            }
            catch (System.Xml.XmlException e)
            {
                throw new TimeTagException("Badly formed XML import document", e);
            }
        }
コード例 #4
0
        /// <summary>
        /// Read the database with the given mode
        /// </summary>
        /// <param name="mode">Mode the database will be opened in</param>
        public void Read(ConnectionMode mode)
        {
            this.mode = mode;

            // Make sure the database status and connection mode are compatible
            if (ValidateDatabaseMode() != true)
            {
                throw new TimeTagException("Connection mode is incompatible with a read only file");
            }

            if (this.dao == null)
            {
                this.dao = GetDaoFactory().CreateTimeSeriesDatabase(this.FilePath);
            }

            // Reset the existing database contents
            Reset();

            try
            {
                // Open a connection to the database
                this.dao.Connect(mode);
            }
            catch (IOException e)
            {
                throw new TimeTagException("Database is locked", e);
            }

            // Read everything in from the database
            TimeSeriesDatabaseDto dto = this.dao.Read();

            // Build the database from the DTO
            FixupFromDto(dto);
        }
コード例 #5
0
 private void FixupDataSourcesFromDto(TimeSeriesDatabaseDto dto)
 {
     foreach (DataSourceDto dataSourceDto in dto.DataSources)
     {
         DataSource newDataSource = this.CreateDataSourceFromDto(dataSourceDto);
         this.dataSources.Add(newDataSource);
     }
 }
コード例 #6
0
 private void FixupArchiveTemplatesFromDto(TimeSeriesDatabaseDto dto)
 {
     foreach (ArchiveTemplateDto archiveTemplateDto in dto.ArchiveTemplates)
     {
         ArchiveTemplate newArchiveTemplate = new ArchiveTemplate(this, archiveTemplateDto);
         this.archiveTemplates.Add(newArchiveTemplate);
     }
 }
コード例 #7
0
 private void WriteDatabaseAttributes(TimeSeriesDatabaseDto dto)
 {
     // Title
     this.writer.WriteStartElement("Title");
     this.writer.WriteString(dto.Title);
     this.writer.WriteEndElement();
     // Start time
     this.writer.WriteStartElement("StartTime");
     this.writer.WriteValue(dto.StartTime);
     this.writer.WriteEndElement();
 }
コード例 #8
0
        public void Create(TimeSeriesDatabaseDto dto)
        {
            Debug.Assert(this.writer == null);

            using (this.writer = new XmlTextWriter(this.filename, Encoding.UTF8))
            {
                this.writer.WriteStartDocument();
                this.writer.WriteStartElement("TimeSeriesDatabase");
                WriteDatabaseAttributes(dto);
                WriteArchiveTemplates(dto.ArchiveTemplates);
                WriteDataSources(dto.DataSources);
                this.writer.WriteEndElement();
                this.writer.WriteEndDocument();

                this.writer.Close();
            }
        }
コード例 #9
0
        private TimeSeriesDatabaseDto CreateDto()
        {
            TimeSeriesDatabaseDto dto = new TimeSeriesDatabaseDto();

            dto.Title     = this.Title;
            dto.StartTime = this.StartTime;
            dto.Dao       = this.dao;

            foreach (ArchiveTemplate archiveTemplate in this.ArchiveTemplates)
            {
                dto.AddArchiveTemplate(archiveTemplate.CreateDto());
            }

            foreach (DataSource ds in this.DataSources)
            {
                dto.AddDataSource(ds.CreateDto());
            }

            return(dto);
        }
コード例 #10
0
        private void CreateDatabase(TimeSeriesDatabaseDto dto)
        {
            this.dao = GetDaoFactory().CreateTimeSeriesDatabase(this.FilePath);
            try
            {
                this.dao.Create(dto);

                foreach (ArchiveTemplate archiveTemplate in this.archiveTemplates)
                {
                    archiveTemplate.Create(this);
                }

                foreach (DataSource dataSource in this.dataSources)
                {
                    dataSource.Create();
                }
            }
            catch (IOException e)
            {
                throw new TimeTagException(e.Message, e);
            }
        }
コード例 #11
0
 private void Create(TimeSeriesDatabaseDto dto)
 {
     this.FixupFromDto(dto);
     this.CreateDatabase(dto);
 }