private void PromptUser(string Message, string StackTrace = null, Severity MsgLevel = Severity.Error) { myLogger.WriteToLogFile(Message, MsgLevel); if (StackTrace != null) { myLogger.WriteToLogFile(StackTrace, Severity.Error); } PromptUser promptUser = new PromptUser(Message + " See log file for more info."); promptUser.ShowDialog(); }
private void SSBackup_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!isConfigSaved) { PromptUser promptUser = new PromptUser("You haven't saved your changes! All changes will be lost. Select OK if you want to continue closing..."); promptUser.ShowDialog(); if (promptUser.DialogResult == System.Windows.Forms.DialogResult.Cancel) { e.Cancel = true; } } }
public MainWindow() { try { myLogger = new Logger(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), ApplicationType.Client); } catch { //fatal if we can't create log file PromptUser promptUser = new PromptUser("Fatal error, unable to create logger. Application will terminate"); promptUser.ShowDialog(); System.Windows.Application.Current.Shutdown(); } try { configFile = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\Configuration.bin"; } catch { try { File.Create(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\Configuration.bin"); } catch (Exception Ex) { PromptUser("Unable to find nor create configuration file. Will exit. Exception is:" + Ex.Message, Ex.StackTrace, Severity.Warning); System.Windows.Application.Current.Shutdown(); } } InitializeComponent(); InitializaeUIObjects(); Items = new List <String>(); this.Width = 691.2; try { myCopyer = new Copyer(ApplicationType.Client); } catch (Exception Ex) //This should never get hit. Here just in case... { PromptUser("Unable to create Copyer and possibly log file. Application will close. Exception is" + Ex.Message); System.Windows.Application.Current.Shutdown(); } //Does this if statement need to be in a Try Catch ? if (Support.Support.CheckPath(configFile, PathType.File)) { string[] configItems = Support.Support.Deserialize(configFile); Destination.Text = configItems[configItems.Length - 2]; //Need to do this before sources to calculate size difference hgb string[] configTime = Support.Support.ReturnFrequency(configItems[configItems.Length - 1]); Hours.Text = configTime[0]; Minutes.Text = configTime[1]; AMPM.Text = configTime[2]; Frequency.Text = configTime[3]; for (int i = 0; i < configItems.Length - 2; i++) { string searchString = @"Source" + (i + 1).ToString(); List <Object> _sourceUIObjects = new List <Object>(); _sourceUIObjects = (from entry in sourceUIObjects where (entry.Key == searchString) select entry.Value).FirstOrDefault(); ((System.Windows.Controls.TextBox)_sourceUIObjects[0]).Text = configItems[i]; Items.Add(configItems[i]); ChangeVisibility(_sourceUIObjects, Visibility.Visible); if (i > 0) { screenSize += 0.125; } } sourceNumber = configItems.Length - 2; destinationPosition = sourceNumber + 1; overviewPosition = destinationPosition + 1; Items.Add(configItems[configItems.Length - 2]); for (int i = configItems.Length - 2; i < 4; i++) { string searchString = @"Source" + (i + 1).ToString(); List <Object> _sourceUIObjects = new List <Object>(); _sourceUIObjects = (from entry in sourceUIObjects where (entry.Key == searchString) select entry.Value).FirstOrDefault(); ChangeVisibility(_sourceUIObjects, Visibility.Hidden); } for (int i = 3; i < 6; i++) { string searchString = @"Source" + (i - 1).ToString(); List <Object> _sourceUIObjects = new List <Object>(); _sourceUIObjects = (from entry in sourceUIObjects where (entry.Key == searchString) select entry.Value).FirstOrDefault(); if (((System.Windows.Controls.TextBox)_sourceUIObjects[0]).Text == null || ((System.Windows.Controls.TextBox)_sourceUIObjects[0]).Text == string.Empty) { UIGrid.RowDefinitions[i].Height = new GridLength(0); } } UIGrid.RowDefinitions[6].Height = new GridLength(0); SourceUIChange(); } else { for (int i = 3; i < 7; i++) { UIGrid.RowDefinitions[i].Height = new GridLength(0); Source1.Text = "Sources Folder"; Destination.Text = "Destination Folder"; } } MoveNonSource(); SetGreen(SaveConfig); SetScreen(); DisplayRemoveSource(); RetrieveServiceStatus(); GetLastBackupTime(); }