示例#1
0
            public static string DownloadCms(IPathManager pathManager, string osArchitecture, string version)
            {
                var packagesPath  = pathManager.GetPackagesPath();
                var name          = GetCmsDownloadName(osArchitecture, version);
                var directoryPath = PathUtils.Combine(packagesPath, name);

                //if (IsCmsDownload(pathManager, osArchitecture, version))
                //{
                //    return directoryPath;
                //}

                var directoryNames = DirectoryUtils.GetDirectoryNames(packagesPath);

                foreach (var directoryName in directoryNames.Where(directoryName => StringUtils.StartsWithIgnoreCase(directoryName, "sscms-")))
                {
                    DirectoryUtils.DeleteDirectoryIfExists(PathUtils.Combine(packagesPath, directoryName));
                }

                DirectoryUtils.CreateDirectoryIfNotExists(directoryPath);

                var filePath = PathUtils.Combine(packagesPath, $"{GetCmsDownloadName(osArchitecture, version)}.zip");

                FileUtils.WriteText(filePath, string.Empty);
                using (var writer = File.OpenWrite(filePath))
                {
                    var client  = new RestClient(GetCmsDownloadUrl(osArchitecture, version));
                    var request = new RestRequest
                    {
                        ResponseWriter = responseStream =>
                        {
                            using (responseStream)
                            {
                                responseStream.CopyTo(writer);
                            }
                        }
                    };

                    client.DownloadData(request);
                }

                pathManager.ExtractZip(filePath, directoryPath);

                FileUtils.DeleteFileIfExists(filePath);

                return(directoryPath);
            }
示例#2
0
            public static bool IsCmsDownload(IPathManager pathManager, string osArchitecture, string version)
            {
                var packagesPath = pathManager.GetPackagesPath();
                var name         = GetCmsDownloadName(osArchitecture, version);

                var directoryPath = PathUtils.Combine(packagesPath, name);

                if (!DirectoryUtils.IsDirectoryExists(directoryPath))
                {
                    return(false);
                }

                if (!FileUtils.IsFileExists(PathUtils.Combine(directoryPath, $"{name}.zip")))
                {
                    return(false);
                }

                var fileNames = DirectoryUtils.GetFileNames(directoryPath);

                return(fileNames.Count > 1);
            }
示例#3
0
        public async Task ExecuteAsync(IPluginJobContext context)
        {
            if (!CliUtils.ParseArgs(_options, context.Args))
            {
                return;
            }

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

            var contentRootPath = _settingsManager.ContentRootPath;

            if (!CliUtils.IsSsCmsExists(contentRootPath) || await _configRepository.IsNeedInstallAsync())
            {
                await WriteUtils.PrintErrorAsync($"SS CMS has not been installed in {contentRootPath}");

                return;
            }

            var(success, result, failureMessage) = _apiService.GetReleases(_settingsManager.Version, null);
            if (!success)
            {
                await WriteUtils.PrintErrorAsync(failureMessage);

                return;
            }

            if (!SemVersion.TryParse(result.Cms.Version, out var version) || version <= _settingsManager.Version)
            {
                Console.WriteLine($"SS CMS {result.Cms.Version} is the latest version and no update is required");
                var proceed = ReadUtils.GetYesNo("do you still want to update?");
                if (!proceed)
                {
                    return;
                }
            }
            else
            {
                var proceed = ReadUtils.GetYesNo($"New version {result.Cms.Version} found, do you want to update?");
                if (!proceed)
                {
                    return;
                }
            }

            Console.WriteLine($"Downloading SS CMS {result.Cms.Version}...");
            var directoryPath = CloudUtils.Dl.DownloadCms(_pathManager, _settingsManager.OSArchitecture, result.Cms.Version);

            FileUtils.DeleteFileIfExists(PathUtils.Combine(directoryPath, Constants.ConfigFileName));
            FileUtils.DeleteFileIfExists(PathUtils.Combine(directoryPath, "wwwroot/404.html"));
            FileUtils.DeleteFileIfExists(PathUtils.Combine(directoryPath, "wwwroot/favicon.ico"));
            FileUtils.DeleteFileIfExists(PathUtils.Combine(directoryPath, "wwwroot/index.html"));

            await WriteUtils.PrintSuccessAsync($"{result.Cms.Version} download successfully!");

            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Please stop website and override files and directories ");
            Console.WriteLine($"     {directoryPath}");
            Console.WriteLine("to");
            Console.WriteLine($"     {contentRootPath}");

            var offlinePath = _pathManager.GetPackagesPath("app_offline.htm");

            FileUtils.WriteText(offlinePath, "down for maintenance");

            //var unOverrides = new List<string>();
            //foreach (var fileName in DirectoryUtils.GetFileNames(directoryPath))
            //{
            //    if (!FileUtils.CopyFile(PathUtils.Combine(directoryPath, fileName),
            //        PathUtils.Combine(contentRootPath, fileName), true))
            //    {
            //        unOverrides.Add(fileName);
            //    }
            //}

            //foreach (var directoryName in DirectoryUtils.GetDirectoryNames(directoryPath))
            //{
            //    DirectoryUtils.Copy(PathUtils.Combine(directoryPath, directoryName), PathUtils.Combine(contentRootPath, directoryName), true);
            //}

            //if (unOverrides.Count > 0)
            //{
            //    Replacing(contentRootPath, directoryPath, unOverrides);
            //}

            //FileUtils.DeleteFileIfExists(offlinePath);

            //await WriteUtils.PrintSuccessAsync($"Congratulations, SS CMS was updated to {result.Cms.Version} successfully!");
        }