public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            if (request.IsMaster == false)
            {
                this.Prompt("只有管理员才能重置菜单");
            }
            this.AsyncDialog("Confirm", g => new UIConfirmDialog("将会清空现有菜单,同时清除菜单权限"));
            var Key = Utility.Guid(Guid.NewGuid());
            var log = new UMC.Data.CSV.Log(Utility.GetRoot(request.Url), Key, "开始重置菜单");
            var p   = Database.Instance().DbProvider;

            var factory = new DbFactory(Database.Instance().DbProvider);

            factory.ObjectEntity <Data.Entities.Menu>().Delete();
            //factory.ObjectEntity<>
            UMC.Data.Reflection.Start(() =>
            {
                var Initializers = Data.Sql.Initializer.Initializers();
                try
                {
                    var now = DateTime.Now;

                    var database = Reflection.Configuration("Database") ?? new UMC.Configuration.ProviderConfiguration();
                    //var count = false;

                    foreach (var initer in Initializers)
                    {
                        if (database.Providers.ContainsKey(initer.ProviderName))
                        {
                            log.Info("正在检测", initer.Caption);
                            initer.Menu(new Hashtable(), factory);
                        }

                        else
                        {
                            log.Info("未安装", initer.Caption);
                        }
                    }


                    log.End("检测菜单已完成");
                }
                catch (Exception ex)
                {
                    log.End("检测失败");
                    log.Info(ex.Message);
                }
            });   //.Start();


            response.Redirect("System", "Log", Key);
        }
Example #2
0
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            if (request.IsMaster == false)
            {
                this.Prompt("只有管理员才能升级");
            }
            var Key = Utility.Guid(Guid.NewGuid());
            var log = new UMC.Data.CSV.Log(Utility.GetRoot(request.Url), Key, "开始安装");

            var Initializers = Data.Sql.Initializer.Initializers();
            var Hask         = new Dictionary <String, DbProvider>();

            foreach (var initer in Initializers)
            {
                Hask[initer.ProviderName] = UMC.Data.Database.Instance(initer.ProviderName).DbProvider;
            }
            Data.Reflection.Start(() =>
            {
                try
                {
                    var now = DateTime.Now;

                    var database = Reflection.Configuration("database") ?? new UMC.Configuration.ProviderConfiguration();
                    foreach (var initer in Initializers)
                    {
                        if (database.Providers.ContainsKey(initer.ProviderName))
                        {
                            log.Info("正在升级", initer.Caption);
                            initer.Check(log, Hask[initer.ProviderName]);
                        }

                        else
                        {
                            log.Info("未安装", initer.Caption);
                        }
                    }


                    log.End("检测升级已完成");
                }
                catch (Exception ex)
                {
                    log.End("安装失败");
                    log.Info(ex.Message);
                }
            });

            this.Context.Send("Initializer", false);

            response.Redirect("System", "Log", Key);
        }
