OpenArchive() public method

Returns a stream that can be used to read the archive.
public OpenArchive ( ) : StreamReader
return System.IO.StreamReader
Esempio n. 1
0
        /// <summary>
        /// Loads the history for the item.
        /// </summary>
        public void LoadHistoryData(ISystemContext context, ArchiveItem item)
        {
            // use the beginning of the current hour for the baseline.
            DateTime baseline = DateTime.UtcNow;

            baseline = new DateTime(baseline.Year, baseline.Month, baseline.Day, baseline.Hour, 0, 0, DateTimeKind.Utc);

            using (StreamReader reader = item.OpenArchive())
            {
                // skip configuration line.
                reader.ReadLine();
                item.DataSet = LoadData(context, baseline, reader);
            }

            // create a random dataset if nothing found in the archive,
            if (item.DataSet == null || item.DataSet.Tables[0].Rows.Count == 0)
            {
                CreateData(item);
            }

            // update the timestamp.
            item.LastLoadTime = DateTime.UtcNow;
        }
Esempio n. 2
0
        /// <summary>
        /// Loads the item configuaration.
        /// </summary>
        public bool LoadConfiguration(ISystemContext context, ArchiveItem item)
        {
            using (StreamReader reader = item.OpenArchive())
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();

                    // check for end or error.
                    if (line == null)
                    {
                        break;
                    }

                    // ignore blank lines.
                    line = line.Trim();

                    if (String.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    // ignore commented out lines.
                    if (line.StartsWith("//"))
                    {
                        continue;
                    }

                    BuiltInType dataType               = BuiltInType.String;
                    int         valueRank              = ValueRanks.Scalar;
                    int         samplingInterval       = 0;
                    int         simulationType         = 0;
                    int         amplitude              = 0;
                    int         period                 = 0;
                    int         archiving              = 0;
                    int         stepped                = 0;
                    int         useSlopedExtrapolation = 0;
                    int         treatUncertainAsBad    = 0;
                    int         percentDataBad         = 0;
                    int         percentDataGood        = 0;

                    // get data type.
                    if (!ExtractField(1, ref line, out dataType))
                    {
                        return(false);
                    }

                    // get value rank.
                    if (!ExtractField(1, ref line, out valueRank))
                    {
                        return(false);
                    }

                    // get sampling interval.
                    if (!ExtractField(1, ref line, out samplingInterval))
                    {
                        return(false);
                    }

                    // get simulation type.
                    if (!ExtractField(1, ref line, out simulationType))
                    {
                        return(false);
                    }

                    // get simulation amplitude.
                    if (!ExtractField(1, ref line, out amplitude))
                    {
                        return(false);
                    }

                    // get simulation period.
                    if (!ExtractField(1, ref line, out period))
                    {
                        return(false);
                    }

                    // get flag indicating whether new data is generated.
                    if (!ExtractField(1, ref line, out archiving))
                    {
                        return(false);
                    }

                    // get flag indicating whether stepped interpolation is used.
                    if (!ExtractField(1, ref line, out stepped))
                    {
                        return(false);
                    }

                    // get flag indicating whether sloped interpolation should be used.
                    if (!ExtractField(1, ref line, out useSlopedExtrapolation))
                    {
                        return(false);
                    }

                    // get flag indicating whether sloped interpolation should be used.
                    if (!ExtractField(1, ref line, out treatUncertainAsBad))
                    {
                        return(false);
                    }

                    // get the maximum permitted of bad data in an interval.
                    if (!ExtractField(1, ref line, out percentDataBad))
                    {
                        return(false);
                    }

                    // get the minimum amount of good data in an interval.
                    if (!ExtractField(1, ref line, out percentDataGood))
                    {
                        return(false);
                    }

                    // update the item.
                    item.DataType               = dataType;
                    item.ValueRank              = valueRank;
                    item.SimulationType         = simulationType;
                    item.Amplitude              = amplitude;
                    item.Period                 = period;
                    item.SamplingInterval       = samplingInterval;
                    item.Archiving              = archiving != 0;
                    item.Stepped                = stepped != 0;
                    item.AggregateConfiguration = new AggregateConfiguration();
                    item.AggregateConfiguration.UseServerCapabilitiesDefaults = false;
                    item.AggregateConfiguration.UseSlopedExtrapolation        = useSlopedExtrapolation != 0;
                    item.AggregateConfiguration.TreatUncertainAsBad           = treatUncertainAsBad != 0;
                    item.AggregateConfiguration.PercentDataBad  = (byte)percentDataBad;
                    item.AggregateConfiguration.PercentDataGood = (byte)percentDataGood;
                    break;
                }
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Loads the item configuaration.
        /// </summary>
        public bool LoadConfiguration(ISystemContext context, ArchiveItem item)
        {
            using (StreamReader reader = item.OpenArchive())
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();

                    // check for end or error.
                    if (line == null)
                    {
                        break;
                    }

                    // ignore blank lines.
                    line = line.Trim();

                    if (String.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    // ignore commented out lines.
                    if (line.StartsWith("//"))
                    {
                        continue;
                    }

                    BuiltInType dataType = BuiltInType.String;
                    int valueRank = ValueRanks.Scalar;
                    int samplingInterval = 0;
                    int simulationType = 0;
                    int amplitude = 0;
                    int period = 0;
                    int archiving = 0;
                    int stepped = 0;
                    int useSlopedExtrapolation = 0;
                    int treatUncertainAsBad = 0;
                    int percentDataBad = 0;
                    int percentDataGood = 0;

                    // get data type.
                    if (!ExtractField(1, ref line, out dataType))
                    {
                        return false;
                    }

                    // get value rank.
                    if (!ExtractField(1, ref line, out valueRank))
                    {
                        return false;
                    }

                    // get sampling interval.
                    if (!ExtractField(1, ref line, out samplingInterval))
                    {
                        return false;
                    }

                    // get simulation type.
                    if (!ExtractField(1, ref line, out simulationType))
                    {
                        return false;
                    }

                    // get simulation amplitude.
                    if (!ExtractField(1, ref line, out amplitude))
                    {
                        return false;
                    }

                    // get simulation period.
                    if (!ExtractField(1, ref line, out period))
                    {
                        return false;
                    }

                    // get flag indicating whether new data is generated.
                    if (!ExtractField(1, ref line, out archiving))
                    {
                        return false;
                    }

                    // get flag indicating whether stepped interpolation is used.
                    if (!ExtractField(1, ref line, out stepped))
                    {
                        return false;
                    }

                    // get flag indicating whether sloped interpolation should be used.
                    if (!ExtractField(1, ref line, out useSlopedExtrapolation))
                    {
                        return false;
                    }

                    // get flag indicating whether sloped interpolation should be used.
                    if (!ExtractField(1, ref line, out treatUncertainAsBad))
                    {
                        return false;
                    }

                    // get the maximum permitted of bad data in an interval.
                    if (!ExtractField(1, ref line, out percentDataBad))
                    {
                        return false;
                    }

                    // get the minimum amount of good data in an interval.
                    if (!ExtractField(1, ref line, out percentDataGood))
                    {
                        return false;
                    }
                    
                    // update the item.
                    item.DataType = dataType;
                    item.ValueRank = valueRank;
                    item.SimulationType = simulationType;
                    item.Amplitude = amplitude;
                    item.Period = period;
                    item.SamplingInterval = samplingInterval;
                    item.Archiving = archiving != 0;
                    item.Stepped = stepped != 0;
                    item.AggregateConfiguration = new AggregateConfiguration();
                    item.AggregateConfiguration.UseServerCapabilitiesDefaults = false;
                    item.AggregateConfiguration.UseSlopedExtrapolation = useSlopedExtrapolation != 0;
                    item.AggregateConfiguration.TreatUncertainAsBad = treatUncertainAsBad != 0;
                    item.AggregateConfiguration.PercentDataBad = (byte)percentDataBad;
                    item.AggregateConfiguration.PercentDataGood = (byte)percentDataGood;
                    break;
                }
            }

            return true;
        }
Esempio n. 4
0
        /// <summary>
        /// Loads the history for the item.
        /// </summary>
        public void LoadHistoryData(ISystemContext context, ArchiveItem item)
        {
            // use the beginning of the current hour for the baseline.
            DateTime baseline = DateTime.UtcNow;
            baseline = new DateTime(baseline.Year, baseline.Month, baseline.Day, baseline.Hour, 0, 0, DateTimeKind.Utc);

            using (StreamReader reader = item.OpenArchive())
            {
                // skip configuration line.
                reader.ReadLine();
                item.DataSet = LoadData(context, baseline, reader);
            }

            // create a random dataset if nothing found in the archive,
            if (item.DataSet == null || item.DataSet.Tables[0].Rows.Count == 0)
            {
                CreateData(item);
            }

            // update the timestamp.
            item.LastLoadTime = DateTime.UtcNow;
        }