private void button2_Click(object sender, EventArgs e) { using (AdoDataConnection connection = new AdoDataConnection("systemSettings")) { GSF.Data.Model.TableOperations <PQds.Model.CustomField> customFldTbl = new GSF.Data.Model.TableOperations <PQds.Model.CustomField>(connection); if (this.textBox1.Text.Length < 1) { MessageBox.Show("A Domain name has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (customFldTbl.QueryRecordCountWhere("domain = {0}", this.textBox1.Text) > 0) { MessageBox.Show("This domain already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { PQds.Model.CustomField fld = new Model.CustomField() { EventID = m_eventid, AssetID = m_assetid, key = "Key", Value = "Value", Type = "T", domain = this.textBox1.Text }; customFldTbl.AddNewRecord(fld); } } this.Close(); }
private void button2_Click(object sender, EventArgs e) { string localAppData = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}{Path.DirectorySeparatorChar}PQio{Path.DirectorySeparatorChar}DataBase.db"; string connectionstring = $"Data Source={localAppData}; Version=3; Foreign Keys=True; FailIfMissing=True"; using (AdoDataConnection connection = new AdoDataConnection(connectionstring, dataprovider)) { GSF.Data.Model.TableOperations <PQio.Model.CustomField> customFldTbl = new GSF.Data.Model.TableOperations <PQio.Model.CustomField>(connection); if (this.textBox1.Text.Length < 1) { MessageBox.Show("A Domain name has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (customFldTbl.QueryRecordCountWhere("domain = {0}", this.textBox1.Text) > 0) { MessageBox.Show("This domain already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { PQio.Model.CustomField fld = new Model.CustomField() { EventID = m_eventid, AssetID = m_assetid, key = "Key", Value = "Value", Type = "T", domain = this.textBox1.Text }; customFldTbl.AddNewRecord(fld); } } this.Close(); }
private void ParseSeries(GSF.PQDIF.Logical.ChannelInstance channelInstance, PQds.Model.Channel channel, PQds.Model.Event evt) { PQds.Model.DataSeries dataSeries = new DataSeries(); dataSeries.EventID = evt.ID; dataSeries.ChannelID = channel.ID; Guid quantityType = channelInstance.Definition.QuantityTypeID; SeriesInstance timeSeries = null; SeriesInstance valuesSeries = null; if (isPOW(quantityType)) { timeSeries = channelInstance.SeriesInstances.Single(series => series.Definition.ValueTypeID == SeriesValueType.Time); valuesSeries = channelInstance.SeriesInstances.Single(series => series.Definition.ValueTypeID == SeriesValueType.Val); } else { return; } List <double> values = valuesSeries.OriginalValues.Select(val => Convert.ToDouble(val)).ToList(); List <DateTime> timeStamps = new List <DateTime>(); if (timeSeries.Definition.QuantityUnits == QuantityUnits.Seconds) { // If time series is in seconds from start time of the observation record, // TimeValues must be calculated by adding values to start time timeStamps = timeSeries.OriginalValues .Select(Convert.ToDouble) .Select(seconds => (long)(seconds * TimeSpan.TicksPerSecond)) .Select(TimeSpan.FromTicks) .Select(timeSpan => channelInstance.ObservationRecord.StartTime + timeSpan) .ToList(); } else if (timeSeries.Definition.QuantityUnits == QuantityUnits.Timestamp) { // If time series is a collection of absolute time, seconds from start time // must be calculated by subtracting the start time of the observation record timeStamps = timeSeries.OriginalValues.Cast <DateTime>().ToList(); } dataSeries.Series = timeStamps.Select((item, index) => new PQds.Model.DataPoint() { Time = item, Value = values[index] }).ToList(); using (AdoDataConnection connection = new AdoDataConnection("systemSettings")) { GSF.Data.Model.TableOperations <PQds.Model.DataSeries> dataSeriesTable = new GSF.Data.Model.TableOperations <PQds.Model.DataSeries>(connection); dataSeriesTable.AddNewRecord(dataSeries); } }
private PQio.Model.Event ParseObservationRecord(GSF.PQDIF.Logical.ObservationRecord record, AdoDataConnection connection) { Event evt = new Event(); evt.EventTime = record.StartTime; evt.Name = record.Name; evt.GUID = new Guid().ToString(); //Add Disturbance Category record in GSF GSF.Data.Model.TableOperations <Event> evtTable = new GSF.Data.Model.TableOperations <Event>(connection); evtTable.AddNewRecord(evt); evt.ID = ModelID.GetID <Event>(connection); return(evt); }
private PQds.Model.Event ParseObservationRecord(GSF.PQDIF.Logical.ObservationRecord record) { Event evt = new Event(); evt.EventTime = record.StartTime; evt.Name = record.Name; evt.GUID = new Guid().ToString(); //Add Disturbance Category record in GSF using (AdoDataConnection connection = new AdoDataConnection("systemSettings")) { GSF.Data.Model.TableOperations <PQds.Model.Event> evtTable = new GSF.Data.Model.TableOperations <PQds.Model.Event>(connection); evtTable.AddNewRecord(evt); evt.ID = PQds.Model.ModelID.GetID <Event>(connection); } return(evt); }
private void GenereateDataSensitivities(string note, int code) { // If we overwrite we need to create a set of Asset and event IDs that need to create a Data Sesitivity Code List <Tuple <int, int> > combinations = new List <Tuple <int, int> >(); using (AdoDataConnection connection = new AdoDataConnection(connectionstring, dataprovider)) { GSF.Data.Model.TableOperations <PQio.Model.Channel> channelTbl = new GSF.Data.Model.TableOperations <PQio.Model.Channel>(connection); GSF.Data.Model.TableOperations <PQio.Model.Asset> assetTbl = new GSF.Data.Model.TableOperations <PQio.Model.Asset>(connection); GSF.Data.Model.TableOperations <PQio.Model.DataSeries> seriesTbl = new GSF.Data.Model.TableOperations <PQio.Model.DataSeries>(connection); GSF.Data.Model.TableOperations <PQio.Model.DataSensitivity> sensitivityTbl = new GSF.Data.Model.TableOperations <PQio.Model.DataSensitivity>(connection); foreach (int assetID in assetTbl.QueryRecords().Select(item => item.ID)) { foreach (int channelID in channelTbl.QueryRecordsWhere("AssetID = {0}", assetID).Select(item => item.ID)) { foreach (int evtID in seriesTbl.QueryRecordsWhere("ChannelID = {0}", channelID).Select(item => item.EventID)) { combinations.Add(new Tuple <int, int>(assetID, evtID)); } } } combinations = combinations.Distinct().ToList(); foreach (Tuple <int, int> item in combinations) { if (sensitivityTbl.QueryRecordCountWhere("Event = {0} AND Asset = {1}", item.Item2, item.Item1) == 0) { sensitivityTbl.AddNewRecord(new Model.DataSensitivity() { Asset = item.Item1, Event = item.Item2, DataSensitivityCode = code, Note = note }); } } } }
private Channel ParseChannel(Meter meter, GSF.PQDIF.Logical.ChannelDefinition channeldef, AdoDataConnection connection) { Channel channel = new Channel(); channel.MeterID = meter.ID; channel.Name = channeldef.ChannelName; GSF.PQDIF.Logical.QuantityMeasured quantity = channeldef.QuantityMeasured; Guid quantityType = channeldef.QuantityTypeID; GSF.PQDIF.Logical.Phase phase = channeldef.Phase; if (isRMS(quantityType)) { channel.SignalType = SignalType.RMS; } else if (isPOW(quantityType)) { channel.SignalType = SignalType.PointOnWave; } else { channel.SignalType = SignalType.other; } Boolean isV = quantity == QuantityMeasured.Voltage; Boolean isI = quantity == QuantityMeasured.Current; Boolean isA = (phase == Phase.AN) || (phase == Phase.AB); Boolean isB = (phase == Phase.BN) || (phase == Phase.BC); Boolean isC = (phase == Phase.CN) || (phase == Phase.CA); Boolean isN = phase == Phase.Residual; string measurementname = MeasurementType.other; if (isV && isA) { measurementname = MeasurementType.VoltageA; } else if (isV && isB) { measurementname = MeasurementType.VoltageB; } else if (isV && isC) { measurementname = MeasurementType.VoltageC; } else if (isI && isA) { measurementname = MeasurementType.CurrentA; } else if (isI && isB) { measurementname = MeasurementType.CurrentB; } else if (isI && isC) { measurementname = MeasurementType.CurrentC; } else if (isV && isN) { measurementname = MeasurementType.other; } else if (isI && isN) { measurementname = MeasurementType.other; } GSF.Data.Model.TableOperations <Channel> channelTable = new GSF.Data.Model.TableOperations <Channel>(connection); channel.MeasurementType = measurementname; channelTable.AddNewRecord(channel); channel.ID = ModelID.GetID <Channel>(connection); return(channel); }
private void Parse(string filename) { List <ObservationRecord> observationRecords; List <DataSourceRecord> dataSourceRecords; using (LogicalParser logicalParser = new LogicalParser(filename)) { observationRecords = new List <ObservationRecord>(); logicalParser.Open(); while (logicalParser.HasNextObservationRecord()) { observationRecords.Add(logicalParser.NextObservationRecord()); } dataSourceRecords = logicalParser.DataSourceRecords; } this.m_previousProgress = this.m_previousProgress + 50; this.mProgress.Report(this.m_previousProgress); if (observationRecords.Count == 0) { return; } if (dataSourceRecords.Count != 1) { return; } //create Meter Definition //For now assume a single meter Meter meter = new Meter(); meter.DeviceName = dataSourceRecords[0].DataSourceName; meter.Owner = dataSourceRecords[0].DataSourceOwner; meter.DeviceAlias = GSF.PQDIF.Logical.Equipment.ToString(dataSourceRecords[0].EquipmentID); meter.DeviceLocation = dataSourceRecords[0].DataSourceLocation; if (dataSourceRecords[0].Latitude < uint.MaxValue) { meter.Latitude = dataSourceRecords[0].Latitude; } if (dataSourceRecords[0].Longitude < uint.MaxValue) { meter.Longitude = dataSourceRecords[0].Longitude; } meter.AccountName = GSF.PQDIF.Logical.Vendor.ToString(dataSourceRecords[0].VendorID); using (TransactionScope scope = new TransactionScope()) { AdoDataConnection connection = new AdoDataConnection(connectionstring, dataprovider); GSF.Data.Model.TableOperations <Meter> meterTable = new GSF.Data.Model.TableOperations <Meter>(connection); meterTable.AddNewRecord(meter); meter.ID = ModelID.GetID <Meter>(connection); //create Channel Definitions List <PQio.Model.Channel> channels = dataSourceRecords[0].ChannelDefinitions.Select(channel => ParseChannel(meter, channel, connection)).ToList(); List <PQio.Model.Event> events = new List <Event>(); //create Event Definitions foreach (ObservationRecord record in observationRecords) { //Create Event Event evt = ParseObservationRecord(record, connection); //create DataSeries objects foreach (ChannelInstance channelInstance in record.ChannelInstances) { ParseSeries(channelInstance, channels[(int)channelInstance.ChannelDefinitionIndex], evt, connection); } events.Add(evt); } // Remove Channels whithout data channels = channels.FindAll(item => RemoveEmptyChannel(item, connection)).ToList(); events = events.FindAll(item => RemoveEmptyEvents(item, connection)).ToList(); // Remove Channels whithout data channels = channels.FindAll(item => RemoveEmptyChannel(item, connection)).ToList(); // If only one set of data it's easy to keep only single line int nVa = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.VoltageA); int nVb = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.VoltageB); int nVc = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.VoltageC); int nIa = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.CurrentA); int nIb = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.CurrentB); int nIc = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.CurrentC); if (nVa == 1 && nVb == 1 && nVc == 1) { //Create new asset Asset asset = new Asset() { AssetKey = String.Format("Asset 1 ({0})", meter.AccountName) }; GSF.Data.Model.TableOperations <Asset> assetTable = new GSF.Data.Model.TableOperations <Asset>(connection); assetTable.AddNewRecord(asset); asset.ID = ModelID.GetID <Asset>(connection); GSF.Data.Model.TableOperations <Channel> channelTable = new GSF.Data.Model.TableOperations <Channel>(connection); Channel Va = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.VoltageA); Channel Vb = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.VoltageB); Channel Vc = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.VoltageC); Va.AssetID = asset.ID; Vb.AssetID = asset.ID; Vc.AssetID = asset.ID; channelTable.UpdateRecord(Va); channelTable.UpdateRecord(Vb); channelTable.UpdateRecord(Vc); if (nIa == 1 && nIb == 1 && nIc == 1) { Channel Ia = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.CurrentA); Channel Ib = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.CurrentB); Channel Ic = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.CurrentC); Ia.AssetID = asset.ID; Ib.AssetID = asset.ID; Ic.AssetID = asset.ID; channelTable.UpdateRecord(Ia); channelTable.UpdateRecord(Ib); channelTable.UpdateRecord(Ic); } } scope.Complete(); } this.m_previousProgress = this.m_previousProgress + 50; this.mProgress.Report(this.m_previousProgress); }