public static List<ErrorLog> ReadExceptionLog(int numberOfLogs) { DataConnection connection = new DataConnection(); try { List<ErrorLog> errorLogList = new List<ErrorLog>(); IDbCommand command = connection.Connection.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = "Select Top " + numberOfLogs.ToString() + " * From ErrorLog Order By CreatedOn DESC"; DataTable resultTable = new DataTable(); resultTable.Load(command.ExecuteReader()); errorLogList = (from item in resultTable.AsEnumerable() select new ErrorLog() { ID = Convert.ToInt32(item.Field<object>("ID")), Source = item.Field<string>("Source"), Message = item.Field<string>("Message"), CreatedOn = Convert.ToDateTime(item.Field<object>("CreatedOn")), Detail = item.Field<string>("Detail") }).ToList(); return errorLogList; } finally { if (connection != null) connection.Dispose(); } }
public void SaveDevice(Device device, bool isNew, int digitalCount, int analogCount) { SystemMessages sm; DataConnection connection = new DataConnection(); try { string result = CommonFunctions.SaveDevice(connection, device, isNew, digitalCount, analogCount); //get the ID of the new device added to the system so we can associate that ID to the phasors of the original device. int deviceID; if (isNew) deviceID = CommonFunctions.GetDeviceByAcronym(connection, device.Acronym).ID; else deviceID = device.ID; if (m_deviceToCopy != null && isNew) //if we are copying device then make sure we copy phasors also. { List<Phasor> phasorList = CommonFunctions.GetPhasorList(connection, m_deviceToCopy.ID); foreach (Phasor phasor in phasorList) { phasor.DeviceID = deviceID; CommonFunctions.SavePhasor(connection, phasor, true); } } 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(); //update statistic measurement for a device if device is being updated and acronym has changed. try { if (!isNew && !string.IsNullOrEmpty(m_oldAcronym) && m_oldAcronym != device.Acronym) { CommonFunctions.UpdateDeviceStatistics(connection, deviceID, m_oldAcronym, device.Acronym, m_oldDeviceName, device.Name); //also if acronym has changed then make those changes } } catch (Exception ex) { CommonFunctions.LogException(connection, "WPF.UpdateDeviceStatistics", ex); sm = new SystemMessages(new Message() { UserMessage = "Failed to Update Device Statistics", SystemMessage = ex.Message, UserMessageType = MessageType.Error }, ButtonType.OkOnly); sm.Owner = Window.GetWindow(this); sm.WindowStartupLocation = WindowStartupLocation.CenterOwner; sm.ShowPopup(); } //Update Metadata in the openPDC Service. try { if (serviceClient != null && serviceClient.Helper.RemotingClient.CurrentState == TVA.Communication.ClientState.Connected) { if (device.Enabled) //if device is enabled then send initialize command otherwise send reloadconfig command. CommonFunctions.SendCommandToWindowsService(serviceClient, "Initialize " + CommonFunctions.GetRuntimeID(connection, "Device", deviceID)); // Convert.ToInt32(TextBlockRuntimeID.Text)); else CommonFunctions.SendCommandToWindowsService(serviceClient, "ReloadConfig"); //we do this to make sure all statistical measurements are in the system. if (device.HistorianID != null) //Update historian metadata { string runtimeID = CommonFunctions.GetRuntimeID(connection, "Historian", (int)device.HistorianID); CommonFunctions.SendCommandToWindowsService(serviceClient, "Invoke " + runtimeID + " RefreshMetadata"); } //now also update Stat historian metadata. Historian statHistorian = CommonFunctions.GetHistorianByAcronym(connection, "STAT"); if (statHistorian != null) { string statRuntimeID = CommonFunctions.GetRuntimeID(connection, "Historian", statHistorian.ID); CommonFunctions.SendCommandToWindowsService(serviceClient, "Invoke " + statRuntimeID + " RefreshMetadata"); } CommonFunctions.SendCommandToWindowsService(serviceClient, "Invoke 0 ReloadStatistics"); CommonFunctions.SendCommandToWindowsService(serviceClient, "RefreshRoutes"); } 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(connection, "SaveDevice.RefreshMetadata", ex); } ClearForm(); //Navigate to Browse screen upon successful save. BrowseDevicesUserControl browseDevices = new BrowseDevicesUserControl(); ((MasterLayoutWindow)Window.GetWindow(this)).ContentFrame.Navigate(browseDevices); } catch (Exception ex) { CommonFunctions.LogException(connection, "WPF.SaveDevice", ex); sm = new SystemMessages(new Message() { UserMessage = "Failed to Save Device Information", SystemMessage = ex.Message, UserMessageType = MessageType.Error }, ButtonType.OkOnly); sm.Owner = Window.GetWindow(this); sm.WindowStartupLocation = WindowStartupLocation.CenterOwner; sm.ShowPopup(); } finally { if (connection != null) connection.Dispose(); } }
void SavePhasor(Phasor phasor, bool isNew) { SystemMessages sm; DataConnection connection = new DataConnection(); ; try { string result = CommonFunctions.SavePhasor(connection, phasor, isNew); //ClearForm(); 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(); GetPhasors(); GetPhasorList(); //make this newly added or updated item as default selected. So user can click initialize right away. ListBoxPhasorList.SelectedItem = ((List<Phasor>)ListBoxPhasorList.ItemsSource).Find(c => c.Label == phasor.Label); //Update Metadata in the openPDC Service. try { Device device = CommonFunctions.GetDeviceByDeviceID(connection, phasor.DeviceID); WindowsServiceClient serviceClient = ((App)Application.Current).ServiceClient; if (serviceClient != null && serviceClient.Helper.RemotingClient.CurrentState == TVA.Communication.ClientState.Connected) { if (device.HistorianID != null) { string runtimeID = CommonFunctions.GetRuntimeID(connection, "Historian", (int)device.HistorianID); CommonFunctions.SendCommandToWindowsService(serviceClient, "Invoke " + runtimeID + " RefreshMetadata"); } if (device.Enabled) //if device is enabled then send initialize command otherwise send reloadconfig command. { if (device.ParentID == null) CommonFunctions.SendCommandToWindowsService(serviceClient, "Initialize " + CommonFunctions.GetRuntimeID(connection, "Device", device.ID)); else CommonFunctions.SendCommandToWindowsService(serviceClient, "Initialize " + CommonFunctions.GetRuntimeID(connection, "Device", (int)device.ParentID)); } else CommonFunctions.SendCommandToWindowsService(serviceClient, "ReloadConfig"); //we do this to make sure all statistical measurements are in the system. CommonFunctions.SendCommandToWindowsService(serviceClient, "RefreshRoutes"); } 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, "SavePhasor.RefreshMetadata", ex); } } catch (Exception ex) { CommonFunctions.LogException(connection, "WPF.SavePhasor", ex); sm = new SystemMessages(new Message() { UserMessage = "Failed to Save Phasor Information", SystemMessage = ex.Message, UserMessageType = MessageType.Error }, ButtonType.OkOnly); sm.Owner = Window.GetWindow(this); sm.WindowStartupLocation = WindowStartupLocation.CenterOwner; sm.ShowPopup(); } finally { if (connection != null) connection.Dispose(); } }