コード例 #1
0
        /// <summary>
        /// Write the manifest file
        /// </summary>
        /// <param name="parameters">
        /// Publish parameter
        /// </param>
        /// <param name="client">
        /// FTP client. If this parameter is null, the file will only be stored locally according to the publish parameter
        /// </param>
        private void WriteManifest(PublishParameter parameters, FtpClient client)
        {
            // Write version manifest file
            var manifest = Path.Combine(parameters.ProductBasePath, ManifestFileName);
            var sb = new StringBuilder();
            sb.AppendLine(AppUtil.ProductVersion);
            sb.AppendLine(AppUtil.ProductWriteDate.ToUniversalTime().ToString(DateFormatString));
            sb.AppendLine(parameters.FtpX86PackageRelativePath);
            sb.AppendLine(parameters.FtpX64PackageRelativePath);
            sb.AppendLine(parameters.HasInstallers ? parameters.FtpX86InstallerRelativePath : string.Empty);
            sb.AppendLine(parameters.HasInstallers ? parameters.FtpX64InstallerRelativePath : string.Empty);
            var manifestContent = sb.ToString();
            File.WriteAllText(manifest, manifestContent);

            if (client != null)
            {
                string remoteManifest = parameters.FtpProductBasePath + "/" + ManifestFileName;
                this._logger.Info("Creating version manifest for version " + AppUtil.ProductVersion + " at " + remoteManifest);
                client.Upload(manifest, remoteManifest);
            }
        }
コード例 #2
0
        /// <summary>
        /// Publish a new distribution version
        /// </summary>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        internal void Publish(PublishParameter parameters)
        {
            if (!Directory.Exists(parameters.OutputLocation))
            {
                Directory.CreateDirectory(parameters.OutputLocation);
            }

            // Comrpess Zip package
            this._logger.Info("Creating x86 distribtution package into " + parameters.X86PackageFile);
            this.CompressBinariesDir(parameters.X86BuildLocation, parameters.X86PackageFile);
            this._logger.Info("Creating x64 distribtution package into " + parameters.X64PackageFile);
            this.CompressBinariesDir(parameters.X64BuildLocation, parameters.X64PackageFile);

            bool hasInstaller = parameters.HasInstallers;
            if (hasInstaller)
            {
                this._logger.Info("Creating x86 installer into " + parameters.X86InstallerFile);
                this.CreateInstaller(
                    parameters.InnoExecutable,
                    parameters.InnoScriptPath,
                    parameters.InnoExtraParams,
                    parameters.X86BuildLocation,
                    parameters.X86InstallerFile);
                this._logger.Info("Creating x64 installer into " + parameters.X64InstallerFile);
                this.CreateInstaller(
                    parameters.InnoExecutable,
                    parameters.InnoScriptPath,
                    parameters.InnoExtraParams,
                    parameters.X64BuildLocation,
                    parameters.X64InstallerFile);
            }
            else
            {
                this._logger.Info("There is no parameter for creating Installers... Skipped");
            }

            // Write version manifest file locally
            this.WriteManifest(parameters, null);

            if (!string.IsNullOrEmpty(parameters.FtpServer))
            {
                // If parameters for FTP were specified
                this._logger.InfoFormat(
                    "Using FTP server {0} [{1}]",
                    parameters.FtpServerUrl,
                    string.IsNullOrEmpty(parameters.FtpProxyHost) ? null : parameters.FtpProxyHost + ":" + parameters.FtpProxyPort);
                var client = new FtpClient(
                    this._logger,
                    parameters.FtpServer,
                    parameters.FtpPort,
                    parameters.FtpProxyHost,
                    parameters.FtpProxyPort,
                    parameters.FtpUser,
                    parameters.FtpPassword);

                this._logger.Info("Uploading x86 package into " + parameters.FtpFullX86PackagePath);
                client.Upload(parameters.X86PackageFile, parameters.FtpFullX86PackagePath);
                this._logger.Info("Uploading x64 package into " + parameters.FtpFullX64PackagePath);
                client.Upload(parameters.X64PackageFile, parameters.FtpFullX64PackagePath);

                if (hasInstaller)
                {
                    this._logger.Info("Uploading x86 installer into " + parameters.FtpFullX86InstallerPath);
                    client.Upload(parameters.X86InstallerFile, parameters.FtpFullX86InstallerPath);
                    this._logger.Info("Uploading x64 installer into " + parameters.FtpFullX64InstallerPath);
                    client.Upload(parameters.X64InstallerFile, parameters.FtpFullX64InstallerPath);
                }

                // Write version manifest file to server
                this.WriteManifest(parameters, client);

                // Remove old versions
                this.RemoveOldVersions(client, parameters);
            }
        }
コード例 #3
0
        /// <summary>
        /// Remove older versions and only keep the latest version
        /// </summary>
        /// <param name="client">
        /// The client.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        private void RemoveOldVersions(FtpClient client, PublishParameter parameters)
        {
            var dirs = client.ListDirectory(parameters.FtpProductBasePath);
            if (dirs != null)
            {
                var versions = new Dictionary<Version, string>();
                foreach (var f in dirs)
                {
                    var name = Path.GetFileName(f);
                    if (Regex.IsMatch(name, @"\d+?\.\d+?\.\d+?\.\d+?"))
                    {
                        var v = new Version(name);
                        versions.Add(v, name);
                    }
                }

                if (versions.Count > 1)
                {
                    var sortedVersions = versions.OrderBy(p => p.Key).ToList();

                    for (int i = 0; i < sortedVersions.Count - 1; i++)
                    {
                        var pair = sortedVersions[i];
                        var delDir = parameters.FtpProductBasePath + "/" + pair.Value;
                        this._logger.Info("Removing all version folder at: " + delDir);
                        client.RemoveDirectory(delDir);
                    }
                }
            }
        }