void PopulateFormFields(OutputStream selectedOutputStream)
        {
            GridOutputStreamDetail.DataContext = selectedOutputStream;
            ComboBoxNode.SelectedItem = new KeyValuePair<string, string>(selectedOutputStream.NodeID, selectedOutputStream.NodeName);
            if (selectedOutputStream.Type == 0)
                ComboBoxType.SelectedItem = new KeyValuePair<int, string>(0, "IEEE C37.118");
            else
                ComboBoxType.SelectedItem = new KeyValuePair<int, string>(1, "BPA");
            ComboboxCoordinateFormat.SelectedItem = selectedOutputStream.CoordinateFormat;
            ComboboxDownsamplingMethod.SelectedItem = selectedOutputStream.DownsamplingMethod;
            ComboboxDataFormat.SelectedItem = selectedOutputStream.DataFormat;
            CheckBoxAllowSortsByArrival.IsChecked = selectedOutputStream.AllowSortsByArrival;
            CheckBoxAutoPublishConfigFrame.IsChecked = selectedOutputStream.AutoPublishConfigFrame;
            CheckBoxAutoStartDataChannel.IsChecked = selectedOutputStream.AutoStartDataChannel;
            CheckBoxEnabled.IsChecked = selectedOutputStream.Enabled;
            CheckBoxUseLocalClockAsRealTime.IsChecked = selectedOutputStream.UseLocalClockAsRealTime;
            CheckBoxPerformTimestampCheck.IsChecked = selectedOutputStream.PerformTimestampReasonabilityCheck;

            m_oldAcronym = selectedOutputStream.Acronym;
            m_oldName = selectedOutputStream.Name;

            #if !SILVERLIGHT
            if (m_inEditMode)
                ButtonInitialize.Visibility = System.Windows.Visibility.Visible;
            #endif
            TextBoxAcronym.SelectAll();
            TextBoxAcronym.Focus();
        }
        void SaveOutputStream(OutputStream outputStream, bool isNew)
        {
            SystemMessages sm;
            try
            {
                string result = CommonFunctions.SaveOutputStream(null, outputStream, 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 acronym is updated then update related statistics measurements too.
                if (!isNew)
                {
                    try
                    {
                        CommonFunctions.UpdateOutputStreamStatistics(null, ((App)Application.Current).NodeValue, m_oldAcronym, outputStream.Acronym, m_oldName, outputStream.Name);
                    }
                    catch (Exception ex)
                    {
                        sm = new SystemMessages(new openPDCManager.Utilities.Message() { UserMessage = "Failed to Update Output Stream Statistics", SystemMessage = ex.Message, UserMessageType = openPDCManager.Utilities.MessageType.Information }, ButtonType.OkOnly);
                        sm.Owner = Window.GetWindow(this);
                        sm.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                        sm.ShowPopup();
                        CommonFunctions.LogException(null, "UpdateOutputStreamStatistics", ex);
                    }
                }

                GetOutputStreamList();
                //ClearForm();

                //make this newly added or updated item as default selected. So user can click initialize right away.
                ListBoxOutputStreamList.SelectedItem = ((List<OutputStream>)ListBoxOutputStreamList.ItemsSource).Find(c => c.Acronym == outputStream.Acronym);

                //Update Metadata in the openPDC Service.
                try
                {
                    if (serviceClient != null && serviceClient.Helper.RemotingClient.CurrentState == TVA.Communication.ClientState.Connected)
                        CommonFunctions.SendCommandToWindowsService(serviceClient, "ReloadConfig"); //we do this to make sure all statistical measurements are in the system.
                    else
                    {
                        sm = new SystemMessages(new openPDCManager.Utilities.Message() { UserMessage = "Failed to Perform Configuration Changes", SystemMessage = "Application is disconnected from the openPDC Service.", UserMessageType = openPDCManager.Utilities.MessageType.Information }, ButtonType.OkOnly);
                        sm.Owner = Window.GetWindow(this);
                        sm.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                        sm.ShowPopup();
                    }
                }
                catch (Exception ex)
                {
                    sm = new SystemMessages(new openPDCManager.Utilities.Message() { UserMessage = "Failed to Perform Configuration Changes", SystemMessage = ex.Message, UserMessageType = openPDCManager.Utilities.MessageType.Information }, ButtonType.OkOnly);
                    sm.Owner = Window.GetWindow(this);
                    sm.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    sm.ShowPopup();
                    CommonFunctions.LogException(null, "SaveOutputStream.RefreshMetadata", ex);
                }

            }
            catch (Exception ex)
            {
                CommonFunctions.LogException(null, "WPF.SaveOutputStream", ex);
                sm = new SystemMessages(new Message() { UserMessage = "Failed to Save Output Stream Information", SystemMessage = ex.Message, UserMessageType = MessageType.Error },
                        ButtonType.OkOnly);
                sm.Owner = Window.GetWindow(this);
                sm.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                sm.ShowPopup();
            }
        }
        void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            #if SILVERLIGHT
            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();
            #endif
            if (IsValid())
            {
                OutputStream outputStream = new OutputStream();
                outputStream.NodeID = ((KeyValuePair<string, string>)ComboBoxNode.SelectedItem).Key;
                outputStream.Acronym = TextBoxAcronym.Text.CleanText();
                outputStream.Name = TextBoxName.Text.CleanText();
                outputStream.Type = ((KeyValuePair<int, string>)ComboBoxType.SelectedItem).Key;
                outputStream.ConnectionString = TextBoxConnectionString.Text.CleanText();
                outputStream.IDCode = TextBoxIDCode.Text.ToInteger();
                outputStream.CommandChannel = TextBoxCommandChannel.Text.CleanText();
                outputStream.DataChannel = TextBoxDataChannel.Text.CleanText();
                outputStream.AutoPublishConfigFrame = (bool)CheckBoxAutoPublishConfigFrame.IsChecked;
                outputStream.AutoStartDataChannel = (bool)CheckBoxAutoStartDataChannel.IsChecked;
                outputStream.NominalFrequency = TextBoxNominalFrequency.Text.ToInteger();
                outputStream.FramesPerSecond = TextBoxFramesPerSecond.Text.ToInteger();
                outputStream.LagTime = TextBoxLagTime.Text.ToDouble();
                outputStream.LeadTime = TextBoxLeadTime.Text.ToDouble();
                outputStream.UseLocalClockAsRealTime = (bool)CheckBoxUseLocalClockAsRealTime.IsChecked;
                outputStream.AllowSortsByArrival = (bool)CheckBoxAllowSortsByArrival.IsChecked;
                outputStream.LoadOrder = TextBoxLoadOrder.Text.ToInteger();
                outputStream.Enabled = (bool)CheckBoxEnabled.IsChecked;
                outputStream.IgnoreBadTimeStamps = (bool)CheckBoxIgnoreBadTimeStamps.IsChecked;
                outputStream.TimeResolution = TextBoxTimeResolution.Text.ToInteger();
                outputStream.AllowPreemptivePublishing = (bool)CheckBoxAllowPreemptivePublishing.IsChecked;
                outputStream.DownsamplingMethod = ComboboxDownsamplingMethod.SelectedItem.ToString();
                outputStream.DataFormat = ComboboxDataFormat.SelectedItem.ToString();
                outputStream.CoordinateFormat = ComboboxCoordinateFormat.SelectedItem.ToString();
                outputStream.CurrentScalingValue = TextBoxCurrentScalingValue.Text.ToInteger();
                outputStream.VoltageScalingValue = TextBoxVoltageScalingValue.Text.ToInteger();
                outputStream.AnalogScalingValue = TextBoxAnalogScalingValue.Text.ToInteger();
                outputStream.DigitalMaskValue = TextBoxDigitalMaskValue.Text.ToInteger();
                outputStream.PerformTimestampReasonabilityCheck = (bool)CheckBoxPerformTimestampCheck.IsChecked;

                if (m_inEditMode == true && m_outputStreamID > 0)
                {
                    outputStream.ID = m_outputStreamID;
                    SaveOutputStream(outputStream, false);
                }
                else
                    SaveOutputStream(outputStream, true);
            }
        }
