protected ServiceModelCodeGenerator(IDirectory directory, CodeGenerationOptions options)
        {
            this.Options = options;
            this.directory = directory;

            directory.Create(true);
        }
示例#2
0
        public async Task CopyToAsync(IFile destination, bool overwrite = true, bool createDirectory = true)
        {
            _ = destination ?? throw new ArgumentNullException(nameof(destination));

            // Create the directory
            if (createDirectory)
            {
                IDirectory directory = destination.Directory;
                directory.Create();
            }

            // Use the file system APIs if destination is also in the file system
            if (destination is LocalFile)
            {
                LocalFileProvider.RetryPolicy.Execute(() => _file.CopyTo(destination.Path.FullPath, overwrite));
            }
            else
            {
                // Otherwise use streams to perform the copy
                using (Stream sourceStream = OpenRead())
                {
                    using (Stream destinationStream = destination.OpenWrite())
                    {
                        await sourceStream.CopyToAsync(destinationStream);
                    }
                }
            }
        }
示例#3
0
 public static void EnsureExists(this IDirectory dir, FileAttributes attributes = FileAttributes.Directory)
 {
     if (!dir.Exists())
     {
         dir.Create(attributes);
     }
 }
示例#4
0
        protected ServiceModelCodeGenerator(IDirectory directory, CodeGenerationOptions options)
        {
            this.Options   = options;
            this.directory = directory;

            directory.Create(true);
        }
示例#5
0
 public void CreateDirectoryIfNotExists(string path)
 {
     if (!_directory.Exists(path))
     {
         _directory.Create(path);
     }
 }
示例#6
0
        /// <summary>
        /// Copy "this" directory (<paramref name="a_this"/>) to the given destination directory (<paramref name="a_destination"/>).
        /// </summary>
        /// <param name="a_this">"This" directory.</param>
        /// <param name="a_destination">Destination directory.</param>
        /// <exception cref="NullReferenceException">Thrown if <paramref name="a_this"/> is null.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_destination"/> is null.</exception>
        public static void CopyTo(this IDirectory a_this, IDirectory a_destination)
        {
            #region Argument Validation

            if (a_this == null)
                throw new NullReferenceException(nameof(a_this));

            if (a_destination == null)
                throw new ArgumentNullException(nameof(a_destination));

            #endregion

            a_destination.Create();

            foreach (var file in a_this.Files())
            {
                var dest = a_destination.File(file.Name);
                file.CopyTo(dest);
            }

            foreach (var directory in a_this.Directories())
            {
                var dest = a_destination.Directory(directory.Name);
                directory.CopyTo(dest);
            }
        }
示例#7
0
        /// <summary>
        /// 清空发布文件
        /// </summary>

        protected void ClearReleaseDir(IBuildContext context)
        {
            IDirectory releaseDir = context.Disk.Directory(context.ReleasePath, PathTypes.Absolute);

            releaseDir.Delete();
            releaseDir.Create();
        }
示例#8
0
 private static void EnsureDirectoryExists(IDirectory directory)
 {
     if (!directory.Exists())
     {
         directory.Create();
     }
 }
示例#9
0
        /// <summary>
        /// Copy "this" directory (<paramref name="a_this"/>) to the given destination directory (<paramref name="a_destination"/>).
        /// </summary>
        /// <param name="a_this">"This" directory.</param>
        /// <param name="a_destination">Destination directory.</param>
        /// <exception cref="NullReferenceException">Thrown if <paramref name="a_this"/> is null.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_destination"/> is null.</exception>
        public static void CopyTo(this IDirectory a_this, IDirectory a_destination)
        {
            #region Argument Validation

            if (a_this == null)
            {
                throw new NullReferenceException(nameof(a_this));
            }

            if (a_destination == null)
            {
                throw new ArgumentNullException(nameof(a_destination));
            }

            #endregion

            a_destination.Create();

            foreach (var file in a_this.Files)
            {
                var dest = a_destination.File(file.Name);
                file.CopyTo(dest);
            }

            foreach (var directory in a_this.Directories)
            {
                var dest = a_destination.Directory(directory.Name);
                directory.CopyTo(dest);
            }
        }
        Stream OpenManifestFileForWriting()
        {
            cacheDirectory.Create();
            var file = cacheDirectory.GetFile(manifestFilename);

            return(file.Open(FileMode.Create, FileAccess.Write, FileShare.None));
        }
 public TemporaryDirectory(IDirectory unerlyingDirectory)
 {
     UnderlyingDirectory = unerlyingDirectory;
     if (!UnderlyingDirectory.Exists)
     {
         UnderlyingDirectory.Create();
     }
 }
