예제 #1
0
        /// <summary>
        /// Creates an Application Package using the specified
        /// definition file and pushes it to the server.
        /// </summary>
        /// <param name="definitionFilename">The file name of the package definition.</param>
        /// <param name="version">The version of the package to create.</param>
        public async Task Publish(string definitionFilename, string version, CancellationToken token = default(CancellationToken))
        {
            var name = Path.GetFileName(definitionFilename);

            context.Output.WriteLine($"Parsing package definition '{name}'...", ConsoleColor.Gray);

            var definition      = PackageTools.LoadDefinition <ApplicationPackageDefinition>(definitionFilename);
            var rootPath        = Path.GetDirectoryName(definitionFilename);
            var packageFilename = Path.Combine(PackageDirectory, $"{definition.Id}.zip");

            var packageName = $"{definition.Id} @ {version}";

            context.Output.WriteLine($"Packaging '{packageName}'...", ConsoleColor.Gray);

            try {
                await ApplicationPackageTools.CreatePackage(definition, rootPath, version, packageFilename);

                context.Output.WriteLine($"Packaged '{packageName}' successfully.", ConsoleColor.Gray);
            }
            catch (Exception error) {
                using (var block = context.Output.WriteBlock()) {
                    block.Write($"Failed to package '{packageName}'! ", ConsoleColor.DarkRed);
                    block.WriteLine(error.UnfoldMessages(), ConsoleColor.DarkYellow);
                }

                throw;
            }

            context.Output.WriteLine($"Publishing '{packageName}'...", ConsoleColor.Gray);

            try {
                await context.Packages.PushApplicationPackageAsync(packageFilename, token);

                context.Output.WriteLine($"Published '{packageName}' successfully.", ConsoleColor.DarkCyan);
            }
            catch (Exception error) {
                using (var block = context.Output.WriteBlock()) {
                    block.Write($"Failed to publish '{packageName}'! ", ConsoleColor.DarkRed);
                    block.WriteLine(error.UnfoldMessages(), ConsoleColor.DarkYellow);
                }

                throw;
            }
        }
예제 #2
0
        /// <summary>
        /// Creates an Application Package using the specified
        /// definition file and pushes it to the server.
        /// </summary>
        /// <param name="definitionFilename">The file name of the package definition.</param>
        /// <param name="version">The version of the package to create.</param>
        public async Task Publish(string definitionFilename, string version, CancellationToken token = default(CancellationToken))
        {
            var name = Path.GetFileName(definitionFilename);

            using (var block = context.Output.WriteBlock()) {
                block.Write("Parsing package definition ", ConsoleColor.DarkCyan);
                block.Write(name, ConsoleColor.Cyan);
                block.WriteLine("...", ConsoleColor.DarkCyan);
            }

            var definition      = PackageTools.LoadDefinition <ApplicationPackageDefinition>(definitionFilename);
            var rootPath        = Path.GetDirectoryName(definitionFilename);
            var packageFilename = Path.Combine(PackageDirectory, $"{definition.Id}.zip");

            using (var block = context.Output.WriteBlock()) {
                block.Write("Packaging ", ConsoleColor.DarkCyan);
                block.Write(definition.Id, ConsoleColor.Cyan);
                block.Write(" @", ConsoleColor.DarkCyan);
                block.Write(version, ConsoleColor.Cyan);
                block.WriteLine("...", ConsoleColor.DarkCyan);
            }

            try {
                await ApplicationPackageTools.CreatePackage(definition, rootPath, version, packageFilename);

                using (var block = context.Output.WriteBlock()) {
                    block.Write("Packaged ", ConsoleColor.DarkBlue);
                    block.Write(definition.Id, ConsoleColor.Blue);
                    block.Write(" @", ConsoleColor.DarkBlue);
                    block.Write(version, ConsoleColor.Blue);
                    block.WriteLine(" successfully.", ConsoleColor.DarkBlue);
                }
            }
            catch (Exception error) {
                context.Output.WriteBlock()
                .Write("Failed to package ", ConsoleColor.DarkRed)
                .Write(definition.Id, ConsoleColor.Red)
                .Write(" @", ConsoleColor.DarkRed)
                .Write(version, ConsoleColor.Red)
                .WriteLine("!", ConsoleColor.DarkRed)
                .WriteLine(error.UnfoldMessages(), ConsoleColor.DarkYellow)
                .Post();

                throw;
            }

            context.Output.WriteBlock()
            .Write("Publishing ", ConsoleColor.DarkCyan)
            .Write(definition.Id, ConsoleColor.Cyan)
            .Write(" @", ConsoleColor.DarkCyan)
            .Write(version, ConsoleColor.Cyan)
            .WriteLine("...", ConsoleColor.DarkCyan)
            .Post();

            try {
                await context.PushApplicationPackageAsync(packageFilename, token);

                context.Output.WriteBlock()
                .Write("Published ", ConsoleColor.DarkGreen)
                .Write(definition.Id, ConsoleColor.Green)
                .Write(" @", ConsoleColor.DarkGreen)
                .Write(version, ConsoleColor.Green)
                .WriteLine(" successfully.", ConsoleColor.DarkGreen)
                .Post();
            }
            catch (Exception error) {
                context.Output.WriteBlock()
                .Write("Failed to publish ", ConsoleColor.DarkRed)
                .Write(definition.Id, ConsoleColor.Red)
                .Write(" @", ConsoleColor.DarkRed)
                .Write(version, ConsoleColor.Red)
                .WriteLine("!", ConsoleColor.DarkRed)
                .WriteLine(error.UnfoldMessages(), ConsoleColor.DarkYellow)
                .Post();

                throw;
            }
        }