Ejemplo n.º 1
0
        public static long ConvertVersion1FileHandleDuplicates(string oldFileName, string newFileName, EncodingDefinition compressionMethod, out long readTime, out long sortTime, out long writeTime)
        {
            if (!File.Exists(oldFileName))
            {
                throw new ArgumentException("Old file does not exist", "oldFileName");
            }

            if (File.Exists(newFileName))
            {
                throw new ArgumentException("New file already exists", "newFileName");
            }

            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();
            long           startTime;
            int            count;

            // Derived SortedPointBuffer class increments EntryNumbers instead of removing duplicates
            SortedPointBuffer points;

            startTime = DateTime.UtcNow.Ticks;

            using (OldHistorianReader archiveFile = new OldHistorianReader())
            {
                archiveFile.Open(oldFileName);

                count  = archiveFile.PointsArchived;
                points = new SortedPointBuffer(count, false);

                foreach (OldHistorianReader.DataPoint point in archiveFile.Read())
                {
                    key.Timestamp = (ulong)point.Timestamp.Ticks;
                    key.PointID   = (ulong)point.PointID;

                    value.Value1 = BitConvert.ToUInt64(point.Value);
                    value.Value3 = (ulong)point.Flags;

                    points.TryEnqueue(key, value);
                }
            }

            readTime = DateTime.UtcNow.Ticks - startTime;

            startTime            = DateTime.UtcNow.Ticks;
            points.IsReadingMode = true;
            sortTime             = DateTime.UtcNow.Ticks - startTime;

            startTime = DateTime.UtcNow.Ticks;
            SortedTreeFileSimpleWriter <HistorianKey, HistorianValue> .Create(Path.Combine(FilePath.GetDirectoryName(newFileName), FilePath.GetFileNameWithoutExtension(newFileName) + ".~d2i"), newFileName, 4096, null, compressionMethod, points);

            writeTime = DateTime.UtcNow.Ticks - startTime;

            return(count);
        }
Ejemplo n.º 2
0
        void IArchive.WriteData(IDataPoint dataPoint)
        {
            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            key.PointID   = (ulong)dataPoint.HistorianID;
            key.Timestamp = (ulong)dataPoint.Time.ToDateTime().Ticks;

            value.Value1 = BitConvert.ToUInt64(dataPoint.Value);
            value.Value3 = (ulong)dataPoint.Quality.MeasurementQuality();

            m_clientDatabase.Write(key, value);
        }
        /// <summary>
        /// Publishes <paramref name="measurements"/> for archival.
        /// </summary>
        /// <param name="measurements">Measurements to be archived.</param>
        protected override void ProcessMeasurements(IMeasurement[] measurements)
        {
            foreach (IMeasurement measurement in measurements)
            {
                m_key.Timestamp = (ulong)(long)measurement.Timestamp;
                m_key.PointID   = measurement.Key.ID;

                // Since current time-series measurements are basically all floats - values fit into first value,
                // this will change as value types for time-series framework expands
                m_value.Value1 = BitConvert.ToUInt64((float)measurement.AdjustedValue);
                m_value.Value3 = (ulong)measurement.StateFlags;

                m_inputQueue.Enqueue(m_key, m_value);
            }

            m_measurementsPublished += measurements.Length;
        }