Exemple #1
0
 public static DTOBase Create(FileInfo info, Root root)
 {
     if (info == null)
         throw new ArgumentNullException("info");
     if (root == null)
         throw new ArgumentNullException("root");
     string ext = info.Extension.ToLower();
     string parentPath = info.Directory.FullName.Substring(root.Directory.FullName.Length);
     FileDTO response;
     string hash = root.VolumeId + Helper.EncodePath(info.FullName.Substring(root.Directory.FullName.Length));
     if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || info.Extension == ".gif")
     {
         response = new ImageDTO();
         //((ImageDTO)response).Thumbnail = 
     }
     else
     {
         response = new FileDTO();
     }
     response.Read = 1;
     response.Write = root.IsReadOnly ? (byte)0 : (byte)1;
     response.Locked = root.IsReadOnly ? (byte)1 : (byte)0;
     response.Name = info.Name;
     response.Size = info.Length;
     response.UnixTimeStamp = (long)(info.LastWriteTimeUtc - _unixOrigin).TotalSeconds;
     response.Mime = Helper.GetMimeType(info);
     response.Hash = hash;
     response.ParentHash = root.VolumeId + Helper.EncodePath(parentPath.Length > 0 ? parentPath : info.Directory.Name);
     return response;
 }
Exemple #2
0
 public static DTOBase Create(FileInfo info, Root root)
 {
     if (info == null)
         throw new ArgumentNullException("info");
     if (root == null)
         throw new ArgumentNullException("root");
     string parentPath = info.Directory.FullName.Substring(root.Directory.FullName.Length);
     string relativePath = info.FullName.Substring(root.Directory.FullName.Length);
     FileDTO response;
     if (root.CanCreateThumbnail(info))
     {
         ImageDTO imageResponse = new ImageDTO();
         imageResponse.Thumbnail = root.GetExistingThumbHash(info) ?? (object)1;
         var dim = root.GetImageDimension(info);
         imageResponse.Dimension = string.Format("{0}x{1}", dim.Width, dim.Height);
         response = imageResponse;
     }
     else
     {
         response = new FileDTO();
     }
     response.Read = 1;
     response.Write = root.IsReadOnly ? (byte)0 : (byte)1;
     response.Locked = (root.LockedFolders.Any(f => f == info.Directory.Name) || root.IsLocked) ? (byte)1 : (byte)0;
     response.Name = info.Name;
     response.Size = info.Length;
     response.UnixTimeStamp = (long)(info.LastWriteTimeUtc - _unixOrigin).TotalSeconds;
     response.Mime = Helper.GetMimeType(info);
     response.Hash = root.VolumeId + Helper.EncodePath(relativePath);
     response.ParentHash = root.VolumeId + Helper.EncodePath(parentPath.Length > 0 ? parentPath : info.Directory.Name);
     return response;
 }
Exemple #3
0
        public static DTOBase Create(DirInfo file)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            if (file.IsDirectory)
            {
                throw new Exception("Работа с папками не допускается");
            }

            var ext = Path.GetExtension(file.DisplayName);

            if (ext == ".enc")
            {
                var name = file.DisplayName.Substring(0, file.DisplayName.LastIndexOf(".", System.StringComparison.Ordinal));
                var ext2 = Path.GetExtension(name);
                if (ext2 == ".sig")
                {
                    ext = ".sig.enc";
                }
            }
            var response = new FileDTO();

            response.Read              = 1;
            response.Write             = (byte)1;
            response.Locked            = (byte)0;
            response.Name              = file.DisplayName;
            response.VisualizationType = FileDTO.GetVisualization(ext);
            response.Size              = file.ContentLenght;
            response.Hash              = Helper.EncodePath(file.RelPath);
            response.ParentHash        = Helper.EncodePath(file.RelPath);
            response.Mime              = string.IsNullOrEmpty(ext) ? "unknown" : Helper.GetMimeType(ext.ToLower().Substring(1));
            DateTime lastModified;

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

            return(response);
        }
