Ejemplo n.º 1
0
        /// <summary>
        /// Creates a Project Package using the specified
        /// definition file.
        /// </summary>
        /// <param name="definitionFilename">The file name of the package definition.</param>
        /// <param name="version">The version of the package to create.</param>
        /// <param name="outputFilename">The file name of the output package.</param>
        public static async Task CreatePackage(string definitionFilename, string version, string outputFilename)
        {
            var definition     = PackageTools.LoadDefinition <PackageDefinition>(definitionFilename);
            var definitionPath = Path.GetDirectoryName(definitionFilename);

            var outputFilenameFull = Path.GetFullPath(outputFilename);
            var outputPath         = Path.GetDirectoryName(outputFilenameFull);

            if (string.IsNullOrEmpty(outputPath))
            {
                throw new ApplicationException("Empty package output path!");
            }

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            await PackageTools.WriteArchive(outputFilename, async archive => {
                AppendMetadata(archive, definition, version);

                foreach (var fileDefinition in definition.Files)
                {
                    var destPath = Path.Combine("bin", fileDefinition.Destination);

                    await PackageTools.AddFiles(archive, definitionPath, fileDefinition.Path, destPath, fileDefinition.Exclude?.ToArray());
                }
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an Project 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 <ProjectPackageDefinition>(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 ProjectPackageTools.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.PushProjectPackageAsync(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;
            }
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
0
 public static ProjectPackageDefinition LoadDefinition(string filename)
 {
     return(PackageTools.LoadDefinition <ProjectPackageDefinition>(filename));
 }