Ejemplo n.º 1
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); }
        }
Ejemplo n.º 2
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); }
                }
            }
        }