Exemplo n.º 1
0
 /// <summary>
 /// Loads the cache for a view of a folder when we need it.
 /// </summary>
 /// <param name="dir"></param>
 /// <returns></returns>
 private List <FileShortInfo> getCachedFiles(DirectoryCacheInfo dir)
 {
     if (dir.fileCount == 0)
     {
         return(new List <FileShortInfo>());
     }
     else
     {
         //load cache
         try
         {
             FileCacheInfo tempFiles     = new FileCacheInfo();
             string        cacheFilePath = cacheDirectory + "\\" + dir.Guid.ToString();
             using (StreamReader stream = new StreamReader(cacheFilePath, Encoding.UTF8))
             {
                 tempFiles = (FileCacheInfo)xmlSer.Deserialize(stream);
             }
             return(tempFiles.files);
         }
         catch (Exception e)
         {
             throw new Exception("Error reading a set of cache info", e);
         }
     }
 }
Exemplo n.º 2
0
        private void PrepareStatic()
        {
            foreach (var filename in Resources.Enumerate(STATIC_PATH))
            {
                Encoding encoding    = null;
                string   contentType = null;

                if (filename.EndsWith(".html"))
                {
                    encoding    = Encoding.UTF8;
                    contentType = "text/html";
                }
                else if (filename.EndsWith(".js"))
                {
                    encoding    = Encoding.UTF8;
                    contentType = "application/javascript";
                }
                else if (filename.EndsWith(".css"))
                {
                    encoding    = Encoding.UTF8;
                    contentType = "text/css";
                }
                else
                {
                    continue;
                }

                var path          = '/' + filename.Substring(STATIC_PATH.Length);
                var data          = Resources.ReadFile(filename);
                var fileCacheInfo = new FileCacheInfo(data, encoding, contentType);
                _fileCache[path] = fileCacheInfo;
                if (filename.EndsWith(DEFAULT_FILE))
                {
                    _fileCache[path.Substring(0, path.Length - DEFAULT_FILE.Length)] = fileCacheInfo;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads the cache for a view of a folder when we need it. 
        /// </summary>
        /// <param name="dir"></param>
        /// <returns></returns>
        private List<FileShortInfo> getCachedFiles(DirectoryCacheInfo dir)
        {
            if (dir.fileCount == 0) { return new List<FileShortInfo>(); }
            else
            {

                //load cache
                try
                {

                    FileCacheInfo tempFiles = new FileCacheInfo();
                    string cacheFilePath = cacheDirectory + "\\" + dir.Guid.ToString();
                    using (StreamReader stream = new StreamReader(cacheFilePath, Encoding.UTF8))
                    {
                        tempFiles = (FileCacheInfo)xmlSer.Deserialize(stream);
                    }
                    return tempFiles.files;
                }
                catch (Exception e)
                {
                    throw new Exception("Error reading a set of cache info", e);
                }
            }
        }
    public static string GetFileList(string filePath, int folderId, int UserID, int IsSort, int UserModuleID, int CurrentPage, int PageSize)
    {
        List <string> lstPermissionKeys = FileMangerDataProvider.GetPermissionKeys(folderId, UserID, UserModuleID, "superuser");
        StringBuilder sb = new StringBuilder();

        System.IO.DirectoryInfo di         = new System.IO.DirectoryInfo(filePath);
        List <Folder>           lstFolders = new List <Folder>();

        if (!CacheHelper.Get("FileManagerFolders", out lstFolders))
        {
            lstFolders = FileManagerController.GetFolders();
            CacheHelper.Add(lstFolders, "FileManagerFolders");
        }


        List <ATTFile> lstFiles = new List <ATTFile>();

        List <FileCacheInfo> lstCache = new List <FileCacheInfo>();


        if (!CacheHelper.Get("FileManagerFileList", out lstCache))    //if the cache list does not exist,then create on
        {
            try
            {
                lstFiles = FileManagerController.GetFiles(folderId);
                List <FileCacheInfo> lstFCI   = new List <FileCacheInfo>();
                FileCacheInfo        cacheObj = new FileCacheInfo();
                cacheObj.FolderID = folderId;
                cacheObj.LSTFiles = lstFiles;
                lstFCI.Add(cacheObj);
                CacheHelper.Add(lstFCI, "FileManagerFileList");
            }
            catch (Exception ex)
            {
                fb.ProcessException(ex);
            }
        }
        else     //if the cache list exists
        {
            int cacheIndex = lstCache.FindIndex(
                delegate(FileCacheInfo obj)
            {
                return(obj.FolderID == folderId);
            }
                );
            if (cacheIndex > -1)
            {
                lstFiles = lstCache[cacheIndex].LSTFiles;
            }
            else
            {
                try
                {
                    lstFiles = FileManagerController.GetFiles(folderId);
                    List <FileCacheInfo> lstFCI   = lstCache;
                    FileCacheInfo        cacheObj = new FileCacheInfo();
                    cacheObj.FolderID = folderId;
                    cacheObj.LSTFiles = lstFiles;
                    lstFCI.Add(cacheObj);
                    CacheHelper.Add(lstFCI, "FileManagerFileList");
                }
                catch (Exception ex)
                {
                    fb.ProcessException(ex);
                }
            }
        }


        if (IsSort == 1)
        {
            SortList(ref lstFiles);
        }
        if (lstFiles.Count > 0)
        {
            lstFiles = lstFiles.GetRange(GetStartRange(CurrentPage, PageSize), GetEndRange(CurrentPage, PageSize, lstFiles.Count));
        }

        ///Get the dictionary of images used in buttons
        Dictionary <string, string> dictImages = GetImages();

        if (lstFiles.Count > 0)
        {
            sb.Append("<div id='divFileHeader'><span class='selectAll'><input type='checkbox' id='chkSelectAll'/></span><span class='fileName'>FileName<img src=" + dictImages["Sort"].ToString() + "></span><span class='fileInfo'>FileInfo</span></div>");
        }
        sb.Append("<ul class=\"jqueryFileTree\" id=\"fileList\">\n");
        if (lstFiles.Count == 0)
        {
            sb.Append("<div class='cssClassNoFilesDiv'>No Files</div>");
        }
        string downloadPath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority), GetRelativePath("Modules/FileManager/DownloadHandler.ashx?")));
        string test         = HttpContext.Current.Request.PhysicalApplicationPath.ToString();
        string urlPath      = GetUrlPath(filePath);
        string absolutePath = FileManagerHelper.ReplaceBackSlash(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath.ToString(), filePath));



        ///For Users with View and Write Permissions
        bool IsZip = false;
        bool IsImg = false;

        if (((lstPermissionKeys.Contains("BROWSE") && lstPermissionKeys.Contains("VIEW")) && lstPermissionKeys.Contains("EDIT")) || lstPermissionKeys.Contains("EDIT"))
        {
            foreach (ATTFile fi in lstFiles)
            {
                string ext = "";
                if (fi.Extension.Length > 1)
                {
                    ext = fi.Extension.Substring(1).ToLower();
                }
                if (ext == "zip")
                {
                    IsZip = true;
                }
                if (ext == "png" || ext == "gif" || ext == "jpg" || ext == "jpeg")
                {
                    IsImg = true;
                }
                string checkId = "chk_" + fi.FileId;
                if (fi.StorageLocation != (int)StorageLocation.SECURED_DATABASE_SYSTEM)
                {
                    switch (fi.StorageLocation)
                    {
                    case (int)StorageLocation.SECURED_FILE_SYSTEM:
                        if (File.Exists(Path.Combine(absolutePath, fi.FileName + ".resources")))
                        {
                            try
                            {
                                FileManagerHelper.ConstructHTMLString(IsZip, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "edit", dictImages);
                            }
                            catch (Exception ex)
                            {
                                fb.ProcessException(ex);
                            }
                        }
                        break;

                    case (int)StorageLocation.STANDARD:
                        if (File.Exists(Path.Combine(absolutePath, fi.FileName)))
                        {
                            try
                            {
                                FileManagerHelper.ConstructHTMLString(IsZip, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "edit", dictImages);
                            }
                            catch (Exception ex)
                            {
                                fb.ProcessException(ex);
                            }
                        }
                        break;
                    }
                }
                else if (fi.StorageLocation == (int)StorageLocation.SECURED_DATABASE_SYSTEM)
                {
                    try
                    {
                        FileManagerHelper.ConstructHTMLString(IsZip, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "edit", dictImages);
                    }
                    catch (Exception ex)
                    {
                        fb.ProcessException(ex);
                    }
                }
            }
        }
        ///For users with only browse permission
        else if (((lstPermissionKeys.Contains("BROWSE") && !lstPermissionKeys.Contains("VIEW")) && !lstPermissionKeys.Contains("EDIT")))
        {
            foreach (ATTFile fi in lstFiles)
            {
                string ext = "";
                if (fi.Extension.Length > 1)
                {
                    ext = fi.Extension.Substring(1).ToLower();
                }
                if (ext == "zip")
                {
                    IsZip = true;
                }
                if (ext == "png" || ext == "gif" || ext == "jpg" || ext == "jpeg")
                {
                    IsImg = true;
                }
                string checkId = "chk_" + fi.FileId;

                if (fi.StorageLocation != (int)StorageLocation.SECURED_DATABASE_SYSTEM)
                {
                    switch (fi.StorageLocation)
                    {
                    case (int)StorageLocation.SECURED_FILE_SYSTEM:
                        if (File.Exists(Path.Combine(absolutePath, fi.FileName + ".resources")))
                        {
                            try
                            {
                                FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "browse", dictImages);
                            }
                            catch (Exception ex)
                            {
                                fb.ProcessException(ex);
                            }
                        }
                        break;

                    case (int)StorageLocation.STANDARD:
                        if (File.Exists(Path.Combine(absolutePath, fi.FileName)))
                        {
                            try
                            {
                                FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "browse", dictImages);
                            }
                            catch (Exception ex)
                            {
                                fb.ProcessException(ex);
                            }
                        }
                        break;
                    }
                }
                else
                {
                    try
                    {
                        FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "browse", dictImages);
                    }
                    catch (Exception ex)
                    {
                        fb.ProcessException(ex);
                    }
                }
            }
        }
        else if (((lstPermissionKeys.Contains("VIEW")) && !lstPermissionKeys.Contains("EDIT")))
        {
            foreach (ATTFile fi in lstFiles)
            {
                string ext = "";
                if (fi.Extension.Length > 1)
                {
                    ext = fi.Extension.Substring(1).ToLower();
                }
                if (ext == "zip")
                {
                    IsZip = true;
                }
                if (ext == "png" || ext == "gif" || ext == "jpg" || ext == "jpeg")
                {
                    IsImg = true;
                }
                string checkId = "chk_" + fi.FileId;
                if (fi.StorageLocation != (int)StorageLocation.SECURED_DATABASE_SYSTEM)
                {
                    switch (fi.StorageLocation)
                    {
                    case (int)StorageLocation.SECURED_FILE_SYSTEM:
                        if (File.Exists(Path.Combine(absolutePath, fi.FileName + ".resources")))
                        {
                            try
                            {
                                FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "view", dictImages);
                            }
                            catch (Exception ex)
                            {
                                fb.ProcessException(ex);
                            }
                        }
                        break;

                    case (int)StorageLocation.STANDARD:
                        if (File.Exists(Path.Combine(absolutePath, fi.FileName)))
                        {
                            try
                            {
                                FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "view", dictImages);
                            }
                            catch (Exception ex)
                            {
                                fb.ProcessException(ex);
                            }
                        }
                        break;
                    }
                }
                else
                {
                    FileManagerHelper.ConstructHTMLString(false, IsImg, fi.StorageLocation, ext, Path.Combine(urlPath, fi.FileName), Path.Combine(absolutePath, fi.FileName), downloadPath, checkId, folderId, fi, ref sb, "view", dictImages);
                }
            }
        }
        sb.Append("</ul>");
        sb.Append("<div id='divBottomControl'>");
        sb.Append("</div>");
        return(sb.ToString());
    }