Ejemplo n.º 1
0
        /// <summary>
        /// Causes the <see cref="StatisticsReader"/> to open the archive file and retrieve the statistics.
        /// </summary>
        public void Open()
        {
            m_archiveReader = new ArchiveReader();
            m_archiveReader.Open(ArchiveFilePath);

            m_metadataRecords = m_archiveReader.MetadataFile.Read()
                                .Where(record => !string.IsNullOrEmpty(record.Name))
                                .ToList();
        }
Ejemplo n.º 2
0
 private void LoadFactory(Stream stream)
 {
     if (database == null)
     {
         stream.Position = 0;
         var reader = new ArchiveReader();
         reader.Open(stream);
         database = reader.ReadDatabase(null);
     }
 }
Ejemplo n.º 3
0
 private void LoadFactory(Stream stream)
 {
     if (database is null)
     {
         stream.Position = 0;
         var reader = new ArchiveReader();
         reader.Open(stream);
         database = reader.ReadDatabase(new PasswordProvider(ReaderOptions.Password));
     }
 }
        private string OpenGSFHistorianArchive(string sourceFilesLocation, string sourceFilesOffloadLocation, string instanceName, bool reopen = false, string operationName = "Migration")
        {
            if (!string.IsNullOrEmpty(operationName))
            {
                m_operationName = operationName;
            }

            if ((object)m_archiveReader is null)
            {
                m_archiveReader = new ArchiveReader();
                m_archiveReader.RolloverStart                  += m_archiveReader_RolloverStart;
                m_archiveReader.RolloverComplete               += m_archiveReader_RolloverComplete;
                m_archiveReader.HistoricFileListBuildStart     += m_archiveReader_HistoricFileListBuildStart;
                m_archiveReader.HistoricFileListBuildComplete  += m_archiveReader_HistoricFileListBuildComplete;
                m_archiveReader.HistoricFileListBuildException += m_archiveReader_HistoricFileListBuildException;
                m_archiveReader.DataReadException              += m_archiveReader_DataReadException;
            }

            if (!string.IsNullOrEmpty(sourceFilesLocation) && Directory.Exists(sourceFilesLocation) && (reopen || m_archiveReader.StateFile is null || !m_archiveReader.StateFile.IsOpen))
            {
                // Specified directory is a valid one.
                try
                {
                    m_archiveReady.Reset();
                    string[] matches = Directory.GetFiles(sourceFilesLocation, "*_archive.d");

                    // Open the active archive
                    if (matches.Length > 0)
                    {
                        m_archiveReader.Open(matches[0], sourceFilesOffloadLocation);
                        m_enumerator = null;

                        // Find maximum point ID
                        m_maxPointID = FindMaximumPointID(m_archiveReader.MetadataFile);

                        string archiveName = FilePath.GetFileName(m_archiveReader.FileName);
                        instanceName = archiveName.Substring(0, archiveName.IndexOf("_"));

                        ShowUpdateMessage("[GSFHistorian] Archive reader opened for \"{0}\" historian.", instanceName);

                        // Start calculating total number of source points
                        m_pointCount = 0;
                        ThreadPool.QueueUserWorkItem(CalculateSourcePointCount, new[] { sourceFilesLocation, sourceFilesOffloadLocation });
                    }
                }
                catch (Exception ex)
                {
                    ShowUpdateMessage("[GSFHistorian] Error attempting to open archive: {0}", ex.Message);
                }
            }

            return(instanceName);
        }
