Ejemplo n.º 1
0
        /// <summary>
        /// Loads settings file.
        /// </summary>
        /// <param name="fileName">File full name to load.</param>
        /// <param name="isPredefined">Is predefined flag.</param>
        /// <exception cref="T:ESRI.ArcLogistics.SettingsException"> Reports file is invalid.
        /// In property "Source" there is path to invalid reports file.</exception>
        private void _Load(string fileName, bool isPredefined)
        {
            if (!File.Exists(fileName))
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            // Try to load file.
            try
            {
                doc.Load(fileName);
                _LoadContent(doc.DocumentElement, isPredefined);
            }
            catch (Exception ex)
            {
                // If XML corrupted - wrap exception and save path to file.
                if (ex is XmlException || ex is NotSupportedException)
                {
                    SettingsException settingsException = new SettingsException(ex.Message, ex);
                    settingsException.Source = fileName;
                    throw settingsException;
                }
            }
        }
            /// <summary>
            /// Load user settings from file.
            /// </summary>
            /// <param name="configPath">Path to settings file.</param>
            /// <exception cref="T:ESRI.ArcLogistics.SettingsException"> Settings file is invalid.
            /// In property "Source" there is path to invalid settings file.</exception>
            private static XmlDocument _LoadDoc(string path)
            {
                XmlDocument doc = new XmlDocument();

                if (File.Exists(path))
                {
                    // Try to load file.
                    try
                    {
                        doc.Load(path);
                    }
                    catch (XmlException ex)
                    {
                        // If XML corrupted - wrap exception and save path to file.
                        SettingsException settingsException = new SettingsException(ex.Message, ex);
                        settingsException.Source = path;
                        throw settingsException;
                    }
                }
                else
                {
                    _InitDocStructure(doc);
                    doc.Save(path);
                }

                return(doc);
            }
Ejemplo n.º 3
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="fileName">Path to import config file.</param>
        /// <exception cref="T:ESRI.ArcLogistics.SettingsException"> Import file is invalid.
        /// In property "Source" there is path to invalid import file.</exception>
        public ImportFile(string fileName)
        {
            Debug.Assert(!string.IsNullOrEmpty(fileName));

            _profiles.Clear();
            _fileName = fileName;

            if (!File.Exists(fileName))
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            // Try to load file.
            try
            {
                doc.Load(fileName);
                _LoadContent(doc.DocumentElement);
            }
            catch (Exception ex)
            {
                // If XML corrupted - wrap exception and save path to file.
                if (ex is XmlException || ex is NotSupportedException)
                {
                    SettingsException settingsException = new SettingsException(ex.Message, ex);
                    settingsException.Source = fileName;
                    throw settingsException;
                }
            }
        }
