示例#1
0
        public override bool Run()
        {
            if (!CanRun)
            {
                return(true);
            }
            this.CommandStatus = CommandStatus.Running;
            if (InstallContext.IsMakeStore)
            {
                Watch?.Info("正在备份历史文件");
                this.Store();
                Watch?.AddValue(10);
            }
            else if (!Directory.Exists(InstallContext.InstInfo.InstallPath))
            {
                Directory.CreateDirectory(InstallContext.InstInfo.InstallPath);
                newDirs.Push(InstallContext.InstInfo.InstallPath);
            }

            Watch?.Info("开始文件提取");
            if (!UnZip(InstallContext.PackageFile, InstallContext.Files, InstallContext.InstInfo.InstallPath))
            {
                Watch?.Faild();
                this.CommandStatus = CommandStatus.Failed;
                return(false);
            }
            Watch?.Info("文件提取完成");
            this.CommandStatus = CommandStatus.Complete;
            return(true);
        }
示例#2
0
        private bool ExtractionFile(ZipArchiveEntry entry, FileInfo info, FileOverride fileOverride, ExtractionOptions extractionOptions)
        {
            var isExist = info.Exists;

            if (fileOverride == FileOverride.Never && isExist)
            {
                Watch?.Info($"文件已存在 [{info.FullName}]。");
                return(true);
            }
            if (fileOverride == FileOverride.Newer && isExist && entry.LastModifiedTime <= info.LastWriteTime)
            {
                Watch?.Info($"文件已存在 [{info.FullName}]。");
                return(true);
            }

            bool retry;

            do
            {
                retry = false;
                try
                {
                    entry.WriteToFile(info.FullName, extractionOptions);
                    if (!isExist)
                    {
                        newFiles.Add(info.FullName);
                    }
                    return(true);
                }
                catch (Exception e)
                {
                    if (fileOverride == FileOverride.Try)
                    {
                        Watch?.Info($"覆盖文件失败,自动忽略并继续。失败原因:{e.Message}");
                        return(true);
                    }
                    var dr = Helper.AbortRetryIgnore(this.Owner, $"覆盖文件失败,是否重试?失败原因:{Environment.NewLine}{e.Message}");
                    if (dr == DialogResult.Abort)
                    {
                        Watch?.Error($"覆盖文件失败,失败原因:{e.Message}");
                        Watch?.Faild();
                        return(false);
                    }
                    if (dr == DialogResult.Retry)
                    {
                        Watch?.Info($"覆盖文件失败,正在重试。失败原因:{e.Message}");
                        retry = true;
                    }
                    else if (dr == DialogResult.Ignore)
                    {
                        Watch?.Info($"覆盖文件失败,忽略该操作。失败原因:{e.Message}");
                        return(true);
                    }
                }
            } while (retry);

            return(true);
        }
示例#3
0
        public override bool Run()
        {
            if (!CanRun)
            {
                return(true);
            }


            Watch?.Info($"正在执行脚本");
            if (isShowDetails)
            {
                var details = new FrmDetails(sqlHelper, files, scriptPath, storePath, Watch, newDirs, newObjs);
                if (this.Owner is Form from)
                {
                    details.Icon = from.Icon;
                }
                var da = details.ShowDialog(Owner);
                this.CommandStatus = details.CommandStatus;
                var result = da == DialogResult.OK;
                if (result)
                {
                    Watch?.Info("全部脚本执行结束。");
                    this.CommandStatus = CommandStatus.Complete;
                }
                else
                {
                    Watch?.Faild();
                    this.CommandStatus = CommandStatus.Failed;
                }
                return(result);
            }
            else
            {
                var reset  = new AutoResetEvent(false);
                var result = false;
                new Thread(() =>
                {
                    result = TryExecute();
                    reset.Set();
                    Thread.CurrentThread.Abort();
                }).Start();

                this.CommandStatus = CommandStatus.Running;
                reset.WaitOne();
                if (!result)
                {
                    Watch?.Faild();
                    this.CommandStatus = CommandStatus.Failed;
                    return(false);
                }

                this.CommandStatus = CommandStatus.Complete;
                return(true);
            }
        }
