Пример #1
0
        public static DTOBase Create(DirInfo directory, WebDavRoot root)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }

            RootDTO response = new RootDTO()
            {
                Mime     = "directory",
                Dirs     = directory.HasSubDirectories ? (byte)1 : (byte)0,
                Hash     = root.VolumeId + Helper.EncodePath(directory.RelPath),
                Read     = 1,
                Write    = 1,
                Locked   = 0,
                Name     = root.Alias,
                Size     = 0,
                VolumeId = root.VolumeId
            };

            DateTime lastModified;

            if (DateTime.TryParse(directory.LastModified, out lastModified))
            {
                response.UnixTimeStamp = (long)(lastModified - _unixOrigin).TotalSeconds;
            }

            return(response);
        }
Пример #2
0
 public static DTOBase Create(DirectoryInfo directory, Root root)
 {
     if (directory == null)
     {
         throw new ArgumentNullException("directory");
     }
     if (root == null)
     {
         throw new ArgumentNullException("root");
     }
     if (root.Directory.FullName == directory.FullName)
     {
         bool            hasSubdirs = false;
         DirectoryInfo[] subdirs    = directory.GetDirectories();
         foreach (var item in subdirs)
         {
             if ((item.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
             {
                 hasSubdirs = true;
                 break;
             }
         }
         RootDTO response = new RootDTO()
         {
             Mime          = "directory",
             Dirs          = hasSubdirs ? (byte)1 : (byte)0,
             Hash          = root.VolumeId + Helper.EncodePath(directory.Name),
             Read          = 1,
             Write         = root.IsReadOnly ? (byte)0 : (byte)1,
             Locked        = root.IsLocked ? (byte)1 : (byte)0,
             Name          = root.Alias,
             Size          = 0,
             UnixTimeStamp = (long)(directory.LastWriteTimeUtc - _unixOrigin).TotalSeconds,
             VolumeId      = root.VolumeId
         };
         return(response);
     }
     else
     {
         string       parentPath = directory.Parent.FullName.Substring(root.Directory.FullName.Length);
         DirectoryDTO response   = new DirectoryDTO()
         {
             Mime = "directory",
             ContainsChildDirs = directory.GetDirectories().Length > 0 ? (byte)1 : (byte)0,
             Hash          = root.VolumeId + Helper.EncodePath(directory.FullName.Substring(root.Directory.FullName.Length)),
             Read          = 1,
             Write         = root.IsReadOnly ? (byte)0 : (byte)1,
             Locked        = root.IsLocked ? (byte)1 : (byte)0,
             Size          = 0,
             Name          = directory.Name,
             UnixTimeStamp = (long)(directory.LastWriteTimeUtc - _unixOrigin).TotalSeconds,
             ParentHash    = root.VolumeId + Helper.EncodePath(parentPath.Length > 0 ? parentPath : directory.Parent.Name)
         };
         return(response);
     }
 }
Пример #3
0
 public static DTOBase Create(DirectoryInfo directory, Root root)
 {
     if (directory == null)
     {
         throw new ArgumentNullException("directory");
     }
     if (root == null)
     {
         throw new ArgumentNullException("root");
     }
     if (root.Directory.FullName == directory.FullName)
     {
         RootDTO response = new RootDTO()
         {
             Mime          = "directory",
             Dirs          = directory.GetDirectories().Length > 0 ? (byte)1 : (byte)0,
             Hash          = root.VolumeId + Helper.EncodePath(directory.Name),
             Locked        = root.IsReadOnly ? (byte)1 : (byte)0,//(directory.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly ? (byte)1 : (byte)0,
             Name          = root.Alias,
             Read          = 1,
             Size          = 0,
             UnixTimeStamp = (long)(directory.LastWriteTimeUtc - _unixOrigin).TotalSeconds,
             VolumeId      = root.VolumeId,
             Write         = root.IsReadOnly ? (byte)0 : (byte)1//(directory.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly ? (byte)0 : (byte)1
         };
         return(response);
     }
     else
     {
         string       parentPath = directory.Parent.FullName.Substring(root.Directory.FullName.Length);
         DirectoryDTO response   = new DirectoryDTO()
         {
             Mime = "directory",
             ContainsChildDirs = directory.GetDirectories().Length > 0 ? (byte)1 : (byte)0,
             Hash          = root.VolumeId + Helper.EncodePath(directory.FullName.Substring(root.Directory.FullName.Length)),
             Locked        = root.IsReadOnly ? (byte)1 : (byte)0,//(directory.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly ? (byte)1 : (byte)0,
             Read          = 1,
             Size          = 0,
             Name          = directory.Name,
             UnixTimeStamp = (long)(directory.LastWriteTimeUtc - _unixOrigin).TotalSeconds,
             Write         = root.IsReadOnly ? (byte)0 : (byte)1,//(directory.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly ? (byte)0: (byte)1,
             ParentHash    = root.VolumeId + Helper.EncodePath(parentPath.Length > 0 ? parentPath : directory.Parent.Name)
         };
         return(response);
     }
 }
Пример #4
0
 /// <summary> </summary>
 public static DTOBase Create(DirectoryInfo directory, Root root)
 {
     if (directory == null)
     {
         throw new ArgumentNullException("directory");
     }
     if (root == null)
     {
         throw new ArgumentNullException("root");
     }
     if (root.Directory.FullName == directory.FullName)
     {
         RootDTO response = new RootDTO()
         {
             mime     = "directory",
             dirs     = directory.GetDirectories().Length > 0 ? (byte)1 : (byte)0,
             hash     = root.VolumeId + file_helper.encode_path(directory.Name),
             locked   = root.IsReadOnly ? (byte)1 : (byte)0,//(directory.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly ? (byte)1 : (byte)0,
             name     = root.Alias,
             read     = 1,
             size     = 0,
             ts       = (long)(directory.LastWriteTimeUtc - _unixOrigin).TotalSeconds,
             volumeId = root.VolumeId,
             write    = root.IsReadOnly ? (byte)0 : (byte)1//(directory.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly ? (byte)0 : (byte)1
         };
         return(response);
     }
     else
     {
         string       parentPath = directory.Parent.FullName.Substring(root.Directory.FullName.Length);
         DirectoryDTO response   = new DirectoryDTO()
         {
             mime   = "directory",
             dirs   = directory.GetDirectories().Length > 0 ? (byte)1 : (byte)0,
             hash   = root.VolumeId + file_helper.encode_path(directory.FullName.Substring(root.Directory.FullName.Length)),
             locked = root.IsReadOnly ? (byte)1 : (byte)0,//(directory.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly ? (byte)1 : (byte)0,
             read   = 1,
             size   = 0,
             name   = directory.Name,
             ts     = (long)(directory.LastWriteTimeUtc - _unixOrigin).TotalSeconds,
             write  = root.IsReadOnly ? (byte)0 : (byte)1,//(directory.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly ? (byte)0: (byte)1,
             phash  = root.VolumeId + file_helper.encode_path(parentPath.Length > 0 ? parentPath : directory.Parent.Name)
         };
         return(response);
     }
 }
Пример #5
0
 public static DTOBase Create(DirectoryInfo directory, Root root)
 {
     if (directory == null)
         throw new ArgumentNullException("directory");
     if (root == null)
         throw new ArgumentNullException("root");
     if (root.Directory.FullName == directory.FullName)
     {
         RootDTO response = new RootDTO()
         {
             Mime = "directory",
             Dirs = directory.GetDirectories().Length > 0 ? (byte)1 : (byte)0,
             Hash = root.VolumeId + Helper.EncodePath(directory.Name),
             Read = 1,
             Write = root.IsReadOnly ? (byte)0 : (byte)1,
             Locked = root.IsLocked ? (byte)1 : (byte)0,
             Name = root.Alias,
             Size = 0,
             UnixTimeStamp = (long)(directory.LastWriteTimeUtc - _unixOrigin).TotalSeconds,
             VolumeId = root.VolumeId
         };
         return response;
     }
     else
     {
         string parentPath = directory.Parent.FullName.Substring(root.Directory.FullName.Length);
         DirectoryDTO response = new DirectoryDTO()
         {
             Mime = "directory",
             ContainsChildDirs = directory.GetDirectories().Length > 0 ? (byte)1 : (byte)0,
             Hash = root.VolumeId + Helper.EncodePath(directory.FullName.Substring(root.Directory.FullName.Length)),
             Read = 1,
             Write = root.IsReadOnly ? (byte)0 : (byte)1,
             Locked = root.IsLocked ? (byte)1 : (byte)0,
             Size = 0,
             Name = directory.Name,
             UnixTimeStamp = (long)(directory.LastWriteTimeUtc - _unixOrigin).TotalSeconds,
             ParentHash = root.VolumeId + Helper.EncodePath(parentPath.Length > 0 ? parentPath : directory.Parent.Name)
         };
         return response;
     }
 }
Пример #6
0
 public static DTOBase Create(DirectoryInfo directory, Root root)
 {
     if (directory == null)
         throw new ArgumentNullException("directory");
     if (root == null)
         throw new ArgumentNullException("root");
     if (root.Directory.FullName == directory.FullName)
     {
         bool hasSubdirs = false;
         DirectoryInfo[] subdirs = directory.GetDirectories();
         foreach (var item in subdirs)
         {
             if ((item.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
             {
                 hasSubdirs = true;
                 break;
             }
         }
         RootDTO response = new RootDTO()
         {
             Mime = "directory",
             Dirs = hasSubdirs ? (byte)1 : (byte)0,
             Hash = root.VolumeId + Helper.EncodePath(directory.Name),
             Read = 1,
             Write = root.IsReadOnly ? (byte)0 : (byte)1,
             Locked = root.IsLocked ? (byte)1 : (byte)0,                    
             Name = root.Alias,                    
             Size = 0,
             UnixTimeStamp = (long)(directory.LastWriteTimeUtc - _unixOrigin).TotalSeconds,
             VolumeId = root.VolumeId                    
         };
         return response;
     }
     else
     {
         string parentPath = directory.Parent.FullName.Substring(root.Directory.FullName.Length);
         DirectoryDTO response = new DirectoryDTO()
         {
             Mime = "directory",
             ContainsChildDirs = directory.GetDirectories().Length > 0 ? (byte)1 : (byte)0,
             Hash = root.VolumeId + Helper.EncodePath(directory.FullName.Substring(root.Directory.FullName.Length)),
             Read = 1,
             Write = root.IsReadOnly ? (byte)0 : (byte)1,
             Locked = (root.LockedFolders.Any(f => f == directory.Name) || root.IsLocked) ? (byte)1 : (byte)0,                    
             Size = 0,
             Name = directory.Name,
             UnixTimeStamp = (long)(directory.LastWriteTimeUtc - _unixOrigin).TotalSeconds,                    
             ParentHash = root.VolumeId + Helper.EncodePath(parentPath.Length > 0 ? parentPath : directory.Parent.Name)
         };
         return response;
     }
 }