Example #4
0
        public static string SaveOutputStream(DataConnection connection, OutputStream outputStream, bool isNew)
        {
            bool createdConnection = false;
            try
            {
                if (connection == null)
                {
                    connection = new DataConnection();
                    createdConnection = true;
                }

                IDbCommand command = connection.Connection.CreateCommand();
                command.CommandType = CommandType.Text;

                if (isNew)
                    command.CommandText = "INSERT INTO OutputStream (NodeID, Acronym, Name, Type, ConnectionString, IDCode, CommandChannel, DataChannel, AutoPublishConfigFrame, AutoStartDataChannel, NominalFrequency, FramesPerSecond, LagTime, LeadTime, " +
                                        "UseLocalClockAsRealTime, AllowSortsByArrival, LoadOrder, Enabled, IgnoreBadTimeStamps, TimeResolution, AllowPreemptivePublishing, DownsamplingMethod, DataFormat, CoordinateFormat, CurrentScalingValue, VoltageScalingValue, " +
                                        "AnalogScalingValue, DigitalMaskValue, PerformTimestampReasonabilityCheck, UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) VALUES (@nodeID, @acronym, @name, @type, @connectionString, @idCode, @commandChannel, @dataChannel, @autoPublishConfigFrame, @autoStartDataChannel, @nominalFrequency, @framesPerSecond, " +
                                        "@lagTime, @leadTime, @useLocalClockAsRealTime, @allowSortsByArrival, @loadOrder, @enabled, @ignoreBadTimeStamps, @timeResolution, @allowPreemptivePublishing, @downsamplingMethod, @dataFormat, @coordinateFormat, " +
                                        "@currentScalingValue, @voltageScalingValue, @analogScalingValue, @digitalMaskValue, @performTimestampReasonabilityCheck, @updatedBy, @updatedOn, @createdBy, @createdOn)";
                else
                    command.CommandText = "UPDATE OutputStream SET NodeID = @nodeID, Acronym = @acronym, Name = @name, Type = @type, ConnectionString = @connectionString, IDCode = @idCode, CommandChannel = @commandChannel, DataChannel = @dataChannel, AutoPublishConfigFrame = @autoPublishConfigFrame, " +
                                        "AutoStartDataChannel = @autoStartDataChannel, NominalFrequency = @nominalFrequency, FramesPerSecond = @framesPerSecond, LagTime = @lagTime, LeadTime = @leadTime, UseLocalClockAsRealTime = @useLocalClockAsRealTime, " +
                                        "AllowSortsByArrival = @allowSortsByArrival, LoadOrder = @loadOrder, Enabled = @enabled, IgnoreBadTimeStamps = @ignoreBadTimeStamps, TimeResolution = @timeResolution, AllowPreemptivePublishing = @allowPreemptivePublishing, " +
                                        "DownsamplingMethod = @downsamplingMethod, DataFormat = @dataFormat, CoordinateFormat = @coordinateFormat, CurrentScalingValue = @currentScalingValue, VoltageScalingValue = @voltageScalingValue, " +
                                        "AnalogScalingValue = @analogScalingValue, DigitalMaskValue = @digitalMaskValue, PerformTimestampReasonabilityCheck = @performTimestampReasonabilityCheck, UpdatedBy = @updatedBy, UpdatedOn = @updatedOn WHERE ID = @id";

                command.Parameters.Add(AddWithValue(command, "@nodeID", outputStream.NodeID));
                command.Parameters.Add(AddWithValue(command, "@acronym", outputStream.Acronym.Replace(" ", "").ToUpper()));
                command.Parameters.Add(AddWithValue(command, "@name", outputStream.Name));
                command.Parameters.Add(AddWithValue(command, "@type", outputStream.Type));
                command.Parameters.Add(AddWithValue(command, "@connectionString", outputStream.ConnectionString));
                command.Parameters.Add(AddWithValue(command, "@idCode", outputStream.IDCode));
                command.Parameters.Add(AddWithValue(command, "@commandChannel", outputStream.CommandChannel));
                command.Parameters.Add(AddWithValue(command, "@dataChannel", outputStream.DataChannel));
                command.Parameters.Add(AddWithValue(command, "@autoPublishConfigFrame", outputStream.AutoPublishConfigFrame));
                command.Parameters.Add(AddWithValue(command, "@autoStartDataChannel", outputStream.AutoStartDataChannel));
                command.Parameters.Add(AddWithValue(command, "@nominalFrequency", outputStream.NominalFrequency));
                command.Parameters.Add(AddWithValue(command, "@framesPerSecond", outputStream.FramesPerSecond));
                command.Parameters.Add(AddWithValue(command, "@lagTime", outputStream.LagTime));
                command.Parameters.Add(AddWithValue(command, "@leadTime", outputStream.LeadTime));
                command.Parameters.Add(AddWithValue(command, "@useLocalClockAsRealTime", outputStream.UseLocalClockAsRealTime));
                command.Parameters.Add(AddWithValue(command, "@allowSortsByArrival", outputStream.AllowSortsByArrival));
                command.Parameters.Add(AddWithValue(command, "@loadOrder", outputStream.LoadOrder));
                command.Parameters.Add(AddWithValue(command, "@enabled", outputStream.Enabled));
                command.Parameters.Add(AddWithValue(command, "@ignoreBadTimeStamps", outputStream.IgnoreBadTimeStamps));
                command.Parameters.Add(AddWithValue(command, "@timeResolution", outputStream.TimeResolution));
                command.Parameters.Add(AddWithValue(command, "@allowPreemptivePublishing", outputStream.AllowPreemptivePublishing));
                command.Parameters.Add(AddWithValue(command, "@downsamplingMethod", outputStream.DownsamplingMethod));
                command.Parameters.Add(AddWithValue(command, "@dataFormat", outputStream.DataFormat));
                command.Parameters.Add(AddWithValue(command, "@coordinateFormat", outputStream.CoordinateFormat));
                command.Parameters.Add(AddWithValue(command, "@currentScalingValue", outputStream.CurrentScalingValue));
                command.Parameters.Add(AddWithValue(command, "@voltageScalingValue", outputStream.VoltageScalingValue));
                command.Parameters.Add(AddWithValue(command, "@analogScalingValue", outputStream.AnalogScalingValue));
                command.Parameters.Add(AddWithValue(command, "@digitalMaskValue", outputStream.DigitalMaskValue));
                command.Parameters.Add(AddWithValue(command, "@performTimestampReasonabilityCheck", outputStream.PerformTimestampReasonabilityCheck));
                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", outputStream.ID));
                }

                command.ExecuteNonQuery();

                try
                {
                    // Generate Statistical Measurements for the device.
                    //CommonPhasorServices.ValidateStatistics(connection.Connection, connection.AdapterType, "'" + outputStream.NodeID + "'", new Action<object, EventArgs<string>>(StatusMessageHandler), new Action<object, EventArgs<Exception>>(ProcessExceptionHandler));
                }
                catch (Exception ex)
                {
                    //Do not do anything. If this fails then we dont want to interrupt save operation.
                    LogException(connection, "SaveOutputStream: PhasorDataSourceValidation", ex);
                }

                return "Output Stream Information Saved Successfully";
            }

            finally
            {
                if (createdConnection && connection != null)
                    connection.Dispose();
            }
        }