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 FileRepository
        (
            INodeContext C,
            NodeFolderPath RootLocation,
            IEnumerable <FileExtension> SupportedExtensions,
            IEnumerable <FolderName> TopFolderNames
        )
            : base(C)
        {
            this.RootLocation        = RootLocation;
            this.SupportedExtensions = rolist(SupportedExtensions);
            SegmentProvider          =
                TopFolderNames.Any()
                ?  new Func <IEnumerable <FolderName> >(() => TopFolderNames)
                : () => RootLocation.Folders().Select(x => x.FolderName);

            this.Navigator = new FileRepositoryNavigator(C, this);
        }
Beispiel #3
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 #4
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 #5
0
 public DistributionSpecifier(DistributionIdentifier DistId, NodeFolderPath Location, IEnumerable <FolderName> SegmentFolders)
 {
     this.DistId   = DistId;
     this.Location = Location;
     this.Segments = map(SegmentFolders, CreateSegment);
 }
Beispiel #6
0
 public DistributionNavigator(INodeContext C, FolderPath HostRoot)
     : base(C)
 {
     NavRoot = new NodeFolderPath(Host, HostRoot);
 }