예제 #1
0
        /// <summary>
        /// The actual Load Settings function that does all the magic
        /// </summary>
        /// <param name="fileNameAndPath"></param>
        /// <returns></returns>
        private static ConnectySetings load(string fileNameAndPath)
        {
            ConnectySetings loadedSettings = new ConnectySetings();

            try
            {
                ObjectToSerialize objectToSerialize = new ObjectToSerialize();
                Serializer        serializer        = new Serializer();
                objectToSerialize = serializer.DeSerializeObject(fileNameAndPath);

                loadedSettings.connectionSettings  = objectToSerialize.ConnectionSettings;
                loadedSettings.applicationSettings = objectToSerialize.ApplicationSettings;
                loadedSettings.viewSettings        = objectToSerialize.ViewSettings;
            }
            catch (Exception)
            {
                // Configure the message box to be displayed
                string           messageBoxText = "Die Einstellungen konnten nicht geladen werden.";
                string           caption        = "Ungültige Settings Datei";
                MessageBoxButton button         = MessageBoxButton.OK;
                MessageBoxImage  icon           = MessageBoxImage.Warning;

                // Display message box
                MessageBox.Show(messageBoxText, caption, button, icon);
            }

            // Return the loaded Settings
            return(loadedSettings);
        }
예제 #2
0
        /// <summary>
        /// The Actual Save Settings funktion where all the magic happens
        /// </summary>
        /// <param name="fileNameAndPath"></param>
        /// <param name="settings"></param>
        private static void save(string fileNameAndPath, ConnectySetings settings)
        {
            try
            {
                //save the car list to a file
                ObjectToSerialize objectToSerialize = new ObjectToSerialize();
                objectToSerialize.ConnectionSettings = settings.connectionSettings;

                objectToSerialize.ApplicationSettings = settings.applicationSettings;
                objectToSerialize.ViewSettings        = settings.viewSettings;

                Serializer serializer = new Serializer();
                serializer.SerializeObject(fileNameAndPath, objectToSerialize);
            }
            catch (Exception)
            {
                // Configure the message box to be displayed
                string           messageBoxText = "Die Einstellungen konnten nicht gespeichert werden. Bitte prüfen ob die notwendigen rechte für das speichern vorhanden sind.";
                string           caption        = "Datei speichern nicht erfolgreich";
                MessageBoxButton button         = MessageBoxButton.OK;
                MessageBoxImage  icon           = MessageBoxImage.Warning;

                // Display message box
                MessageBox.Show(messageBoxText, caption, button, icon);
            }
        }
예제 #3
0
        public void SerializeObject(string filename, ObjectToSerialize objectToSerialize)
        {
            Stream          stream     = File.Open(filename, FileMode.Create);
            BinaryFormatter bFormatter = new BinaryFormatter();

            bFormatter.Serialize(stream, objectToSerialize);
            stream.Close();
        }