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)); } }
public AssemblyArtifact(IDistributionSegment Segment, NodeFilePath ArtifactPath) : base(Segment, ArtifactPath) { Descriptor = from a in ClrAssembly.Get(ArtifactPath) from d in a.Describe() select d; }
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()); }
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)); } }
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)); } }
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)));
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)));
public DistributionArtifact(IDistributionSegment Segment, NodeFilePath ArtifactPath) { this.Segment = Segment; this.ArtifactPath = ArtifactPath; }
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);
protected virtual IDistributionArtifact DefineArtifact(NodeFilePath ArtifactPath) => new DistributionArtifact(this, ArtifactPath);