public IPhysicalNode CreateTo(PhysicalFolder directory)
        {
            var dirPath = Path.Combine(directory.FullPath, Name);

            PhysicalFolder result;

            if (CopyFromFolder != null)
            {
                CopyDirectoryAndFiles(CopyFromFolder.FullPath, dirPath);
                result = new PhysicalFolder(dirPath, PhysicalFolderDeleteType.NoDelete);
            }
            else
            {
                result = PhysicalFolder.Create(dirPath, PhysicalFolderDeleteType.NoDelete, Nodes);
            }

            if (AttributesValue != null)
            {
                new DirectoryInfo(dirPath).Attributes = AttributesValue.Value;
            }
            if (CreationTimeValue != null)
            {
                Directory.SetCreationTime(dirPath, CreationTimeValue.Value);
            }

            if (LastWriteTimeValue != null)
            {
                Directory.SetLastWriteTime(dirPath, LastWriteTimeValue.Value);
            }

            return(result);
        }
 public static Folder CopyFrom(string name, PhysicalFolder copyFromFolder)
 {
     return(new Folder(name)
     {
         CopyFromFolder = copyFromFolder
     });
 }
        public IPhysicalNode CreateTo(PhysicalFolder directory)
        {
            var filePath = Path.Combine(directory.FullPath, Name);

            if (Content != null)
            {
                File.WriteAllBytes(filePath, Content);
            }
            else if (ContentFactory != null)
            {
                File.WriteAllBytes(filePath, ContentFactory());
            }
            else if (ContentCallBack != null)
            {
                using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    ContentCallBack(stream);
                }
            }
            else if (CopyFromStream != null)
            {
                using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    CopyFromStream.CopyTo(stream);
                }
                if (WillDisposeStream)
                {
                    CopyFromStream.Dispose();
                }
            }
            else if (CopyFromFile != null)
            {
                File.Copy(CopyFromFile.FullPath, filePath);
            }

            if (AttributesValue != null)
            {
                File.SetAttributes(filePath, AttributesValue.Value);
            }
            if (CreationTimeValue != null)
            {
                File.SetCreationTime(filePath, CreationTimeValue.Value);
            }
            if (LastWriteTimeValue != null)
            {
                File.SetLastWriteTime(filePath, LastWriteTimeValue.Value);
            }

            return(new PhysicalFile(Name, filePath));
        }
        public static PhysicalFolder Create(string rootPath, PhysicalFolderDeleteType deleteType, params INode[] nodes)
        {
            if (Directory.Exists(rootPath) == false)
            {
                Directory.CreateDirectory(rootPath);
                while (Directory.Exists(rootPath) == false)
                {
                    Thread.Sleep(10);
                }
            }

            RemoveSubDirectoriesAndFilesInRootDirectory(rootPath);

            var physicalFolder = new PhysicalFolder(rootPath, deleteType);

            foreach (var node in nodes.Where(Empty.NotMatch))
            {
                node.CreateTo(physicalFolder);
            }

            return(physicalFolder);
        }
Exemple #5
0
        public IPhysicalNode CreateTo(PhysicalFolder directory)
        {
            var filePath = Path.Combine(directory.FullPath, Name);

            if (Content != null)
            {
                File.WriteAllText(filePath, Content, Encoding);
            }
            else if (ContentFactory != null)
            {
                File.WriteAllText(filePath, ContentFactory(), Encoding);
            }
            else if (WriteCallback != null)
            {
                using (var streamWriter = new StreamWriter(filePath, false, Encoding))
                {
                    WriteCallback(streamWriter);
                }
            }
            else
            {
                throw new InvalidOperationException();
            }

            if (AttributesValue != null)
            {
                File.SetAttributes(filePath, AttributesValue.Value);
            }
            if (CreationTimeValue != null)
            {
                File.SetCreationTime(filePath, CreationTimeValue.Value);
            }
            if (LastWriteTimeValue != null)
            {
                File.SetLastWriteTime(filePath, LastWriteTimeValue.Value);
            }

            return(new PhysicalFile(Name, filePath));
        }
        public IPhysicalNode CreateTo(PhysicalFolder directory)
        {
            var destFilePath   = Path.Combine(directory.FullPath, Name);
            var tempFolderPath = CreateTempFolderPath();

            if (AnonymousTypeFolder != null)
            {
                using (var dir = TypeBasePhysicalFolder.CreatePhysicalFolder(
                           tempFolderPath,
                           PhysicalFolderDeleteType.DeleteFolder,
                           AnonymousTypeFolder))
                {
                    CreateArchiveFile.Archive(tempFolderPath, destFilePath);
                }
            }
            else
            {
                using (var dir = PhysicalFolder.Create(tempFolderPath, PhysicalFolderDeleteType.DeleteFolder, Nodes))
                {
                    CreateArchiveFile.Archive(dir.FullPath, destFilePath);
                }
            }

            if (AttributesValue != null)
            {
                File.SetAttributes(destFilePath, AttributesValue.Value);
            }
            if (CreationTimeValue != null)
            {
                File.SetCreationTime(destFilePath, CreationTimeValue.Value);
            }
            if (LastWriteTimeValue != null)
            {
                File.SetLastWriteTime(destFilePath, LastWriteTimeValue.Value);
            }
            return(new PhysicalFile(Name, destFilePath));
        }
 public TypeBasePhysicalFolder(T root, PhysicalFolder physicalFolder)
 {
     Root            = root;
     _physicalFolder = physicalFolder;
 }
Exemple #8
0
 public IPhysicalNode CreateTo(PhysicalFolder directory)
 {
     return(new PhysicalFile(Name, _fullPath));
 }