//loading specific CA from file public void LoadCAFromFile(object messageIn) { bool?aDialogResult = null; string aDefaultExtension = ".xml"; string aFileExtensions = "Xml files (.xml)|*.xml"; string aFileName = null; aDialogResult = DialogMediator.ShowOpenFileDialog(this, aFileExtensions, aDefaultExtension, out aFileName); if (aDialogResult == true) { var aCAGrid2DVM = new CAGrid2DVM(); try { //reading CA from specified file and adding it to list of CAs CAGrid2DRW.ReadCA(aFileName, this, ref aCAGrid2DVM); myGrid2DViewModelList.Add(aCAGrid2DVM); } catch (Exception ex) { if (ex is System.IO.FileNotFoundException || ex is System.Security.SecurityException || ex is UriFormatException || ex is System.Xml.XmlException || ex is FormatException || ex is OverflowException || ex is ArgumentOutOfRangeException || ex is NullReferenceException || ex is CAExplorerException) { DialogMediator.ShowMessageBox(null, "Exception during reading CA", "Problem with reading 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 read here. public static void ReadAllAvailableCAs(CAMainWindowVM caMainWindowVMIn) { string[] aAvailableCAs = null; try { aAvailableCAs = Directory.GetFiles(@".\SavedCA\", "*.xml"); } catch (Exception ex) { if (ex is IOException || ex is UnauthorizedAccessException || ex is PathTooLongException || ex is DirectoryNotFoundException) { DialogMediator.ShowMessageBox(null, "Exception during reading CAs", "Problem with reading files from directory \\SavedCA\\ \n" + ex.Message, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); } else { throw; } } if (aAvailableCAs != null) { string aCAsWithProblem = null; string aCAExceptions = null; foreach (string aAvailableCAItem in aAvailableCAs) { try { CAGrid2DVM aCAGrid2DVM = caMainWindowVMIn.CreateNewEmptyCA(); bool aWasOK = CAGrid2DRW.ReadCA(aAvailableCAItem, caMainWindowVMIn, ref aCAGrid2DVM); if (aWasOK == true) { caMainWindowVMIn.AddNewCA(aCAGrid2DVM); } } catch (Exception ex) { if (ex is FileNotFoundException || ex is System.Security.SecurityException || ex is UriFormatException || ex is XmlException || ex is FormatException || ex is OverflowException || ex is ArgumentOutOfRangeException || ex is NullReferenceException || ex is CAExplorerException || ex is InvalidOperationException) { aCAsWithProblem += aAvailableCAItem + "\n"; aCAExceptions += ex.Message + "\n"; } else { throw; } } } if (aCAsWithProblem != null) { DialogMediator.ShowMessageBox(null, "Exception during reading CA", "Problem with reading following CA files : \n" + aCAsWithProblem + "\n" + "Following exceptions occured : \n" + aCAExceptions, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); } } }