Пример #1
0
        private bool UpdateWebConfig(out string errorMessage)
        {
            errorMessage = string.Empty;

            var returnValue = false;

            try
            {
                var isProtectData    = TranslateUtils.ToBool(DdlIsProtectData.SelectedValue);
                var databaseType     = DatabaseTypeUtils.GetEnumType(DdlSqlDatabaseType.SelectedValue);
                var connectionString = GetConnectionString(true);

                WebConfigUtils.UpdateWebConfig(isProtectData, databaseType, connectionString, "api", "SiteServer", "Home", StringUtils.GetShortGuid(), false);

                DataProvider.Reset();

                returnValue = true;
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
            }

            return(returnValue);
        }
        public IHttpActionResult Main()
        {
            var request = new AuthenticatedRequest();

            var isDownload = TranslateUtils.ToBool(CacheDbUtils.GetValueAndRemove(PackageUtils.CacheKeySsCmsIsDownload));

            if (!isDownload)
            {
                return(Unauthorized());
            }

            var version = request.GetPostString("version");

            var idWithVersion        = $"{PackageUtils.PackageIdSsCms}.{version}";
            var packagePath          = PathUtils.GetPackagesPath(idWithVersion);
            var packageWebConfigPath = PathUtils.Combine(packagePath, WebConfigUtils.WebConfigFileName);

            if (!FileUtils.IsFileExists(packageWebConfigPath))
            {
                return(BadRequest($"升级包 {WebConfigUtils.WebConfigFileName} 文件不存在"));
            }

            WebConfigUtils.UpdateWebConfig(packageWebConfigPath, WebConfigUtils.IsProtectData,
                                           WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString, WebConfigUtils.AdminDirectory, WebConfigUtils.HomeDirectory,
                                           WebConfigUtils.SecretKey, WebConfigUtils.IsNightlyUpdate);

            DirectoryUtils.Copy(PathUtils.Combine(packagePath, DirectoryUtils.SiteFiles.DirectoryName), PathUtils.GetSiteFilesPath(string.Empty), true);
            DirectoryUtils.Copy(PathUtils.Combine(packagePath, DirectoryUtils.SiteServer.DirectoryName), PathUtils.GetAdminDirectoryPath(string.Empty), true);
            DirectoryUtils.Copy(PathUtils.Combine(packagePath, DirectoryUtils.Home.DirectoryName), PathUtils.GetHomeDirectoryPath(string.Empty), true);
            DirectoryUtils.Copy(PathUtils.Combine(packagePath, DirectoryUtils.Bin.DirectoryName), PathUtils.GetBinDirectoryPath(string.Empty), true);
            var isCopyFiles = FileUtils.CopyFile(packageWebConfigPath, PathUtils.Combine(WebConfigUtils.PhysicalApplicationPath, WebConfigUtils.WebConfigFileName), true);

            //SystemManager.SyncDatabase();

            return(Ok(new
            {
                isCopyFiles
            }));
        }
Пример #3
0
        private bool UpdateWebConfig(out string errorMessage)
        {
            errorMessage = string.Empty;

            var returnValue = false;

            try
            {
                var isProtectData    = TranslateUtils.ToBool(DdlIsProtectData.SelectedValue);
                var databaseType     = DatabaseTypeUtils.GetEnumType(DdlSqlDatabaseType.SelectedValue);
                var connectionString = GetConnectionString(true);

                WebConfigUtils.UpdateWebConfig(isProtectData, databaseType, connectionString, "siteserver", "vEnfkn16t8aeaZKG3a4Gl9UUlzf4vgqU9xwh8ZV5", false);

                returnValue = true;
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
            }

            return(returnValue);
        }
Пример #4
0
        private bool UpdateWebConfig(out string errorMessage)
        {
            errorMessage = string.Empty;

            var returnValue = false;

            try
            {
                var isProtectData    = TranslateUtils.ToBool(DdlIsProtectData.SelectedValue);
                var isMySql          = StringUtils.EqualsIgnoreCase(DdlSqlDatabaseType.SelectedValue, "MySql");
                var connectionString = GetConnectionString(true);

                WebConfigUtils.UpdateWebConfig(isProtectData, isMySql, connectionString);

                returnValue = true;
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
            }

            return(returnValue);
        }
