public static string BuildNuGetAdd(string aTokenizedCommandLine)
        {
            StringBuilder vResult = new StringBuilder(aTokenizedCommandLine);

            vResult
            .Replace(SOURCE.AsToken(), Source)
            .Replace(CONFIG_FILE.AsToken(), ConfigFile)
            .Replace(VERBOSITY_NUGET.AsToken(), VerbosityNuGet);
            return(vResult.ToString());
        }
        public static string BuildNuGetDelete(string aTokenizedCommandLine)
        {
            StringBuilder vResult = new StringBuilder(aTokenizedCommandLine);

            vResult
            .Replace(PACKAGE_ID.AsToken(), PackageId)
            .Replace(PACKAGE_VERSION.AsToken(), PackageVersion)
            .Replace(API_KEY.AsToken(), ApiKey)
            .Replace(CONFIG_FILE.AsToken(), ConfigFile)
            .Replace(SOURCE.AsToken(), Source)
            .Replace(VERBOSITY_NUGET.AsToken(), VerbosityNuGet);
            return(vResult.ToString());
        }
        public static string BuildNuGetPush(string aTokenizedCommandLine)
        {
            StringBuilder vResult = new StringBuilder(aTokenizedCommandLine);

            vResult
            .Replace(PACKAGE_PATH.AsToken(), PackagePath)
            .Replace(API_KEY.AsToken(), ApiKey)
            .Replace(CONFIG_FILE.AsToken(), ConfigFile)
            .Replace(SOURCE.AsToken(), Source)
            .Replace(SYMBOL_SOURCE.AsToken(), SymbolSource)
            .Replace(SYMBOL_API_KEY.AsToken(), SymbolApiKey)
            .Replace(TIMEOUT.AsToken(), Timeout)
            .Replace(VERBOSITY_NUGET.AsToken(), VerbosityNuGet);
            return(vResult.ToString());
        }
