示例#1
0
        /// <summary>
        /// Attempts to disconnect from this <see cref="LocalOutputAdapter"/>.
        /// </summary>
        protected override void AttemptDisconnection()
        {
            m_archive = null;
            m_server.Dispose();
            m_server = null;

            OnDisconnected();
            m_archivedMeasurements = 0;
        }
示例#2
0
        public Ticks ReadBackHistorianData(HistorianIArchive archive, Action <int> updateProgressBar)
        {
            IEnumerable <ulong> points;

            if (m_settings.ReadFromCsv)
            {
                points = m_indexToPointIDLookup.Skip(1); // First value is always 0 because the timestamp is the first column
            }
            else
            {
                points = m_points;
            }

            if (points == null)
            {
                ShowMessage("Point list not initialized");
                return(new Ticks(0));
            }

            int            count = 0;
            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();
            TreeStream <HistorianKey, HistorianValue> m_stream;

            SeekFilterBase <HistorianKey> timeFilter = TimestampSeekFilter.CreateFromRange <HistorianKey>(DataPoint.RoundTimestamp(m_startTime, m_settings.FrameRate), DataPoint.RoundTimestamp(m_endTime, m_settings.FrameRate));
            MatchFilterBase <HistorianKey, HistorianValue> pointFilter = PointIdMatchFilter.CreateFromList <HistorianKey, HistorianValue>(points);


            m_stream = archive.ClientDatabase.Read(GSF.Snap.Services.Reader.SortedTreeEngineReaderOptions.Default, timeFilter, pointFilter);


            int messageInterval = points.Count() * m_settings.MessageInterval;

            DateTime startTime = DateTime.UtcNow;

            while (m_stream.Read(key, value))
            {
                count++;

                if (count % messageInterval == 0)
                {
                    PercentComplete = (int)((1.0D - (new Ticks(m_endTime.Ticks - (long)key.Timestamp).ToSeconds() / m_timeRange)) * 100.0D);
                    ShowMessage($"{Environment.NewLine}{count} points read back so far, averaging {(count / (DateTime.UtcNow - startTime).TotalSeconds):N0} points per second.");
                    updateProgressBar(PercentComplete);
                }
            }

            return(DateTime.UtcNow - startTime);
        }
示例#3
0
        public DataWriter(Settings settings, int pointCount)
        {
            m_settings = settings;
            if (m_settings.WriteToOpenHistorian) // Initialize OH instance
            {
                string historianName = "DestinationHistorian";
                HistorianServerDatabaseConfig archiveInfo = new HistorianServerDatabaseConfig(historianName, settings.HistorianArchive, true)
                {
                    TargetFileSize     = (long)(1 * SI.Giga), // Just because
                    DirectoryMethod    = ArchiveDirectoryMethod.TopDirectoryOnly,
                    StagingCount       = 3,
                    DiskFlushInterval  = 1000, // Smallest available time interval
                    CacheFlushInterval = 1000  // Largest available value
                };

                m_historianServer  = new HistorianServer(archiveInfo, m_settings.DestinationHistorianDataPort);
                m_historianArchive = m_historianServer[historianName];
                m_historianKey     = new HistorianKey();
                m_historianValue   = new HistorianValue();
            }
            else if (m_settings.WriteToBerkeleyDB) // Initialize BDB instance
            {
                m_berkeleyDbCfg = new BTreeDatabaseConfig()
                {
                    BTreeCompare = BerkeleyDBKeyComparison,
                    CacheSize    = new CacheInfo(10, 0, 1),
                    PageSize     = 65536,
                    NoMMap       = true,
                    Creation     = CreatePolicy.IF_NEEDED
                };

                string databasePath = null;
                if (!m_settings.InMemoryBerkeleyDB)
                {
                    databasePath = Path.Combine(settings.HistorianArchive, settings.HistorianName);
                }

                m_berkeleyDb = BTreeDatabase.Open(databasePath, m_berkeleyDbCfg);

                m_berkeleyDbKey   = new DatabaseEntry();
                m_berkeleyDbValue = new DatabaseEntry();

                m_berkeleyDbPointList = new KeyValuePair <DatabaseEntry, DatabaseEntry> [pointCount];
                Parallel.For(0, m_berkeleyDbPointList.Length, (i) => m_berkeleyDbPointList[i] = new KeyValuePair <DatabaseEntry, DatabaseEntry>(
                                 new DatabaseEntry(),
                                 new DatabaseEntry()));
            }
        }
示例#4
0
        /// <summary>
        /// Attempts to connect to this <see cref="LocalOutputAdapter"/>.
        /// </summary>
        protected override void AttemptConnection()
        {
            // Open archive files
            Dictionary <string, string> settings = m_dataChannel.ParseKeyValuePairs();
            string setting;
            int    port;

            if (!settings.TryGetValue("port", out setting) || !int.TryParse(setting, out port))
            {
                port = DefaultPort;
            }

            m_server  = new HistorianServer(m_archiveInfo, port);
            m_archive = m_server[InstanceName];

            // Initialization of services needs to occur after files are open
            m_dataServices.Initialize();
            m_replicationProviders.Initialize();

            OnConnected();
        }