示例#1
0
        public static IEnumerable <FileElement> Flatten(this FolderElement @this)
        {
            yield return(@this);

            foreach (var file in @this.Files)
            {
                yield return(file);
            }

            foreach (var folder in @this.Folders)
            {
                foreach (var element in folder.Flatten())
                {
                    yield return(element);
                }
            }
        }
        protected static T FileElementPipe <T>(T element, XElement node, FolderElement parent) where T : FileElement
        {
            element.Parent = parent;
            element.Target = node.Attribute(nameof(Target))?.Value;
            element.Source = node.Attribute(nameof(Source))?.Value;

            if (string.IsNullOrWhiteSpace(element.Source))
            {
                element.Source = Path.Combine(parent.Source, element.Target ?? throw new InvalidOperationException());
            }

            element.Source = element.Source
                             .ReplaceConfigurationPlaceholder()
                             .ReplaceVersionPlaceholder()
                             .GetFullPath(parent?.Source);

            element.Target = element.Target
                             .ReplaceConfigurationPlaceholder()
                             .ReplaceVersionPlaceholder(element.Source)
                             .GetFullPath(parent?.Target);

            return(element);
        }
示例#3
0
        private static void Pack(FolderElement info, bool openFolder = true)
        {
            string zipTargetPath;

            using (var tempFolder = new TempDirectory(info.Target))
            {
                Print.Info($"Start Copying: {info.Source} --> {info.Target}");
                info
                .Flatten()
                .Where(item => !(item is FolderElement folder) ||
                       !folder.Files.Any() && !folder.Folders.Any())
                .ForEach(item => item.Source.CopyTo(item.Target));
                Print.Info("Completed Copying. ");

                zipTargetPath = $"{tempFolder.Path}.zip";
                Print.Info($"Start Package: {zipTargetPath}...");
                if (File.Exists(zipTargetPath))
                {
                    File.Delete(zipTargetPath);
                }
                ZipFile.CreateFromDirectory(
                    tempFolder.Path,
                    zipTargetPath,
                    CompressionLevel.Optimal,
                    true);

                Print.Info("Completed Package. ");
            }

            if (openFolder)
            {
                Print.Info($"Opening the file: {zipTargetPath}...");
                Process.Start("explorer.exe", $"/select, {zipTargetPath}");
            }

            Print.Divider();
        }
 public static FileElement Create(XElement node, FolderElement parent)
 {
     return(FileElementPipe(new FileElement(), node, parent));
 }