Exemplo n.º 1
0
        private void LoadHostConfigFile(string configFile, ImportParameters importParams)
        {
            XDocument serviceConfig = XDocument.Load(configFile);

            string connectionString = serviceConfig
                                      .Descendants("systemSettings")
                                      .SelectMany(systemSettings => systemSettings.Elements("add"))
                                      .Where(element => "ConnectionString".Equals((string)element.Attribute("name"), StringComparison.OrdinalIgnoreCase))
                                      .Select(element => (string)element.Attribute("value"))
                                      .FirstOrDefault();

            string dataProviderString = serviceConfig
                                        .Descendants("systemSettings")
                                        .SelectMany(systemSettings => systemSettings.Elements("add"))
                                        .Where(element => "DataProviderString".Equals((string)element.Attribute("name"), StringComparison.OrdinalIgnoreCase))
                                        .Select(element => (string)element.Attribute("value"))
                                        .FirstOrDefault();

            Guid nodeID = Guid.Parse(serviceConfig
                                     .Descendants("systemSettings")
                                     .SelectMany(systemSettings => systemSettings.Elements("add"))
                                     .Where(element => "NodeID".Equals((string)element.Attribute("name"), StringComparison.OrdinalIgnoreCase))
                                     .Select(element => (string)element.Attribute("value"))
                                     .FirstOrDefault() ?? Guid.Empty.ToString());

            importParams.InitializeConnection(connectionString, dataProviderString, nodeID);

            StartConsoleProcess(configFile);
        }
Exemplo n.º 2
0
        private static void SavePMUDevice(ImportParameters importParams, ConfigurationCell configCell, Device parentDevice)
        {
            ConfigurationFrame       configFrame = importParams.TargetConfigFrame;
            TableOperations <Device> deviceTable = importParams.DeviceTable;
            Guid   nodeID        = importParams.NodeID;
            Device device        = s_devices.FindChildDeviceByIDCode(parentDevice.ID, configCell.IDCode) ?? deviceTable.NewDevice();
            string deviceAcronym = configCell.IDLabel;
            string deviceName    = null;

            if (string.IsNullOrWhiteSpace(deviceAcronym))
            {
                if (string.IsNullOrWhiteSpace(configCell.StationName))
                {
                    throw new InvalidOperationException("Unable to get station name or ID label for PMU from parsed device configuration cell");
                }

                deviceAcronym = configCell.StationName.GetCleanAcronym();
            }

            if (!string.IsNullOrWhiteSpace(configCell.StationName))
            {
                deviceName = configCell.StationName;
            }

            // Keep old device acronym for measurement updates
            device.OldAcronym = string.IsNullOrWhiteSpace(device.Acronym) ? deviceAcronym : device.Acronym;

            // Assign new device fields
            device.NodeID          = nodeID;
            device.ParentID        = parentDevice.ID;
            device.HistorianID     = configFrame.HistorianID;
            device.Acronym         = deviceAcronym;
            device.Name            = deviceName ?? deviceAcronym;
            device.ProtocolID      = importParams.IeeeC37_118ProtocolID;
            device.FramesPerSecond = configCell.FrameRate;
            device.AccessID        = configCell.IDCode;
            device.IsConcentrator  = false;
            device.Enabled         = true;

            // Check if this is a new device or an edit to an existing one
            if (device.ID == 0)
            {
                // Add new device record
                deviceTable.AddNewDevice(device);

                // Get newly added device with auto-incremented ID
                Device newDevice = deviceTable.QueryDevice(device.Acronym);

                // Save associated device records
                SaveDeviceRecords(importParams, configCell, newDevice);
            }
            else
            {
                // Update existing device record
                deviceTable.UpdateDevice(device);

                // Save associated device records
                SaveDeviceRecords(importParams, configCell, device);
            }
        }
