예제 #1
0
        public static void ServiceRemove(string toolsFolder, string toolsTempFolder, string servicedesc, string exepath, bool isshow)
        {
            DataTable dtPar = new DataTable();

            dtPar.Columns.Add("name", typeof(string));
            dtPar.Columns.Add("value", typeof(string));
            //然后把你想要加的数据加进DataTable 里
            dtPar.Rows.Add(new object[] { "servicedesc", servicedesc });
            dtPar.Rows.Add(new object[] { "exepath", exepath });
            setConfig setconfig = new setConfig();

            setconfig.repalceParByDefine(toolsFolder, "Service_Unistall.bat", toolsTempFolder, dtPar);
            setBAT.RunBat(toolsTempFolder + @"\Service_Unistall.bat", isshow);
        }
예제 #2
0
        public static void SqlExec(string toolsFolder, string toolsTempFolder, string user, string password, string datasource, string sqlfilename, List <string[]> inputList, bool isShow)
        {
            string batfilePath = toolsFolder + "\\sql_exec.bat";
            string sqlfilePath = toolsFolder + "\\sqls\\" + sqlfilename + ".sql";

            DataTable dtPar = new DataTable();

            dtPar.Columns.Add("name", typeof(string));
            dtPar.Columns.Add("value", typeof(string));
            //然后把你想要加的数据加进DataTable 里
            foreach (string[] str in inputList)
            {
                dtPar.Rows.Add(new object[] { str[0], str[1] });
            }
            setConfig setconfig = new setConfig();

            setconfig.repalceParByDefine(toolsFolder + "\\sqls", sqlfilename + ".sql", toolsTempFolder, dtPar);


            string sqlpath = toolsTempFolder + "\\" + sqlfilename + ".sql";
            string logpath = toolsTempFolder + "\\" + sqlfilename + System.Guid.NewGuid().ToString() + ".log";

            List <string[]> BatinputList = new List <string[]>();

            string[] str1 = new string[2];
            str1[0] = "user";
            str1[1] = user;
            BatinputList.Add(str1);
            string[] str2 = new string[2];
            str2[0] = "password";
            str2[1] = password;
            BatinputList.Add(str2);
            string[] str3 = new string[2];
            str3[0] = "datasource";
            str3[1] = datasource;
            BatinputList.Add(str3);
            string[] str4 = new string[2];
            str4[0] = "sqlpath";
            str4[1] = sqlpath;
            BatinputList.Add(str4);
            string[] str5 = new string[2];
            str5[0] = "logpath";
            str5[1] = logpath;
            BatinputList.Add(str5);

            RunBatByDefine(toolsFolder, toolsTempFolder, "sql_exec", BatinputList, isShow);
        }
