/// <summary>
        /// 关闭前处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window1_OnClosing(object sender, CancelEventArgs e)
        {
            //保存所有便签设置
            NotepadManage.SaveSetings(this);

            //Application.Current.MainWindow
            try
            {
                RichTextBoxTool.Writer(RichTextBox1, CacheFileName);

                //如果ShowInTaskbar设置为true,则关闭时先关闭子窗体
                //如果设置为false,则先关闭主窗体
                //if (!ShowInTaskbar)
                NotepadManage.RemoveNotepad(this);

                NotepadManage.ShowWindowListCount--;
                if (NotepadManage.ShowWindowListCount == 0)
                {
                    //关闭一个应用程序。
                    SystemCommon.ExitSystem();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存出了点问题..." + ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                e.Cancel = true;
            }
        }
 /// <summary>
 /// 创建新页
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BtnAdd_OnMouseUp(object sender, MouseButtonEventArgs e)
 {
     if (e.ChangedButton != MouseButton.Left)
     {
         return;
     }
     NotepadManage.CreateNotepad(this);
 }
        /// <summary>
        /// 激活所有便签
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Activated(object sender, EventArgs e)
        {
            //this.WindowState = WindowState.Minimized;
            NotepadManage.ActivatedNotepad();

            Top  = -500;
            Left = -500;
        }
        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnClose_OnMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton != MouseButton.Left)
            {
                return;
            }

            //如果是空内容,关闭不提示
            string resutStr = RichTextBoxTool.StringFromRichTextBox(RichTextBox1);

            if (string.IsNullOrEmpty(resutStr) || resutStr == Environment.NewLine)
            {
                Close();

                if (File.Exists(CacheFileName))
                {
                    File.Delete(CacheFileName);
                }

                return;
            }

            WindowMessage windowMessage = new WindowMessage("删除", "隐藏", "取消");

            windowMessage.Text  = "确认删除或隐藏?删除之后可在回收站中查找。";
            windowMessage.Title = "确认删除或隐藏";
            windowMessage.ShowDialog();

            //保存所有便签设置
            NotepadManage.SaveSetings(this);
            string ret = windowMessage.OperatingButton;

            switch (ret)
            {
            case "删除":

                Close();

                //移动
                File.Move(CacheFileName, RichTextBoxTool.PathCacheDelete + Path.GetFileName(CacheFileName));

                break;

            case "隐藏":

                Close();

                //移动
                File.Move(CacheFileName, RichTextBoxTool.PathCacheHidden + Path.GetFileName(CacheFileName));

                break;

            case "取消":
                return;

                break;
            }
        }
        /// <summary>
        /// 窗体关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainWindow_OnClosing(object sender, CancelEventArgs e)
        {
            //保存设置
            _settings.Title       = Title;
            _settings.WinLocation = new Point(Left, Top);
            _settings.Save();

            //保存所有便签设置--已经在APP中设置
            NotepadManage.SaveSetings();

            //关闭一个应用程序。
            SystemCommon.ExitSystem();
        }
        /// <summary>
        /// 窗体加载,打开所有便签
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
            //加载设置
            _settings.Reload();
            Title = _settings.Title;
            Left  = _settings.WinLocation.X;
            Top   = _settings.WinLocation.Y;

            RichTextBoxTool.AddExtenstion();
            NotepadManage.OpenAllNotepad();

            Top  = -500;
            Left = -500;


            //设置主窗体
            SystemCommon.SetWindowMain(this);
            //设置主窗体
            ShowInTaskbar = !NotepadManage.SystemSetting.ShowInTaskbar;
            //打开导入的文件
            NotepadManage.OpenImputFileTask();
        }
        /// <summary>
        /// 在窗口变成前台窗口时发生。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void WindowNotepad_OnActivated(object sender, EventArgs e)
        {
            NotepadManage.SetIndexOrderBy(WindowSettings.Index);

            IsShosButton(true);
        }
Example #8
0
        public App()
        {
            #region  序退出异常处理

            var pro = Process.GetCurrentProcess();
            pro.EnableRaisingEvents = true;

            pro.Exited += (sender, e1) =>
            {
                ToolLogs.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "在进程退出时发生");
            };

            AppDomain.CurrentDomain.ProcessExit += (sender, e1) =>
            {
                ////晚于this.Exit
                //System.Threading.Monitor.TryEnter(obj, 500);
                ////后来改为
                //System.Threading.Monitor.Enter(obj);

                ToolLogs.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "当默认应用程序域的父进程存在时发生");

                ////不能在这保存所有便签设置,因为这时所有的程序已经全部关闭。
                //NotepadManage.SaveSetings();
            };

            //异常处理
            this.DispatcherUnhandledException += (sender, e1) =>
            {
                ToolLogs.Debug(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "系统异常处理", e1.Exception);

                e1.Handled = true;//使用这一行代码告诉运行时,该异常被处理了,不再作为UnhandledException抛出了。
                SystemCommon.IsExitSystem = true;

                MessageBox.Show("我们很抱歉,当前应用程序遇到一些问题,该操作已经终止,将要重新启动。" + e1.Exception.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);//这里通常需要给用户一些较为友好的提示,并且后续可能的操作


                //保存所有便签设置
                NotepadManage.SaveSetings();

                //不要在这打开程序,如果你的程序是刚打开时出现错误,用户将无法关闭。这将是用户的恶梦。
                SystemCommon.ExitSystem();
                //System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
            };

            this.Exit += (sender, e1) =>
            {
                //早于AppDomain.CurrentDomain.ProcessExit
                ToolLogs.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "在进程退出时发生Exit");
                ////不能在这保存所有便签设置,因为这时所有的程序已经全部关闭。
                // NotepadManage.SaveSetings();
                //e1.ApplicationExitCode
            };

            #endregion

            bool result = ImputCacheFile();

            //非调试模式
            if (!System.Diagnostics.Debugger.IsAttached)
            {
                Client.Pub.ServiceProxyFactoryLib.ProxyBinding.ReplaceAddress = true;
                Client.Pub.ServiceProxyFactoryLib.ProxyBinding.ReplacePort    = true;

                //检测是否已有一个程序实例运行
                this.Startup += new StartupEventHandler(App_Startup);


                //下载版本不同的文件
                string loadPath = Path.Combine(SystemCommon.Path, "AutoUpdate");

                //复制自动更新程序文件
                Tools.FileManage.CopyDir(Path.Combine(loadPath, "LoadDown\\AutoUpdate\\"), loadPath);

                Tools.FileManage.IsUpdateThread();

                //绑定扩展名
                Task task = new Task(() =>
                {
                    try
                    {
                        BindingExtend();
                    }
                    catch (Exception e)
                    {
                        ToolLogs.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "绑定扩展名", e);
                    }
                });
                task.Start();
            }
        }