Exemple #1
0
        public MainWindow()
        {
#if !DEBUG
            //     try
            {
#endif
            InitializeComponent();
            MainDescription.MainFrm = this;


            notifier = new Notifier(cfg =>
            {
                cfg.PositionProvider = new WindowPositionProvider(Application.Current.MainWindow, Corner.TopRight, 10,
                                                                  10);

                cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(
                    TimeSpan.FromSeconds(2),
                    MaximumNotificationCount.FromCount(3));

                cfg.Dispatcher = Application.Current.Dispatcher;
            });
            ToolTipService.ShowDurationProperty.OverrideMetadata(
                typeof(DependencyObject), new FrameworkPropertyMetadata(60000));
            Application.Current.Resources["ThemeDictionary"] = new ResourceDictionary();
            //   this.SetCurrentTheme("ShinyBlue");
            ;
            if (ConfigurationManager.AppSettings["PluginLocationRelative"] == "true")
            {
                MainPluginLocation = MainStartUpLocation
                                     + ConfigurationManager.AppSettings["MainPluginLocation"];
            }
            else
            {
                MainPluginLocation = ConfigurationManager.AppSettings["MainPluginLocation"];
            }

            XmlConfigurator.Configure(new FileInfo("log4net.config"));

            var icon = ConfigurationManager.AppSettings["Icon"];
            try
            {
                Icon = new BitmapImage(new Uri(MainPluginLocation + icon, UriKind.Absolute));
            }
            catch (Exception)
            {
                XLogSys.Print.Error(GlobalHelper.Get("IconNotExist"));
            }

            PluginManager = new PluginManager();
#if !DEBUG
            Dispatcher.UnhandledException += (s, e) =>
            {
                if (MessageBox.Show(GlobalHelper.Get("key_0"), GlobalHelper.Get("key_1"), MessageBoxButton.YesNoCancel) ==
                    MessageBoxResult.Yes)
                {
                    dynamic process = PluginDictionary["DataProcessManager"];
                    process.SaveCurrentTasks();
                }

                MessageBox.Show(GlobalHelper.Get("key_2") + e.Exception);
                XLogSys.Print.Fatal(e.Exception);
            };
#endif
            AppHelper.LoadLanguage();
            ViewDictionary = new List <ViewItem>();
            Title          = ConfigurationManager.AppSettings["Title"];

            //    this.myDebugSystemUI.MainFrmUI = this;
            PluginManager.MainFrmUI = this;

            //  this.myDebugSystemUI.Init();
            PluginManager.Init(new[] { MainStartUpLocation });


            PluginManager.LoadPlugins();
            PluginManager.LoadView();

            DataContext = this;
            foreach (var action in CommandCollection.Concat(Commands))
            {
                SetCommandKeyBinding(action);
            }
            XLogSys.Print.Info(Title + GlobalHelper.Get("Start"));


            AutoUpdater.Start("https://raw.githubusercontent.com/ferventdesert/Hawk/global/Hawk/autoupdate.xml");
            Closing += (s, e) =>
            {
                List <IDataProcess> revisedTasks;
                var processmanager = PluginDictionary["DataProcessManager"] as DataProcessManager;
                revisedTasks = processmanager.GetRevisedTasks().ToList();
                if (!revisedTasks.Any())
                {
                    if (
                        MessageBox.Show(GlobalHelper.Get("Closing"), GlobalHelper.Get("Tips"), MessageBoxButton.OKCancel) ==
                        MessageBoxResult.OK)
                    {
                        PluginManager.Close();
                        PluginManager.SaveConfigFile();
                    }
                    else
                    {
                        e.Cancel = true;
                    }
                }
                else
                {
                    var result =
                        MessageBox.Show(GlobalHelper.FormatArgs(
                                            "RemaindSave", " ".Join(revisedTasks.Select(d => d.Name).ToArray())),
                                        GlobalHelper.Get("Tips"), MessageBoxButton.YesNoCancel);
                    if (result == MessageBoxResult.Yes || result == MessageBoxResult.No)
                    {
                        if (result == MessageBoxResult.Yes)
                        {
                            revisedTasks.Execute(d => processmanager.SaveTask(d, false));
                        }
                        PluginManager.Close();
                        PluginManager.SaveConfigFile();
                    }
                    else
                    {
                        e.Cancel = true;
                    }
                }
            };
            //File.WriteAllText("helper.md", ETLHelper.GetTotalMarkdownDoc());
            // var md = ETLHelper.GetAllToolMarkdownDoc();
            // File.WriteAllText("HawkDoc.md", md);
            //  TestCode();
#if !DEBUG
        }

        // catch (Exception ex)
        {
            //   MessageBox.Show(ex.ToString());
        }
#endif
        }