예제 #3
0
        public void backup(Set set, string toolsFolder, string toolsTempFolder)
        {
            BackupContents bcs = new BackupContents();

            bcs = JsonClassHelper.Json2Class <BackupContents>(set.Backup.Content);

            if (bcs == null || bcs.content == null)
            {
                return;
            }
            else
            {
                exp_tem_path = toolsFolder;
                exp_path     = toolsTempFolder;
                dayString    = DateTime.Now.Year + "-" + (DateTime.Now.Month < 10 ? "0" + DateTime.Now.Month : DateTime.Now.Month + "") + "-" + (DateTime.Now.Day < 10 ? "0" + DateTime.Now.Day : DateTime.Now.Day + ""); //DateTime.Now.ToShortDateString();
                string timeString = DateTime.Now.Hour.ToString() + "-" + DateTime.Now.Minute.ToString() + "--" + DateTime.Now.Second.ToString();

                backup_path = set.Backup.Path + "\\backup-" + dayString + "\\" + timeString;
                if (!System.IO.Directory.Exists(backup_path))
                {
                    System.IO.Directory.CreateDirectory(backup_path);
                }


                setConfig setconfig = new setConfig();
                string    ansStr    = "开始备份数据\r\n";


                if (bcs.content.Find((BackupContent bc) => bc.Name == "sde") != null && bcs.content.Find((BackupContent bc) => bc.Name == "sde").Type.Count > 0)
                {
                    //备份 sde库
                    //初始化 esri授权
                    setArcgis.init();
                    setArcgis.grant();
                }


                foreach (BackupContent bc in bcs.content)
                {
                    if (bc.Type == null)
                    {
                        continue;
                    }


                    foreach (BackupContentType bctype in bc.Type)
                    {
                        if (bc.Name == "dmp")
                        {
                            string name   = bctype.Name;
                            DbUser dbuser = set.Db.DbUserList.Find((DbUser du) => du.Name == name);

                            if (bctype.Set != null && bctype.Set.Count > 0)
                            {
                                string    remoteInfo  = bctype.Set.Find((BackupContentSet bcsset) => bcsset.SetKey == "remoteInfo").SetValue;
                                string [] remoteInfos = remoteInfo.Split(',');

                                setBAT.OracleExpdp(exp_tem_path, exp_path, dbuser.User, dbuser.Password, set.Db.Datasource, dbuser.Label, backup_path, remoteInfos[0], remoteInfos[1], remoteInfos[2], bctype.getValueList("excludeTable"), true);
                                setBAT.FilePackage(exp_tem_path, exp_path, "正在压缩" + dbuser.Label + "dmpdp文件", backup_path + "\\EXP-" + dbuser.User.ToUpper() + ".DMPDP", backup_path + "\\exp-" + dbuser.User, false, null, null, true);
                                File.Delete(backup_path + "\\exp-" + dbuser.User + ".dmpdp");
                                ansStr += dbuser.Label + "数据expdp导出完成\r\n";
                            }
                            else
                            {
                                setBAT.OracleExp(exp_tem_path, exp_path, dbuser.User, dbuser.Password, set.Db.Datasource, dbuser.Label, backup_path, true);
                                setBAT.FilePackage(exp_tem_path, exp_path, "正在压缩" + dbuser.Label + "dmp文件", backup_path + "\\exp-" + dbuser.User + ".dmp", backup_path + "\\exp-" + dbuser.User, false, null, null, true);
                                File.Delete(backup_path + "\\exp-" + dbuser.User + ".dmp");
                                ansStr += dbuser.Label + "数据导出完成\r\n";
                            }
                        }
                        else if (bc.Name == "app")
                        {
                            string type = bctype.Type;
                            string name = bctype.Name;

                            string labelStr    = "";
                            string appfolder   = "";
                            string appfilename = "";

                            dynamic typeObject = System.Reflection.Assembly.Load("QuickConfig.Model").CreateInstance(type, false);;

                            if (typeObject is ServiceApp)
                            {
                                ServiceApp dbuser = set.Apps.ServiceAppList.Find((ServiceApp du) => du.Name == name);
                                labelStr    = dbuser.Label;
                                appfolder   = dbuser.Path;
                                appfilename = dbuser.Label;
                            }
                            else if (typeObject is WebApp)
                            {
                                WebApp dbuser = set.Apps.WebAppList.Find((WebApp du) => du.Name == name);
                                labelStr    = dbuser.Label;
                                appfolder   = dbuser.Path;
                                appfilename = dbuser.Label;
                            }
                            else if (typeObject is App)
                            {
                                App dbuser = set.Apps.AppList.Find((App du) => du.Name == name);
                                labelStr    = dbuser.Label;
                                appfolder   = dbuser.Path;
                                appfilename = dbuser.Label;
                            }
                            else if (typeObject is Ftp)
                            {
                                Ftp dbuser = set.Apps.FtpList.Find((Ftp du) => du.Name == name);
                                labelStr    = dbuser.Label;
                                appfolder   = dbuser.Path;
                                appfilename = dbuser.Label;
                            }
                            else if (typeObject is Gxml)
                            {
                                Gxml dbuser = set.Apps.GxmlList.Find((Gxml du) => du.Name == name);
                                labelStr    = dbuser.Label;
                                appfolder   = dbuser.Path;
                                appfilename = dbuser.Label;
                            }

                            setBAT.FilePackage(exp_tem_path, exp_path, labelStr, appfolder, backup_path + "\\" + appfilename, true, bctype.getValueList("excludeFolder"), bctype.getValueList("excludeFile"), true);

                            ansStr += appfilename + "程序备份完成\r\n";
                        }
                        else if (bc.Name == "sde")
                        {
                            string         name   = bctype.Name;
                            DbSdeUser      dbuser = set.Db.DbSdeUserList.Find((DbSdeUser du) => du.Name == name);
                            EngineDatabase engine = new EngineDatabase();
                            engine.createGDBFile(backup_path, dbuser.Tablespace + ".gdb");
                            string ans1 = engine.exportSDE2GDBWithWorkspace(set.Db.Ip, "sde:oracle10g:" + set.Db.Datasource, dbuser.User, dbuser.Password, backup_path + "\\" + dbuser.Tablespace + ".gdb");
                            // setBAT.FilePackage(exp_tem_path, exp_path, "正在压缩" + dbuser.Label + "gdb文件", backup_path + "\\" + dbuser.Tablespace + ".gdb", backup_path + "\\" + dbuser.User,true,null,null, true);
                            ansStr += dbuser.Label + "导出结果如下:\r\n" + ans1 + "\r\n";

                            ansStr += dbuser.Label + "导出导出完成\r\n";
                        }
                    }
                }
                ansStr += "备份结束\r\n";
                StreamWriter sw = null;
                if (!File.Exists(backup_path + "\\" + dayString + ".log"))
                {
                    //不存在就新建一个文本文件,并写入一些内容
                    sw = File.CreateText(backup_path + "\\" + dayString + ".log");
                }
                else
                {
                    sw = new StreamWriter(backup_path + "\\" + dayString + ".log");
                }

                sw.Write(ansStr);
                sw.Close();
            }
        }