private void ButtonSaveSettings_Click(object sender, RoutedEventArgs e) { IsolatedStorageManager.WriteToIsolatedStorage("InputMonitoringPoints", TextBoxLastSelectedMeasurements.Text); IsolatedStorageManager.WriteToIsolatedStorage("ForceIPv4", CheckBoxForceIPv4.IsChecked.GetValueOrDefault()); IsolatedStorageManager.WriteToIsolatedStorage("NumberOfDataPointsToPlot", TextBoxNumberOFDataPointsToPlot.Text); IsolatedStorageManager.WriteToIsolatedStorage("DataResolution", TextBoxDataResolution.Text); IsolatedStorageManager.WriteToIsolatedStorage("LagTime", TextBoxLagTime.Text); IsolatedStorageManager.WriteToIsolatedStorage("LeadTime", TextBoxLeadTime.Text); IsolatedStorageManager.WriteToIsolatedStorage("UseLocalClockAsRealtime", CheckBoxUseLocalClockAsRealTime.IsChecked.GetValueOrDefault()); IsolatedStorageManager.WriteToIsolatedStorage("IgnoreBadTimestamps", CheckBoxIgnoreBadTimestamps.IsChecked.GetValueOrDefault()); IsolatedStorageManager.WriteToIsolatedStorage("ChartRefreshInterval", TextBoxChartRefreshInterval.Text); IsolatedStorageManager.WriteToIsolatedStorage("StatisticsDataRefreshInterval", TextBoxStatisticDataRefreshInterval.Text); IsolatedStorageManager.WriteToIsolatedStorage("MeasurementsDataRefreshInterval", TextBoxMeasurementDataRefreshInterval.Text); IsolatedStorageManager.WriteToIsolatedStorage("DisplayXAxis", CheckBoxDisplayXAxis.IsChecked.GetValueOrDefault()); IsolatedStorageManager.WriteToIsolatedStorage("DisplayFrequencyYAxis", CheckBoxDisplayFrequencyYAxis.IsChecked.GetValueOrDefault()); IsolatedStorageManager.WriteToIsolatedStorage("DisplayPhaseAngleYAxis", CheckBoxDisplayPhaseAngleYAxis.IsChecked.GetValueOrDefault()); IsolatedStorageManager.WriteToIsolatedStorage("DisplayVoltageYAxis", CheckBoxDisplayVoltageMagnitudeYAxis.IsChecked.GetValueOrDefault()); IsolatedStorageManager.WriteToIsolatedStorage("DisplayCurrentYAxis", CheckBoxDisplayCurrentMagnitudeYAxis.IsChecked.GetValueOrDefault()); IsolatedStorageManager.WriteToIsolatedStorage("FrequencyRangeMin", TextBoxFrequencyRangeMin.Text); IsolatedStorageManager.WriteToIsolatedStorage("FrequencyRangeMax", TextBoxFrequencyRangeMax.Text); IsolatedStorageManager.WriteToIsolatedStorage("DisplayLegend", CheckBoxDisplayLegend.IsChecked.GetValueOrDefault()); RetrieveSettingsFromIsolatedStorage(); PopulateSettings(); PopupSettings.IsOpen = false; CommonFunctions.LoadUserControl(CommonFunctions.GetHeaderText("Graph Real-time Measurements"), typeof(InputStatusMonitorUserControl)); }
private void InputStatusMonitorUserControl_Unloaded(object sender, RoutedEventArgs e) { m_restartConnectionCycle = false; m_dataContext.RestartConnectionCycle = false; Unsubscribe(); m_dataContext.UnsubscribeUnsynchronizedData(); IsolatedStorageManager.WriteToIsolatedStorage("InputMonitoringPoints", m_selectedSignalIDs); }
private void ButtonSave_Click(object sender, RoutedEventArgs e) { if (int.TryParse(TextBoxNumberOfMessages.Text, out m_numberOfMessages)) { IsolatedStorageManager.WriteToIsolatedStorage("NumberOfMessages", m_numberOfMessages); PopupSettings.IsOpen = false; } else { MessageBox.Show("Please provide integer value.", "ERROR: Invalid Value", MessageBoxButton.OK); } }
/// <summary> /// Attempts to run the PMU Connection Tester from the path given by the user. /// </summary> private void RunConnectionTesterQuery_OK(object sender, RoutedEventArgs e) { string connectionTesterPath = ConnectionTesterPathTextBox.Text; if (TryRunConnectionTester(connectionTesterPath)) { IsolatedStorageManager.WriteToIsolatedStorage("PMUConnectionTester.exe", connectionTesterPath); TraverseDecisionTree("ConnectionFileQuery"); } else { TraverseDecisionTree("NumberOfChannelsQuery"); } }
/// <summary> /// Called when the view is unloaded. /// </summary> public virtual void Unload() { string virtualDeviceNameKey; if ((object)m_calculator != null) { virtualDeviceNameKey = string.Format("AverageFrequency.{0}.VirtualDeviceName", m_calculator.AdapterName); if (!string.IsNullOrEmpty(m_selectedVirtualDeviceName)) { IsolatedStorageManager.WriteToIsolatedStorage(virtualDeviceNameKey, m_selectedVirtualDeviceName); } } }
/// <summary> /// Called when the view is unloaded. /// </summary> public virtual void Unload() { const string calculatorNameKey = "AverageFrequency.CalculatorName"; string virtualDeviceNameKey = string.Format("AverageFrequency.{0}.VirtualDeviceName", m_selectedCalculatorName); if (!string.IsNullOrEmpty(m_selectedCalculatorName)) { IsolatedStorageManager.WriteToIsolatedStorage(calculatorNameKey, m_selectedCalculatorName); } if (!string.IsNullOrEmpty(m_selectedVirtualDeviceName)) { IsolatedStorageManager.WriteToIsolatedStorage(virtualDeviceNameKey, m_selectedVirtualDeviceName); } }
private void ButtonSave_Click(object sender, RoutedEventArgs e) { if (int.TryParse(TextBoxRefreshInterval.Text, out m_measurementsDataRefreshInterval)) { m_dataContext.RestartConnectionCycle = false; m_dataContext.UnsubscribeUnsynchronizedData(); IsolatedStorageManager.WriteToIsolatedStorage("RealtimeMeasurementsDataRefreshInterval", m_measurementsDataRefreshInterval); //int.TryParse(IsolatedStorageManager.ReadFromIsolatedStorage("RealtimeMeasurementsDataRefreshInterval").ToString(), out m_measurementsDataRefreshInterval); PopupSettings.IsOpen = false; CommonFunctions.LoadUserControl(CommonFunctions.GetHeaderText("Monitor Device Outputs"), typeof(RealTimeMeasurementUserControl)); } else { MessageBox.Show("Please provide integer value.", "ERROR: Invalid Value", MessageBoxButton.OK); } }
// Saves changes to settings made in the popup. private void ButtonSave_Click(object sender, RoutedEventArgs e) { int refreshInterval; if (int.TryParse(TextBoxRefreshInterval.Text, out refreshInterval)) { IsolatedStorageManager.WriteToIsolatedStorage("AlarmStatusRefreshInterval", refreshInterval); TextBlockAlarmRefreshInterval.Text = refreshInterval.ToString(); m_dataContext.Monitor.RefreshInterval = refreshInterval; PopupSettings.IsOpen = false; } else { m_dataContext.DisplayStatusMessage("Please provide integer value."); } }
private void ButtonSave_Click(object sender, RoutedEventArgs e) { if (int.TryParse(TextBoxRefreshInterval.Text, out m_statisticDataRefreshInterval)) { m_dataContext.Stop(); IsolatedStorageManager.WriteToIsolatedStorage("StreamStatisticsDataRefreshInterval", m_statisticDataRefreshInterval); //int.TryParse(IsolatedStorageManager.ReadFromIsolatedStorage("StreamStatisticsDataRefreshInterval").ToString(), out m_statisticDataRefreshInterval); TextBlockMeasurementRefreshInterval.Text = m_statisticDataRefreshInterval.ToString(); PopupSettings.IsOpen = false; CommonFunctions.LoadUserControl(CommonFunctions.GetHeaderText("Stream Statistics"), typeof(RealTimeStatisticUserControl)); } else { MessageBox.Show("Please provide integer value.", "ERROR: Invalid Value", MessageBoxButton.OK); } }
/// <summary> /// Creates an instance of <see cref="App"/> class. /// </summary> public App() { AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); m_errorLogger = new ErrorLogger(); m_defaultErrorText = m_errorLogger.ErrorTextMethod; m_errorLogger.ErrorTextMethod = ErrorText; m_errorLogger.ExitOnUnhandledException = false; m_errorLogger.HandleUnhandledException = true; m_errorLogger.LogToEmail = false; m_errorLogger.LogToEventLog = true; m_errorLogger.LogToFile = true; m_errorLogger.LogToScreenshot = true; m_errorLogger.LogToUI = true; m_errorLogger.Initialize(); m_title = AssemblyInfo.EntryAssembly.Title; // Setup default cache for measurement keys and associated Guid based signal ID's AdoDataConnection database = null; try { database = new AdoDataConnection(CommonFunctions.DefaultSettingsCategory); MeasurementKey.EstablishDefaultCache(database.Connection, database.AdapterType); } catch (Exception ex) { // First attempt to display a modal dialog will fail to block this // thread -- modal dialog displayed by the error logger will block now MessageBox.Show(ex.Message); // Log and display error, then exit application - manager must connect to database to continue m_errorLogger.Log(new InvalidOperationException(string.Format("{0} cannot connect to database: {1}", m_title, ex.Message), ex), true); } finally { if (database != null) { database.Dispose(); } } IsolatedStorageManager.WriteToIsolatedStorage("MirrorMode", false); }
/// <summary> /// Saves advanced find settings to isolated storage. /// </summary> public void SaveSettings() { string searchCategories = string.Empty; if (SearchCategories.Any(category => category.Selected)) { searchCategories = SearchCategories .Where(category => category.Selected) .Select(category => category.Name) .Aggregate((str1, str2) => str1 + "," + str2); } IsolatedStorageManager.WriteToIsolatedStorage("MeasurementSearchText", SearchText); IsolatedStorageManager.WriteToIsolatedStorage("MeasurementSearchIgnoreCase", IgnoreCase.ToString()); IsolatedStorageManager.WriteToIsolatedStorage("MeasurementSearchUseWildcards", UseWildcards.ToString()); IsolatedStorageManager.WriteToIsolatedStorage("MeasurementSearchUseRegex", UseRegex.ToString()); IsolatedStorageManager.WriteToIsolatedStorage("MeasurementSearchCategories", searchCategories); }
/// <summary> /// Handles loaded event for select measurement user control. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SelectMeasurementUserControl_Loaded(object sender, RoutedEventArgs e) { if (IsolatedStorageManager.ReadFromIsolatedStorage("DisplayInternal") == null) { IsolatedStorageManager.WriteToIsolatedStorage("DisplayInternal", false); } if (FilterByInternal) { CheckboxDisplayInternal.Visibility = Visibility.Visible; CheckboxDisplayInternal.IsChecked = IsolatedStorageManager.ReadFromIsolatedStorage("DisplayInternal").ToString().ParseBoolean(); } else { CheckboxDisplayInternal.Visibility = Visibility.Collapsed; } if (!DesignerProperties.GetIsInDesignMode(this)) { Refresh(); } }
private void PopupAddMore_Closed(object sender, EventArgs e) { IsolatedStorageManager.WriteToIsolatedStorage(PhaseFilterSetting, TextBoxPhaseFilter.Text); }
/// <summary> /// When the user unchecks the "Do not show at startup" checkbox. /// </summary> private void DoNotShowAtStartup_Unchecked(object sender, RoutedEventArgs e) { IsolatedStorageManager.WriteToIsolatedStorage("ShowWalkthroughAtStartup", true); }
/// <summary> /// Creates an instance of <see cref="App"/> class. /// </summary> public App() { string systemName = null; AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); Application.Current.SessionEnding += Application_SessionEnding; try { string getElementValue(XElement[] elements, string name) { XElement element = elements.Elements("add").FirstOrDefault(elem => elem.Attributes("name").Any(nameAttribute => string.Compare(nameAttribute.Value, name, StringComparison.OrdinalIgnoreCase) == 0)); return(element?.Attributes("value").FirstOrDefault()?.Value); } string configPath = FilePath.GetAbsolutePath(ConfigurationFile.Current.Configuration.FilePath.Replace("Manager", "")); if (File.Exists(configPath)) { XDocument hostConfig = XDocument.Load(configPath); XElement[] systemSettings = hostConfig.Descendants(SystemSettings).ToArray(); // Get system name from host service config systemName = getElementValue(systemSettings, "SystemName"); // Validate manager database connection as compared to host service string hostConnectionString = getElementValue(systemSettings, "ConnectionString"); string hostDataProviderString = getElementValue(systemSettings, "DataProviderString"); string hostNodeID = getElementValue(systemSettings, "NodeID"); ConfigurationFile config = ConfigurationFile.Current; CategorizedSettingsElementCollection configSettings = config.Settings[SystemSettings]; configSettings.Add("KeepCustomConnection", "false", "Determines if manager should keep custom database connection setting separate from host service."); if (!configSettings["KeepCustomConnection"].Value.ParseBoolean()) { MethodInfo getRawValueMethod = typeof(CategorizedSettingsElement).GetMethod("GetRawValue", BindingFlags.Instance | BindingFlags.NonPublic); string getRawValue(CategorizedSettingsElement element) { if (getRawValueMethod is null) { return(element.Value); } return(getRawValueMethod.Invoke(element, Array.Empty <object>()) as string); } // Get value from connection string that is still encrypted for proper comparison string connectionString = getRawValue(configSettings["ConnectionString"]); string dataProviderString = configSettings["DataProviderString"].Value; string nodeID = configSettings["NodeID"].Value; if (!hostConnectionString.Equals(connectionString, StringComparison.OrdinalIgnoreCase) || !hostDataProviderString.Equals(dataProviderString, StringComparison.OrdinalIgnoreCase) || !hostNodeID.Equals(nodeID, StringComparison.OrdinalIgnoreCase)) { bool mismatchHandled = false; if (Environment.CommandLine.Contains("-elevated") && Environment.CommandLine.Contains("-connection")) { if (Environment.CommandLine.Contains("-connectionFix")) { configSettings["ConnectionString"].Value = hostConnectionString; configSettings["DataProviderString"].Value = hostDataProviderString; configSettings["NodeID"].Value = hostNodeID; config.Save(); mismatchHandled = true; } else if (Environment.CommandLine.Contains("-connectionKeep")) { configSettings["KeepCustomConnection"].Value = "true"; config.Save(); mismatchHandled = true; } } if (!mismatchHandled) { bool correctMismatch = System.Windows.Forms.MessageBox.Show(new NativeWindow(), "Manager database connection does not match host service. Do you want to correct this?", "Database Mismatch", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes; string elevatedOperation = correctMismatch ? "-connectionFix" : "-connectionKeep"; ProcessStartInfo startInfo = new ProcessStartInfo { FileName = Environment.GetCommandLineArgs()[0], Arguments = $"{string.Join(" ", Environment.GetCommandLineArgs().Skip(1))} -elevated {elevatedOperation}", UseShellExecute = true, Verb = "runas" }; using (Process.Start(startInfo)) { } Environment.Exit(0); } } } } } catch { // If this fails, it's not a huge deal } m_errorLogger = new ErrorLogger { ErrorTextMethod = ErrorText, ExitOnUnhandledException = false, HandleUnhandledException = true, LogToEmail = false, LogToEventLog = true, LogToFile = true, LogToScreenshot = true, LogToUI = true }; m_errorLogger.Initialize(); m_defaultErrorText = m_errorLogger.ErrorTextMethod; Title = AssemblyInfo.EntryAssembly.Title; // Add system name to title if (!string.IsNullOrWhiteSpace(systemName)) { Title = $"{Title} [{systemName.Trim()}]"; } // Setup default cache for measurement keys and associated Guid based signal ID's AdoDataConnection database = null; try { database = new AdoDataConnection(SystemSettings); if (!Environment.CommandLine.Contains("-elevated")) { ConfigurationFile configurationFile = ConfigurationFile.Current; CategorizedSettingsElementCollection systemSettings = configurationFile.Settings[SystemSettings]; string elevateSetting = systemSettings["ElevateProcess"]?.Value; bool elevateProcess = !string.IsNullOrEmpty(elevateSetting) ? elevateSetting.ParseBoolean() : database.IsSqlite; if (elevateProcess) { ProcessStartInfo startInfo = new ProcessStartInfo { FileName = Environment.GetCommandLineArgs()[0], Arguments = $"{string.Join(" ", Environment.GetCommandLineArgs().Skip(1))} -elevated", UseShellExecute = true, Verb = "runas" }; using (Process.Start(startInfo)) { } Environment.Exit(0); } } MeasurementKey.EstablishDefaultCache(database.Connection, database.AdapterType); } catch (Exception ex) { // First attempt to display a modal dialog will fail to block this // thread -- modal dialog displayed by the error logger will block now MessageBox.Show(ex.Message); // Log and display error, then exit application - manager must connect to database to continue m_errorLogger.Log(new InvalidOperationException($"{Title} cannot connect to database: {ex.Message}", ex), true); } finally { database?.Dispose(); } bool mirrorMode = true; try { CategorizedSettingsElementCollection systemSettings = ConfigurationFile.Current.Settings["systemSettings"]; CategorizedSettingsElement mirrorModeSetting = systemSettings["MirrorMode"]; if (!(mirrorModeSetting is null)) { mirrorMode = mirrorModeSetting.ValueAsBoolean(); } } catch (Exception ex) { // First attempt to display a modal dialog will fail to block this // thread -- modal dialog displayed by the error logger will block now MessageBox.Show(ex.Message); // Log and display error, but continue on - if manager fails to load MirrorMode from the config file, it can just fall back on the default m_errorLogger.Log(new InvalidOperationException($"{Title} cannot access mirror mode setting in configuration file - defaulting to true: {ex.Message}", ex)); } IsolatedStorageManager.WriteToIsolatedStorage("MirrorMode", mirrorMode); }
/// <summary> /// Creates an instance of <see cref="App"/> class. /// </summary> public App() { AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); m_errorLogger = new ErrorLogger(); m_defaultErrorText = m_errorLogger.ErrorTextMethod; m_errorLogger.ErrorTextMethod = ErrorText; m_errorLogger.ExitOnUnhandledException = false; m_errorLogger.HandleUnhandledException = true; m_errorLogger.LogToEmail = false; m_errorLogger.LogToEventLog = true; m_errorLogger.LogToFile = true; m_errorLogger.LogToScreenshot = true; m_errorLogger.LogToUI = true; m_errorLogger.Initialize(); m_title = AssemblyInfo.EntryAssembly.Title; // Setup default cache for measurement keys and associated Guid based signal ID's AdoDataConnection database = null; try { database = new AdoDataConnection(CommonFunctions.DefaultSettingsCategory); if (!Environment.CommandLine.Contains("-elevated")) { ConfigurationFile configurationFile = ConfigurationFile.Current; CategorizedSettingsElementCollection systemSettings = configurationFile.Settings["SystemSettings"]; string elevateSetting = systemSettings["ElevateProcess"]?.Value; bool elevateProcess; if (!string.IsNullOrEmpty(elevateSetting)) { elevateProcess = elevateSetting.ParseBoolean(); } else { elevateProcess = database.IsSqlite; } if (elevateProcess && !Environment.CommandLine.Contains("-elevated")) { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = Environment.GetCommandLineArgs()[0]; startInfo.Arguments = string.Join(" ", Environment.GetCommandLineArgs().Skip(1)) + " -elevated"; startInfo.UseShellExecute = true; startInfo.Verb = "runas"; using (Process.Start(startInfo)) { } Environment.Exit(0); } } MeasurementKey.EstablishDefaultCache(database.Connection, database.AdapterType); } catch (Exception ex) { // First attempt to display a modal dialog will fail to block this // thread -- modal dialog displayed by the error logger will block now MessageBox.Show(ex.Message); // Log and display error, then exit application - manager must connect to database to continue m_errorLogger.Log(new InvalidOperationException(string.Format("{0} cannot connect to database: {1}", m_title, ex.Message), ex), true); } finally { if (database != null) { database.Dispose(); } } IsolatedStorageManager.WriteToIsolatedStorage("MirrorMode", false); }
private void CheckboxDisplayInternal_Unchecked(object sender, RoutedEventArgs e) { Refresh(m_currentDeviceID); IsolatedStorageManager.WriteToIsolatedStorage("DisplayInternal", false); }
/// <summary> /// Creates an instance of <see cref="App"/> class. /// </summary> public App() { bool mirrorMode = true; AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); m_errorLogger = new ErrorLogger(); m_defaultErrorText = m_errorLogger.ErrorTextMethod; m_errorLogger.ErrorTextMethod = ErrorText; m_errorLogger.ExitOnUnhandledException = false; m_errorLogger.HandleUnhandledException = true; m_errorLogger.LogToEmail = false; m_errorLogger.LogToEventLog = true; m_errorLogger.LogToFile = true; m_errorLogger.LogToScreenshot = true; m_errorLogger.LogToUI = true; m_errorLogger.Initialize(); m_title = AssemblyInfo.EntryAssembly.Title; // Setup default cache for measurement keys and associated Guid based signal ID's AdoDataConnection database = null; try { database = new AdoDataConnection(CommonFunctions.DefaultSettingsCategory); MeasurementKey.EstablishDefaultCache(database.Connection, database.AdapterType); } catch (Exception ex) { // First attempt to display a modal dialog will fail to block this // thread -- modal dialog displayed by the error logger will block now MessageBox.Show(ex.Message); // Log and display error, then exit application - manager must connect to database to continue m_errorLogger.Log(new InvalidOperationException(string.Format("{0} cannot connect to database: {1}", m_title, ex.Message), ex), true); } finally { if (database != null) { database.Dispose(); } } try { CategorizedSettingsElementCollection systemSettings = ConfigurationFile.Current.Settings["systemSettings"]; CategorizedSettingsElement mirrorModeSetting = systemSettings["MirrorMode"]; if ((object)mirrorModeSetting != null) { mirrorMode = mirrorModeSetting.ValueAsBoolean(); } } catch (Exception ex) { // First attempt to display a modal dialog will fail to block this // thread -- modal dialog displayed by the error logger will block now MessageBox.Show(ex.Message); // Log and display error, but continue on - if manager fails to load MirrorMode from the config file, it can just fall back on the default m_errorLogger.Log(new InvalidOperationException(string.Format("{0} cannot access mirror mode setting in configuration file - defaulting to true: {1}", m_title, ex.Message), ex)); } IsolatedStorageManager.WriteToIsolatedStorage("MirrorMode", mirrorMode); }