示例#4
0
        private void Install_Click(object sender, EventArgs e)
        {
            try
            {
                if (VERSION_TARGET.SelectedIndex < 0)
                {
                    MessageBox.Show("请选择发布版本", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                #region 保存配置
                {
                    this.configSetting.Config.WriteXml("Properties.XML");
                    SetMessage("参数配置保存完成", 10);
                    /////////////////////////////////////////////
                    Dictionary <String, String> ht = new Dictionary <String, String>();
                    ht.Add(DIR_TOMCAT.Name, DIR_TOMCAT.Text);
                    ht.Add(DIR_JDK.Name, DIR_JDK.Text);
                    ht.Add(DIR_MEMCACHE.Name, DIR_MEMCACHE.Text);
                    ht.Add(DIR_MYSQL.Name, DIR_MYSQL.Text);

                    ht.Add(DIR_LIB.Name, DIR_LIB.Text);
                    ht.Add(DIR_INSTALL.Name, DIR_INSTALL.Text);
                    ht.Add(DIR_SQL.Name, DIR_SQL.Text);
                    ht.Add(DIR_PROJECT.Name, DIR_PROJECT.Text);


                    ht.Add(TOMCAT_OTHER.Name, TOMCAT_OTHER.Text);
                    ht.Add(TOMCAT_RUN.Name, TOMCAT_RUN.Text);
                    ht.Add(TOMCAT_RUN_SAFE.Name, TOMCAT_RUN_SAFE.Text);
                    ht.Add(TOMCAT_SHUTDOWN.Name, TOMCAT_SHUTDOWN.Text);
                    ht.Add(MEM_RUN.Name, MEM_RUN.Text);
                    ht.Add(MEM_SIZE.Name, MEM_SIZE.Text);

                    ht.Add(CONFIG_FILE.Name, CONFIG_FILE.Text);

                    ht.Add(DB_DRIVER.Name, DB_DRIVER.Text);
                    ht.Add(DB_URI.Name, DB_URI.Text);
                    ht.Add(DB_USER.Name, DB_USER.Text);
                    ht.Add(DB_PWD.Name, DB_PWD.Text);

                    ConfigSetting.ConfigDataTable bcs = new ConfigSetting.ConfigDataTable();
                    foreach (KeyValuePair <String, String> item in ht)
                    {
                        ConfigSetting.ConfigRow bcsr = bcs.NewConfigRow();
                        bcsr.Puk   = bcs.Rows.Count;
                        bcsr.Key   = item.Key;
                        bcsr.Value = item.Value;
                        bcs.AddConfigRow(bcsr);
                    }
                    bcs.WriteXml("Config.XML");
                    SetMessage("环境配置保存完成", 20);
                }
                #endregion
                #region 设定配置
                {
                    #region 设定系统参数
                    FileInfo f = new FileInfo(CONFIG_FILE.Text);
                    if (f.Exists == false)
                    {
                        MessageBox.Show("请正确设定系统核心配置文件路径");
                        CONFIG_FILE.Focus();
                        return;
                    }

                    StringBuilder sb = new StringBuilder();
                    foreach (ConfigSetting.ConfigRow item in configSetting.Config.Rows)
                    {
                        sb.AppendLine(item.Key + "=" + item.Value);
                    }

                    File.WriteAllText(CONFIG_FILE.Text, sb.ToString());
                    SetMessage("系统参数设定成功", 30);
                    #endregion
                }
                String ApplicationDriver = Application.StartupPath.Substring(0, 2);
                {
                    #region 设定TOMCAT端口
                    DirectoryInfo di = new DirectoryInfo(DIR_TOMCAT.Text);
                    if (di.Exists == false)
                    {
                        MessageBox.Show("请正确设定Tomcat目录");
                        DIR_TOMCAT.Focus();
                        return;
                    }
                    if (File.Exists(di.FullName + "\\conf\\server-bak.xml") == false)
                    {
                        File.Copy(di.FullName + "\\conf\\server.xml", di.FullName + "\\conf\\server-bak.xml");
                    }
                    else
                    {
                        File.Copy(di.FullName + "\\conf\\server-bak.xml", di.FullName + "\\conf\\server.xml", true);
                    }
                    FileInfo f     = new FileInfo(di.FullName + "\\conf\\server.xml");
                    String   value = File.ReadAllText(f.FullName);
                    value = value.Replace("8005", TOMCAT_SHUTDOWN.Text).Replace("8080", TOMCAT_RUN.Text).Replace("8443", TOMCAT_RUN_SAFE.Text).Replace("8009", TOMCAT_OTHER.Text);
                    File.WriteAllText(f.FullName, value);
                    SetMessage("TOMCAT端口设定成功", 40);
                    #endregion
                }
                {
                    DirectoryInfo di;
                    ConfigSetting.ConfigDataTable scs = new ConfigSetting.ConfigDataTable();
                    #region 获得SQL清单
                    {
                        //发布路径设定
                        //org.isotopes.jfp.business.install.sql
                        String newName = DIR_INSTALL.Text + "\\WEB-INF\\classes\\org\\isotopes\\jfp\\business\\install\\sql\\";
                        Directory.CreateDirectory(newName);
                        //制作SQL清单配置(需要插入到数据库)
                        foreach (String ditem in Directory.GetDirectories(DIR_SQL.Text))
                        {
                            di = new DirectoryInfo(ditem);
                            foreach (FileInfo fitem in di.GetFiles("*.sql"))
                            {
                                ConfigSetting.ConfigRow scsr = scs.NewConfigRow();
                                scsr.Puk   = scs.Rows.Count;
                                scsr.Key   = fitem.Name;
                                scsr.Value = (fitem.Length / 1024).ToString();
                                scs.AddConfigRow(scsr);
                                //根据版本ID判断是否运行
                                fitem.CopyTo(newName + fitem.Name, true);
                            }
                            if (ditem.IndexOf(VERSION_TARGET.Text) > 0)
                            {
                                break;
                            }
                        }
                    }
                    //创建备份目录
                    if (Directory.Exists(Application.StartupPath + "\\BAK"))
                    {
                        Directory.Delete(Application.StartupPath + "\\BAK", true);
                    }
                    Directory.CreateDirectory(Application.StartupPath + "\\BAK");
                    //Directory.Move(DIR_SQL.Text,Application.StartupPath+"\\BAK\\SQL");
                    scs.WriteXml("Version.XML");
                    SetMessage("版本升级发布清单制作成功", 45);
                    //拷贝SQL清单
                    //File.Move("Version.XML", DIR_INSTALL.Text + "\\WEB-INF\\classes\\Version.XML");
                    SetMessage("版本发布准备成功", 50);
                    #endregion
                    #region 部署运行
                    //拷贝ROOT
                    SetMessage("开始发布项目...", 55);
                    if (DIR_PROJECT.Text.EndsWith("ROOT"))
                    {
                        if (Directory.Exists(DIR_TOMCAT.Text + "\\webapps\\ROOT"))
                        {
                            Directory.Delete(DIR_TOMCAT.Text + "\\webapps\\ROOT", true);
                        }
                    }
                    di = new DirectoryInfo(DIR_PROJECT.Text);
                    CopyDirectory(DIR_PROJECT.Text, DIR_TOMCAT.Text + "\\webapps\\" + di.Name);                //移动工程
                    //Directory.Move(DIR_PROJECT.Text, Application.StartupPath + "\\BAK\\" + di.Name);//移动工程
                    CopyDirectory(DIR_LIB.Text, DIR_TOMCAT.Text + "\\webapps\\" + di.Name + "\\WEB-INF\\lib"); //拷贝lib
                    SetMessage("项目发布成功!", 60);
                    //拷贝install
                    FileInfo      d  = new FileInfo(Application.StartupPath + "\\Project\\install\\WEB-INF\\classes\\jdbc.properties");
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("work.driverClassName=" + DB_DRIVER.Text);
                    sb.AppendLine("work.url=" + DB_URI.Text);
                    sb.AppendLine("work.username="******"work.password="******"开始发布安装环境...", 65);
                    di = new DirectoryInfo(DIR_INSTALL.Text);
                    CopyDirectory(DIR_INSTALL.Text, DIR_TOMCAT.Text + "\\webapps\\" + di.Name);
                    //Directory.Move(DIR_INSTALL.Text, Application.StartupPath + "\\BAK\\" + di.Name);
                    CopyDirectory(DIR_LIB.Text, DIR_TOMCAT.Text + "\\webapps\\" + di.Name + "\\WEB-INF\\lib");
                    //Directory.Move(DIR_LIB.Text, Application.StartupPath + "\\BAK\\lib");
                    SetMessage("安装环境发布成功", 70);

                    #region 注册缓存服务
                    sb = new StringBuilder();
                    sb.AppendLine(ApplicationDriver);
                    sb.AppendLine("cd " + DIR_MEMCACHE.Text);
                    sb.AppendLine("memcached.exe -d install");
                    DosCommandUtils.DoDosCMD(sb.ToString());
                    if (WindowsServiceUtils.IsServiceIsExisted("memcached") == false)
                    {
                        SetMessage("缓存服务注册失败,请手动解决!", 75);
                        MessageBox.Show("缓存服务注册失败,请手动解决!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    SetMessage("缓存服务注册成功", 75);

                    //修改注册表
                    RegistUtils.SetMemcachedRegist(DIR_MEMCACHE.Text + "\\memcached.exe", Int32.Parse(MEM_RUN.Text), Int32.Parse(MEM_SIZE.Text));

                    //ServiceController psc = new ServiceController("memcached");
                    //String[] CommandLine = new String[1];
                    //CommandLine[0] = " -p 8848 -m 256";
                    //psc.Start(CommandLine);
                    sb = new StringBuilder();
                    sb.AppendLine("net start memcached");
                    DosCommandUtils.DoDosCMD(sb.ToString());
                    if (WindowsServiceUtils.IsServiceStart("memcached") == false)
                    {
                        SetMessage("缓存服务启动失败,请手动解决!", 80);
                        MessageBox.Show("缓存服务启动失败,请手动解决!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    SetMessage("缓存服务启动成功", 80);
                    #endregion

                    //注册TOMCAT服务
                    sb = new StringBuilder();
                    sb.AppendLine(ApplicationDriver);
                    sb.AppendLine("cd " + this.DIR_MEMCACHE.Text);
                    sb.AppendLine("set JAVA_HOME=" + DIR_JDK.Text);
                    sb.AppendLine("call service.bat install " + SERVICE_NAME.Text);
                    DosCommandUtils.DoDosCMD(sb.ToString());

                    if (WindowsServiceUtils.IsServiceIsExisted(SERVICE_NAME.Text) == false)
                    {
                        SetMessage("TOMCAT注册失败,请手动解决!", 85);
                        MessageBox.Show("TOMCAT注册失败,请手动解决!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    SetMessage("TOMCAT注册成功", 85);

                    //启动TOMCAT
                    sb = new StringBuilder();
                    sb.AppendLine("net start " + SERVICE_NAME.Text);
                    DosCommandUtils.DoDosCMD(sb.ToString());
                    if (WindowsServiceUtils.IsServiceStart(SERVICE_NAME.Text) == false)
                    {
                        SetMessage("TOMCAT启动失败,请手动解决!", 90);
                        MessageBox.Show("TOMCAT启动失败,请手动解决!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    SetMessage("TOMCAT启动成功", 90);
                    //运行IE,请求安装SQL
                    //http://127.0.0.1:8080/install/DBC/Init.go
                    //http://127.0.0.1:8888/DBC/Init.go
                    Boolean bk = ServerServiceUtils.ServerDownloadString("http://127.0.0.1:" + TOMCAT_RUN.Text + "/DBC/Init.go");
                    if (bk)
                    {
                        SetMessage("数据库安装成功", 95);
                        //安装成功后,删除SQL文件
                        di = new DirectoryInfo(DIR_INSTALL.Text);
                        String newName = DIR_TOMCAT.Text + "\\webapps\\" + di.Name + "\\WEB-INF\\classes\\org\\isotopes\\jfp\\business\\install\\sql\\";
                        Directory.Delete(newName, true);
                        SetMessage("部署成功,请登录系统", 100);
                        MessageBox.Show("部署成功,请登录系统", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        System.Diagnostics.Process.Start("http://127.0.0.1:" + TOMCAT_RUN.Text);
                        Application.Exit();
                    }
                    else
                    {
                        MessageBox.Show("发生未知错误,请检查TOMCAT下面相关日志!\r\n", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    #endregion
                }
                #endregion
            }
            catch (Exception Ex)
            {
                MessageBox.Show("发生未知错误,请联系管理员!\r\n" + Ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }