Exemplo n.º 1
0
        //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;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        //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);
            }
        }
Exemplo n.º 3
0
        //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;
                    }
                }
            }
        }
Exemplo n.º 4
0
        //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);
                }
            }
        }