示例#12
0
        /// <summary>
        ///     Creates a junction point from the specified directory to the specified target directory.
        /// </summary>
        /// <remarks>
        ///     Only works on NTFS.
        /// </remarks>
        /// <param name = "junctionPoint">The junction point path</param>
        /// <param name = "targetDir">The target directory</param>
        /// <param name = "overwrite">If true overwrites an existing reparse point or empty directory</param>
        /// <exception cref = "IOException">Thrown when the junction point could not be created or when
        ///     an existing directory was found and <paramref name = "overwrite" /> if false</exception>
        public static void Create(IDirectory junctionPoint, string targetDir, bool overwrite)
        {
            //targetDir = Path.GetFullPath(targetDir);

            if (!Directory.Exists(targetDir))
            {
                throw new IOException("Target path does not exist or is not a directory.");
            }

            if (junctionPoint.Exists)
            {
                if (!overwrite)
                {
                    throw new IOException("Directory already exists and overwrite parameter is false.");
                }
            }
            else
            {
                junctionPoint.Create();
            }

            using (var handle = OpenReparsePoint(junctionPoint.Path.FullPath, EFileAccess.GenericWrite))
            {
                var targetDirBytes = Encoding.Unicode.GetBytes(NonInterpretedPathPrefix + Path.GetFullPath(targetDir));

                var reparseDataBuffer = new REPARSE_DATA_BUFFER();

                reparseDataBuffer.ReparseTag           = IO_REPARSE_TAG_MOUNT_POINT;
                reparseDataBuffer.ReparseDataLength    = (ushort)(targetDirBytes.Length + 12);
                reparseDataBuffer.SubstituteNameOffset = 0;
                reparseDataBuffer.SubstituteNameLength = (ushort)targetDirBytes.Length;
                reparseDataBuffer.PrintNameOffset      = (ushort)(targetDirBytes.Length + 2);
                reparseDataBuffer.PrintNameLength      = 0;
                reparseDataBuffer.PathBuffer           = new byte[0x3ff0];
                Array.Copy(targetDirBytes, reparseDataBuffer.PathBuffer, targetDirBytes.Length);

                var inBufferSize = Marshal.SizeOf(reparseDataBuffer);
                var inBuffer     = Marshal.AllocHGlobal(inBufferSize);

                try
                {
                    Marshal.StructureToPtr(reparseDataBuffer, inBuffer, false);

                    int bytesReturned;
                    var result = DeviceIoControl(handle.DangerousGetHandle(), FSCTL_SET_REPARSE_POINT,
                                                 inBuffer, targetDirBytes.Length + 20, IntPtr.Zero, 0, out bytesReturned, IntPtr.Zero);

                    if (!result)
                    {
                        ThrowLastWin32Error("Unable to create junction point.");
                    }
                }
                finally
                {
                    Marshal.FreeHGlobal(inBuffer);
                }
            }
        }
示例#13
0
 public void WriteDbFile_If_Temporary_Folder_Doesnt_Exists_Should_Create_It()
 {
     //Arrange
     A.CallTo(() => _directory.Exists).Returns(false);
     //Act
     mUnderTest.WriteDbFile("filename", new List <string>());
     //Assert
     A.CallTo(() => _directory.Create()).MustHaveHappened();
 }
 /// <summary>
 /// Moves the file to a new directory
 /// </summary>
 /// <param name="Directory">Directory to move to</param>
 public override void MoveTo(IDirectory Directory)
 {
     if (Directory == null || !Exists)
     {
         return;
     }
     Directory.Create();
     InternalFile.MoveTo(Directory.FullName + "\\" + Name);
     InternalFile = new System.IO.FileInfo(Directory.FullName + "\\" + Name);
 }
示例#15
0
 /// <summary>
 /// Moves the file to a new directory
 /// </summary>
 /// <param name="directory">Directory to move to</param>
 public override IFile MoveTo(IDirectory directory)
 {
     if (directory is null || !Exists || string.IsNullOrEmpty(directory.FullName))
     {
         return(this);
     }
     directory.Create();
     InternalFile.MoveTo(directory.FullName + "\\" + Name);
     InternalFile = new System.IO.FileInfo(directory.FullName + "\\" + Name);
     return(this);
 }
        public Hooks(VariableController variableController,
                     FeatureContext featureContext, ScenarioContext scenarioContext)
        {
            this.variableController = variableController;
            this.featureContext     = featureContext;
            this.scenarioContext    = scenarioContext;

            BinDirectory.Create();
            var configuration = ConfigurationFactory.Create(BinDirectory);

            config.Value = ConfigOptionsFactory.Create(configuration);
        }
