Esempio 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());
                }
            });
        }
Esempio n. 2
0
        public async Task <ProjectPackage> UnpackAsync(string filename, string path)
        {
            PathEx.CreatePath(path);

            ProjectPackage metadata = null;

            await PackageTools.ReadArchive(filename, async archive => {
                metadata = await PackageTools.ParseMetadataAsync <ProjectPackage>(archive);

                var packageName = $"{metadata.Id} @ {metadata.Version}";

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

                try {
                    await PackageTools.UnpackBin(archive, path);

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

                    throw;
                }
            });

            return(metadata);
        }
Esempio n. 3
0
        public static async Task <ProjectPackage> GetMetadataAsync(string filename)
        {
            ProjectPackage package = null;

            await PackageTools.ReadArchive(filename, async archive => {
                package = await PackageTools.ParseMetadataAsync <ProjectPackage>(archive);
            });

            return(package);
        }
Esempio n. 4
0
        private static void AppendMetadata(ZipArchive archive, ApplicationPackageDefinition definition, string version)
        {
            var metadata = new ApplicationPackage {
                Id          = definition.Id,
                Name        = definition.Name,
                Description = definition.Description,
                Version     = version,
            };

            PackageTools.AppendMetadata(archive, metadata, version);
        }
Esempio n. 5
0
        private static void AppendMetadata(ZipArchive archive, PackageDefinition definition, string version)
        {
            var metadata = new ProjectPackage {
                Id               = definition.Id,
                Name             = definition.Name,
                Description      = definition.Description,
                AssemblyFilename = definition.Assembly,
                ScriptName       = definition.Script,
                Version          = version,
            };

            PackageTools.AppendMetadata(archive, metadata, version);
        }
Esempio n. 6
0
        public static async Task <ApplicationPackage> UnpackAsync(string filename, string path)
        {
            PathEx.CreatePath(path);

            ApplicationPackage metadata = null;

            await PackageTools.ReadArchive(filename, async archive => {
                metadata = await PackageTools.ParseMetadataAsync <ApplicationPackage>(archive);

                await PackageTools.UnpackBin(archive, path);
            });

            return(metadata);
        }
Esempio n. 7
0
        public static async Task <ProjectPackage> UnpackAsync(string filename, string path)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            ProjectPackage metadata = null;

            await PackageTools.ReadArchive(filename, async archive => {
                metadata = await PackageTools.ParseMetadataAsync <ProjectPackage>(archive);

                await PackageTools.UnpackBin(archive, path);
            });

            return(metadata);
        }
Esempio n. 8
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;
            }
        }
Esempio n. 9
0
        public async Task <ApplicationPackage> UnpackAsync(string filename, string path)
        {
            PathEx.CreatePath(path);

            ApplicationPackage metadata = null;

            await PackageTools.ReadArchive(filename, async archive => {
                metadata = await PackageTools.ParseMetadataAsync <ApplicationPackage>(archive);

                context.Output.WriteBlock()
                .Write("Unpacking ", ConsoleColor.DarkCyan)
                .Write(metadata.Id, ConsoleColor.Cyan)
                .Write(" @", ConsoleColor.DarkCyan)
                .Write(metadata.Version, ConsoleColor.Cyan)
                .WriteLine("...", ConsoleColor.DarkCyan)
                .Post();

                try {
                    await PackageTools.UnpackBin(archive, path);

                    context.Output.WriteBlock()
                    .Write("Unpacked ", ConsoleColor.DarkBlue)
                    .Write(metadata.Id, ConsoleColor.Blue)
                    .Write(" @", ConsoleColor.DarkBlue)
                    .Write(metadata.Version, ConsoleColor.Blue)
                    .WriteLine(" successfully.", ConsoleColor.DarkBlue)
                    .Post();
                }
                catch (Exception error) {
                    context.Output.WriteBlock()
                    .Write("Failed to unpack ", ConsoleColor.DarkRed)
                    .Write(metadata.Id, ConsoleColor.Red)
                    .Write(" @", ConsoleColor.DarkRed)
                    .Write(metadata.Version, ConsoleColor.Red)
                    .WriteLine("!", ConsoleColor.DarkRed)
                    .WriteLine(error.UnfoldMessages(), ConsoleColor.DarkYellow)
                    .Post();

                    throw;
                }
            });

            return(metadata);
        }
Esempio n. 10
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;
            }
        }
Esempio n. 11
0
 public static ProjectPackageDefinition LoadDefinition(string filename)
 {
     return(PackageTools.LoadDefinition <ProjectPackageDefinition>(filename));
 }