Exemple #2
0
        public MainWindow()
        {
#if !DEBUG
            //     try
            {
#endif
            InitializeComponent();
            MainDescription.MainFrm = this;
            Application.Current.Resources["ThemeDictionary"] = new ResourceDictionary();
            //   this.SetCurrentTheme("ShinyBlue");
            ;
            if (ConfigurationManager.AppSettings["PluginLocationRelative"] == "true")
            {
                pluginPosition = MainStartUpLocation
                                 + ConfigurationManager.AppSettings["MainPluginLocation"];
            }
            else
            {
                pluginPosition = ConfigurationManager.AppSettings["MainPluginLocation"];
            }

            XmlConfigurator.Configure(new FileInfo("log4net.config"));


            string icon = ConfigurationManager.AppSettings["Icon"];
            try
            {
                Icon = new BitmapImage(new Uri(pluginPosition + icon, UriKind.Absolute));
            }
            catch (Exception ex)
            {
                XLogSys.Print.Error(Core.Properties.Resources.IconNotExist);
            }

            PluginManager = new PluginManager();
#if !DEBUG
            Dispatcher.UnhandledException += (s, e) =>
            {
                if (MessageBox.Show("是否保存当前工程的内容?您只有一次机会这样做,", "警告信息", MessageBoxButton.YesNoCancel) ==
                    MessageBoxResult.Yes)
                {
                    dynamic process = PluginDictionary["模块管理"];
                    process.SaveCurrentTasks();
                }

                MessageBox.Show("系统出现异常" + e.Exception);
                XLogSys.Print.Fatal(e.Exception);
            };
#endif
            ViewDictionary = new List <ViewItem>();
            Title          = ConfigurationManager.AppSettings["Title"];

            //    this.myDebugSystemUI.MainFrmUI = this;
            PluginManager.MainFrmUI = this;

            //  this.myDebugSystemUI.Init();

            PluginManager.Init(new[] { MainStartUpLocation });
            PluginManager.LoadPlugins();
            PluginManager.LoadView();

            DataContext = this;
            foreach (ICommand action in CommandCollection.Concat(Commands))
            {
                SetCommandKeyBinding(action);
            }
            XLogSys.Print.Info(Title + Core.Properties.Resources.Start);


            Closing += (s, e) =>
            {
                if (MessageBox.Show(Core.Properties.Resources.Closing, Core.Properties.Resources.Tips, MessageBoxButton.OKCancel) == MessageBoxResult.OK)

                {
                    PluginManager.Close();
                    PluginManager.SaveConfigFile();
                    Process.GetCurrentProcess().Kill();
                }
                else
                {
                    e.Cancel = true;
                }
            };
            //  TestCode();
#if !DEBUG
        }

        // catch (Exception ex)
        {
            //   MessageBox.Show(ex.ToString());
        }
#endif
        }