示例#17
0
        public void Save(string sessionKey, IDictionary <string, object> sessionState)
        {
            if (!_directory.Exists(_path))
            {
                _directory.Create(_path);
            }
            var sessionFilename = Path.Combine(_path, sessionKey);

            var bytes = _sessionStateSerializer.Serialize(sessionState);

            _file.WriteAllBytes(sessionFilename, bytes);
        }
示例#18
0
        public void DirectoryRenameTest()
        {
            var        Manager    = new FileManager();
            IDirectory TempObject = Manager.Directory("~/Data/Test");

            TempObject.Create();
            string DirectoryPath = TempObject.Parent.FullName;

            TempObject.Rename("Test2");
            Assert.Equal(DirectoryPath + "\\Test2", TempObject.FullName);
            TempObject.Delete();
        }
示例#19
0
        public IFile MoveTo(IDirectory directory)
        {
            if (!directory.Exists)
            {
                directory.Create();
            }

            var targetFile = directory.File(Name);

            File.Move(Path, targetFile.Path);

            return(targetFile);
        }
        private static void EnsureDirectoryExists(string filePath, IDirectory directoryWrapper, ILogger logger)
        {
            // Exception handling: not much point in catch exceptions here - if we can't
            // create a missing directory then the creation of the file watcher will
            // fail too, so the monitor class won't be constructed correctly.
            var dirPath = Path.GetDirectoryName(filePath);

            if (!directoryWrapper.Exists(dirPath))
            {
                directoryWrapper.Create(dirPath);
                logger.WriteLine(AnalysisStrings.FileMonitory_CreatedDirectory, dirPath);
            }
        }
示例#21
0
        public void FileMoveToTest()
        {
            var   Manager    = new FileManager();
            IFile TempObject = Manager.File("~/Data/Test/Data.txt");

            TempObject.Write("This is a test");
            IDirectory NewParent = Manager.Directory("~/Data2/");

            NewParent.Create();
            TempObject.MoveTo(NewParent);
            Assert.Equal(NewParent.FullName + "Data.txt", TempObject.FullName);
            TempObject.Delete();
        }
示例#22
0
        private void EnsureFileExists(string filePath)
        {
            var directoryPath = Path.GetDirectoryName(filePath);

            if (!directoryWrapper.Exists(directoryPath))
            {
                directoryWrapper.Create(directoryPath);
            }
            if (!fileWrapper.Exists(filePath))
            {
                WriteToXmlFile();
            }
        }
示例#23
0
        public void DirectoryMoveToTest()
        {
            var        Manager    = new FileManager();
            IDirectory TempObject = Manager.Directory("~/Data/Test");

            TempObject.Create();
            IDirectory NewParent = Manager.Directory("~/Data2/");

            NewParent.Create();
            TempObject.MoveTo(NewParent);
            Assert.Equal(NewParent.FullName + "Test", TempObject.FullName);
            TempObject.Delete();
        }
示例#24
0
        private static async Task MoveUsingStreams(IDirectory destination, IDirectory source, CancellationToken token)
        {
            destination.Create();
            foreach (var subDir in source.AllSubDirectories())
            {
                await MoveUsingStreams(destination.SubDirectory(subDir.Name), subDir, token);
            }

            foreach (var file in source.AllFiles())
            {
                await MoveUsingStreams(destination.File(file.Name), file, token, source.Attributes);
            }
            source.Delete();
        }
