Exemplo n.º 1
0
 private void Show()
 {
     if (this._win == null)
     {
         this._win = new WaitDialog();
         this._win.IsIndeterminate = true;
         this._win.Show();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 使用异步线程执行某个Action
        /// </summary>
        /// <param name="isIndeterminate">是否需要不停的来回显示提示条。
        /// 如果是false:可以使用ActionParam.ProgressValue来设置进度条进度。</param>
        /// <param name="action">The action.</param>
        /// <param name="endAsyncCallBack">执行完异步操作后调用的回调函数</param>
        /// <param name="promptContent">Content of the prompt.</param>
        public static void Execute(bool isIndeterminate,
                                   Action <IProgressReporter> action,
                                   Action endAsyncCallBack = null,
                                   string promptContent    = null)
        {
            WaitDialog win = new WaitDialog();

            if (promptContent != null)
            {
                win.Text = promptContent;
            }
            if (isIndeterminate)
            {
                win.IsIndeterminate = true;
            }

            //在后台线程中,执行这个操作
            //ThreadHelper.SafeInvoke(() =>
            ThreadPool.QueueUserWorkItem(e =>
            {
                Exception exception = null;
                try
                {
                    //执行Action
                    action(new ActionParam(win));
                }
                catch (Exception ex)
                {
                    //保存下来,在关闭窗口后再弹出。
                    exception = ex;
                }
                finally
                {
                    //执行完毕,关闭提示框
                    Action closeWindow = () =>
                    {
                        win.Close();
                        if (exception != null)
                        {
                            exception.Alert();
                        }

                        if (endAsyncCallBack != null)
                        {
                            endAsyncCallBack();
                        }
                    };
                    win.Dispatcher.BeginInvoke(closeWindow);
                }
            });

            //打开提示框
            win.Show();
        }
Exemplo n.º 3
0
        private void Close()
        {
            // 执行完毕,关闭提示框
            Action closeWindow = () =>
            {
                if (this._win != null)
                {
                    this._win.Close();
                    this._win = null;
                }
            };

            this._win.Dispatcher.BeginInvoke(closeWindow);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 使用异步线程执行某个Action
        /// </summary>
        /// <param name="isIndeterminate">是否需要不停的来回显示提示条。
        /// 如果是false:可以使用ActionParam.ProgressValue来设置进度条进度。</param>
        /// <param name="action">The action.</param>
        /// <param name="endAsyncCallBack">执行完异步操作后调用的回调函数</param>
        /// <param name="promptContent">Content of the prompt.</param>
        public static void Execute(bool isIndeterminate,
            Action<IProgressReporter> action,
            Action endAsyncCallBack = null,
            string promptContent = null)
        {
            WaitDialog win = new WaitDialog();
            if (promptContent != null)
            {
                win.Text = promptContent;
            }
            if (isIndeterminate)
            {
                win.IsIndeterminate = true;
            }

            //在后台线程中,执行这个操作
            //ThreadHelper.SafeInvoke(() =>
            ThreadPool.QueueUserWorkItem(e =>
            {
                Exception exception = null;
                try
                {
                    //执行Action
                    action(new ActionParam(win));
                }
                catch (Exception ex)
                {
                    //保存下来,在关闭窗口后再弹出。
                    exception = ex;
                }
                finally
                {
                    //执行完毕,关闭提示框
                    Action closeWindow = () =>
                    {
                        win.Close();
                        if (exception != null)
                        {
                            exception.Alert();
                        }

                        if (endAsyncCallBack != null)
                        {
                            endAsyncCallBack();
                        }
                    };
                    win.Dispatcher.BeginInvoke(closeWindow);
                }
            });

            //打开提示框
            win.Show();
        }
Exemplo n.º 5
0
 private void Show()
 {
     if (this._win == null)
     {
         this._win = new WaitDialog();
         this._win.IsIndeterminate = true;
         this._win.Show();
     }
 }
Exemplo n.º 6
0
 private void Close()
 {
     // 执行完毕,关闭提示框
     Action closeWindow = () =>
     {
         if (this._win != null)
         {
             this._win.Close();
             this._win = null;
         }
     };
     this._win.Dispatcher.BeginInvoke(closeWindow);
 }
Exemplo n.º 7
0
 public ActionParam(WaitDialog win)
 {
     this._win = win;
 }
Exemplo n.º 8
0
        /// <summary>
        /// 调用服务在服务端升级数据库。
        /// </summary>
        /// <param name="options"></param>
        private static void MigrateOnServer(MigratingOptions options)
        {
            var win = new WaitDialog();
            win.Width = 500;
            win.IsIndeterminate = true;
            win.ShowInTaskbar = false;
            win.Text = "正在服务端执行数据库升级操作,请稍等……";

            Exception exception = null;

            ThreadPool.QueueUserWorkItem(oo =>
            {
                try
                {
                    var svc = ServiceFactory.Create<MigrateService>();
                    svc.Options = options;
                    svc.Invoke();
                }
                catch (Exception ex)
                {
                    exception = ex;
                }

                Action ac = () => win.DialogResult = true;
                win.Dispatcher.BeginInvoke(ac);
            });

            win.ShowDialog();

            if (exception != null) { throw new Rafy.DbMigration.DbMigrationException("数据库升级时出错,请查看 InnerException。", exception); }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 在进行条中执行指定数据库的升级操作。
        /// </summary>
        /// <param name="dbSetting"></param>
        /// <param name="action"></param>
        private static void MigrateInProgressBar(string dbSetting, Action<RafyDbMigrationContext> action)
        {
            using (var c = new RafyDbMigrationContext(dbSetting))
            {
                c.RunDataLossOperation = DataLossOperation.All;

                if (!RafyDbMigrationContext.IsEnabled())
                {
                    action(c);

                    //c.DeleteDatabase();
                    //c.AutoMigrate();

                    //其它一些可用的API
                    //c.ClassMetaReader.IgnoreTables.Add("ReportObjectMetaData");
                    //c.RollbackToHistory(DateTime.Parse("2008-12-31 23:59:58.700"), RollbackAction.DeleteHistory);
                    //c.DeleteDatabase();
                    //c.ResetHistories();
                    //c.RollbackAll();
                    //c.JumpToHistory(DateTime.Parse("2012-01-07 21:27:00.000"));
                }
                else
                {
                    var win = new WaitDialog();
                    win.Width = 500;
                    win.Opacity = 0;
                    win.ShowInTaskbar = false;
                    win.Text = string.Format("正在生成 {0} 数据库,请稍侯……", dbSetting);

                    Exception exception = null;

                    ThreadPool.QueueUserWorkItem(oo =>
                    {
                        try
                        {
                            bool first = false;
                            c.ItemMigrated += (o, e) =>
                            {
                                if (!first)
                                {
                                    Action setVisible = () => win.Opacity = 1;
                                    win.Dispatcher.Invoke(setVisible);
                                    first = true;
                                }
                                win.ProgressValue = new ProgressValue
                                {
                                    Percent = 100 * e.Index / (double)e.TotalCount
                                };
                            };

                            action(c);
                        }
                        catch (Exception ex)
                        {
                            exception = ex;
                        }

                        Action ac = () => win.DialogResult = true;
                        win.Dispatcher.BeginInvoke(ac);
                    });

                    win.ShowDialog();

                    if (exception != null) { throw new Rafy.DbMigration.DbMigrationException("数据库升级时出错,请查看 InnerException。", exception); }
                }
            }
        }
Exemplo n.º 10
0
 public ActionParam(WaitDialog win)
 {
     this._win = win;
 }