Exemplo n.º 1
0
        public GalleryRepository(string basePhysicalPath)
        {
            Comments   = new List <Comment>();
            Folders    = new List <PGFolder>();
            AllFolders = new List <PGFolder>();
            Images     = new List <PGImage>();

            _basePhysicalPath = basePhysicalPath;

            //initialize
            PGFolder repFolder = new PGFolder();

            repFolder.PhysicalPath = _basePhysicalPath;

            string        cache           = "cache_rootfolders";
            List <string> filenames_cache = new List <string>();

            FillSubFoldersRecursive(ref repFolder, new PGFolderNameASCComparer(), out filenames_cache);
            filenames_cache.Add(Configuration.ConfigurationFilePhysicalPath);

            //cache
            lock (cacheLock)
            {
                HttpContext.Current.Cache.Add(cache, repFolder,
                                              new System.Web.Caching.CacheDependency(filenames_cache.ToArray <string>()), System.Web.Caching.Cache.NoAbsoluteExpiration,
                                              new TimeSpan(0, 20, 0), System.Web.Caching.CacheItemPriority.Normal, new System.Web.Caching.CacheItemRemovedCallback(RemovedCallback));
            }

            Folders     = repFolder.SubFolders;
            _RootFolder = repFolder;
        }
Exemplo n.º 2
0
    public bool IsPrivateFolder()
    {
        if (Security.PrivateFolder)
        {
            return(true);
        }

        PGFolder parent = ParentFolder;

        if (parent == null)
        {
            return(Security.PrivateFolder);
        }
        else
        {
            if (!parent.Security.PrivateFolder)
            {
                return(parent.IsPrivateFolder());
            }
            else
            {
                return(true);
            }
        }
    }
Exemplo n.º 3
0
        private void FillSubFoldersRecursive(ref PGFolder folder, PGFolderComparer defaultSortingComparer, out List <string> filenames_cache)
        {
            filenames_cache = new List <string>();

            DirectoryInfo directory = new DirectoryInfo(folder.PhysicalPath);

            if (!directory.Exists)
            {
                throw new DirectoryNotFoundException(string.Format("Directory {0} not found", directory));
            }
            else
            {
                //1. READ INFO FILE
                folder.ReadFolder();

                Images.AddRange(folder.Images);     //cache images for easy access
                Comments.AddRange(folder.Comments); //cache comments for easy access.

                //2. LOAD SUB FOLDERS from disk (RECURSIVE)
                folder.SubFolders = new List <PGFolder>();

                defaultSortingComparer = PGFolderComparer.GetComparerBySortAction(folder.SortAction, defaultSortingComparer);

                //3. subfolder recursive
                foreach (DirectoryInfo subDirectory in directory.GetDirectories())
                {
                    if (!IsDirectoryIgnored(subDirectory.FullName))
                    {
                        PGFolder subfolder = new PGFolder()
                        {
                            Name = subDirectory.Name, PhysicalPath = subDirectory.FullName
                        };
                        subfolder.ParentFolder = folder;

                        List <string> filename_cache_subfolder = new List <string>();
                        FillSubFoldersRecursive(ref subfolder, defaultSortingComparer, out filename_cache_subfolder);
                        filenames_cache.AddRange(filename_cache_subfolder);
                        folder.SubFolders.Add(subfolder);
                        folder.NumberNestedImages += subfolder.NumberNestedImages; //todo refactor, inside pgfolder.
                    }
                }

                //4. Sorting?
                folder.SortSubFolders(folder.SortAction, ref defaultSortingComparer);

                AllFolders.Add(folder); //index for faster access

                filenames_cache.Add(folder.FolderInfoFileLocation());
            }

            //5. WRITE if necessary
            if (!folder.ExistFolderInfoFile())
            {
                folder.WriteFolderFileInfo();
            }
        }
Exemplo n.º 4
0
        public void UpdateImageInfo(PGImage image)
        {
            //save info file.
            PGFolder folder = image.ParentFolder;

            if (folder == null)
            {
                throw new Exception("parent folder doesn't exist");
            }
            folder.WriteFolderFileInfo();
        }
Exemplo n.º 5
0
        public PGImage GetImageFromVPath(string ImageVPath)
        {
            PGFolder folder = GetFolderFromVPath(Util.GetVirtualFolderPathFromImagePath(ImageVPath));

            foreach (PGImage image in folder.Images)
            {
                if (Util.IsSameVpath(image.VPath, ImageVPath))
                {
                    return(image);
                }
            }
            return(null);
        }
Exemplo n.º 6
0
    private List <string> GetRecursiveAccessList()
    {
        List <string> users = Security.UserAccessList;

        PGFolder parent = ParentFolder;

        if (parent == null)
        {
            return(users);
        }
        else
        {
            users.AddRange(parent.GetRecursiveAccessList());
        }
        return(users);
    }
Exemplo n.º 7
0
    public PGFolder SearchSubFolderByPhysicalPath(string physicalPath)
    {
        if (this.PhysicalPath == physicalPath)
        {
            return(this);
        }

        foreach (PGFolder folder in this.SubFolders)
        {
            PGFolder f = folder.SearchSubFolderByPhysicalPath(physicalPath);
            if (f != null)
            {
                return(f);
            }
        }
        return(null);
    }
