示例#1
0
        void ComboBoxMeasurements_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ComboBoxMeasurements.Items.Count > 0 && ComboBoxMeasurements.SelectedIndex >= 0)
            {
                openPDCManager.Data.Entities.Measurement measurement = (openPDCManager.Data.Entities.Measurement)ComboBoxMeasurements.SelectedItem;

                //This was done for WPF to make sure there are measurements available in the dropdown before calling time series data service. Otherwise ComboboxMeasurements.SelectedItem returned NULL.
                m_measurementForSubscription = measurement.HistorianAcronym + ":" + measurement.PointID;
                ReconnectToService();

                m_framesPerSecond = (int)measurement.FramesPerSecond;
                LinearAxis yAxis = (LinearAxis)ChartRealTimeData.Axes[1];
                if (measurement.SignalSuffix == "PA")
                {
                    yAxis.Minimum  = -180;
                    yAxis.Maximum  = 180;
                    yAxis.Interval = 60;
                }
                else
                {
                    yAxis.Minimum  = Convert.ToDouble(IsolatedStorageManager.ReadFromIsolatedStorage("FrequencyRangeMin")); // 59.95;
                    yAxis.Maximum  = Convert.ToDouble(IsolatedStorageManager.ReadFromIsolatedStorage("FrequencyRangeMax")); // 60.05;
                    yAxis.Interval = (yAxis.Maximum - yAxis.Minimum) / 5.0;                                                 // 0.02;
                }
            }
        }
示例#2
0
        void SaveMeasurement(Measurement measurement, bool isNew)
        {
            SystemMessages sm;
            try
            {
                string result = CommonFunctions.SaveMeasurement(null, measurement, isNew);
                sm = new SystemMessages(new Message()
                {
                    UserMessage = result, SystemMessage = string.Empty, UserMessageType = MessageType.Success
                },
                        ButtonType.OkOnly);
                sm.Owner = Window.GetWindow(this);
                sm.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                sm.ShowPopup();

                if (m_deviceID > 0)
                    GetMeasurementsByDevice();
                else
                    GetMeasurementList();

                //make this newly added or updated item as default selected. So user can click initialize right away.
                ListBoxMeasurementList.SelectedItem = (m_measurementList).Find(c => c.SignalReference == measurement.SignalReference);

                //Update Metadata in the openPDC Service.
                try
                {
                    if (measurement.HistorianID != null)
                    {
                        string runtimeID = CommonFunctions.GetRuntimeID(null, "Historian", (int)measurement.HistorianID);
                        WindowsServiceClient serviceClient = ((App)Application.Current).ServiceClient;
                        if (serviceClient.Helper.RemotingClient.CurrentState == TVA.Communication.ClientState.Connected)
                        {
                            CommonFunctions.SendCommandToWindowsService(serviceClient, "Invoke " + runtimeID + " RefreshMetadata");
                            CommonFunctions.SendCommandToWindowsService(serviceClient, "RefreshRoutes");
                        }
                    }
                }
                catch (Exception ex)
                {
                    CommonFunctions.LogException(null, "SaveMeasurement.RefreshMetadata", ex);
                }

                //ClearForm();
            }
            catch (Exception ex)
            {
                CommonFunctions.LogException(null, "WPF.SaveMeasurement", ex);
                sm = new SystemMessages(new Message()
                {
                    UserMessage = "Failed to Save Measurement Information", SystemMessage = ex.Message, UserMessageType = MessageType.Error
                },
                        ButtonType.OkOnly);
                sm.Owner = Window.GetWindow(this);
                sm.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                sm.ShowPopup();
            }
        }
