//saving specific CA To file public void SaveCAToFile(object messageIn) { if (mySelectedCAGrid2DViewModel != null) { bool?aDialogResult = null; string aDefaultExtension = ".xml"; string aFileExtensions = "Xml files (.xml)|*.xml"; string aFileName = null; aDialogResult = DialogMediator.ShowSaveFileDialog(this, aFileExtensions, aDefaultExtension, out aFileName); if (aDialogResult == true) { try { //writing specific CA to file. CAGrid2DRW.WriteCA(aFileName, mySelectedCAGrid2DViewModel); } catch (Exception ex) { if (ex is InvalidOperationException || ex is EncoderFallbackException || ex is ArgumentException || ex is UnauthorizedAccessException || ex is System.IO.DirectoryNotFoundException || ex is System.IO.IOException || ex is System.Security.SecurityException || ex is System.IO.PathTooLongException) { DialogMediator.ShowMessageBox(null, "Exception during writing of CA", "Problem with writing following CA file : \n" + aFileName + "\n" + "Following exception occured : \n" + ex.Message, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); } else { throw; } } } } }
//all available CAs are written here. public static void WriteAllAvailableCAs(CAMainWindowVM caMainWindowVMIn) { string aCAsWithProblem = null; string aCAExceptions = null; foreach (CAGrid2DVM aCAGrid2DVMItem in caMainWindowVMIn.Grid2DViewModelList) { if (aCAGrid2DVMItem != null) { string aFilename = null; try { aFilename = @".\SavedCA\" + aCAGrid2DVMItem.CAName + ".xml"; CAGrid2DRW.WriteCA(aFilename, aCAGrid2DVMItem); } catch (Exception ex) { if (ex is InvalidOperationException || ex is EncoderFallbackException || ex is ArgumentException || ex is UnauthorizedAccessException || ex is DirectoryNotFoundException || ex is IOException || ex is System.Security.SecurityException || ex is PathTooLongException) { aCAsWithProblem += aFilename + "\n"; aCAExceptions += ex.Message + "\n"; } else { throw; } } } } if (aCAsWithProblem != null) { DialogMediator.ShowMessageBox(null, "Exception during writing CA", "Problem with writing following CA files : \n" + aCAsWithProblem + "\n" + "Following exceptions occured : \n" + aCAExceptions, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); } }