Beispiel #1
0
        public MainViewModel()
        {
            try
            {
                _settings = TextFilterSettings.Settings;
                if (!_settings.ReadConfigFile())
                {
                    Environment.Exit(1);
                    Application.Current.Shutdown(1);
                    return;
                }

                _colorNames = GetColorNames();
                // clean up old log file if exists
                if (!string.IsNullOrEmpty(Settings.DebugFile) && File.Exists(Settings.DebugFile))
                {
                    File.Delete(Settings.DebugFile);
                }

                SetStatus("Starting textFilter: " + Process.GetCurrentProcess().Id.ToString());
                Base.NewCurrentStatus += HandleNewCurrentStatus;

                _filterViewModel = new FilterViewModel();
                _logViewModel    = new LogViewModel(_filterViewModel);

                _filterViewModel._LogViewModel = _logViewModel;

                App.Current.MainWindow.Title = string.Format("{0} {1}", // {2}",
                                                             Process.GetCurrentProcess().MainModule.ModuleName,
                                                             Process.GetCurrentProcess().MainModule.FileVersionInfo.FileVersion);

                SetStatus(App.Current.MainWindow.Title);

                // to embed external libraries
                // http: //blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx
                AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
                {
                    String resourceName = "TextFilter." + new AssemblyName(args.Name).Name + ".dll";

                    using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                    {
                        Byte[] assemblyData = new Byte[stream.Length];

                        stream.Read(assemblyData, 0, assemblyData.Length);

                        return(Assembly.Load(assemblyData));
                    }
                };

                _timer           = new System.Timers.Timer(10000);
                _timer.AutoReset = false;
                _timer.Elapsed  += _timer_Elapsed;
                _timer.Enabled   = true;

                SetStatus("loaded");
            }
            catch (Exception e)
            {
                MessageBox.Show("Exception:" + e.ToString());
            }
        }