Exemplo n.º 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);
        }
Exemplo n.º 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
            });
        }
Exemplo n.º 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();
        }
Exemplo n.º 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;
        }
Exemplo n.º 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());
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 7
0
 internal static void Save(Data.LiftItems liftItems)
 {
     SaveToSettings(liftItems);
 }