示例#25
0
        /// <summary>
        /// Copies the directory to the specified parent directory
        /// </summary>
        /// <param name="directory">Directory to copy to</param>
        /// <param name="options">Copy options</param>
        /// <returns></returns>
        public async Task <IDirectory> CopyToAsync(IDirectory directory, CopyOptions options = CopyOptions.CopyAlways)
        {
            if (InternalDirectory is null || directory is null || string.IsNullOrEmpty(directory.FullName))
            {
                return(this);
            }
            directory.Create();
            List <Task> Tasks = new List <Task>();

            foreach (var TempFile in EnumerateFiles())
            {
                switch (options)
                {
                case CopyOptions.CopyAlways:
                    Tasks.Add(TempFile.CopyToAsync(directory, true));
                    break;

                case CopyOptions.CopyIfNewer:
                    if (new FileInfo(directory.FullName + "\\" + TempFile.Name.Replace("/", "").Replace("\\", ""), Credentials).Exists)
                    {
                        var FileInfo = new FileInfo(directory.FullName + "\\" + TempFile.Name.Replace("/", "").Replace("\\", ""), Credentials);
                        if (FileInfo.Modified.CompareTo(TempFile.Modified) < 0)
                        {
                            Tasks.Add(TempFile.CopyToAsync(directory, true));
                        }
                    }
                    else
                    {
                        Tasks.Add(TempFile.CopyToAsync(directory, true));
                    }

                    break;

                case CopyOptions.DoNotOverwrite:
                    Tasks.Add(TempFile.CopyToAsync(directory, true));
                    break;
                }
            }
            await Task.WhenAll(Tasks).ConfigureAwait(false);

            Tasks.Clear();
            foreach (var SubDirectory in EnumerateDirectories())
            {
                Tasks.Add(SubDirectory.CopyToAsync(new DirectoryInfo(directory.FullName + "\\" + SubDirectory.Name.Replace("/", "").Replace("\\", ""), Credentials), options));
            }
            await Task.WhenAll(Tasks).ConfigureAwait(false);

            return(directory);
        }
示例#26
0
        public static async Task CopyFrom(this IDirectory destination, IDirectory source, CancellationToken?token = null)
        {
            CancellationToken token1 = token ?? CancellationToken.None;

            destination.Create();
            foreach (var subDir in source.AllSubDirectories())
            {
                await CopyFrom(destination.SubDirectory(subDir.Name), subDir, token1);
            }

            foreach (var file in source.AllFiles())
            {
                await CopyFrom(destination.File(file.Name), file, token1, source.Attributes);
            }
        }
示例#27
0
        /// <summary>
        /// Copies the file to another directory
        /// </summary>
        /// <param name="directory">Directory to copy the file to</param>
        /// <param name="overwrite">Should the file overwrite another file if found</param>
        /// <returns>The newly created file</returns>
        public override IFile CopyTo(IDirectory directory, bool overwrite)
        {
            if (directory is null || !Exists || string.IsNullOrEmpty(directory.FullName))
            {
                return(null);
            }
            directory.Create();
            var File = new FileInfo(directory.FullName + "\\" + Name.Right(Name.Length - (Name.LastIndexOf("/", StringComparison.OrdinalIgnoreCase) + 1)), Credentials);

            if (!File.Exists || overwrite)
            {
                File.Write(ReadBinary());
                return(File);
            }
            return(this);
        }
        /// <summary>
        /// Copies the file to another directory
        /// </summary>
        /// <param name="Directory">Directory to copy the file to</param>
        /// <param name="Overwrite">Should the file overwrite another file if found</param>
        /// <returns>The newly created file</returns>
        public override IFile CopyTo(IDirectory Directory, bool Overwrite)
        {
            if (Directory == null || !Exists)
            {
                return(null);
            }
            Directory.Create();
            var File = new FileInfo(Directory.FullName + "\\" + Name.Right(Name.Length - (Name.LastIndexOf("/", StringComparison.OrdinalIgnoreCase) + 1)), UserName, Password, Domain);

            if (!File.Exists || Overwrite)
            {
                File.Write(ReadBinary());
                return(File);
            }
            return(this);
        }
示例#29
0
        public void Execute()
        {
            var dir = App.BaseMigrationsDirectory + @"\" + _args.Name;

            if (_ds.Exists(dir))
            {
                throw new GatorException("Warning -- A migration with that name already exists - exiting");
            }

            _ds.Create(dir);

            var cfg = new MigrationConfig {
                created = DateTime.Now, versionNumber = "0.0.0"
            };

            _fs.CreateWithContent(dir + "/version.json", JsonConvert.SerializeObject(cfg));
        }
示例#30
0
        public void Execute()
        {
            if (_fs.Exists(App.DbJsonCfgFile))
            {
                throw new GatorException("Warning -- Application already exists at this location");
            }

            var cfg = new DbConfig {
                type = "unspecified", connectionString = "", currentVersion = "0.0.0", lastMigration = "none"
            };

            _fs.CreateWithContent(App.DbJsonCfgFile, JsonConvert.SerializeObject(cfg, Formatting.Indented, new IsoDateTimeConverter()));

            _ds.Create(App.BaseMigrationsDirectory);

            Console.WriteLine("Database config file and versions directory created.");
        }