Exemplo n.º 8
0
        /// <summary>
        /// Gets repository folder based on virtual Path
        /// </summary>
        /// <param name="vfolderpath"></param>
        /// <returns></returns>
        public PGFolder GetFolderFromVPath(string vfolderpath)
        {
            if (vfolderpath == "default")
            {
                PGFolder found = Folders.FirstOrDefault();
                return(found);
            }

            foreach (PGFolder folder in Folders)
            {
                PGFolder found = folder.SearchSubFolderRecursiveByVPath(vfolderpath);
                if (found != null)
                {
                    return(found);
                }
            }
            return(null);
        }
Exemplo n.º 9
0
    }                                                    //takes into consideration parent folders

    #region Search items inside this folder
    public PGFolder SearchSubFolderRecursiveByVPath(string virtualPath)
    {
        if (Util.IsSameVpath(this.VPath, virtualPath))
        {
            return(this);
        }

        foreach (PGFolder folder in this.SubFolders)
        {
            //Console.Write("Looking for folder " + virtualPath + " in folder " + folder.Name);
            PGFolder f = folder.SearchSubFolderRecursiveByVPath(virtualPath);
            if (f != null)
            {
                return(f);
            }
        }
        return(null);
    }
Exemplo n.º 10
0
        public PGImage GetNextImage(PGImage image)
        {
            if (image.ParentFolder != null)
            {
                PGFolder parentFolder = image.ParentFolder;
                //List<PGImage> images = GetImagesFromDiskFolderByVirtualPath(parentFolder);

                PGImage nextImg = null;
                bool    getNext = false;
                foreach (PGImage img in parentFolder.Images)
                {
                    if (getNext)
                    {
                        return(img);
                    }

                    if (img.PhysicalPath == image.PhysicalPath)
                    {
                        getNext = true;
                    }
                }
            }
            return(null);
        }
Exemplo n.º 11
0
        public PGImage GetPreviousImage(PGImage image)
        {
            //where is this image?
            if (image.ParentFolder != null)
            {
                PGFolder parentFolder = image.ParentFolder;
//                List<PGImage> images = GetImagesFromDiskFolderByVirtualPath(parentFolder);

                PGImage prevImg = null;
                foreach (PGImage img in parentFolder.Images)
                {
                    if (prevImg != null)
                    {
                        if (img.PhysicalPath == image.PhysicalPath)
                        {
                            return(prevImg);
                        }
                    }
                    prevImg = img;
                }
            }

            return(null);
        }
Exemplo n.º 12
0
        //[OutputCache(Duration = 0, VaryByParam = "folder")] //carefull, don't use cache here, different responses whatever is ajax request or not!
        public ActionResult List(string folder)
        {
            if (string.IsNullOrEmpty(folder))
            {
                Response.StatusCode = 400;
                return(Json(new { error = "No folder parameter found" }, JsonRequestBehavior.AllowGet));
            }

            GalleryRepository rep         = this.GetGalleryRepository();
            string            vPathFolder = Util.StripFirstSlashFromVirtualPath(HttpUtility.UrlDecode(folder));

            PGFolder pgfolder = rep.GetFolderFromVPath(vPathFolder);

            if (pgfolder == null)
            {
                Response.StatusCode = 400;
                return(Json(new { error = "Error, folder not found on " + vPathFolder }, JsonRequestBehavior.AllowGet));
            }

            //check security
            if (!pgfolder.IsUserGranted(User.Identity.Name))
            {
                Response.StatusCode = 403;
                return(Json(new { error = "This is a private folder. You need access to read its content." }, JsonRequestBehavior.AllowGet));
            }

            string content = pgfolder.GetHtmlContentIfAny();

            System.Collections.ArrayList list = new System.Collections.ArrayList();
            foreach (var image in pgfolder.Images)
            {
                list.Add(new {
                    VPath        = image.VPath,
                    UrlThumbnail = image.ImageThumbnailFullUrl,
                    Url          = image.MainPageVirtualUrl,
                    UrlFullImage = image.ImageFullUrl,
                    Name         = image.FileName,
                });
            }

            if (string.IsNullOrWhiteSpace(content) && list.Count == 0)
            {
                if (pgfolder.NumberNestedImages == 0)
                {
                    content += "<p>This folder has no images</p>";
                }
                else
                {
                    content += string.Format("<p>This folder has no images, but there are {0} in nested subfolder</p>", pgfolder.NumberNestedImages);
                }
            }


            if (Request.IsAjaxRequest())
            {
                return(Json(new { thumbnails = list, htmlcontent = content }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                ViewBag.Folders        = rep.Folders;
                ViewBag.SelectedFolder = pgfolder.VPath;
                return(View("../Main/Index"));
            }
        }
Exemplo n.º 13
0
 public override int Compare(PGFolder x, PGFolder y)
 {
     return(y.TimeStamp.CompareTo(x.TimeStamp));
 }
Exemplo n.º 14
0
 public override int Compare(PGFolder x, PGFolder y)
 {
     return(y.Name.CompareTo(x.Name));
 }
Exemplo n.º 15
0
 public override int Compare(PGFolder x, PGFolder y)
 {
     return(x.Order.CompareTo(y.Order));
 }