示例#1
0
        internal static Data.LiftItems ImportFromFile(string filepath)
        {
            Data.LiftItems result = null;
            try
            {
                using (var reader = new StreamReader(filepath))
                {
                    result = NewLiftItemsSerializer().Deserialize(reader) as Data.LiftItems;
                    //SaveToSettings();
                }
            }
            catch (InvalidOperationException ex)
            {
                // do something with this exception, report it back to the user
                var msg = String.Format("Could not import the file '{0}', Exception: {1}", filepath, ex);
                Console.WriteLine(msg);
            }
            catch (Exception ex)
            {
                // an error that occurred while opening the file
                var msg = String.Format("Could read the file '{0}', Exception: {1}", filepath, ex);
                Console.WriteLine(msg);
            }

            return(result);
        }
示例#2
0
        public static GlobalState Load()
        {
            Data.Options   options   = Persistence.OptionsStore.Load();
            Data.LiftItems liftItems = Persistence.LiftItemsStore.Load();
            Resources.Localization.Translations translations = new Lift.Resources.Localization.Translations();

            return(new GlobalState {
                Options = options, LiftItems = liftItems, Translations = translations
            });
        }
示例#3
0
        private static void SaveToSettings(Data.LiftItems liftItems)
        {
            string str;

            using (var writer = new StringWriter())
            {
                NewLiftItemsSerializer().Serialize(writer, liftItems);
                str = writer.ToString();
            }

            Persistence.MiSettings.Default.LiftItems = str;
            Persistence.MiSettings.Default.Save();
        }
示例#4
0
        public Options(Persistence.GlobalState state)
        {
            InitializeComponent();
            internalData = state;

            System.Windows.Application.Current.MainWindow.Title = state.Translations["Options.Title"];
            DataContext = internalData;

            // TODO set itemsSource from xaml (relative path)
            cbLanguage.ItemsSource = internalData.Translations.SupportedLanguages;

            SelectActiveLanguage();
            _liftItems = internalData.LiftItems;
        }
示例#5
0
 internal static void ExportToFile(string filepath, Data.LiftItems liftItems)
 {
     try
     {
         using (var file = new System.IO.StreamWriter(filepath))
         {
             NewLiftItemsSerializer().Serialize(file, liftItems);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("An error occurred while writing the file, do something about it! {0}", ex.ToString());
     }
 }
示例#6
0
        private static Data.LiftItems LoadLiftItemsFromSettings()
        {
            Data.LiftItems result = null;
            string         loaded = Persistence.MiSettings.Default.LiftItems;

            try
            {
                using (var reader = new StringReader(loaded))
                {
                    result = NewLiftItemsSerializer().Deserialize(reader) as Data.LiftItems;
                }
            }
            catch (InvalidOperationException) { }
            catch (ArgumentNullException) { }

            return(result);
        }
示例#7
0
 internal static void Save(Data.LiftItems liftItems)
 {
     SaveToSettings(liftItems);
 }