コード例 #1
0
 /// <summary>
 /// Throws VfsException if entity is not directory or does not exist
 /// </summary>
 private static void AssertDirIsNullOrIsFile(string path, VfsEntity entity)
 {
     if (entity == null)
     {
         throw new VfsException(VfsExceptionType.VfsDirNotExists, $"Directory {path} does not exist!");
     }
     if (entity is VfsFile)
     {
         throw new VfsException(VfsExceptionType.DirCorrespondToFile, $"Directory {entity.Path} corresponds to a file!");
     }
 }
コード例 #2
0
        /// <summary>
        /// Copies file or directory
        ///<param name="depth">destination path depth</param>
        /// </summary>
        private void CopyEntity(VfsEntity entity, string destPath, int depth)
        {
            if (depth > 0)
            {
                var subdir = FindSubDir(destPath, out string newPath, depth == 1 ? 0 : 1) as VfsDirectory;
                subdir.CopyEntity(entity, newPath, depth - 1);
                return;
            }
            lock (_entities)
            {
                var destObj = _entities.FirstOrDefault(f => f.Name == entity.Name);

                if (destObj != null)
                {
                    throw new VfsException(VfsExceptionType.ObjAlreadyExists, $"Object {entity.Name} already exists!");
                }
                var copiedObj = entity.Copy();
                copiedObj.Parent = this;
                _entities.Add(copiedObj);
                DateModified = DateTime.Now;
            }
        }