예제 #1
0
        internal NDirectory(NDirectory parentDirectory, string folderName)
        {
            Contract.Requires<ArgumentNullException>(parentDirectory != null);
            Contract.Requires<ArgumentNullException>(folderName != null);

            FullPath = Path.Combine(parentDirectory.FullPath, folderName);

            CreateDirectory(FullPath);
        }
예제 #2
0
파일: NFile.cs 프로젝트: SvyatSlav/NoFake
        private void CheckBeforeCreate(NDirectory directory)
        {
            Contract.Requires(directory != null);
            FullPath = Path.Combine(directory.FullPath, FileName);

            if (File.Exists(FullPath))
            {
                throw new Exception("file already exist");
            }
        }
예제 #3
0
        /// <summary>
        /// Adds the specified parent directory.
        /// </summary>
        /// <param name="parentDirectory">The parent directory.</param>
        /// <param name="folderName">The folder name, only one-level path</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">@FolderName contains invalid directory separator char, example '\'</exception>
        public static NDirectory Add(NDirectory parentDirectory, string folderName)
        {
            Contract.Requires<ArgumentNullException>(parentDirectory != null);
            Contract.Requires<ArgumentNullException>(folderName != null);

            Helper.CheckForSeparatorChar(folderName);

            var dir = new NDirectory(parentDirectory, folderName);
            parentDirectory.AddChild(dir);
            return dir;
        }
예제 #4
0
        /// <summary>
        /// Adds file to the specified parent directory.
        /// </summary>
        /// <param name="parentDirectory">The parent directory.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="content">The binary content, ex: text, image, etc</param>
        /// <returns></returns>
        public static NFile Add(NDirectory parentDirectory, string fileName, byte[] content)
        {
            Contract.Requires<ArgumentNullException>(parentDirectory != null);
            Contract.Requires<ArgumentNullException>(fileName != null);
            Contract.Ensures(Contract.Result<NFile>() != null);

            Helper.CheckForSeparatorChar(fileName);

            var file = new ContentFile(parentDirectory, fileName, content);
            CreateFile(parentDirectory, file);

            return file;
        }
예제 #5
0
파일: NFile.cs 프로젝트: SvyatSlav/NoFake
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object" /> class.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="fileName">Name of the file.</param>
        protected internal NFile(NDirectory directory, string fileName)
        {
            Contract.Requires<ArgumentException>(directory != null, "NDirectory is null");
            Contract.Requires<ArgumentException>(!String.IsNullOrEmpty(fileName), "FileName is empty");
            Contract.Requires<ArgumentException>(!Path.IsPathRooted(fileName), "FileName can't be a rooted path");

            FileName = fileName;

            try
            {
                CheckBeforeCreate(directory);
            }
            catch (Exception ex)
            {
                ThrowConstructorException(ex);
            }
        }
예제 #6
0
 private static void CreateFile(NDirectory parentDirectory, NFile file)
 {
     file.Create();
     parentDirectory.AddChild(file);
 }
예제 #7
0
 internal void AddChild(NDirectory file)
 {
     Contract.Requires(file != null);
     _folderChildren.Add(file);
 }