示例#1
0
        public MainWindow()
        {
            InitializeComponent();
            Model          = LoadConfigFile(CONFIG_FILE_NAME);
            timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            List <string> args = new List <string>(Environment.GetCommandLineArgs());

            if (args.Contains("-auto"))
            {
                appMode = ExecutionMode.Autostart;
            }
        }
示例#2
0
        private MainWindowDataModel LoadConfigFile(string fileName)
        {
            if (fileName == null)
            {
                throw new NullReferenceException("fileName is null");
            }

            MainWindowDataModel newModel = new MainWindowDataModel();

            if (File.Exists(fileName))
            {
                try
                {
                    XmlSerializer deserializer = new XmlSerializer(typeof(MainWindowDataModel));

                    TextReader reader = new StreamReader(fileName);

                    object obj = deserializer.Deserialize(reader);
                    reader.Close();

                    newModel = (MainWindowDataModel)obj;
                }
                catch (Exception ex)
                {
                    string additionalInfo = "";
                    additionalInfo = ex.Message;
                    if (ex.InnerException != null)
                    {
                        additionalInfo += "\n" + ex.InnerException.Message;
                    }
                    MessageBox.Show("Error reading the config file:\n" + additionalInfo, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(null);
                }
            }
            return(newModel);
        }