示例#3
0
        void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            //Storyboard sb = new Storyboard();
            //sb = Application.Current.Resources["ButtonPressAnimation"] as Storyboard;
            //sb.Completed += new EventHandler(delegate(object obj, EventArgs es) { sb.Stop(); });
            //Storyboard.SetTarget(sb, ButtonSaveTransform);
            //sb.Begin();

            if (IsValid())
            {
                Measurement measurement = new Measurement();
                measurement.HistorianID = ((KeyValuePair<int, string>)ComboBoxHistorian.SelectedItem).Key == 0 ? (int?)null : ((KeyValuePair<int, string>)ComboBoxHistorian.SelectedItem).Key;
                measurement.DeviceID = ((KeyValuePair<int, string>)ComboBoxDevice.SelectedItem).Key == 0 ? (int?)null : ((KeyValuePair<int, string>)ComboBoxDevice.SelectedItem).Key;
                measurement.PointTag = TextBoxPointTag.Text.CleanText();
                measurement.AlternateTag = TextBoxAlternateTag.Text.CleanText();
                measurement.SignalTypeID = ((KeyValuePair<int, string>)ComboBoxSignalType.SelectedItem).Key;
                measurement.PhasorSourceIndex = ((KeyValuePair<int, string>)ComboBoxPhasorSource.SelectedItem).Key == 0 ? (int?)null : ((KeyValuePair<int, string>)ComboBoxPhasorSource.SelectedItem).Key;
                measurement.SignalReference = TextBoxSignalReference.Text.CleanText();
                measurement.Adder = TextBoxAdder.Text.ToDouble();
                measurement.Multiplier = TextBoxMultiplier.Text.ToDouble();
                measurement.Description = TextBoxDescription.Text.CleanText();
                measurement.Enabled = (bool)CheckboxEnabled.IsChecked;

                if (m_inEditMode == true && !string.IsNullOrEmpty(m_signalID))
                {
                    measurement.SignalID = m_signalID;
                    SaveMeasurement(measurement, false);
                }
                else
                    SaveMeasurement(measurement, true);
            }
        }
