Beispiel #1
0
        public Option <Link <NodeFolderPath, NodeFilePath> > CreateArchive(NodeFolderPath SrcDir,
                                                                           NodeFilePath DstPath, bool Overwrite = true, AppMessageObserver Observer = null)
        {
            try
            {
                DstPath.Folder.CreateIfMissing();

                var dstPath = Overwrite
                    ? DstPath.DeleteIfExists().Require()
                    : (DstPath.Exists() ? DstPath.UniqueName() : DstPath);

                using (var stream = new FileStream(dstPath.AbsolutePath, FileMode.OpenOrCreate))
                {
                    using (var archive = new ZipArchive(stream, ZipArchiveMode.Create))
                    {
                        foreach (var srcFile in SrcDir.Files("*.*", true))
                        {
                            Observer?.Invoke(AddingFileToArchive(srcFile, dstPath));
                            var entry = CreateEntry(SrcDir, srcFile, archive);
                            using (var writer = new StreamWriter(entry.Open()))
                                using (var reader = new StreamReader(srcFile.AbsolutePath))
                                    reader.BaseStream.CopyTo(writer.BaseStream);
                        }
                    }
                }
                return(link(SrcDir, dstPath));
            }
            catch (Exception e)
            {
                return(none <Link <NodeFolderPath, NodeFilePath> >(e));
            }
        }
Beispiel #2
0
 public AssemblyArtifact(IDistributionSegment Segment, NodeFilePath ArtifactPath)
     : base(Segment, ArtifactPath)
 {
     Descriptor = from a in ClrAssembly.Get(ArtifactPath)
                  from d in a.Describe()
                  select d;
 }
Beispiel #3
0
        public static RelativePath RelativeTo(this NodeFilePath File, FolderPath Folder)
        {
            var srcUri  = new Uri(File.AbsolutePath);
            var rootUri = new Uri(Folder);
            var relUri  = rootUri.MakeRelativeUri(srcUri);

            return(relUri.ToString());
        }
Beispiel #4
0
 protected override IDistributionArtifact DefineArtifact(NodeFilePath ArtifactPath)
 {
     if (ArtifactPath.HasExtension(CommonFileExtensions.Dll) || ArtifactPath.HasExtension(CommonFileExtensions.Exe))
     {
         return(new AssemblyArtifact(this, ArtifactPath));
     }
     else
     {
         return(new DistributionArtifact(this, ArtifactPath));
     }
 }
Beispiel #5
0
        public Option <Link <NodeFiles, NodeFilePath> > CreateArchive(IEnumerable <NodeFilePath> Src,
                                                                      NodeFilePath Dst, bool Overwrite = true)
        {
            try
            {
                var folder = Dst.Folder.CreateIfMissing();
                if (folder.IsNone())
                {
                    return(folder.ToNone <Link <NodeFiles, NodeFilePath> >());
                }

                var dstPath = Overwrite
                    ? Dst.DeleteIfExists().Require()
                    : (Dst.Exists() ? Dst.UniqueName() : Dst);

                using (var stream = new FileStream(Dst.AbsolutePath, FileMode.OpenOrCreate))
                {
                    using (var archive = new ZipArchive(stream, ZipArchiveMode.Create))
                    {
                        foreach (var srcFile in Src)
                        {
                            var entry = CreateEntry(srcFile.Folder.AbsolutePath, srcFile.AbsolutePath, archive);
                            using (var writer = new StreamWriter(entry.Open()))
                                using (var reader = new StreamReader(srcFile.AbsolutePath))
                                    reader.BaseStream.CopyTo(writer.BaseStream);
                        }
                    }

                    return(new Link <ReadOnlyList <NodeFilePath>, NodeFilePath>(metacore.rolist(Src), Dst));
                }
            }
            catch (Exception e)
            {
                return(none <Link <NodeFiles, NodeFilePath> >(e));
            }
        }
Beispiel #6
0
 public static Option <Link <NodeFilePath> > MoveTo(this NodeFilePath SrcPath, NodeFolderPath DstFolder, bool overwrite = true, bool createFolder = true)
 => from result in SrcPath.AbsolutePath.MoveTo(DstFolder + SrcPath.FileName, x => new NodeFilePath(DstFolder.Node, x), overwrite, createFolder)
 select new Link <NodeFilePath>(SrcPath, (new NodeFilePath(DstFolder.Node, result)));
Beispiel #7
0
 public static Option <Link <NodeFilePath> > CopyTo(this NodeFilePath SrcPath, NodeFolderPath DstPath, bool overwrite = true)
 => from result in SrcPath.AbsolutePath.CopyTo(DstPath + SrcPath.FileName, overwrite)
 select new Link <NodeFilePath>(SrcPath, (new NodeFilePath(DstPath.Node, result)));
Beispiel #8
0
 public DistributionArtifact(IDistributionSegment Segment, NodeFilePath ArtifactPath)
 {
     this.Segment      = Segment;
     this.ArtifactPath = ArtifactPath;
 }
Beispiel #9
0
 public Option <Link <NodeFilePath> > CreateArchive(NodeFilePath Src, NodeFilePath Dst,
                                                    bool Overwrite = true)
 => from link in CreateArchive(stream(Src), Dst, Overwrite)
 select new Link <NodeFilePath>(link.Source.Single(), link.Target);
Beispiel #10
0
 protected virtual IDistributionArtifact DefineArtifact(NodeFilePath ArtifactPath)
 => new DistributionArtifact(this, ArtifactPath);