Exemple #3
0
        public MainWindow()
        {
#if !DEBUG
            //     try
            {
#endif
            InitializeComponent();
            MainDescription.MainFrm = this;
            this.notifier           = new Notifier(cfg =>
            {
                cfg.PositionProvider = new WindowPositionProvider(
                    parentWindow: Application.Current.MainWindow,
                    corner: Corner.TopRight,
                    offsetX: 10,
                    offsetY: 10);

                cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(
                    notificationLifetime: TimeSpan.FromSeconds(3),
                    maximumNotificationCount: MaximumNotificationCount.FromCount(5));

                cfg.Dispatcher = Application.Current.Dispatcher;
            });

            Application.Current.Resources["ThemeDictionary"] = new ResourceDictionary();
            //   this.SetCurrentTheme("ShinyBlue");
            ;
            if (ConfigurationManager.AppSettings["PluginLocationRelative"] == "true")
            {
                pluginPosition = MainStartUpLocation
                                 + ConfigurationManager.AppSettings["MainPluginLocation"];
            }
            else
            {
                pluginPosition = ConfigurationManager.AppSettings["MainPluginLocation"];
            }

            XmlConfigurator.Configure(new FileInfo("log4net.config"));


            string icon = ConfigurationManager.AppSettings["Icon"];
            try
            {
                Icon = new BitmapImage(new Uri(pluginPosition + icon, UriKind.Absolute));
            }
            catch (Exception ex)
            {
                XLogSys.Print.Error(Core.Properties.Resources.IconNotExist);
            }

            PluginManager = new PluginManager();
#if !DEBUG
            Dispatcher.UnhandledException += (s, e) =>
            {
                if (MessageBox.Show("是否保存当前工程的内容?您只有一次机会这样做,", "Hawk由于内部异常而崩溃", MessageBoxButton.YesNoCancel) ==
                    MessageBoxResult.Yes)
                {
                    dynamic process = PluginDictionary["模块管理"];
                    process.SaveCurrentTasks();
                }

                MessageBox.Show("系统出现异常" + e.Exception);
                XLogSys.Print.Fatal(e.Exception);
            };
#endif
            ViewDictionary = new List <ViewItem>();
            Title          = ConfigurationManager.AppSettings["Title"];

            //    this.myDebugSystemUI.MainFrmUI = this;
            PluginManager.MainFrmUI = this;

            //  this.myDebugSystemUI.Init();

            PluginManager.Init(new[] { MainStartUpLocation });
            PluginManager.LoadPlugins();
            PluginManager.LoadView();

            DataContext = this;
            foreach (ICommand action in CommandCollection.Concat(Commands))
            {
                SetCommandKeyBinding(action);
            }
            XLogSys.Print.Info(Title + Core.Properties.Resources.Start);


            Closing += (s, e) =>
            {
                List <IDataProcess> revisedTasks;
                var processmanager = PluginDictionary["模块管理"] as DataProcessManager;
                revisedTasks = processmanager.GetRevisedTasks().ToList();
                if (!revisedTasks.Any())
                {
                    if (MessageBox.Show(Core.Properties.Resources.Closing, Core.Properties.Resources.Tips, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                    {
                        PluginManager.Close();
                        PluginManager.SaveConfigFile();
                        Process.GetCurrentProcess().Kill();
                    }
                    else
                    {
                        e.Cancel = true;
                    }
                }
                else
                {
                    var result =
                        MessageBox.Show(
                            $"【{" ".Join(revisedTasks.Select(d => d.Name).ToArray())}】任务可能还没有保存,\n【是】:保存任务并退出, \n【否】:不保存退出,\n【取消】:取消退出", Core.Properties.Resources.Tips,
                            MessageBoxButton.YesNoCancel);
                    if (result == MessageBoxResult.Yes || result == MessageBoxResult.No)
                    {
                        if (result == MessageBoxResult.Yes)
                        {
                            revisedTasks.Execute(d => processmanager.SaveTask(d, false));
                        }
                        PluginManager.Close();
                        PluginManager.SaveConfigFile();
                        Process.GetCurrentProcess().Kill();
                    }
                    else
                    {
                        e.Cancel = true;
                    }
                }
            };
            //  TestCode();
#if !DEBUG
        }

        // catch (Exception ex)
        {
            //   MessageBox.Show(ex.ToString());
        }
#endif
        }