Exemple #4
0
        public static DTOBase Create(FileInfo info, Root root)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }
            string  parentPath   = info.Directory.FullName.Substring(root.Directory.FullName.Length);
            string  relativePath = info.FullName.Substring(root.Directory.FullName.Length);
            FileDTO response;

            if (root.CanCreateThumbnail(info))
            {
                ImageDTO imageResponse = new ImageDTO();
                imageResponse.Thumbnail = root.GetExistingThumbHash(info) ?? (object)1;
                var dim = root.GetImageDimension(info);
                imageResponse.Dimension = string.Format("{0}x{1}", dim.Width, dim.Height);
                response = imageResponse;
            }
            else
            {
                response = new FileDTO();
            }
            response.Read              = 1;
            response.Write             = root.IsReadOnly ? (byte)0 : (byte)1;
            response.Locked            = root.IsLocked ? (byte)1 : (byte)0;
            response.Name              = info.Name;
            response.VisualizationType = FileDTO.GetVisualization(info.Extension);
            response.Size              = info.Length;
            response.UnixTimeStamp     = (long)(info.LastWriteTimeUtc - _unixOrigin).TotalSeconds;
            response.Mime              = Helper.GetMimeType(info);
            response.Hash              = root.VolumeId + Helper.EncodePath(relativePath);
            response.ParentHash        = root.VolumeId + Helper.EncodePath(parentPath.Length > 0 ? parentPath : info.Directory.Name);
            return(response);
        }
Exemple #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);
            }
        }
Exemple #6
0
        /// <summary> </summary>
        public static DTOBase Create(FileInfo info, Root root, Hashtable posting_json_obj)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }
            string  ext        = info.Extension.ToLower();
            string  parentPath = info.Directory.FullName.Substring(root.Directory.FullName.Length);
            FileDTO response;
            String  relative_path = info.FullName.Substring(root.Directory.FullName.Length);
            string  hash          = root.VolumeId + file_helper.encode_path(relative_path);

            if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || info.Extension == ".gif")
            {
                response = new ImageDTO();
            }
            else
            {
                response = new FileDTO();
            }
            response.read   = 1;
            response.write  = root.IsReadOnly ? (byte)0 : (byte)1;
            response.locked = root.IsReadOnly ? (byte)1 : (byte)0;
            response.name   = info.Name;
            response.size   = info.Length;
            response.ts     = (long)(info.LastWriteTimeUtc - _unixOrigin).TotalSeconds;
            response.mime   = file_helper.get_mime_type(info);
            response.hash   = hash;
            response.phash  = root.VolumeId + file_helper.encode_path(parentPath.Length > 0 ? parentPath : info.Directory.Name);

            Hashtable post    = new Hashtable();
            int       pid     = 0;
            posting   posting = postingService.get_posting_by_hash(hash, false);

            pid = posting.baseid;
            if (pid > 0)
            {
                post = postingService.make_post_json_table(pid);
            }
            else
            {
                posting = postingService.get_posting_by_file(relative_path, false);
                pid     = posting.baseid;
                if (pid > 0)
                {
                    post = postingService.make_post_json_table(pid);
                    if (String.IsNullOrWhiteSpace(posting.filehash))
                    {
                        posting.filehash = hash;
                        ActiveRecordMediator <posting> .Save(posting);
                    }
                }
                else
                {
                    if (HttpContext.Current.Request.Params.AllKeys.Contains("iid"))
                    {
                        pid  = Int16.Parse(HttpContext.Current.Request.Params["iid"]);
                        post = postingService.make_post_json_table(pid);
                    }
                    else
                    {
                        if (HttpContext.Current.Request.Params.AllKeys.Contains("ptype"))
                        {
                            //Boolean dev = false; // for now

                            String    type = HttpContext.Current.Request.Params["ptype"];
                            Hashtable all  = new Hashtable();
                            Dictionary <string, string> queries   = httpService.get_request_parmas_obj();
                            List <AbstractCriterion>    filtering = new List <AbstractCriterion>();
                            filtering.Add(Expression.Eq("post_type", ActiveRecordBase <posting_type> .FindFirst(
                                                            new List <AbstractCriterion>()
                            {
                                Expression.Eq("alias", type)
                            }.ToArray())
                                                        ));
                            posting[] posts = ActiveRecordBase <posting> .FindAll(new Order[] { Order.Desc("revision"), Order.Desc("version") }, filtering.ToArray());

                            //var i = 0;
                            foreach (posting posted in posts)
                            {
                                if (posted.static_file.IndexOf(info.Name) > -1)
                                {
                                    pid = posted.baseid;
                                }
                                post = postingService.make_post_json_table(pid);
                            }
                        }
                    }
                }
            }
            response.post = post;

            if (pid > 0 && (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || info.Extension == ".gif"))
            {
                //response = new ImageDTO();

                String   path       = image_handler.image(pid, 50, 50, 0, "constrain", false, "thumb_", "", false);
                String[] path_parts = path.Split(new string[] { "uploads/" }, StringSplitOptions.None);
                //note that the root will always be uploads?  well it is atm
                ((ImageDTO)response).tmb = path_parts[path_parts.Length - 1].Trim('/');
            }



            return(response);
        }