Ejemplo n.º 1
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);
     }
 }
Ejemplo n.º 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)
     {
         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);
     }
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
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;
     }
 }
Ejemplo n.º 5
0
        public static DTOBase Create(DirInfo directory, DirInfo parent, WebDavRoot root)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }

            if (parent == null && directory.IsDirectory)
            {
                //throw new Exception("Что то пошло не так!");
            }

            if (directory.IsDirectory)
            {
                var response = new DirectoryDTO()
                {
                    Mime = "directory",
                    ContainsChildDirs = directory.HasSubDirectories ? (byte)1 : (byte)0,
                    Hash   = root.VolumeId + Helper.EncodePath(directory.RelPath),
                    Read   = 1,
                    Write  = 1,
                    Locked = 0,
                    Size   = 0,
                    Name   = directory.DisplayName
                };

                if (parent != null)
                {
                    response.ParentHash = root.VolumeId + Helper.EncodePath(parent.RelPath);
                }

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

                return(response);
            }
            else
            {
                var ext = Path.GetExtension(directory.DisplayName);
                if (ext == ".enc")
                {
                    var name = directory.DisplayName.Substring(0, directory.DisplayName.LastIndexOf(".", System.StringComparison.Ordinal));
                    var ext2 = Path.GetExtension(name);
                    if (ext2 == ".sig")
                    {
                        ext = ".sig.enc";
                    }
                }
                FileDTO response = new FileDTO();
                response.Read              = 1;
                response.Write             = (byte)1;
                response.Locked            = (byte)0;
                response.Name              = directory.DisplayName;
                response.VisualizationType = FileDTO.GetVisualization(ext);
                response.Size              = directory.ContentLenght;
                response.Hash              = root.VolumeId + Helper.EncodePath(directory.RelPath);
                response.ParentHash        = root.VolumeId + Helper.EncodePath(parent.RelPath);
                response.Mime              = string.IsNullOrEmpty(ext) ? "unknown" : Helper.GetMimeType(ext.ToLower().Substring(1));
                DateTime lastModified;
                if (DateTime.TryParse(directory.LastModified, out lastModified))
                {
                    response.UnixTimeStamp = (long)(lastModified - _unixOrigin).TotalSeconds;
                }

                return(response);
            }
        }
Ejemplo n.º 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;
     }
 }