Connects to a socket based remote historian database collection.
Inheritance: SnapNetworkClient
        private void StartStream(object args)
        {
            HistorianKey key = new HistorianKey();
            HistorianValue value = new HistorianValue();

            using (HistorianClient client = new HistorianClient("127.0.0.1", 54996))
            using (ClientDatabaseBase<HistorianKey, HistorianValue> database = client.GetDatabase<HistorianKey, HistorianValue>(string.Empty))
            {
                using (SortedTreeTable<HistorianKey, HistorianValue> file = SortedTreeFile.OpenFile(@"H:\OGE 2009.d2", isReadOnly: true).OpenOrCreateTable<HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding))
                {
                    using (SortedTreeTableReadSnapshot<HistorianKey, HistorianValue> read = file.BeginRead())
                    {
                        SortedTreeScannerBase<HistorianKey, HistorianValue> scan = read.GetTreeScanner();
                        scan.SeekToStart();
                        long count = 0;
                        while (scan.Read(key, value))
                        {
                            count++;
                            database.Write(key, value);
                            if ((count % 10) == 1)
                                Thread.Sleep(1);
                        }
                    }
                }
            }
        }
        public SnapDBClient(string hostAddress, int port, string instanceName, ulong startTime, ulong endTime, int frameRate, IEnumerable<ulong> pointIDs)
        {
            m_client = new HistorianClient(hostAddress, port);
            m_database = m_client.GetDatabase<HistorianKey, HistorianValue>(instanceName);
            m_key = new HistorianKey();
            m_value = new HistorianValue();

            SeekFilterBase<HistorianKey> timeFilter = TimestampSeekFilter.CreateFromRange<HistorianKey>(DataPoint.RoundTimestamp(startTime, frameRate), DataPoint.RoundTimestamp(endTime, frameRate));
            MatchFilterBase<HistorianKey, HistorianValue> pointFilter = PointIdMatchFilter.CreateFromList<HistorianKey, HistorianValue>(pointIDs);

            m_stream = m_database.Read(SortedTreeEngineReaderOptions.Default, timeFilter, pointFilter);
        }
        public void TestReadData()
        {
            var key = new HistorianKey();
            var value = new HistorianValue();

            var settings = new HistorianServerDatabaseConfig("DB", @"c:\temp\Scada\", true);
            using (HistorianServer server = new HistorianServer(settings, 12345))
            {
                using (var client = new HistorianClient("127.0.0.1", 12345))
                using (var database = client.GetDatabase<HistorianKey, HistorianValue>("DB"))
                {
                    var stream = database.Read(0, 1000);
                    while (stream.Read(key, value))
                        Console.WriteLine(key.Timestamp);
                }
            }
        }
        public void TestReadData()
        {
            var config1 = new HistorianServerDatabaseConfig("Scada", @"c:\temp\Scada\", true);
            var config2 = new HistorianServerDatabaseConfig("Synchrophasor", @"c:\temp\Synchrophasor\", true);

            using (HistorianServer server = new HistorianServer(12345))
            {
                server.AddDatabase(config1);
                server.AddDatabase(config2);

                using (var client = new HistorianClient("127.0.0.1", 12345))
                {
                    var database = client.GetDatabase<HistorianKey, HistorianValue>("Scada");
                    TreeStream<HistorianKey, HistorianValue> stream = database.Read(0, 100);
                    stream.Dispose();
                    database.Dispose();

                    database = client.GetDatabase<HistorianKey, HistorianValue>("Synchrophasor");
                    stream = database.Read(0, 100);
                    stream.Dispose();
                    database.Dispose();
                }
            }
        }
        public static void ReadAllPoints()
        {
            Stopwatch sw = new Stopwatch();
            int pointCount = 0;

            var settings = new HistorianServerDatabaseConfig("PPA", @"C:\Program Files\openHistorian\Archive\", true);
            using (HistorianServer server = new HistorianServer(settings))
            {
                DateTime start = DateTime.FromBinary(Convert.ToDateTime("2/1/2014").Date.Ticks + Convert.ToDateTime("6:00:00PM").TimeOfDay.Ticks).ToUniversalTime();

                using (var client = new HistorianClient("127.0.0.1", 12345))
                using (var database = client.GetDatabase<HistorianKey, HistorianValue>(String.Empty))
                {
                    HistorianKey key = new HistorianKey();
                    HistorianValue value = new HistorianValue();

                    sw.Start();
                    var scan = database.Read((ulong)start.Ticks, ulong.MaxValue);
                    while (scan.Read(key, value) && pointCount < 10000000)
                        pointCount++;
                    sw.Stop();

                    //sw.Start();
                    //using (var frameReader = database.GetPointStream(DateTime.MinValue, DateTime.MaxValue))
                    //{
                    //    while (frameReader.Read())
                    //        ;
                    //}
                    //sw.Stop();
                }
            }
            Console.WriteLine(pointCount);
            Console.WriteLine(sw.Elapsed.TotalSeconds.ToString());
            Console.WriteLine((pointCount / sw.Elapsed.TotalSeconds / 1000000).ToString());

        }
        public void CreateScadaDatabase()
        {
            Array.ForEach(Directory.GetFiles(@"c:\temp\Scada\", "*.d2", SearchOption.AllDirectories), File.Delete);

            var key = new HistorianKey();
            var value = new HistorianValue();

            var settings = new HistorianServerDatabaseConfig("DB", @"c:\temp\Scada\", true);
            using (var server = new HistorianServer(settings, 12345))
            {
                using (var client = new HistorianClient("127.0.0.1", 12345))
                using (var database = client.GetDatabase<HistorianKey, HistorianValue>("DB"))
                {
                    for (ulong x = 0; x < 1000; x++)
                    {
                        key.Timestamp = x;
                        database.Write(key, value);
                    }

                    database.HardCommit();
                    System.Threading.Thread.Sleep(1200);
                }
            }
        }
        /// <summary>
        /// Creates a new openHistorian <see cref="Connection"/>.
        /// </summary>
        /// <param name="historianServer">Historian server connection string, e.g., "localhost" or "myhistorian:38402"</param>
        /// <param name="instanceName">Instance name of historian, e.g., "PPA".</param>
        public Connection(string historianServer, string instanceName)
        {
            if (string.IsNullOrEmpty(historianServer))
                throw new ArgumentNullException(nameof(historianServer), "Missing historian server parameter");

            if (string.IsNullOrEmpty(instanceName))
                throw new ArgumentNullException(nameof(instanceName), "Missing historian instance name parameter");

            string[] parts = historianServer.Split(':');
            string hostName = parts[0];
            int port;

            if (parts.Length < 2 || !int.TryParse(parts[1], out port))
                port = DefaultHistorianPort;

            m_client = new HistorianClient(hostName, port);
            m_instanceName = instanceName;
        }
    public static IEnumerable GetHistorianDataSampled(SqlString historianServer, SqlString instanceName, DateTime startTime, DateTime stopTime, TimeSpan interval, [SqlFacet(MaxSize = -1)] SqlString measurementIDs)
    {
        const int DefaultHistorianPort = 38402;

        if (historianServer.IsNull || string.IsNullOrEmpty(historianServer.Value))
            throw new ArgumentNullException("historianServer", "Missing historian server parameter");

        if (instanceName.IsNull || string.IsNullOrEmpty(instanceName.Value))
            throw new ArgumentNullException("instanceName", "Missing historian instance name parameter");

        if (startTime > stopTime)
            throw new ArgumentException("Invalid time range specified", "startTime");

        string[] parts = historianServer.Value.Split(':');
        string hostName = parts[0];
        int port;

        if (parts.Length < 2 || !int.TryParse(parts[1], out port))
            port = DefaultHistorianPort;

        using (HistorianClient client = new HistorianClient(hostName, port))
        using (ClientDatabaseBase<HistorianKey, HistorianValue> reader = client.GetDatabase<HistorianKey, HistorianValue>(instanceName.Value))
        {
            var timeFilter = interval.Ticks == 0 ? TimestampSeekFilter.CreateFromRange<HistorianKey>(startTime, stopTime) :
                                            TimestampSeekFilter.CreateFromIntervalData<HistorianKey>(startTime, stopTime, interval, new TimeSpan(TimeSpan.TicksPerMillisecond));

            MatchFilterBase<HistorianKey, HistorianValue> pointFilter = null;
            HistorianKey key = new HistorianKey();
            HistorianValue value = new HistorianValue();

            if (!measurementIDs.IsNull && !string.IsNullOrEmpty(measurementIDs.Value))
                pointFilter = PointIdMatchFilter.CreateFromList<HistorianKey, HistorianValue>(measurementIDs.Value.Split(',').Select(ulong.Parse));

            // Start stream reader for the provided time window and selected points
            using (TreeStream<HistorianKey, HistorianValue> stream = reader.Read(SortedTreeEngineReaderOptions.Default, timeFilter, pointFilter))
            {
                while (stream.Read(key, value))
                    yield return new Measurement(key.PointID, key.TimestampAsDate, value.AsSingle);
            }
        }
    }
 public void Start(string ip, int port, string database)
 {
     HistorianClient client = new HistorianClient(ip, port);
     m_database = database;
     HistorianQuery query = new HistorianQuery(client);
     m_updateFramework.Start(query);
     m_updateFramework.Mode = ExecutionMode.Manual;
     m_updateFramework.Enabled = true;
 }
        void ReaderThread()
        {
            int threadId = Interlocked.Increment(ref ThreadNumber);

            try
            {

                DateTime start = DateTime.FromBinary(Convert.ToDateTime("2/1/2014").Date.Ticks + Convert.ToDateTime("6:00:00PM").TimeOfDay.Ticks).ToUniversalTime();
                while (!StopReading)
                {

                    int myId = Interlocked.Increment(ref ReaderNumber);
                    Stopwatch sw = new Stopwatch();
                    int pointCount = 0;
                    using (var client = new HistorianClient("127.0.0.1", 12345))
                    using (var database = client.GetDatabase<HistorianKey, HistorianValue>(String.Empty))
                    {
                        HistorianKey key = new HistorianKey();
                        HistorianValue value = new HistorianValue();

                        sw.Start();
                        var scan = database.Read((ulong)start.Ticks, ulong.MaxValue);//, new ulong[] { 65, 953, 5562 });
                        while (scan.Read(key, value) && pointCount < PointsToRead)
                            pointCount++;
                        sw.Stop();
                    }

                    //Console.WriteLine("Thread: " + threadId.ToString() + " " + "Run Number: " + myId.ToString() + " " + (pointCount / sw.Elapsed.TotalSeconds / 1000000).ToString());
                }
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.ToString());
            }
            Console.WriteLine("Thread: " + threadId.ToString() + " Quit");
        }
        // Closes the archive files and clears the archive file collection.
        private void ClearArchives()
        {
            if ((object)m_client != null)
            {
                m_client.Dispose();
                m_client = null;
            }

            m_metadata.Clear();
        }
        private void OpenArchives()
        {
            ClearArchives();

            ArchiveIsOpen = true;

            m_metadata = Metadata.Query().Select(row => new MetadataWrapper(row)).ToList();
            FilterBySearchResults();

            m_client = new HistorianClient(ConnectionDialog.ServerHost.Text, int.Parse(ConnectionDialog.HistorianPort.Text));
            m_chartWindow.ArchiveReader = m_client.GetDatabase<HistorianKey, HistorianValue>(ConnectionDialog.InstanceName.Text);

            TrySetChartInterval(null);
            m_chartWindow.UpdateChart();
        }
        public void TestReadData()
        {
            HistorianKey key = new HistorianKey();
            HistorianValue value = new HistorianValue();

            var settings = new HistorianServerDatabaseConfig("PPA", @"c:\temp\Scada\", true);
            using (HistorianServer server = new HistorianServer(settings))
            {
                double count = 0;

                DebugStopwatch sw = new DebugStopwatch();
                double time = sw.TimeEvent(() =>
                    {
                        count = 0;
                        using (HistorianClient client = new HistorianClient("127.0.0.1", 12345))
                        using (ClientDatabaseBase<HistorianKey, HistorianValue> database = client.GetDatabase<HistorianKey, HistorianValue>(String.Empty))
                        {
                            //IHistorianDatabase<HistorianKey, HistorianValue> database = server.GetDefaultDatabase();//.GetDatabase();
                            //TreeStream<HistorianKey, HistorianValue> stream = reader.Read(0, ulong.MaxValue, new ulong[] { 2 });
                            TreeStream<HistorianKey, HistorianValue> stream = database.Read(0, ulong.MaxValue);
                            while (stream.Read(key,value))
                            {
                                count++;
                            }
                        }
                    });

                Console.WriteLine((count / 1000000 / time).ToString() + " Million PPS");
            }

            //Console.WriteLine("KeyMethodsBase calls");
            //for (int x = 0; x < 23; x++)
            //{
            //    Console.WriteLine(TreeKeyMethodsBase<HistorianKey>.CallMethods[x] + "\t" + ((TreeKeyMethodsBase<HistorianKey>.Method)(x)).ToString());
            //}
            //Console.WriteLine("ValueMethodsBase calls");
            //for (int x = 0; x < 5; x++)
            //{
            //    Console.WriteLine(TreeValueMethodsBase<HistorianValue>.CallMethods[x] + "\t" + ((TreeValueMethodsBase<HistorianValue>.Method)(x)).ToString());
            //}
            //for (int x = 0; x < 15; x++)
            //{
            //    Console.WriteLine(BinaryStreamBase.CallMethods[x] + "\t" + ((BinaryStreamBase.Method)(x)).ToString());
            //}
        }
Exemplo n.º 14
0
        //private void BtnExport_Click(object sender, EventArgs e)
        //{
        //    Settings.Default.Save();
        //    if (m_meta == null)
        //    {
        //        MessageBox.Show("Please download the metadata first.");
        //        return;
        //    }
        //    if (m_selectedMeasurements == null || m_selectedMeasurements.Count == 0)
        //    {
        //        MessageBox.Show("There are no measurements to extract");
        //        return;
        //    }
        //    DateTime startTime = dateStartTime.Value;
        //    DateTime stopTime = dateStopTime.Value;
        //    if (startTime > stopTime)
        //    {
        //        MessageBox.Show("Start and Stop times are invalid");
        //        return;
        //    }
        //    TimeSpan interval = Resolutions.GetInterval((string)cmbResolution.SelectedItem);


        //    HistorianClientOptions clientOptions = new HistorianClientOptions();
        //    clientOptions.DefaultDatabase = Settings.Default.HistorianInstanceName;
        //    clientOptions.NetworkPort = Settings.Default.HistorianStreamingPort;
        //    clientOptions.ServerNameOrIp = Settings.Default.ServerIP;
        //    using (HistorianClient client = new HistorianClient(clientOptions))
        //    {
        //        KeySeekFilterBase<HistorianKey> timeFilter;
        //        if (interval.Ticks != 0)
        //            timeFilter = TimestampFilter.CreateFromIntervalData<HistorianKey>(startTime, stopTime, interval, new TimeSpan(TimeSpan.TicksPerMillisecond));
        //        else
        //            timeFilter = TimestampFilter.CreateFromRange<HistorianKey>(startTime, stopTime);

        //        var points = m_selectedMeasurements.Select((x) => (ulong)x.PointID).ToArray();
        //        var pointFilter = PointIDFilter.CreateFromList<HistorianKey>(points);

        //        var database = client.GetDefaultDatabase();
        //        var frames = database.GetFrames(timeFilter, pointFilter).RoundToTolerance(1);
        //        using (var csvStream = new StreamWriter("C:\\temp\\file.csv"))
        //        {
        //            //csvStream.AutoFlush = false;
        //            csvStream.Write("Timestamp,");
        //            foreach (var signal in m_selectedMeasurements)
        //            {
        //                csvStream.Write(signal.Description);
        //                csvStream.Write(',');
        //            }
        //            csvStream.WriteLine();

        //            foreach (var frame in frames)
        //            {
        //                csvStream.Write(frame.Key.ToString("MM/dd/yyyy hh:mm:ss.fffffff"));
        //                csvStream.Write(',');

        //                foreach (var signal in m_selectedMeasurements)
        //                {
        //                    HistorianValueStruct value;
        //                    if (frame.Value.Points.TryGetValue((ulong)signal.PointID, out value))
        //                    {
        //                        csvStream.Write(value.AsSingle);
        //                    }
        //                    csvStream.Write(',');
        //                }
        //                csvStream.WriteLine();
        //            }
        //            csvStream.Flush();
        //        }
        //        database.Disconnect();
        //    }


        //}

        //private void BtnExport_Click(object sender, EventArgs e)
        //{
        //    Settings.Default.Save();
        //    if (m_meta == null)
        //    {
        //        MessageBox.Show("Please download the metadata first.");
        //        return;
        //    }
        //    if (m_selectedMeasurements == null || m_selectedMeasurements.Count == 0)
        //    {
        //        MessageBox.Show("There are no measurements to extract");
        //        return;
        //    }
        //    DateTime startTime = dateStartTime.Value;
        //    DateTime stopTime = dateStopTime.Value;
        //    if (startTime > stopTime)
        //    {
        //        MessageBox.Show("Start and Stop times are invalid");
        //        return;
        //    }
        //    TimeSpan interval = Resolutions.GetInterval((string)cmbResolution.SelectedItem);


        //    HistorianClientOptions clientOptions = new HistorianClientOptions();
        //    clientOptions.DefaultDatabase = Settings.Default.HistorianInstanceName;
        //    clientOptions.NetworkPort = Settings.Default.HistorianStreamingPort;
        //    clientOptions.ServerNameOrIp = Settings.Default.ServerIP;
        //    using (HistorianClient client = new HistorianClient(clientOptions))
        //    {
        //        KeySeekFilterBase<HistorianKey> timeFilter;
        //        if (interval.Ticks != 0)
        //            timeFilter = TimestampFilter.CreateFromIntervalData<HistorianKey>(startTime, stopTime, interval, new TimeSpan(TimeSpan.TicksPerMillisecond));
        //        else
        //            timeFilter = TimestampFilter.CreateFromRange<HistorianKey>(startTime, stopTime);

        //        var points = m_selectedMeasurements.Select((x) => (ulong)x.PointID).ToArray();
        //        var pointFilter = PointIDFilter.CreateFromList<HistorianKey>(points);

        //        var database = client.GetDefaultDatabase();

        //        using (var frameReader = database.GetPointStream(timeFilter, pointFilter).GetFrameReader())
        //        using (var csvStream = new StreamWriter("C:\\temp\\file.csv"))
        //        {
        //            var ultraStream = new UltraStreamWriter(csvStream);
        //            //csvStream.AutoFlush = false;
        //            csvStream.Write("Timestamp,");
        //            foreach (var signal in m_selectedMeasurements)
        //            {
        //                csvStream.Write(signal.Description);
        //                csvStream.Write(',');
        //            }
        //            csvStream.WriteLine();

        //            while (frameReader.Read())
        //            {
        //                csvStream.Write(frameReader.FrameTime.ToString("MM/dd/yyyy hh:mm:ss.fffffff"));
        //                csvStream.Write(',');

        //                foreach (var signal in m_selectedMeasurements)
        //                {
        //                    HistorianValueStruct value;
        //                    if (frameReader.Frame.TryGetValue((ulong)signal.PointID, out value))
        //                    {
        //                        ultraStream.Write(value.AsSingle);
        //                        //csvStream.Write(value.AsSingle);
        //                    }
        //                    //csvStream.Write(',');
        //                    ultraStream.Write(',');
        //                }
        //                ultraStream.Flush();
        //                csvStream.WriteLine();
        //            }

        //            csvStream.Flush();
        //        }
        //        database.Disconnect();
        //    }
        //}

        //private void BtnExport_Click(object sender, EventArgs e)
        //{
        //    Settings.Default.Save();
        //    if (m_meta == null)
        //    {
        //        MessageBox.Show("Please download the metadata first.");
        //        return;
        //    }
        //    if (m_selectedMeasurements == null || m_selectedMeasurements.Count == 0)
        //    {
        //        MessageBox.Show("There are no measurements to extract");
        //        return;
        //    }
        //    DateTime startTime = dateStartTime.Value;
        //    DateTime stopTime = dateStopTime.Value;
        //    if (startTime > stopTime)
        //    {
        //        MessageBox.Show("Start and Stop times are invalid");
        //        return;
        //    }
        //    TimeSpan interval = Resolutions.GetInterval((string)cmbResolution.SelectedItem);


        //    HistorianClientOptions clientOptions = new HistorianClientOptions();
        //    clientOptions.DefaultDatabase = Settings.Default.HistorianInstanceName;
        //    clientOptions.NetworkPort = Settings.Default.HistorianStreamingPort;
        //    clientOptions.ServerNameOrIp = Settings.Default.ServerIP;
        //    using (HistorianClient client = new HistorianClient(clientOptions))
        //    {
        //        m_readIndex = 0;
        //        m_fillMeasurements.Clear();
        //        m_measurementsInOrder.Clear();
        //        foreach (var signal in m_selectedMeasurements)
        //        {
        //            var m = new Measurements();
        //            m_fillMeasurements.Add((ulong)signal.PointID, m);
        //            m_measurementsInOrder.Add(m);
        //        }

        //        KeySeekFilterBase<HistorianKey> timeFilter;
        //        if (interval.Ticks != 0)
        //            timeFilter = TimestampFilter.CreateFromIntervalData<HistorianKey>(startTime, stopTime, interval, new TimeSpan(TimeSpan.TicksPerMillisecond));
        //        else
        //            timeFilter = TimestampFilter.CreateFromRange<HistorianKey>(startTime, stopTime);

        //        var points = m_selectedMeasurements.Select((x) => (ulong)x.PointID).ToArray();
        //        var pointFilter = PointIDFilter.CreateFromList<HistorianKey>(points);

        //        var database = client.GetDefaultDatabase();

        //        using (var fillAdapter = database.GetPointStream(timeFilter, pointFilter).GetFillAdapter())
        //        using (var csvStream = new StreamWriter("C:\\temp\\file.csv"))
        //        {
        //            var ultraStream = new UltraStreamWriter(csvStream);
        //            //csvStream.AutoFlush = false;
        //            csvStream.Write("Timestamp,");
        //            foreach (var signal in m_selectedMeasurements)
        //            {
        //                csvStream.Write(signal.Description);
        //                csvStream.Write(',');
        //            }
        //            csvStream.WriteLine();

        //            m_readIndex++;
        //            while (fillAdapter.Fill(FillData))
        //            {
        //                csvStream.Write(fillAdapter.FrameTime.ToString("MM/dd/yyyy hh:mm:ss.fffffff"));
        //                csvStream.Write(',');

        //                foreach (var signal in m_measurementsInOrder)
        //                {
        //                    if (signal.ReadNumber == m_readIndex)
        //                    {
        //                        ultraStream.Write(signal.Value);
        //                    }
        //                    ultraStream.Write(',');
        //                }
        //                ultraStream.Flush();
        //                csvStream.WriteLine();
        //                m_readIndex++;

        //            }

        //            csvStream.Flush();
        //        }
        //        database.Disconnect();
        //    }
        //}

        private void BtnExport_Click(object sender, EventArgs e)
        {
            Settings.Default.Save();
            if (m_meta == null)
            {
                MessageBox.Show("Please download the metadata first.");
                return;
            }
            if (m_selectedMeasurements == null || m_selectedMeasurements.Count == 0)
            {
                MessageBox.Show("There are no measurements to extract");
                return;
            }
            DateTime startTime = dateStartTime.Value;
            DateTime stopTime = dateStopTime.Value;
            if (startTime > stopTime)
            {
                MessageBox.Show("Start and Stop times are invalid");
                return;
            }

            BtnExport.Tag = BtnExport.Text;
            BtnExport.Text = "Exporting...";
            BtnExport.Enabled = false;
            Cursor.Current = Cursors.WaitCursor;
            Application.DoEvents();

            TimeSpan interval = Resolutions.GetInterval((string)cmbResolution.SelectedItem);
            Thread workerThread = new Thread(start =>
            {
                long processingStartTime = DateTime.UtcNow.Ticks;

                using (HistorianClient client = new HistorianClient(TxtServerIP.Text,int.Parse(TxtHistorianPort.Text)))
                {
                    m_readIndex = 0;
                    m_fillMeasurements.Clear();
                    m_measurementsInOrder.Clear();

                    foreach (var signal in m_selectedMeasurements)
                    {
                        var m = new Measurements();
                        m_fillMeasurements.Add((ulong)signal.PointID, m);
                        m_measurementsInOrder.Add(m);
                    }

                    SeekFilterBase<HistorianKey> timeFilter;
                    if (interval.Ticks != 0)
                        timeFilter = TimestampSeekFilter.CreateFromIntervalData<HistorianKey>(startTime, stopTime, interval, new TimeSpan(TimeSpan.TicksPerMillisecond));
                    else
                        timeFilter = TimestampSeekFilter.CreateFromRange<HistorianKey>(startTime, stopTime);

                    var points = m_selectedMeasurements.Select((x) => (ulong)x.PointID).ToArray();
                    var pointFilter = PointIdMatchFilter.CreateFromList<HistorianKey, HistorianValue>(points);

                    using (var database = client.GetDatabase<HistorianKey, HistorianValue>(TxtHistorianInstance.Text))
                    {
                        string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "Export.csv");

                        using (var fillAdapter = database.GetPointStream(timeFilter, pointFilter).GetFillAdapter())
                        using (var csvStream = new StreamWriter(fileName))
                        {
                            var ultraStream = new UltraStreamWriter(csvStream);
                            //csvStream.AutoFlush = false;
                            csvStream.Write("Timestamp,");
                            foreach (var signal in m_selectedMeasurements)
                            {
                                csvStream.Write(signal.Description);
                                csvStream.Write(',');
                            }
                            csvStream.WriteLine();

                            m_readIndex++;
                            while (fillAdapter.Fill(FillData))
                            {
                                csvStream.Write(fillAdapter.FrameTime.ToString("MM/dd/yyyy hh:mm:ss.fffffff"));
                                csvStream.Write(',');

                                foreach (var signal in m_measurementsInOrder)
                                {
                                    if (signal.ReadNumber == m_readIndex)
                                    {
                                        ultraStream.Write(signal.Value);
                                    }
                                    ultraStream.Write(',');
                                }
                                ultraStream.Flush();
                                csvStream.WriteLine();
                                m_readIndex++;
                            }

                            csvStream.Flush();
                        }
                    }
                }

                Ticks runtime = DateTime.UtcNow.Ticks - processingStartTime;

                BeginInvoke(new Action<Ticks>(r => MessageBox.Show(r.ToElapsedTimeString(2), "Processing Time", MessageBoxButtons.OK, MessageBoxIcon.Information)), runtime);
                BeginInvoke(new Action(RestoreExportButton));
            });


            workerThread.Start();
        }
        public static void TestReadPoints2()
        {
            int pointCount = 0;
            HistorianKey key = new HistorianKey();
            HistorianValue value = new HistorianValue();
            var settings = new HistorianServerDatabaseConfig("PPA", @"C:\Program Files\openHistorian\Archive\", true);
            using (HistorianServer server = new HistorianServer(settings))
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                using (var client = new HistorianClient("127.0.0.1", 12345))
                using (var database = client.GetDatabase<HistorianKey, HistorianValue>(String.Empty))
                {

                    var stream = database.Read(0, (ulong)DateTime.MaxValue.Ticks, new ulong[] { 65, 953, 5562 });
                    while (stream.Read(key, value))
                        pointCount++;

                }
                sw.Stop();
                //MessageBox.Show(sw.Elapsed.TotalSeconds.ToString());
            }
        }
Exemplo n.º 16
0
        private void OpenArchives()
        {
            ArchiveIsOpen = true;

            List<Metadata> measurements = new List<Metadata>();
            string connectionString = "server=" + serverHost + ":" + GEPPort + "; interface=0.0.0.0";
            DataSet metadata = MetadataRetriever.GetMetadata(connectionString, 30000);

            // Reference meta-data tables
            DataTable measurementTable = metadata.Tables["MeasurementDetail"];
            foreach (DataRow measurement in measurementTable.Select("SignalAcronym <> 'STAT' and SignalAcronym <> 'DIGI'"))
            {
                measurements.Add(new Metadata(measurement));
            }

            m_client = new HistorianClient(serverHost, int.Parse(historianPort));
            ArchiveReader = m_client.GetDatabase<HistorianKey, HistorianValue>(instanceName);

            StreamWriter sw = new StreamWriter("measurementList.txt");
            sw.WriteLine("Last opened at {0}", DateTime.Now);
            sw.WriteLine("Historian Instance: {0}, Port: {1}\n", instanceName, historianPort);
            foreach (var item in measurements)
            {
                sw.WriteLine("PointID: {0}, SignalReference: {1}, Description: {2}", item.PointID, item.SignalReference, item.Description);
            }
            sw.Close();
        }