Exemplo n.º 1
0
        private static MsgBoxViewModel DeserializeFromXML()
        {
            MsgBoxViewModel me = null;

            try
            {
                XmlSerializer deserializer = new XmlSerializer(typeof(MsgBoxViewModel));
                using (var textReader = new StreamReader(_settingsXMLFilename))
                {
                    Object obj = deserializer.Deserialize(textReader);
                    me = (MsgBoxViewModel)obj;
                }
            }
            catch (Exception x)
            {
                Console.WriteLine(x.GetType().ToString() + " in MsgBoxViewModel.DeserializeFromXML, " + x.Message);
                Console.WriteLine("Because I can't read the Settings file " + _settingsXMLFilename + ", I'm deleting it to start anew.");
                if (File.Exists(_settingsXMLFilename))
                {
                    File.Delete(_settingsXMLFilename);
                }
                Console.WriteLine("Creating new Settings.");
                me = new MsgBoxViewModel();
            }
            return(me);
        }
 public MainWindow()
 {
     InitializeComponent();
     _messageBoxManager = JhMessageBox.GetNewInstance("Invensys", "JhMessageBoxTestApp");
     rbUserMistake.IsChecked = true;
     _viewModel = MsgBoxViewModel.The;
     DataContext = _viewModel;
     Loaded += new RoutedEventHandler(MainWindow_Loaded);
 }
 private static MsgBoxViewModel DeserializeFromXML()
 {
     MsgBoxViewModel me = null;
     try
     {
         XmlSerializer deserializer = new XmlSerializer(typeof(MsgBoxViewModel));
         using (var textReader = new StreamReader(_settingsXMLFilename))
         {
             Object obj = deserializer.Deserialize(textReader);
             me = (MsgBoxViewModel)obj;
         }
     }
     catch (Exception x)
     {
         Console.WriteLine(x.GetType().ToString() + " in MsgBoxViewModel.DeserializeFromXML, " + x.Message);
         Console.WriteLine("Because I can't read the Settings file " + _settingsXMLFilename + ", I'm deleting it to start anew.");
         if (File.Exists(_settingsXMLFilename))
         {
             File.Delete(_settingsXMLFilename);
         }
         Console.WriteLine("Creating new Settings.");
         me = new MsgBoxViewModel();
     }
     return me;
 }