示例#4
0
        public override bool Run()
        {
            if (!this.CanRun)
            {
                return(true);
            }
            this.CommandStatus = CommandStatus.Running;

            Watch?.SetStep("写注册表");
            Watch?.Info("正在写入注册表");
            if (!RegisterHelper.Write(regInfo))
            {
                Watch?.Faild();
                this.CommandStatus = CommandStatus.Failed;
                return(false);
            }

            this.CommandStatus = CommandStatus.Complete;
            return(true);
        }
示例#5
0
        private bool TryExecuteFile(ScriptFile file)
        {
            bool retry;

            do
            {
                var flag = ExecuteFile(file.File, out string message);
                if (flag)
                {
                    file.Status = ScriptStatus.Success;
                    return(true);
                }

                retry = false;
                var dr = Helper.AbortRetryIgnore(this.Owner, $"执行脚本失败,是否重试?失败原因:{Environment.NewLine}{message}");
                if (dr == DialogResult.Abort)
                {
                    Watch?.Error($"执行脚本失败,失败原因:{message}");
                    Watch?.Faild();
                    file.Status = ScriptStatus.Failed;
                    return(false);
                }

                if (dr == DialogResult.Retry)
                {
                    Watch?.Info("重试该脚本。");
                    retry = true;
                }
                else if (dr == DialogResult.Ignore)
                {
                    Watch?.Info("忽略该脚本。");
                    file.Status = ScriptStatus.Ignore;
                    return(true);
                }
            } while (retry);

            return(true);
        }
示例#6
0
        public override bool Run()
        {
            if (!CanRun)
            {
                return(true);
            }
            this.CommandStatus = CommandStatus.Running;
            Watch?.Info("正在配置IIS");
            MakeBackup();

            var siteName  = this.InstallContext.GetPageItemValue("IIS_SiteName");
            var poolName  = this.InstallContext.GetPageItemValue("IIS_PoolName");
            var hostName  = this.InstallContext.GetPageItemValue("IIS_HostName");
            var type      = this.InstallContext.GetPageItemValue("IIS_BindType");
            var ip        = this.InstallContext.GetPageItemValue("IIS_IpAddress");
            var port      = this.InstallContext.GetPageItemValue("IIS_Port");
            var logicPath = this.InstallContext.GetPageItemValue("IIS_LogicPath");

            logicPath = this.InstallContext.ConvertVars(logicPath);

            var host = hostName;

            if (string.IsNullOrEmpty(hostName))
            {
                host = ip == "*" ? "localhost" : ip;
            }

            if (port != "80")
            {
                host += $":{port}";
            }
            siteAddress = $"{type}://{host}";

            //var siteName = "NewSite";
            //var poolName = "NewSite";
            //var hostName = "www.newsite.com";
            //var type = "http";
            //var ip = "*";
            //var port = "4049";
            //var logicPath = @"E:\Projects\09-物资云\物资云.药品V2.0\代码\QuickShare.Cloud\QuickShare.Cloud.Web";

            if (!MakeAppPool(poolName))
            {
                Watch?.Faild();
                this.CommandStatus = CommandStatus.Failed;
                return(false);
            }

            var bindings = $"{type}/{ip}:{port}:{hostName}";

            if (!MakeSite(siteName, logicPath, bindings))
            {
                Watch?.Faild();
                this.CommandStatus = CommandStatus.Failed;
                return(false);
            }

            if (SetSitePool(siteName, poolName))
            {
                StartSite(siteName, siteAddress);
            }

            Watch?.Info($"IIS站点 {siteName} 部署完成。");
            this.CommandStatus = CommandStatus.Complete;
            return(true);
        }