Ejemplo n.º 4
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Loads export profiles from file.
        /// </summary>
        /// <param name="fileName">Storage file path.</param>
        /// <param name="structureKeeper">Export structure reader.</param>
        /// <returns>Loaded list of <see cref="P:ESRI.ArcLogistics.Export.Profile" />.</returns>
        /// <exception cref="T:ESRI.ArcLogistics.SettingsException"> Export file is invalid.
        /// In property "Source" there is path to invalid export file.</exception>
        public List <Profile> Load(string fileName, ExportStructureReader structureKeeper)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException(); // exception
            }
            var profiles = new List <Profile> ();

            if (File.Exists(fileName))
            {
                var doc = new XmlDocument();

                // Try to load file.
                try
                {
                    doc.Load(fileName);

                    // create navigation tree in memory
                    profiles = _LoadContent(doc.DocumentElement, structureKeeper);
                }
                catch (Exception ex)
                {
                    // If XML corrupted - wrap exception and save path to file.
                    if (ex is XmlException || ex is NotSupportedException)
                    {
                        SettingsException settingsException = new SettingsException(ex.Message, ex);
                        settingsException.Source = fileName;
                        throw settingsException;
                    }
                }
            }

            return(profiles);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// This method will be used to get the app setting from the viewmodel and save it in the App.config file
 /// </summary>
 /// <param name="appSettings">Appsetting object</param>
 /// <returns>bool whether settings were saved successfully or not</returns>
 public bool SaveSettings(AppSettings appSettings)
 {
     try
     {
         SettingsHelper.ServerUrl  = appSettings.ServerURL;
         SettingsHelper.Username   = EncryptionHelper.EncryptString(appSettings.Username);
         SettingsHelper.Password   = EncryptionHelper.EncryptString(appSettings.Password);
         SettingsHelper.BucketName = EncryptionHelper.EncryptString(appSettings.BucketName);
         SettingsHelper.AccessKey  = EncryptionHelper.EncryptString(appSettings.AccessKey);
         SettingsHelper.SecretKey  = EncryptionHelper.EncryptString(appSettings.SecretKey);
         SettingsHelper.Save();
         return(true);
     }
     catch (Exception ex)
     {
         SettingsException?.Invoke("There was an exception while saving settings. Exception: " + ex.Message);
         return(false);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// This method will load the AppSettings (configured by the user) to be displayed on the settings page when it's loaded
 /// </summary>
 /// <returns>Appsetting model</returns>
 public AppSettings LoadSettings()
 {
     try
     {
         return(new AppSettings
         {
             ServerURL = SettingsHelper.ServerUrl,
             Username = !string.IsNullOrEmpty(SettingsHelper.Username) ? EncryptionHelper.DecryptString(SettingsHelper.Username) : string.Empty,
             Password = !string.IsNullOrEmpty(SettingsHelper.Password) ? EncryptionHelper.DecryptString(SettingsHelper.Password) : string.Empty,
             BucketName = !string.IsNullOrEmpty(SettingsHelper.BucketName) ? EncryptionHelper.DecryptString(SettingsHelper.BucketName) : string.Empty,
             SecretKey = !string.IsNullOrEmpty(SettingsHelper.SecretKey) ? EncryptionHelper.DecryptString(SettingsHelper.SecretKey) : string.Empty,
             AccessKey = !string.IsNullOrEmpty(SettingsHelper.AccessKey) ? EncryptionHelper.DecryptString(SettingsHelper.AccessKey) : string.Empty
         });
     }
     catch (Exception ex)
     {
         SettingsException?.Invoke("There was an exception while loading settings. Exception: " + ex.Message);
         return(new AppSettings());
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Loads settings file.
        /// </summary>
        /// <param name="fileName">File full name to load.</param>
        /// <param name="isPredefined">Is predefined flag.</param>
        /// <exception cref="T:ESRI.ArcLogistics.SettingsException"> Reports file is invalid.
        /// In property "Source" there is path to invalid reports file.</exception>
        private void _Load(string fileName, bool isPredefined)
        {
            if (!File.Exists(fileName))
                return;

            XmlDocument doc = new XmlDocument();
            // Try to load file.
            try
            {
                doc.Load(fileName);
                _LoadContent(doc.DocumentElement, isPredefined);
            }
            catch (Exception ex)
            {
                // If XML corrupted - wrap exception and save path to file.
                if (ex is XmlException || ex is NotSupportedException)
                {
                    SettingsException settingsException = new SettingsException(ex.Message, ex);
                    settingsException.Source = fileName;
                    throw settingsException;
                }
            }
        }
Ejemplo n.º 8
0
        //All uncaught exceptions will go here instead. We will replace the default windows popup with our own custom one and filter out what kind of exception is being thrown
        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            ErrorPrompt p = new ErrorPrompt(e.Exception); p.Show();

            if (e.Exception is SettingsException)
            {
                SettingsException ex = (SettingsException)e.Exception;
                BLIO.WriteError(e.Exception, ex.Message + "\r\n" + ex.Description);
            }
            else if (e.Exception is DirectoryNotFoundException)
            {
                DirectoryNotFoundException theException = (DirectoryNotFoundException)e.Exception;
                BLIO.WriteError(theException, "Folder not found.");
            }

            else if (e.Exception is UnauthorizedAccessException)
            {
                UnauthorizedAccessException theException = (UnauthorizedAccessException)e.Exception;
                BLIO.WriteError(e.Exception, "Unauthorized!");
            }

            //Here we just filter out some type of exceptions and give different messages, at the bottom is the super Exception, which can be anything.
            else if (e.Exception is FileNotFoundException)
            {
                FileNotFoundException theException = (FileNotFoundException)e.Exception; //needs in instance to call .FileName
                BLIO.WriteError(theException, "Could not find the file located at \"" + theException.FileName);
            }

            else if (e.Exception is System.Data.Entity.Core.EntityException)
            {
                BLIO.WriteError(e.Exception, "System.Data.Entity.Core.EntityException");
            }

            else if (e.Exception is ArgumentNullException)
            {
                BLIO.WriteError(e.Exception, "Null argument");
            }

            else if (e.Exception is NullReferenceException)
            {
                BLIO.WriteError(e.Exception, "Null reference");
            }

            else if (e.Exception is SQLiteException)
            {
                BLIO.WriteError(e.Exception, "SQLite Database exception");
            }

            else if (e.Exception is PathTooLongException)
            {
                BLIO.WriteError(e.Exception, "The path to the file is too long.");
            }

            else if (e.Exception is StackOverflowException)
            {
                BLIO.WriteError(e.Exception, "StackOverFlowException");
            }

            else if (e.Exception is OutOfMemoryException)
            {
                BLIO.WriteError(e.Exception, "Out of Memory");
            }
            else if (e.Exception is DbUpdateConcurrencyException)
            {
                BLIO.WriteError(e.Exception, "Database error.");
            }

            else if (e.Exception is Exception)
            {
                BLIO.WriteError(e.Exception, "Unknown exception in main.");
            }
        }
Ejemplo n.º 9
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="fileName">Path to import config file.</param>
        /// <exception cref="T:ESRI.ArcLogistics.SettingsException"> Import file is invalid.
        /// In property "Source" there is path to invalid import file.</exception>
        public ImportFile(string fileName)
        {
            Debug.Assert(!string.IsNullOrEmpty(fileName));

            _profiles.Clear();
            _fileName = fileName;

            if (!File.Exists(fileName))
                return;

            XmlDocument doc = new XmlDocument();
            // Try to load file.
            try
            {
                doc.Load(fileName);
                _LoadContent(doc.DocumentElement);
            }
            catch (Exception ex)
            {
                // If XML corrupted - wrap exception and save path to file.
                if (ex is XmlException || ex is NotSupportedException)
                {
                    SettingsException settingsException = new SettingsException(ex.Message, ex);
                    settingsException.Source = fileName;
                    throw settingsException;
                }
            }
        }
            /// <summary>
            /// Load user settings from file.
            /// </summary>
            /// <param name="configPath">Path to settings file.</param>
            /// <exception cref="T:ESRI.ArcLogistics.SettingsException"> Settings file is invalid.
            /// In property "Source" there is path to invalid settings file.</exception>
            private static XmlDocument _LoadDoc(string path)
            {
                XmlDocument doc = new XmlDocument();

                if (File.Exists(path))
                {
                    // Try to load file.
                    try
                    {
                        doc.Load(path);
                    }
                    catch (XmlException ex)
                    {
                        // If XML corrupted - wrap exception and save path to file.
                        SettingsException settingsException = new SettingsException(ex.Message, ex);
                        settingsException.Source = path;
                        throw settingsException;
                    }
                }
                else
                {
                    _InitDocStructure(doc);
                    doc.Save(path);
                }

                return doc;
            }
Ejemplo n.º 11
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads export profiles from file.
        /// </summary>
        /// <param name="fileName">Storage file path.</param>
        /// <param name="structureKeeper">Export structure reader.</param>
        /// <returns>Loaded list of <see cref="P:ESRI.ArcLogistics.Export.Profile" />.</returns>
        /// <exception cref="T:ESRI.ArcLogistics.SettingsException"> Export file is invalid.
        /// In property "Source" there is path to invalid export file.</exception>
        public List<Profile> Load(string fileName, ExportStructureReader structureKeeper)
        {
            if (string.IsNullOrEmpty(fileName))
                throw new ArgumentNullException(); // exception

            var profiles = new List<Profile> ();
            if (File.Exists(fileName))
            {
                var doc = new XmlDocument();

                // Try to load file.
                try
                {
                    doc.Load(fileName);

                    // create navigation tree in memory
                    profiles = _LoadContent(doc.DocumentElement, structureKeeper);
                }
                catch (Exception ex )
                {
                    // If XML corrupted - wrap exception and save path to file.
                    if (ex is XmlException || ex is NotSupportedException)
                    {
                        SettingsException settingsException = new SettingsException(ex.Message, ex);
                        settingsException.Source = fileName;
                        throw settingsException;
                    }
                }
            }

            return profiles;
        }