Exemplo n.º 3
0
        private static void SaveDeviceRecords(ImportParameters importParams, ConfigurationCell configCell, Device device)
        {
            ConfigurationFrame            configFrame      = importParams.TargetConfigFrame;
            AdoDataConnection             connection       = importParams.Connection;
            TableOperations <Measurement> measurementTable = new(connection);

            // Add frequency
            SaveFixedMeasurement(importParams, s_deviceSignalTypes["FREQ"], device, measurementTable);

            // Add dF/dt
            SaveFixedMeasurement(importParams, s_deviceSignalTypes["DFDT"], device, measurementTable);

            // Add status flags
            SaveFixedMeasurement(importParams, s_deviceSignalTypes["FLAG"], device, measurementTable);

            // Add analogs
            SignalType analogSignalType = s_deviceSignalTypes["ALOG"];

            for (int i = 0; i < configCell.AnalogDefinitions.Count; i++)
            {
                if (configCell.AnalogDefinitions[i] is not AnalogDefinition analogDefinition)
                {
                    continue;
                }

                int    index = i + 1;
                string oldSignalReference = $"{device.OldAcronym}-{analogSignalType.Suffix}{index}";
                string newSignalReference = $"{device.Acronym}-{analogSignalType.Suffix}{index}";

                // Query existing measurement record for specified signal reference - function will create a new blank measurement record if one does not exist
                Measurement measurement = measurementTable.QueryMeasurement(oldSignalReference);
                string      pointTag    = importParams.CreateIndexedPointTag(device.Acronym, analogSignalType.Acronym, index);

                measurement.DeviceID        = device.ID;
                measurement.HistorianID     = configFrame.HistorianID;
                measurement.PointTag        = pointTag;
                measurement.AlternateTag    = analogDefinition.Label;
                measurement.Description     = $"{device.Acronym} Analog Value {index} {analogDefinition.AnalogType}: {analogDefinition.Label}{(string.IsNullOrWhiteSpace(analogDefinition.Description) ? "" : $" - {analogDefinition.Description}")}";
                measurement.SignalReference = newSignalReference;
                measurement.SignalTypeID    = analogSignalType.ID;
                measurement.Internal        = true;
                measurement.Enabled         = true;

                measurementTable.AddNewOrUpdateMeasurement(measurement);
            }
Exemplo n.º 4
0
        private static void UpdatePMUDevices(ImportParameters importParams, Device parentDevice)
        {
            ConfigurationFrame configFrame = importParams.TargetConfigFrame;

            foreach (IConfigurationCell cell in configFrame.Cells)
            {
                if (cell is ConfigurationCell configCell)
                {
                    if (configCell.Delete)
                    {
                        DeletePMUDevice(importParams, configCell, parentDevice);
                    }
                    else
                    {
                        SavePMUDevice(importParams, configCell, parentDevice);
                    }
                }
            }
        }
Exemplo n.º 5
0
 private static void DeletePMUDevice(ImportParameters importParams, ConfigurationCell configCell, Device parentDevice) =>
 s_devices.DeleteChildDeviceByIDCode(importParams.DeviceTable, parentDevice.ID, configCell.IDCode);
Exemplo n.º 6
0
        public static void SaveConnection(ImportParameters importParams)
        {
            AdoDataConnection            connection      = importParams.Connection;
            ConfigurationFrame           configFrame     = importParams.TargetConfigFrame;
            TableOperations <Device>     deviceTable     = importParams.DeviceTable;
            TableOperations <SignalType> signalTypeTable = new(connection);
            Guid   nodeID           = importParams.NodeID;
            string connectionString = importParams.EditedConnectionString;

            // Load a list of all existing device records
            s_devices = deviceTable.QueryRecords().ToArray();

            // Apply other connection string parameters that are specific to device operation
            importParams.EditedConnectionString = string.Format(ConnectionStringTemplate, importParams.EditedConnectionString);

            if (s_deviceSignalTypes is null)
            {
                s_deviceSignalTypes = signalTypeTable.LoadSignalTypes("PMU").ToDictionary(key => key.Acronym, StringComparer.OrdinalIgnoreCase);
            }

            if (s_phasorSignalTypes is null)
            {
                s_phasorSignalTypes = signalTypeTable.LoadSignalTypes("Phasor").ToDictionary(key => key.Acronym, StringComparer.OrdinalIgnoreCase);
            }

            Device device = s_devices.FindDeviceByIDCodeAndIPAddress(configFrame.IDCode, importParams.IPAddress) ?? deviceTable.NewDevice();
            Dictionary <string, string> settings = connectionString.ParseKeyValuePairs();

            bool autoStartDataParsingSequence = true;
            bool skipDisableRealTimeData      = false;

            // Handle connection string parameters that are fields in the device table
            if (settings.ContainsKey("autoStartDataParsingSequence"))
            {
                autoStartDataParsingSequence = bool.Parse(settings["autoStartDataParsingSequence"]);
                settings.Remove("autoStartDataParsingSequence");
                connectionString = settings.JoinKeyValuePairs();
            }

            if (settings.ContainsKey("skipDisableRealTimeData"))
            {
                skipDisableRealTimeData = bool.Parse(settings["skipDisableRealTimeData"]);
                settings.Remove("skipDisableRealTimeData");
                connectionString = settings.JoinKeyValuePairs();
            }

            string deviceAcronym = configFrame.Acronym;
            string deviceName    = null;

            if (string.IsNullOrWhiteSpace(deviceAcronym))
            {
                if (string.IsNullOrWhiteSpace(configFrame.Name))
                {
                    throw new InvalidOperationException("Unable to get name or acronym for PDC from parsed configuration frame");
                }

                deviceAcronym = configFrame.Name.GetCleanAcronym();
            }

            if (!string.IsNullOrWhiteSpace(configFrame.Name))
            {
                deviceName = configFrame.Name;
            }

            device.NodeID                       = nodeID;
            device.ParentID                     = null;
            device.HistorianID                  = configFrame.HistorianID;
            device.Acronym                      = deviceAcronym;
            device.Name                         = deviceName ?? deviceAcronym;
            device.ProtocolID                   = importParams.IeeeC37_118ProtocolID;
            device.FramesPerSecond              = configFrame.FrameRate;
            device.AccessID                     = configFrame.IDCode;
            device.IsConcentrator               = true;
            device.ConnectionString             = connectionString;
            device.AutoStartDataParsingSequence = autoStartDataParsingSequence;
            device.SkipDisableRealTimeData      = skipDisableRealTimeData;
            device.Enabled                      = true;

            // Check if this is a new device or an edit to an existing one
            if (device.ID == 0)
            {
                // Add new device record
                deviceTable.AddNewDevice(device);

                // Get newly added device with auto-incremented ID
                Device newDevice = deviceTable.QueryDevice(device.Acronym);

                // Save associated PMU records
                UpdatePMUDevices(importParams, newDevice);
            }
            else
            {
                // Update existing device record
                deviceTable.UpdateDevice(device);

                // Save associated PMU records
                UpdatePMUDevices(importParams, device);
            }
        }