Ejemplo n.º 5
0
        private void ArchiveLocationInput_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(ArchiveLocationInput.Text) && Directory.Exists(ArchiveLocationInput.Text))
            {
                // Specified directory is a valid one.
                try
                {
                    this.Cursor = Cursors.WaitCursor;

                    string[] matches = Directory.GetFiles(ArchiveLocationInput.Text, "*_archive.d");

                    if (matches.Length > 0)
                    {
                        // Open the active archive
                        m_archiveReader.Open(matches[0]);

                        MetadataRecord definition;
                        List <string>  previousSelection = new List <string>(ConfigurationFile.Current.Settings.General["Selection", true].ValueAs("").Split(','));

                        IDInput.Items.Clear();

                        for (int i = 1; i <= m_archiveReader.MetadataFile.RecordsOnDisk; i++)
                        {
                            definition = m_archiveReader.MetadataFile.Read(i);

                            if (definition.GeneralFlags.Enabled)
                            {
                                IDInput.Items.Add(new Metadata(definition));

                                if (previousSelection.Contains(definition.HistorianID.ToString()))
                                {
                                    IDInput.SetItemChecked(IDInput.Items.Count - 1, true);
                                }

                                Application.DoEvents();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ShowUpdateMessage("Error initializing application - {0}", ex.Message);
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Attempts to connect to this <see cref="LocalInputAdapter"/>.
        /// </summary>
        protected override void AttemptConnection()
        {
            // This adapter is only engaged for history, so we don't process any data unless a temporal constraint is defined
            if (this.TemporalConstraintIsDefined())
            {
                // Turn off read timer if it's active
                m_readTimer.Enabled = false;

                // Attempt to open historian files
                if (Directory.Exists(m_archiveLocation))
                {
                    // Specified directory is a valid one.
                    string[] matches = Directory.GetFiles(m_archiveLocation, "*_archive*.d");

                    if (matches.Length > 0)
                    {
                        // Capture the instance name
                        string fileName = matches[0].Remove(matches[0].IndexOf("_archive", StringComparison.OrdinalIgnoreCase)) + "_archive.d";

                        // Setup historian reader
                        m_archiveReader = new ArchiveReader();
                        m_archiveReader.HistoricFileListBuildStart     += m_archiveReader_HistoricFileListBuildStart;
                        m_archiveReader.HistoricFileListBuildComplete  += m_archiveReader_HistoricFileListBuildComplete;
                        m_archiveReader.HistoricFileListBuildException += m_archiveReader_HistoricFileListBuildException;
                        m_archiveReader.DataReadException += m_archiveReader_DataReadException;

                        // Open the active archive
                        m_archiveReader.Open(fileName, m_archiveLocation);

                        try
                        {
                            // Start the data reader on its own thread so connection attempt can complete in a timely fashion...
                            ThreadPool.QueueUserWorkItem(StartDataReader);
                        }
                        catch (Exception ex)
                        {
                            // Process exception for logging
                            OnProcessException(MessageLevel.Warning, new InvalidOperationException("Failed to start data reader due to exception: " + ex.Message, ex));
                        }
                    }
                }
                else
                {
                    OnProcessException(MessageLevel.Warning, new InvalidOperationException("Cannot open historian files, directory does not exist: " + m_archiveLocation));
                }
            }
        }
Ejemplo n.º 7
0
        private string GenerateStatsTable(string deviceAcronym, string parentAcronym)
        {
            string tbl = "ID".PadRight(11) + "Description".PadRight(201) + "Value".PadRight(21) + "Time (UTC)".PadRight(20) + "\r\n";

            tbl += string.Concat(Enumerable.Repeat("-", 253)) + "\r\n";

            // Grab Stat Measurements
            IEnumerable <MeasurementDetail> statmeasurements = DataContext.Table <MeasurementDetail>().QueryRecordsWhere("DeviceAcronym IN ({0},{1}) AND SignalAcronym = 'STAT'", deviceAcronym, parentAcronym);

            // Read Current Values (+ 30 seconds back)
            ConfigurationFile config = ConfigurationFile.Current;
            CategorizedSettingsElementCollection settings = config.Settings["statArchiveFile"];

            ArchiveReader archiveReader = new ArchiveReader();

            archiveReader.Open(settings["FileName"].ValueAsString());

            List <MetadataRecord> metadataRecords = archiveReader.MetadataFile.Read()
                                                    .Where(record => !string.IsNullOrEmpty(record.Name))
                                                    .ToList();

            Dictionary <long, IEnumerable <IDataPoint> > data = statmeasurements.Select(item => item.PointID).ToDictionary(record => record, record => archiveReader.ReadData((int)record, DateTime.UtcNow.Subtract(new TimeSpan(0, 1, 0)), DateTime.UtcNow, false));

            foreach (MeasurementDetail meas in statmeasurements)
            {
                tbl += meas.PointTag.Substring(meas.PointTag.LastIndexOf("!") + 1).Trim().PadRight(10) + " " + meas.Description.Trim().PadRight(200) + " ";
                if (data.ContainsKey(meas.PointID) && data[meas.PointID].Count() > 0)
                {
                    if (!StatisticsEngine.TryLookupStatisticSource(meas.SignalReference, out string source, out int signalIndex))
                    {
                        tbl += "N/A".PadRight(20) + " " + "N/A".PadRight(20) + "\r\n";
                    }
                    else
                    {
                        Statistic stat     = DataContext.Table <Statistic>().QueryRecordWhere("Source = {0} AND SignalIndex = {1}", source, signalIndex);
                        Type      statType = Type.GetType(stat.DataType);
                        if (statType == typeof(DateTime))
                        {
                            tbl += String.Format(stat.DisplayFormat, new GSF.UnixTimeTag((decimal)data[meas.PointID].First().Value)).PadRight(20) + " " + data[meas.PointID].First().Time.ToString("HH:mm:ss.fff").PadRight(20) + "\r\n";
                        }
                        else
                        {
                            tbl += String.Format(stat.DisplayFormat, Convert.ChangeType(data[meas.PointID].First().Value, statType)).PadRight(20) + " " + data[meas.PointID].First().Time.ToString("HH:mm:ss.fff").PadRight(20) + "\r\n";
                        }
                    }
                }