示例#31
0
        public IFile MoveTo(IDirectory directory)
        {
            if (!directory.Exists)
            {
                directory.Create();
            }

            var targetFile = (FileImpl)directory.File(Name);

            targetFile.CreateOnDemand();
            targetFile.myContent = new byte[myContent.Length];
            Array.Copy(myContent, targetFile.myContent, myContent.Length);

            Delete();

            return(targetFile);
        }
示例#32
0
        public void DirectoryTest()
        {
            var        Manager    = new FileManager();
            IDirectory TempObject = Manager.Directory("~/Data/Test");

            Assert.Equal(false, TempObject.Exists);
            Assert.Equal("Test", TempObject.Name);
            Assert.Equal("Data", TempObject.Parent.Name);
            Assert.Equal(0, TempObject.Size);
            TempObject.Create();
            Assert.Equal(true, TempObject.Exists);
            Assert.Equal("Test", TempObject.Name);
            Assert.Equal("Data", TempObject.Parent.Name);
            TempObject.Delete();
            Assert.Equal(false, TempObject.Exists);
            Assert.Equal("Test", TempObject.Name);
            Assert.Equal("Data", TempObject.Parent.Name);
        }
 public DirectoryMigrationsLibrary(IDirectory getDirectoryInfo = null)
 {
     _getDirectoryInfo = getDirectoryInfo;
     if (_getDirectoryInfo != null) _getDirectoryInfo.Create();
 }
		/// <summary>
		/// 	Creates a junction point from the specified directory to the specified target directory.
		/// </summary>
		/// <remarks>
		/// 	Only works on NTFS.
		/// </remarks>
		/// <param name = "junctionPoint">The junction point path</param>
		/// <param name = "targetDir">The target directory</param>
		/// <param name = "overwrite">If true overwrites an existing reparse point or empty directory</param>
		/// <exception cref = "IOException">Thrown when the junction point could not be created or when
		/// 	an existing directory was found and <paramref name = "overwrite" /> if false</exception>
		public static void Create(IDirectory junctionPoint, string targetDir, bool overwrite)
		{
			//targetDir = Path.GetFullPath(targetDir);

			if (!Directory.Exists(targetDir))
				throw new IOException("Target path does not exist or is not a directory.");

			if (junctionPoint.Exists)
			{
				if (!overwrite)
					throw new IOException("Directory already exists and overwrite parameter is false.");
			}
			else
				junctionPoint.Create();

			using (var handle = OpenReparsePoint(junctionPoint.Path.FullPath, EFileAccess.GenericWrite))
			{
				var targetDirBytes = Encoding.Unicode.GetBytes(NonInterpretedPathPrefix + Path.GetFullPath(targetDir));

				var reparseDataBuffer = new REPARSE_DATA_BUFFER();

				reparseDataBuffer.ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;
				reparseDataBuffer.ReparseDataLength = (ushort) (targetDirBytes.Length + 12);
				reparseDataBuffer.SubstituteNameOffset = 0;
				reparseDataBuffer.SubstituteNameLength = (ushort) targetDirBytes.Length;
				reparseDataBuffer.PrintNameOffset = (ushort) (targetDirBytes.Length + 2);
				reparseDataBuffer.PrintNameLength = 0;
				reparseDataBuffer.PathBuffer = new byte[0x3ff0];
				Array.Copy(targetDirBytes, reparseDataBuffer.PathBuffer, targetDirBytes.Length);

				var inBufferSize = Marshal.SizeOf(reparseDataBuffer);
				var inBuffer = Marshal.AllocHGlobal(inBufferSize);

				try
				{
					Marshal.StructureToPtr(reparseDataBuffer, inBuffer, false);

					int bytesReturned;
					var result = DeviceIoControl(handle.DangerousGetHandle(), FSCTL_SET_REPARSE_POINT,
					                             inBuffer, targetDirBytes.Length + 20, IntPtr.Zero, 0, out bytesReturned, IntPtr.Zero);

					if (!result)
						ThrowLastWin32Error("Unable to create junction point.");
				}
				finally
				{
					Marshal.FreeHGlobal(inBuffer);
				}
			}
		}
示例#35
0
		public TemporaryDirectory(IDirectory unerlyingDirectory)
		{
			UnderlyingDirectory = unerlyingDirectory;
			if (!UnderlyingDirectory.Exists)
				UnderlyingDirectory.Create();
		}