Пример #5
0
        public static bool UpdatePackage(string idWithVersion, PackageType packageType, out string errorMessage)
        {
            try
            {
                var packagePath = PathUtils.GetPackagesPath(idWithVersion);

                string nuspecPath;
                string dllDirectoryPath;
                var    metadata = GetPackageMetadataFromPackages(idWithVersion, out nuspecPath, out dllDirectoryPath, out errorMessage);
                if (metadata == null)
                {
                    return(false);
                }

                if (packageType == PackageType.SsCms)
                {
                    var packageWebConfigPath = PathUtils.Combine(packagePath, WebConfigUtils.WebConfigFileName);
                    if (!FileUtils.IsFileExists(packageWebConfigPath))
                    {
                        errorMessage = $"升级包 {WebConfigUtils.WebConfigFileName} 文件不存在";
                        return(false);
                    }

                    WebConfigUtils.UpdateWebConfig(packageWebConfigPath, WebConfigUtils.IsProtectData,
                                                   WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString, WebConfigUtils.ApiPrefix, WebConfigUtils.AdminDirectory, WebConfigUtils.HomeDirectory,
                                                   WebConfigUtils.SecretKey, WebConfigUtils.IsNightlyUpdate);

                    //DirectoryUtils.Copy(PathUtils.Combine(packagePath, DirectoryUtils.SiteFiles.DirectoryName),
                    //    PathUtils.GetSiteFilesPath(string.Empty), true);
                    //DirectoryUtils.Copy(PathUtils.Combine(packagePath, DirectoryUtils.SiteServer.DirectoryName),
                    //    PathUtils.GetAdminDirectoryPath(string.Empty), true);
                    //DirectoryUtils.Copy(PathUtils.Combine(packagePath, DirectoryUtils.Bin.DirectoryName),
                    //    PathUtils.GetBinDirectoryPath(string.Empty), true);
                    //FileUtils.CopyFile(packageWebConfigPath,
                    //    PathUtils.Combine(WebConfigUtils.PhysicalApplicationPath, WebConfigUtils.WebConfigFileName),
                    //    true);
                }
                else if (packageType == PackageType.Plugin)
                {
                    var pluginPath = PathUtils.GetPluginPath(metadata.Id);
                    DirectoryUtils.CreateDirectoryIfNotExists(pluginPath);

                    DirectoryUtils.Copy(PathUtils.Combine(packagePath, "content"), pluginPath, true);
                    DirectoryUtils.Copy(dllDirectoryPath, PathUtils.Combine(pluginPath, "Bin"), true);

                    //var dependencyPackageDict = GetDependencyPackages(metadata);
                    //foreach (var dependencyPackageId in dependencyPackageDict.Keys)
                    //{
                    //    var dependencyPackageVersion = dependencyPackageDict[dependencyPackageId];
                    //    var dependencyDdlDirectoryPath =
                    //        FindDllDirectoryPath(
                    //            PathUtils.GetPackagesPath($"{dependencyPackageId}.{dependencyPackageVersion}"));
                    //    DirectoryUtils.Copy(dependencyDdlDirectoryPath, PathUtils.Combine(pluginPath, "Bin"), true);
                    //}

                    var configFilelPath = PathUtils.Combine(pluginPath, $"{metadata.Id}.nuspec");
                    FileUtils.CopyFile(nuspecPath, configFilelPath, true);

                    PluginManager.ClearCache();
                }
                else if (packageType == PackageType.Library)
                {
                    var fileNames = DirectoryUtils.GetFileNames(dllDirectoryPath);
                    foreach (var fileName in fileNames)
                    {
                        if (StringUtils.EndsWithIgnoreCase(fileName, ".dll"))
                        {
                            var sourceDllPath = PathUtils.Combine(dllDirectoryPath, fileName);
                            var destDllPath   = PathUtils.GetBinDirectoryPath(fileName);
                            if (!FileUtils.IsFileExists(destDllPath))
                            {
                                FileUtils.CopyFile(sourceDllPath, destDllPath, false);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
                return(false);
            }

            return(true);
        }
Пример #6
0
        public static async Task Execute(IJobContext context)
        {
            if (!CliUtils.ParseArgs(Options, context.Args))
            {
                return;
            }

            if (_isHelp)
            {
                PrintUsage();
                return;
            }

            try
            {
                if (string.IsNullOrEmpty(_userName))
                {
                    await CliUtils.PrintErrorAsync("未设置参数管理员用户名:{userName} !");

                    return;
                }

                if (string.IsNullOrEmpty(_password))
                {
                    await CliUtils.PrintErrorAsync("未设置参数管理员密码:{password} !");

                    return;
                }

                if (_password.Length < 6)
                {
                    await CliUtils.PrintErrorAsync("管理员密码必须大于6位 !");

                    return;
                }

                if (!EUserPasswordRestrictionUtils.IsValid(_password, EUserPasswordRestrictionUtils.GetValue(EUserPasswordRestriction.LetterAndDigit)))
                {
                    await CliUtils.PrintErrorAsync($"管理员密码不符合规则,请包含{EUserPasswordRestrictionUtils.GetText(EUserPasswordRestriction.LetterAndDigit)}");

                    return;
                }

                var webConfigPath = PathUtils.Combine(CliUtils.PhysicalApplicationPath, "web.config");
                if (!FileUtils.IsFileExists(webConfigPath))
                {
                    await CliUtils.PrintErrorAsync($"系统配置文件不存在:{webConfigPath}!");

                    return;
                }

                if (string.IsNullOrEmpty(WebConfigUtils.ConnectionString))
                {
                    await CliUtils.PrintErrorAsync("web.config 中数据库连接字符串 connectionString 未设置");

                    return;
                }

                WebConfigUtils.Load(CliUtils.PhysicalApplicationPath, "web.config");

                await Console.Out.WriteLineAsync($"数据库类型: {WebConfigUtils.DatabaseType.Value}");

                await Console.Out.WriteLineAsync($"连接字符串: {WebConfigUtils.ConnectionString}");

                await Console.Out.WriteLineAsync($"系统文件夹: {CliUtils.PhysicalApplicationPath}");

                if (!DataProvider.DatabaseDao.IsConnectionStringWork(WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString))
                {
                    await CliUtils.PrintErrorAsync("系统无法连接到 web.config 中设置的数据库");

                    return;
                }

                if (!SystemManager.IsNeedInstall())
                {
                    await CliUtils.PrintErrorAsync("系统已安装在 web.config 指定的数据库中,命令执行失败");

                    return;
                }

                WebConfigUtils.UpdateWebConfig(WebConfigUtils.IsProtectData, WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString, WebConfigUtils.AdminDirectory, StringUtils.GetShortGuid(), false);

                DataProvider.Reset();

                SystemManager.InstallDatabase(_userName, _password);
            }
            catch (Exception e)
            {
                await CliUtils.PrintErrorAsync(e.Message);

                return;
            }

            await Console.Out.WriteLineAsync("恭喜,系统安装成功!");
        }