コード例 #1
0
        public void TestOpt3()
        {
            using (StreamWriter csvStream = new StreamWriter("C:\\temp\\file.csv"))
            {
                UltraStreamWriter usw    = new UltraStreamWriter(csvStream);
                IFormatProvider   format = csvStream.FormatProvider;
                NumberFormatInfo  info   = NumberFormatInfo.GetInstance(format);

                Stopwatch sw = new Stopwatch();
                sw.Start();
                for (float x = 0.216421654f; x < 2000000; x++)
                {
                    usw.Write(x);
                    usw.Write(',');
                }
                usw.Flush();
                sw.Stop();
                Console.WriteLine(sw.Elapsed.TotalSeconds);
            }
        }
コード例 #2
0
        public void TestOpt3()
        {
            using (var csvStream = new StreamWriter("C:\\temp\\file.csv"))
            {
                var usw = new UltraStreamWriter(csvStream);
                var format = csvStream.FormatProvider;
                var info = NumberFormatInfo.GetInstance(format);

                Stopwatch sw = new Stopwatch();
                sw.Start();
                for (float x = 0.216421654f; x < 2000000; x++)
                {
                    usw.Write(x);
                    usw.Write(',');
                }
                usw.Flush();
                sw.Stop();
                Console.WriteLine(sw.Elapsed.TotalSeconds);
            }
        }
コード例 #3
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();
        }