Example #3
0
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var type = this.AsyncDialog("type", g =>
            {
                return(this.DialogValue("SQLite"));

                var fm = new UISheetDialog()
                {
                    Title = "安装数据库"
                };

                //fm.Options.Add(new UIClick("Oracle") { Text = "Oracle数据库" }.Send(request.Model, request.Command));
                //fm.Options.Add(new UIClick("MySql") { Text = "MySql数据库" }.Send(request.Model, request.Command));
                //fm.Options.Add(new UIClick("MSSQL") { Text = "SQL Server数据库" }.Send(request.Model, request.Command));
                fm.Options.Add(new UIClick("SQLite")
                {
                    Text = "SQLite文件数据库"
                }.Send(request.Model, request.Command));
                return(fm);
            });
            var Settings = this.AsyncDialog("Settings", g =>
            {
                var fm = new UIFormDialog()
                {
                    Title = "选择数据库"
                };

                fm.AddText("服务地址", "Server");
                fm.AddText("用户名", "User");
                fm.AddText("密码", "Password");
                fm.AddText("数据库名", "Database");
                switch (type)
                {
                case "SQLite":
                    return(this.DialogValue(new WebMeta().Put("File", "UMC")));

                case "Oracle":
                    fm.AddText("端口", "Port", "1521");
                    fm.AddText("表前缀", "Prefix").Put("tip", "分表设置");
                    fm.Title = "Oracle连接配置";
                    break;

                case "MySql":
                    fm.AddText("端口", "Port", "3306");
                    fm.AddText("表前缀", "Prefix").Put("tip", "分表设置");
                    fm.Title = "MySql连接配置";
                    break;

                case "MSSQL":
                    fm.AddText("端口", "Port", "1433");
                    fm.AddText("表前缀", "Prefix").Put("tip", "分表设置");
                    fm.AddText("拆表符", "Delimiter", "_");
                    fm.Title = "SQL Server连接配置";
                    break;

                default:
                    this.Prompt("数据类型错误");
                    break;
                }
                fm.Submit("确认安装", request, "Initializer");
                return(fm);
            });

            UMC.Data.Provider provder = null;


            switch (type)
            {
            case "SQLite":
                provder = UMC.Data.Provider.Create("Database", typeof(UMC.Data.Sql.SQLiteDbProvider).FullName);

                var file = Settings["File"];
                if (file.IndexOf('.') == -1)
                {
                    file = file + ".sqlite";
                }
                var path = UMC.Data.Utility.MapPath(String.Format("~App_Data/{0}", file));

                if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(path)))
                {
                    System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
                }
                if (System.IO.File.Exists(path))
                {
                    int i = 1;
                    var m = String.Format("{0}.{1}.bak", path, i);
                    while (System.IO.File.Exists(m))
                    {
                        i++;
                        String.Format("{0}.{1}.bak", path, i);
                    }
                    System.IO.File.Move(path, m);
                }
                provder.Attributes["db"] = file;
                break;

            case "Oracle":
                provder = UMC.Data.Provider.Create("Database", typeof(UMC.Data.Sql.OracleDbProvider).FullName);
                provder.Attributes["conString"] = Oracle(Settings);
                break;

            case "MySql":
                provder = UMC.Data.Provider.Create("Database", typeof(UMC.Data.Sql.MySqlDbProvider).FullName);
                provder.Attributes["conString"] = MySQL(Settings);
                break;

            case "MSSQL":
                provder = UMC.Data.Provider.Create("Database", typeof(UMC.Data.Sql.SqlDbProvider).FullName);
                provder.Attributes["conString"] = MSSQL(Settings);
                break;

            default:
                this.Prompt("数据类型错误");
                break;
            }
            if (String.IsNullOrEmpty(Settings["Prefix"]) == false)
            {
                provder.Attributes["delimiter"] = Settings["Delimiter"] ?? "_";
                provder.Attributes["prefix"]    = Settings["Prefix"];
            }
            DbProvider provider = Reflection.CreateObject(provder) as DbProvider;

            DbFactory factory = new DbFactory(provider);

            try
            {
                factory.Open();
                factory.Close();
            }
            catch (Exception ex)
            {
                this.Prompt(ex.Message);
            }

            var Key = Utility.Guid(Guid.NewGuid());
            var log = new UMC.Data.CSV.Log(Utility.GetRoot(request.Url), Key, "开始安装");

            Data.Reflection.Start(() =>
            {
                var Initializers = Data.Sql.Initializer.Initializers();
                try
                {
                    var now      = DateTime.Now;
                    var Names    = new Hashtable();
                    var database = Reflection.Configuration("database") ?? new UMC.Configuration.ProviderConfiguration();
                    var count    = false;
                    foreach (var initer in Initializers)
                    {
                        var dataPro  = database[initer.ProviderName] ?? UMC.Data.Provider.Create(initer.ProviderName, provder.Type);
                        var setupKey = dataPro["setup"] ?? "";
                        if (setupKey.Contains(initer.Name) == false)
                        {
                            count = true;
                            initer.Setup(new Hashtable(), log, provider);
                            initer.Menu(new Hashtable(), new DbFactory(provider));
                            var de = UMC.Data.Provider.Create(initer.ProviderName, provder.Type);
                            de.Attributes.Add(provder.Attributes);
                            de.Attributes["setup"] = String.Format("{0}{1},", setupKey, initer.Name);
                            database.Providers[initer.ProviderName] = de;
                        }
                        else
                        {
                            initer.Check(log, Reflection.CreateObject(dataPro) as DbProvider);
                        }
                    }

                    UMC.Configuration.ProviderConfiguration.Cache.Clear();
                    if (count == false)
                    {
                        log.End("对应组件已经安装");
                    }
                    else
                    {
                        var file = Reflection.AppDataPath("UMC\\database.xml");
                        if (System.IO.File.Exists(file))
                        {
                            int i = 1;
                            var m = Reflection.AppDataPath(String.Format("UMC\\database.xml.{0}.bak", i));
                            while (System.IO.File.Exists(m))
                            {
                                i++;
                                m = Reflection.AppDataPath(String.Format("UMC\\database.xml.{0}.bak", i));
                            }
                            System.IO.File.Move(file, m);
                        }
                        database.WriteTo(file);
                        log.End("安装完成", "默认账户:admin 密码:admin", "请刷新界面");
                        log.Info(String.Format("用时{0}", DateTime.Now - now));
                    }
                }
                catch (Exception ex)
                {
                    log.End("安装失败");
                    log.Info(ex.Message);
                }
                finally
                {
                    log.Close();
                }
            });

            this.Context.Send("Initializer", false);

            response.Redirect("System", "Log", Key);
        }
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            if (request.IsMaster == false)
            {
                this.Prompt("只有管理员才能还原");
            }

            var files = System.IO.Directory.GetFiles(UMC.Data.Utility.MapPath(String.Format("~App_Data/BackUp/{0}", Utility.GetRoot(request.Url))), "*.umc", System.IO.SearchOption.TopDirectoryOnly);
            var index = Utility.IntParse(this.AsyncDialog("Index", g =>
            {
                var rd   = new UIRadioDialog();
                rd.Title = "请选择备份";
                for (var i = 0; i < files.Length; i++)
                {
                    rd.Options.Add(System.IO.Path.GetFileName(files[i]), i.ToString());
                }
                if (files.Length == 0)
                {
                    this.Prompt("未有备份文件");
                }
                return(rd);
            }), 0);
            var path   = String.Format("BackUp/{0}/{1}", Utility.GetRoot(request.Url), System.IO.Path.GetFileName(files[index]));
            var Key    = Utility.Guid(Guid.NewGuid());
            var log    = new UMC.Data.CSV.Log(Utility.GetRoot(request.Url), Key, "开始备份");
            var appKey = Security.Principal.Current.AppKey ?? Guid.Empty;

            Data.Reflection.Start(() =>
            {
                var Initializers = Data.Sql.Initializer.Initializers();
                try
                {
                    var now = DateTime.Now;

                    var database = Reflection.Configuration("database") ?? new UMC.Configuration.ProviderConfiguration();
                    //var count = false;
                    foreach (var initer in Initializers)
                    {
                        if (database.Providers.ContainsKey(initer.ProviderName))
                        {
                            log.Info("正在还原", initer.Caption);
                            var provider2 = Reflection.CreateObject(Reflection.Instance().DatabaseProvider(initer.ProviderName, appKey)) as DbProvider;

                            initer.Restore(log, provider2, path);
                        }

                        else
                        {
                            log.Info("未安装", initer.Caption);
                        }
                    }


                    log.End("还原已完成");
                }
                catch (Exception ex)
                {
                    log.End("还原失败");
                    log.Info(ex.ToString());
                }
            });

            this.Context.Send("Initializer", false);

            response.Redirect("System", "Log", Key);
        }