示例#4
0
        public static string SavePhasor(DataConnection connection, Phasor phasor, bool isNew)
        {
            //DataConnection connection = new DataConnection();
            bool createdConnection = false;
            try
            {
                if (connection == null)
                {
                    connection = new DataConnection();
                    createdConnection = true;
                }

                IDbCommand command = connection.Connection.CreateCommand();

                if (isNew)
                    command.CommandText = "Insert Into Phasor (DeviceID, Label, Type, Phase, DestinationPhasorID, SourceIndex, UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) Values (@deviceID, @label, @type, @phase, " +
                        "@destinationPhasorID, @sourceIndex, @updatedBy, @updatedOn, @createdBy, @createdOn)";
                else
                    command.CommandText = "Update Phasor Set DeviceID =@deviceID, Label = @label, Type = @type, Phase = @phase, DestinationPhasorID = @destinationPhasorID, " +
                        "SourceIndex = @sourceIndex, UpdatedBy = @updatedBy, UpdatedOn = @updatedOn Where ID = @id";

                command.Parameters.Add(AddWithValue(command, "@deviceID", phasor.DeviceID));
                command.Parameters.Add(AddWithValue(command, "@label", phasor.Label));
                command.Parameters.Add(AddWithValue(command, "@type", phasor.Type));
                command.Parameters.Add(AddWithValue(command, "@phase", phasor.Phase));
                command.Parameters.Add(AddWithValue(command, "@destinationPhasorID", phasor.DestinationPhasorID ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@sourceIndex", phasor.SourceIndex));
                command.Parameters.Add(AddWithValue(command, "@updatedBy", s_currentUser));
                command.Parameters.Add(AddWithValue(command, "@updatedOn", command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB") ? DateTime.UtcNow.Date : DateTime.UtcNow));

                if (isNew)
                {
                    command.Parameters.Add(AddWithValue(command, "@createdBy", s_currentUser));
                    command.Parameters.Add(AddWithValue(command, "@createdOn", command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB") ? DateTime.UtcNow.Date : DateTime.UtcNow));
                }
                else
                    command.Parameters.Add(AddWithValue(command, "@id", phasor.ID));

                command.ExecuteNonQuery();

                Device device = new Device();
                device = GetDeviceByDeviceID(connection, phasor.DeviceID);

                Measurement measurement;

                if (s_voltagePhasorSignalTypes == null || s_voltagePhasorSignalTypes.Rows.Count == 0)
                    s_voltagePhasorSignalTypes = GetPhasorSignalTypes(connection, "V");

                if (s_currentPhasorSignalTypes == null || s_currentPhasorSignalTypes.Rows.Count == 0)
                    s_currentPhasorSignalTypes = GetPhasorSignalTypes(connection, "I");

                if (phasor.Type == "V")
                    s_phasorSignalTypes = s_voltagePhasorSignalTypes;
                else
                    s_phasorSignalTypes = s_currentPhasorSignalTypes;

                Phasor addedPhasor = new Phasor();
                //addedPhasor = GetPhasorByLabel(phasor.DeviceID, phasor.Label);
                addedPhasor = GetPhasorBySourceIndex(connection, phasor.DeviceID, phasor.SourceIndex);

                //we will try again just to make sure we get information back about the added phasor. As MS Access is very slow and sometimes fails to retrieve data.
                if (addedPhasor == null)
                {
                    System.Threading.Thread.Sleep(500);
                    //addedPhasor = GetPhasorByLabel(phasor.DeviceID, phasor.Label);
                    addedPhasor = GetPhasorBySourceIndex(connection, phasor.DeviceID, phasor.SourceIndex);
                }

                foreach (DataRow row in s_phasorSignalTypes.Rows)
                {
                    measurement = new Measurement();
                    measurement.HistorianID = device.HistorianID;
                    measurement.DeviceID = device.ID;
                    if (addedPhasor.DestinationPhasorID.HasValue)
                        measurement.PointTag = device.CompanyAcronym + "_" + device.Acronym + "-" + GetPhasorByID(connection, addedPhasor.DeviceID, (int)addedPhasor.DestinationPhasorID).Label + ":" + device.VendorAcronym + row["Abbreviation"].ToString();
                    else
                        measurement.PointTag = device.CompanyAcronym + "_" + device.Acronym + "-" + row["Suffix"].ToString() + addedPhasor.SourceIndex.ToString() + ":" + device.VendorAcronym + row["Abbreviation"].ToString();
                    measurement.AlternateTag = string.Empty;
                    measurement.SignalTypeID = Convert.ToInt32(row["ID"]);
                    measurement.PhasorSourceIndex = addedPhasor.SourceIndex;
                    measurement.SignalReference = device.Acronym + "-" + row["Suffix"].ToString() + addedPhasor.SourceIndex.ToString();
                    measurement.Adder = 0.0d;
                    measurement.Multiplier = 1.0d;
                    measurement.Description = device.Name + " " + addedPhasor.Label + " " + device.VendorDeviceName + " " + addedPhasor.PhaseType + " " + row["Name"].ToString();
                    measurement.Enabled = true;
                    if (isNew)	//if it is a new phasor then add measurements as new.
                        SaveMeasurement(connection, measurement, true);
                    else //Check if measurement exists, if so then update them otherwise add new.
                    {
                        Measurement existingMeasurement = new Measurement();
                        existingMeasurement = GetMeasurementInfo(connection, measurement.DeviceID, row["Suffix"].ToString(), measurement.PhasorSourceIndex);
                        if (existingMeasurement == null)
                            SaveMeasurement(connection, measurement, true);
                        else
                        {
                            measurement.SignalID = existingMeasurement.SignalID;
                            SaveMeasurement(connection, measurement, false);
                        }
                    }
                }

                return "Phasor Information Saved Successfully";
            }
            finally
            {
                if (createdConnection && connection != null)
                    connection.Dispose();
            }
        }
示例#5
0
        public static string SaveMeasurement(DataConnection connection, Measurement measurement, bool isNew)
        {
            //DataConnection connection = new DataConnection();
            bool createdConnection = false;
            try
            {
                if (connection == null)
                {
                    connection = new DataConnection();
                    createdConnection = true;
                }
                IDbCommand command = connection.Connection.CreateCommand();

                if (isNew)
                    command.CommandText = "Insert Into Measurement (HistorianID, DeviceID, PointTag, AlternateTag, SignalTypeID, PhasorSourceIndex, SignalReference, Adder, Multiplier, Description, Enabled, UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) " +
                        "Values (@historianID, @deviceID, @pointTag, @alternateTag, @signalTypeID, @phasorSourceIndex, @signalReference, @adder, @multiplier, @description, @enabled, @updatedBy, @updatedOn, @createdBy, @createdOn)";
                else
                    command.CommandText = "Update Measurement Set HistorianID = @historianID, DeviceID = @deviceID, PointTag = @pointTag, AlternateTag = @alternateTag, SignalTypeID = @signalTypeID, " +
                        "PhasorSourceIndex = @phasorSourceIndex, SignalReference = @signalReference, Adder = @adder, Multiplier = @multiplier, Description = @description, Enabled = @enabled, UpdatedBy = @updatedBy, UpdatedOn = @updatedOn Where SignalID = @signalID";

                command.Parameters.Add(AddWithValue(command, "@historianID", measurement.HistorianID ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@deviceID", measurement.DeviceID ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@pointTag", measurement.PointTag));
                command.Parameters.Add(AddWithValue(command, "@alternateTag", measurement.AlternateTag ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@signalTypeID", measurement.SignalTypeID));
                command.Parameters.Add(AddWithValue(command, "@phasorSourceIndex", measurement.PhasorSourceIndex ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@signalReference", measurement.SignalReference));
                command.Parameters.Add(AddWithValue(command, "@adder", measurement.Adder));
                command.Parameters.Add(AddWithValue(command, "@multiplier", measurement.Multiplier));
                command.Parameters.Add(AddWithValue(command, "@description", measurement.Description.RemoveDuplicateWhiteSpace()));
                command.Parameters.Add(AddWithValue(command, "@enabled", measurement.Enabled));
                command.Parameters.Add(AddWithValue(command, "@updatedBy", s_currentUser));
                command.Parameters.Add(AddWithValue(command, "@updatedOn", command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB") ? DateTime.UtcNow.Date : DateTime.UtcNow));

                if (isNew)
                {
                    command.Parameters.Add(AddWithValue(command, "@createdBy", s_currentUser));
                    command.Parameters.Add(AddWithValue(command, "@createdOn", command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB") ? DateTime.UtcNow.Date : DateTime.UtcNow));
                }
                else
                {
                    if (command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB"))
                        command.Parameters.Add(AddWithValue(command, "@signalID", "{" + measurement.SignalID + "}"));
                    else
                        command.Parameters.Add(AddWithValue(command, "@signalID", measurement.SignalID));
                }

                command.ExecuteNonQuery();
                return "Measurement Information Saved Successfully";
            }
            finally
            {
                if (createdConnection && connection != null)
                    connection.Dispose();
            }
        }
示例#6
0
        public static string SaveDevice(DataConnection connection, Device device, bool isNew, int digitalCount, int analogCount)
        {
            //DataConnection connection = new DataConnection();
            bool createdConnection = false;
            try
            {
                if (connection == null)
                {
                    connection = new DataConnection();
                    createdConnection = true;
                }

                IDbCommand command = connection.Connection.CreateCommand();

                if (isNew)
                    command.CommandText = "Insert Into Device (NodeID, ParentID, Acronym, Name, IsConcentrator, CompanyID, HistorianID, AccessID, VendorDeviceID, ProtocolID, Longitude, Latitude, InterconnectionID, ConnectionString, TimeZone, FramesPerSecond, TimeAdjustmentTicks, " +
                        "DataLossInterval, ContactList, MeasuredLines, LoadOrder, Enabled, AllowedParsingExceptions, ParsingExceptionWindow, DelayedConnectionInterval, AllowUseOfCachedConfiguration, AutoStartDataParsingSequence, SkipDisableRealTimeData, MeasurementReportingInterval, UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) " +
                        "Values (@nodeID, @parentID, @acronym, @name, @isConcentrator, @companyID, @historianID, @accessID, @vendorDeviceID, @protocolID, @longitude, @latitude, @interconnectionID, " +
                        "@connectionString, @timezone, @framesPerSecond, @timeAdjustmentTicks, @dataLossInterval, @contactList, @measuredLines, @loadOrder, @enabled, @allowedParsingExceptions, " +
                        "@parsingExceptionWindow, @delayedConnectionInterval, @allowUseOfCachedConfiguration, @autoStartDataParsingSequence, @skipDisableRealTimeData, @measurementReportingInterval, @updatedBy, @updatedOn, @createdBy, @createdOn)";
                else
                    command.CommandText = "Update Device Set NodeID = @nodeID, ParentID = @parentID, Acronym = @acronym, Name = @name, IsConcentrator = @isConcentrator, CompanyID = @companyID, HistorianID = @historianID, AccessID = @accessID, VendorDeviceID = @vendorDeviceID, " +
                        "ProtocolID = @protocolID, Longitude = @longitude, Latitude = @latitude, InterconnectionID = @interconnectionID, ConnectionString = @connectionString, TimeZone = @timezone, FramesPerSecond = @framesPerSecond, TimeAdjustmentTicks = @timeAdjustmentTicks, DataLossInterval = @dataLossInterval, " +
                        "ContactList = @contactList, MeasuredLines = @measuredLines, LoadOrder = @loadOrder, Enabled = @enabled, AllowedParsingExceptions = @allowedParsingExceptions, ParsingExceptionWindow = @parsingExceptionWindow, DelayedConnectionInterval = @delayedConnectionInterval, " +
                        "AllowUseOfCachedConfiguration = @allowUseOfCachedConfiguration, AutoStartDataParsingSequence = @autoStartDataParsingSequence, SkipDisableRealTimeData = @skipDisableRealTimeData, MeasurementReportingInterval = @measurementReportingInterval, UpdatedBy = @updatedBy, UpdatedOn = @updatedOn WHERE ID = @id";

                command.CommandType = CommandType.Text;
                command.Parameters.Add(AddWithValue(command, "@nodeID", device.NodeID));
                command.Parameters.Add(AddWithValue(command, "@parentID", device.ParentID ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@acronym", device.Acronym.Replace(" ", "").ToUpper()));
                command.Parameters.Add(AddWithValue(command, "@name", device.Name));
                command.Parameters.Add(AddWithValue(command, "@isConcentrator", device.IsConcentrator));
                command.Parameters.Add(AddWithValue(command, "@companyID", device.CompanyID ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@historianID", device.HistorianID ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@accessID", device.AccessID));
                command.Parameters.Add(AddWithValue(command, "@vendorDeviceID", device.VendorDeviceID == null ? (object)DBNull.Value : device.VendorDeviceID == 0 ? (object)DBNull.Value : device.VendorDeviceID));
                command.Parameters.Add(AddWithValue(command, "@protocolID", device.ProtocolID ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@longitude", device.Longitude ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@latitude", device.Latitude ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@interconnectionID", device.InterconnectionID ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@connectionString", device.ConnectionString));
                command.Parameters.Add(AddWithValue(command, "@timezone", device.TimeZone));
                command.Parameters.Add(AddWithValue(command, "@framesPerSecond", device.FramesPerSecond ?? 30));
                command.Parameters.Add(AddWithValue(command, "@timeAdjustmentTicks", device.TimeAdjustmentTicks));
                command.Parameters.Add(AddWithValue(command, "@dataLossInterval", device.DataLossInterval));
                command.Parameters.Add(AddWithValue(command, "@contactList", device.ContactList));
                command.Parameters.Add(AddWithValue(command, "@measuredLines", device.MeasuredLines ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@loadOrder", device.LoadOrder));
                command.Parameters.Add(AddWithValue(command, "@enabled", device.Enabled));
                command.Parameters.Add(AddWithValue(command, "@allowedParsingExceptions", device.AllowedParsingExceptions));
                command.Parameters.Add(AddWithValue(command, "@parsingExceptionWindow", device.ParsingExceptionWindow));
                command.Parameters.Add(AddWithValue(command, "@delayedConnectionInterval", device.DelayedConnectionInterval));
                command.Parameters.Add(AddWithValue(command, "@allowUseOfCachedConfiguration", device.AllowUseOfCachedConfiguration));
                command.Parameters.Add(AddWithValue(command, "@autoStartDataParsingSequence", device.AutoStartDataParsingSequence));
                command.Parameters.Add(AddWithValue(command, "@skipDisableRealTimeData", device.SkipDisableRealTimeData));
                command.Parameters.Add(AddWithValue(command, "@measurementReportingInterval", device.MeasurementReportingInterval));
                command.Parameters.Add(AddWithValue(command, "@updatedBy", s_currentUser));
                command.Parameters.Add(AddWithValue(command, "@updatedOn", command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB") ? DateTime.UtcNow.Date : DateTime.UtcNow));

                if (isNew)
                {
                    command.Parameters.Add(AddWithValue(command, "@createdBy", s_currentUser));
                    command.Parameters.Add(AddWithValue(command, "@createdOn", command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB") ? DateTime.UtcNow.Date : DateTime.UtcNow));
                }
                else
                    command.Parameters.Add(AddWithValue(command, "@id", device.ID));

                command.ExecuteNonQuery();

                if (device.IsConcentrator)
                    return "Concentrator Device Information Saved Successfully";		//As we do not add measurements for PDC device or device which is concentrator.

                //DataTable pmuSignalTypes = new DataTable();
                if (s_pmuSignalTypes == null || s_pmuSignalTypes.Rows.Count == 0)
                    s_pmuSignalTypes = GetPmuSignalTypes(connection);

                Measurement measurement;

                Device addedDevice = new Device();
                addedDevice = GetDeviceByAcronym(connection, device.Acronym);

                //We will try again in a while if addedDevice is NULL. This is done because MS Access is very slow and was returning NULL.
                if (addedDevice == null)
                {
                    System.Threading.Thread.Sleep(500);
                    addedDevice = GetDeviceByAcronym(connection, device.Acronym);
                }

                foreach (DataRow row in s_pmuSignalTypes.Rows)	//This will only create or update PMU related measurements and not phasor related.
                {
                    measurement = new Measurement();
                    measurement.HistorianID = addedDevice.HistorianID;
                    measurement.DeviceID = addedDevice.ID;
                    measurement.PointTag = addedDevice.CompanyAcronym + "_" + addedDevice.Acronym + ":" + addedDevice.VendorAcronym + row["Abbreviation"].ToString();
                    measurement.AlternateTag = string.Empty;
                    measurement.SignalTypeID = Convert.ToInt32(row["ID"]);
                    measurement.PhasorSourceIndex = (int?)null;
                    measurement.SignalReference = addedDevice.Acronym + "-" + row["Suffix"].ToString();
                    measurement.Adder = 0.0d;
                    measurement.Multiplier = 1.0d;
                    measurement.Description = addedDevice.Name + " " + addedDevice.VendorDeviceName + " " + row["Name"].ToString();
                    measurement.Enabled = true;
                    if (isNew)	//if it is a new device then measurements are new too. So don't worry about updating them.
                        SaveMeasurement(connection, measurement, true);
                    else	//if device is existing one, then check and see if its measusremnts exist, if so then update measurements.
                    {
                        Measurement existingMeasurement = new Measurement();
                        existingMeasurement = GetMeasurementInfo(connection, measurement.DeviceID, row["Suffix"].ToString(), measurement.PhasorSourceIndex);

                        if (existingMeasurement == null)	//measurement does not exist for this device and signal type then add as a new measurement otherwise update.
                            SaveMeasurement(connection, measurement, true);
                        else
                        {
                            measurement.SignalID = existingMeasurement.SignalID;
                            SaveMeasurement(connection, measurement, false);
                        }
                    }
                }

                if (digitalCount > 0)
                {
                    for (int i = 1; i <= digitalCount; i++)
                    {
                        measurement = new Measurement();
                        measurement.HistorianID = addedDevice.HistorianID;
                        measurement.DeviceID = addedDevice.ID;
                        measurement.PointTag = addedDevice.CompanyAcronym + "_" + addedDevice.Acronym + ":" + addedDevice.VendorAcronym + "D" + i.ToString();
                        measurement.AlternateTag = string.Empty;
                        measurement.SignalTypeID = GetSignalTypeID(connection, "DV");
                        measurement.PhasorSourceIndex = (int?)null;
                        measurement.SignalReference = addedDevice.Acronym + "-DV" + i.ToString();
                        measurement.Adder = 0.0d;
                        measurement.Multiplier = 1.0d;
                        measurement.Description = addedDevice.Name + " " + addedDevice.VendorDeviceName + " Digital Value " + i.ToString();
                        measurement.Enabled = true;
                        if (isNew)	//if it is a new device then measurements are new too. So don't worry about updating them.
                            SaveMeasurement(connection, measurement, true);
                        else	//if device is existing one, then check and see if its measusremnts exist, if so then update measurements.
                        {
                            Measurement existingMeasurement = new Measurement();
                            //we will compare using signal reference as signal suffix doesn't provide uniqueness.
                            existingMeasurement = GetMeasurementInfoBySignalReference(connection, measurement.DeviceID, measurement.SignalReference, measurement.PhasorSourceIndex);

                            if (existingMeasurement == null)	//measurement does not exist for this device and signal type then add as a new measurement otherwise update.
                                SaveMeasurement(connection, measurement, true);
                            else
                            {
                                measurement.SignalID = existingMeasurement.SignalID;
                                SaveMeasurement(connection, measurement, false);
                            }
                        }
                    }
                }

                if (analogCount > 0)
                {
                    for (int i = 1; i <= analogCount; i++)
                    {
                        measurement = new Measurement();
                        measurement.HistorianID = addedDevice.HistorianID;
                        measurement.DeviceID = addedDevice.ID;
                        measurement.PointTag = addedDevice.CompanyAcronym + "_" + addedDevice.Acronym + ":" + addedDevice.VendorAcronym + "A" + i.ToString();
                        measurement.AlternateTag = string.Empty;
                        measurement.SignalTypeID = GetSignalTypeID(connection, "AV");
                        measurement.PhasorSourceIndex = (int?)null;
                        measurement.SignalReference = addedDevice.Acronym + "-AV" + i.ToString();
                        measurement.Adder = 0.0d;
                        measurement.Multiplier = 1.0d;
                        measurement.Description = addedDevice.Name + " " + addedDevice.VendorDeviceName + " Analog Value " + i.ToString();
                        measurement.Enabled = true;
                        if (isNew)	//if it is a new device then measurements are new too. So don't worry about updating them.
                            SaveMeasurement(connection, measurement, true);
                        else	//if device is existing one, then check and see if its measusremnts exist, if so then update measurements.
                        {
                            Measurement existingMeasurement = new Measurement();
                            existingMeasurement = GetMeasurementInfoBySignalReference(connection, measurement.DeviceID, measurement.SignalReference, measurement.PhasorSourceIndex);

                            if (existingMeasurement == null)	//measurement does not exist for this device and signal type then add as a new measurement otherwise update.
                                SaveMeasurement(connection, measurement, true);
                            else
                            {
                                measurement.SignalID = existingMeasurement.SignalID;
                                SaveMeasurement(connection, measurement, false);
                            }
                        }
                    }
                }

                if (!isNew)
                {
                    //After all the PMU related measurements are updated then lets go through each phasors for the PMU
                    //and update all the phasors and their measurements to reflect changes made to the PMU configuration.
                    //We are not going to make any changes to the Phasor definition itselft but only to reflect PMU related
                    //changes in the measurement.

                    foreach (Phasor phasor in GetPhasorList(connection, addedDevice.ID))
                    {
                        SavePhasor(connection, phasor, false);	//we will save phasor without modifying it so that only measurements will reflect changes related to PMU.
                        //nothing will change in phasor itself.
                    }
                }

                return "Device Information Saved Successfully";
            }
            finally
            {
                if (createdConnection && connection != null)
                    connection.Dispose();
            }
        }