/// <summary>
        /// Loads <see cref="OutputStreamDeviceDigital"/> information as an <see cref="ObservableCollection{T}"/> style list.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="keys">Keys of the measurement to be loaded from  the database</param>
        /// <returns>Collection of <see cref="OutputStreamDeviceDigital"/>.</returns>
        public static ObservableCollection <OutputStreamDeviceDigital> Load(AdoDataConnection database, IList <int> keys)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                string query;
                string commaSeparatedKeys;

                OutputStreamDeviceDigital[] outputStreamDeviceDigitalList = null;
                DataTable outputStreamDeviceDigitalTable;
                int       id;

                if ((object)keys != null && keys.Count > 0)
                {
                    commaSeparatedKeys = keys.Select(key => "" + key.ToString() + "").Aggregate((str1, str2) => str1 + "," + str2);
                    query = database.ParameterizedQueryString(string.Format("SELECT NodeID, OutputStreamDeviceID, ID, Label, MaskValue, LoadOrder " +
                                                                            "FROM OutputStreamDeviceDigital WHERE ID IN ({0})", commaSeparatedKeys));

                    outputStreamDeviceDigitalTable = database.Connection.RetrieveData(database.AdapterType, query, DefaultTimeout);
                    outputStreamDeviceDigitalList  = new OutputStreamDeviceDigital[outputStreamDeviceDigitalTable.Rows.Count];

                    foreach (DataRow row in outputStreamDeviceDigitalTable.Rows)
                    {
                        id = row.ConvertField <int>("ID");

                        outputStreamDeviceDigitalList[keys.IndexOf(id)] = new OutputStreamDeviceDigital()
                        {
                            NodeID = database.Guid(row, "NodeID"),
                            OutputStreamDeviceID = row.ConvertField <int>("OutputStreamDeviceID"),
                            ID        = id,
                            Label     = row.Field <string>("Label"),
                            MaskValue = row.ConvertField <int>("MaskValue"),
                            LoadOrder = row.ConvertField <int>("LoadOrder")
                        };
                    }
                }

                return(new ObservableCollection <OutputStreamDeviceDigital>(outputStreamDeviceDigitalList ?? new OutputStreamDeviceDigital[0]));
            }
            finally
            {
                if (createdConnection && database != null)
                {
                    database.Dispose();
                }
            }
        }
        /// <summary>
        /// Saves <see cref="OutputStreamDeviceDigital"/> information to database.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="outputStreamDeviceDigital">Information about <see cref="OutputStreamDeviceDigital"/>.</param>
        /// <returns>String, for display use, indicating success.</returns>
        public static string Save(AdoDataConnection database, OutputStreamDeviceDigital outputStreamDeviceDigital)
        {
            bool   createdConnection = false;
            string query;

            try
            {
                createdConnection = CreateConnection(ref database);

                if (outputStreamDeviceDigital.ID == 0)
                {
                    query = database.ParameterizedQueryString("INSERT INTO OutputStreamDeviceDigital (NodeID, OutputStreamDeviceID, Label, MaskValue, LoadOrder, " +
                                                              "UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8})", "nodeID", "outputStreamDeviceID", "label",
                                                              "maskValue", "loadOrder", "updatedBy", "updatedOn", "createdBy", "createdOn");

                    database.Connection.ExecuteNonQuery(query, DefaultTimeout, database.CurrentNodeID(), outputStreamDeviceDigital.OutputStreamDeviceID,
                                                        outputStreamDeviceDigital.Label, outputStreamDeviceDigital.MaskValue, outputStreamDeviceDigital.LoadOrder, CommonFunctions.CurrentUser,
                                                        database.UtcNow, CommonFunctions.CurrentUser, database.UtcNow);
                }
                else
                {
                    query = database.ParameterizedQueryString("UPDATE OutputStreamDeviceDigital SET NodeID = {0}, OutputStreamDeviceID = {1}, Label = {2}, MaskValue = {3}, " +
                                                              "LoadOrder = {4}, UpdatedBy = {5}, UpdatedOn = {6} WHERE ID = {7}", "nodeID", "outputStreamDeviceID", "label", "maskValue", "loadOrder", "updatedBy",
                                                              "updatedOn", "id");

                    database.Connection.ExecuteNonQuery(query, DefaultTimeout, outputStreamDeviceDigital.NodeID, outputStreamDeviceDigital.OutputStreamDeviceID,
                                                        outputStreamDeviceDigital.Label, outputStreamDeviceDigital.MaskValue, outputStreamDeviceDigital.LoadOrder, CommonFunctions.CurrentUser,
                                                        database.UtcNow, outputStreamDeviceDigital.ID);
                }

                return("OutputStreamDeviceDigital information saved successfully");
            }
            finally
            {
                if (createdConnection && database != null)
                {
                    database.Dispose();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds multiple devices to output steam.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="outputStreamID">ID of the output stream to which devices needs to be added.</param>
        /// <param name="devices">Collection of devices to be added.</param>
        /// <param name="addDigitals">Boolean flag indicating if analogs should be added.</param>
        /// <param name="addAnalogs">Boolean flag indicating if digirals should be added.</param>
        /// <returns>String, for display use, indicating success.</returns>
        public static string AddDevices(AdoDataConnection database, int outputStreamID, ObservableCollection <Device> devices, bool addDigitals, bool addAnalogs)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                foreach (Device device in devices)
                {
                    OutputStreamDevice outputStreamDevice = new OutputStreamDevice();
                    outputStreamDevice.NodeID     = device.NodeID;
                    outputStreamDevice.AdapterID  = outputStreamID;
                    outputStreamDevice.Acronym    = device.Acronym.Substring(device.Acronym.LastIndexOf("!", StringComparison.Ordinal) + 1);
                    outputStreamDevice.BpaAcronym = string.Empty;
                    outputStreamDevice.Name       = device.Name;
                    outputStreamDevice.LoadOrder  = device.LoadOrder;
                    outputStreamDevice.Enabled    = true;
                    outputStreamDevice.IDCode     = device.AccessID;
                    Save(database, outputStreamDevice);

                    outputStreamDevice = GetOutputStreamDevice(database, "WHERE Acronym = '" + outputStreamDevice.Acronym + "' AND AdapterID = " + outputStreamID);

                    if ((object)outputStreamDevice != null)
                    {
                        IList <int> keys = Phasor.LoadKeys(database, device.ID);
                        ObservableCollection <Phasor> phasors = Phasor.Load(database, keys);
                        foreach (Phasor phasor in phasors)
                        {
                            OutputStreamDevicePhasor outputStreamDevicePhasor = new OutputStreamDevicePhasor();
                            outputStreamDevicePhasor.NodeID = device.NodeID;
                            outputStreamDevicePhasor.OutputStreamDeviceID = outputStreamDevice.ID;
                            outputStreamDevicePhasor.Label     = phasor.Label;
                            outputStreamDevicePhasor.Type      = phasor.Type;
                            outputStreamDevicePhasor.Phase     = phasor.Phase;
                            outputStreamDevicePhasor.LoadOrder = phasor.SourceIndex;
                            OutputStreamDevicePhasor.Save(database, outputStreamDevicePhasor);
                        }

                        ObservableCollection <Measurement> measurements = Measurement.Load(database, device.ID);
                        int analogIndex = 0;
                        foreach (Measurement measurement in measurements)
                        {
                            if (measurement.SignalAcronym != "STAT" && measurement.SignalAcronym != "QUAL")
                            {
                                measurement.SignalReference = measurement.SignalReference.Substring(measurement.SignalReference.LastIndexOf("!", StringComparison.Ordinal) + 1);

                                if ((measurement.SignalAcronym != "ALOG" && measurement.SignalAcronym != "DIGI") || (measurement.SignalAcronym == "ALOG" && addAnalogs) || (measurement.SignalAcronym == "DIGI" && addDigitals))
                                {
                                    OutputStreamMeasurement outputStreamMeasurement = new OutputStreamMeasurement();
                                    outputStreamMeasurement.NodeID          = device.NodeID;
                                    outputStreamMeasurement.AdapterID       = outputStreamID;
                                    outputStreamMeasurement.HistorianID     = measurement.HistorianID;
                                    outputStreamMeasurement.PointID         = measurement.PointID;
                                    outputStreamMeasurement.SignalReference = measurement.SignalReference;
                                    OutputStreamMeasurement.Save(database, outputStreamMeasurement);
                                }

                                if (addAnalogs && measurement.SignalAcronym == "ALOG")
                                {
                                    OutputStreamDeviceAnalog outputStreamDeviceAnalog = new OutputStreamDeviceAnalog();
                                    outputStreamDeviceAnalog.NodeID = device.NodeID;
                                    outputStreamDeviceAnalog.OutputStreamDeviceID = outputStreamDevice.ID;
                                    outputStreamDeviceAnalog.Label = string.IsNullOrEmpty(measurement.AlternateTag) ? device.Acronym.Length > 12 ? device.Acronym.Substring(0, 12) + ":A" + analogIndex : device.Acronym + ":A" + analogIndex : measurement.AlternateTag; // measurement.PointTag;

                                    int charIndex = measurement.SignalReference.LastIndexOf("-", StringComparison.Ordinal);
                                    int signalIndex;

                                    if (charIndex >= 0 && charIndex + 3 < measurement.SignalReference.Length && int.TryParse(measurement.SignalReference.Substring(charIndex + 3), out signalIndex))
                                    {
                                        outputStreamDeviceAnalog.LoadOrder = signalIndex;
                                    }
                                    else
                                    {
                                        outputStreamDeviceAnalog.LoadOrder = 999;
                                    }

                                    OutputStreamDeviceAnalog.Save(database, outputStreamDeviceAnalog);
                                    analogIndex++;
                                }
                                else if (addDigitals && measurement.SignalAcronym == "DIGI")
                                {
                                    OutputStreamDeviceDigital outputStreamDeviceDigital = new OutputStreamDeviceDigital();
                                    outputStreamDeviceDigital.NodeID = device.NodeID;
                                    outputStreamDeviceDigital.OutputStreamDeviceID = outputStreamDevice.ID;
                                    outputStreamDeviceDigital.Label = string.IsNullOrEmpty(measurement.AlternateTag) ? DefaultDigitalLabel : measurement.AlternateTag;     // measurement.PointTag;

                                    int charIndex = measurement.SignalReference.LastIndexOf("-", StringComparison.Ordinal);
                                    int signalIndex;

                                    if (charIndex >= 0 && charIndex + 3 < measurement.SignalReference.Length && int.TryParse(measurement.SignalReference.Substring(charIndex + 3), out signalIndex))
                                    {
                                        outputStreamDeviceDigital.LoadOrder = signalIndex;
                                    }
                                    else
                                    {
                                        outputStreamDeviceDigital.LoadOrder = 999;
                                    }

                                    OutputStreamDeviceDigital.Save(database, outputStreamDeviceDigital);
                                }
                            }
                        }
                    }
                }

                return("Output Stream Device(s) added successfully!");
            }
            finally
            {
                if (createdConnection && database != null)
                {
                    database.Dispose();
                }
            }
        }
        /// <summary>
        /// Adds multiple devices to output steam.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="outputStreamID">ID of the output stream to which devices needs to be added.</param>
        /// <param name="devices">Collection of devices to be added.</param>
        /// <param name="addDigitals">Boolean flag indicating if analogs should be added.</param>
        /// <param name="addAnalogs">Boolean flag indicating if digirals should be added.</param>
        /// <returns>String, for display use, indicating success.</returns>
        public static string AddDevices(AdoDataConnection database, int outputStreamID, ObservableCollection<Device> devices, bool addDigitals, bool addAnalogs)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                foreach (Device device in devices)
                {
                    OutputStreamDevice outputStreamDevice = new OutputStreamDevice();
                    outputStreamDevice.NodeID = device.NodeID;
                    outputStreamDevice.AdapterID = outputStreamID;
                    outputStreamDevice.Acronym = device.Acronym.Substring(device.Acronym.LastIndexOf("!", StringComparison.Ordinal) + 1);
                    outputStreamDevice.BpaAcronym = string.Empty;
                    outputStreamDevice.Name = device.Name;
                    outputStreamDevice.LoadOrder = device.LoadOrder;
                    outputStreamDevice.Enabled = true;
                    outputStreamDevice.IDCode = device.AccessID;
                    Save(database, outputStreamDevice);

                    outputStreamDevice = GetOutputStreamDevice(database, "WHERE Acronym = '" + outputStreamDevice.Acronym + "' AND AdapterID = " + outputStreamID);

                    if ((object)outputStreamDevice != null)
                    {
                        IList<int> keys = Phasor.LoadKeys(database, device.ID);
                        ObservableCollection<Phasor> phasors = Phasor.Load(database, keys);
                        foreach (Phasor phasor in phasors)
                        {
                            OutputStreamDevicePhasor outputStreamDevicePhasor = new OutputStreamDevicePhasor();
                            outputStreamDevicePhasor.NodeID = device.NodeID;
                            outputStreamDevicePhasor.OutputStreamDeviceID = outputStreamDevice.ID;
                            outputStreamDevicePhasor.Label = phasor.Label;
                            outputStreamDevicePhasor.Type = phasor.Type;
                            outputStreamDevicePhasor.Phase = phasor.Phase;
                            outputStreamDevicePhasor.LoadOrder = phasor.SourceIndex;
                            OutputStreamDevicePhasor.Save(database, outputStreamDevicePhasor);
                        }

                        ObservableCollection<Measurement> measurements = Measurement.Load(database, device.ID);
                        int analogIndex = 0;
                        foreach (Measurement measurement in measurements)
                        {
                            if (measurement.SignalAcronym != "STAT" && measurement.SignalAcronym != "QUAL")
                            {
                                measurement.SignalReference = measurement.SignalReference.Substring(measurement.SignalReference.LastIndexOf("!", StringComparison.Ordinal) + 1);

                                if ((measurement.SignalAcronym != "ALOG" && measurement.SignalAcronym != "DIGI") || (measurement.SignalAcronym == "ALOG" && addAnalogs) || (measurement.SignalAcronym == "DIGI" && addDigitals))
                                {
                                    OutputStreamMeasurement outputStreamMeasurement = new OutputStreamMeasurement();
                                    outputStreamMeasurement.NodeID = device.NodeID;
                                    outputStreamMeasurement.AdapterID = outputStreamID;
                                    outputStreamMeasurement.HistorianID = measurement.HistorianID;
                                    outputStreamMeasurement.PointID = measurement.PointID;
                                    outputStreamMeasurement.SignalReference = measurement.SignalReference;
                                    OutputStreamMeasurement.Save(database, outputStreamMeasurement);
                                }

                                if (addAnalogs && measurement.SignalAcronym == "ALOG")
                                {
                                    OutputStreamDeviceAnalog outputStreamDeviceAnalog = new OutputStreamDeviceAnalog();
                                    outputStreamDeviceAnalog.NodeID = device.NodeID;
                                    outputStreamDeviceAnalog.OutputStreamDeviceID = outputStreamDevice.ID;
                                    outputStreamDeviceAnalog.Label = string.IsNullOrEmpty(measurement.AlternateTag) ? device.Acronym.Length > 12 ? device.Acronym.Substring(0, 12) + ":A" + analogIndex : device.Acronym + ":A" + analogIndex : measurement.AlternateTag; // measurement.PointTag;                                    

                                    int charIndex = measurement.SignalReference.LastIndexOf("-", StringComparison.Ordinal);
                                    int signalIndex;

                                    if (charIndex >= 0 && charIndex + 3 < measurement.SignalReference.Length && int.TryParse(measurement.SignalReference.Substring(charIndex + 3), out signalIndex))
                                        outputStreamDeviceAnalog.LoadOrder = signalIndex;
                                    else
                                        outputStreamDeviceAnalog.LoadOrder = 999;

                                    OutputStreamDeviceAnalog.Save(database, outputStreamDeviceAnalog);
                                    analogIndex++;
                                }
                                else if (addDigitals && measurement.SignalAcronym == "DIGI")
                                {
                                    OutputStreamDeviceDigital outputStreamDeviceDigital = new OutputStreamDeviceDigital();
                                    outputStreamDeviceDigital.NodeID = device.NodeID;
                                    outputStreamDeviceDigital.OutputStreamDeviceID = outputStreamDevice.ID;
                                    outputStreamDeviceDigital.Label = string.IsNullOrEmpty(measurement.AlternateTag) ? DefaultDigitalLabel : measurement.AlternateTag;     // measurement.PointTag;

                                    int charIndex = measurement.SignalReference.LastIndexOf("-", StringComparison.Ordinal);
                                    int signalIndex;

                                    if (charIndex >= 0 && charIndex + 3 < measurement.SignalReference.Length && int.TryParse(measurement.SignalReference.Substring(charIndex + 3), out signalIndex))
                                        outputStreamDeviceDigital.LoadOrder = signalIndex;
                                    else
                                        outputStreamDeviceDigital.LoadOrder = 999;

                                    OutputStreamDeviceDigital.Save(database, outputStreamDeviceDigital);
                                }
                            }
                        }
                    }
                }

                return "Output Stream Device(s) added successfully!";
            }
            finally
            {
                if (createdConnection && database != null)
                    database.Dispose();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Saves <see cref="OutputStreamDeviceDigital"/> information to database.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="outputStreamDeviceDigital">Information about <see cref="OutputStreamDeviceDigital"/>.</param>        
        /// <returns>String, for display use, indicating success.</returns>
        public static string Save(AdoDataConnection database, OutputStreamDeviceDigital outputStreamDeviceDigital)
        {
            bool createdConnection = false;
            string query;

            try
            {
                createdConnection = CreateConnection(ref database);

                if (outputStreamDeviceDigital.ID == 0)
                {
                    query = database.ParameterizedQueryString("INSERT INTO OutputStreamDeviceDigital (NodeID, OutputStreamDeviceID, Label, MaskValue, LoadOrder, " +
                        "UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8})", "nodeID", "outputStreamDeviceID", "label",
                        "maskValue", "loadOrder", "updatedBy", "updatedOn", "createdBy", "createdOn");

                    database.Connection.ExecuteNonQuery(query, DefaultTimeout, database.CurrentNodeID(), outputStreamDeviceDigital.OutputStreamDeviceID,
                        outputStreamDeviceDigital.Label, outputStreamDeviceDigital.MaskValue, outputStreamDeviceDigital.LoadOrder, CommonFunctions.CurrentUser,
                        database.UtcNow, CommonFunctions.CurrentUser, database.UtcNow);
                }
                else
                {
                    query = database.ParameterizedQueryString("UPDATE OutputStreamDeviceDigital SET NodeID = {0}, OutputStreamDeviceID = {1}, Label = {2}, MaskValue = {3}, " +
                        "LoadOrder = {4}, UpdatedBy = {5}, UpdatedOn = {6} WHERE ID = {7}", "nodeID", "outputStreamDeviceID", "label", "maskValue", "loadOrder", "updatedBy",
                        "updatedOn", "id");

                    database.Connection.ExecuteNonQuery(query, DefaultTimeout, outputStreamDeviceDigital.NodeID, outputStreamDeviceDigital.OutputStreamDeviceID,
                        outputStreamDeviceDigital.Label, outputStreamDeviceDigital.MaskValue, outputStreamDeviceDigital.LoadOrder, CommonFunctions.CurrentUser,
                        database.UtcNow, outputStreamDeviceDigital.ID);
                }

                return "OutputStreamDeviceDigital information saved successfully";
            }
            finally
            {
                if (createdConnection && database != null)
                    database.Dispose();
            }
        }
Beispiel #6
0
        /// <summary>
        /// Loads <see cref="OutputStreamDeviceDigital"/> information as an <see cref="ObservableCollection{T}"/> style list.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="keys">Keys of the measurement to be loaded from  the database</param>
        /// <returns>Collection of <see cref="OutputStreamDeviceDigital"/>.</returns>
        public static ObservableCollection<OutputStreamDeviceDigital> Load(AdoDataConnection database, IList<int> keys)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                string query;
                string commaSeparatedKeys;

                OutputStreamDeviceDigital[] outputStreamDeviceDigitalList = null;
                DataTable outputStreamDeviceDigitalTable;
                int id;

                if ((object)keys != null && keys.Count > 0)
                {
                    commaSeparatedKeys = keys.Select(key => "" + key.ToString() + "").Aggregate((str1, str2) => str1 + "," + str2);
                    query = database.ParameterizedQueryString(string.Format("SELECT NodeID, OutputStreamDeviceID, ID, Label, MaskValue, LoadOrder " +
                             "FROM OutputStreamDeviceDigital WHERE ID IN ({0})", commaSeparatedKeys));

                    outputStreamDeviceDigitalTable = database.Connection.RetrieveData(database.AdapterType, query, DefaultTimeout);
                    outputStreamDeviceDigitalList = new OutputStreamDeviceDigital[outputStreamDeviceDigitalTable.Rows.Count];

                    foreach (DataRow row in outputStreamDeviceDigitalTable.Rows)
                    {
                        id = row.ConvertField<int>("ID");

                        outputStreamDeviceDigitalList[keys.IndexOf(id)] = new OutputStreamDeviceDigital()
                        {
                            NodeID = database.Guid(row, "NodeID"),
                            OutputStreamDeviceID = row.ConvertField<int>("OutputStreamDeviceID"),
                            ID = id,
                            Label = row.Field<string>("Label"),
                            MaskValue = row.ConvertField<int>("MaskValue"),
                            LoadOrder = row.ConvertField<int>("LoadOrder")
                        };
                    }
                }

                return new ObservableCollection<OutputStreamDeviceDigital>(outputStreamDeviceDigitalList ?? new OutputStreamDeviceDigital[0]);
            }
            finally
            {
                if (createdConnection && database != null)
                    database.Dispose();
            }
        }