Пример #1
0
    public override void Process()
    {
        Func <string, bool> predicate = null;

        try
        {
            this.Start = string.IsNullOrEmpty(base.Request["start"]) ? 0 : Convert.ToInt32(base.Request["start"]);
            this.Size  = string.IsNullOrEmpty(base.Request["size"]) ? Config.GetInt("imageManagerListSize") : Convert.ToInt32(base.Request["size"]);
        }
        catch (FormatException)
        {
            this.State = ResultState.InvalidParam;
            this.WriteResult();
            return;
        }
        List <string> list = new List <string>();

        try
        {
            string localPath = base.Server.MapPath(this.PathToList);
            if (predicate == null)
            {
                predicate = x => this.SearchExtensions.Contains <string>(Path.GetExtension(x).ToLower());
            }
            list.AddRange(from x in Directory.GetFiles(localPath, "*", SearchOption.AllDirectories).Where <string>(predicate) select this.PathToList + x.Substring(localPath.Length).Replace(@"\", "/"));
            this.Total    = list.Count;
            this.FileList = (from x in list
                             orderby x
                             select x).Skip <string>(this.Start).Take <string>(this.Size).ToArray <string>();
        }
        catch (UnauthorizedAccessException)
        {
            this.State = ResultState.AuthorizError;
        }
        catch (DirectoryNotFoundException)
        {
            this.State = ResultState.PathNotFound;
        }
        catch (IOException)
        {
            this.State = ResultState.IOError;
        }
        finally
        {
            this.WriteResult();
        }
    }
Пример #2
0
 public override void Process()
 {
     try
     {
         this.Start = (string.IsNullOrEmpty(base.Request["start"]) ? 0 : System.Convert.ToInt32(base.Request["start"]));
         this.Size  = (string.IsNullOrEmpty(base.Request["size"]) ? Config.GetInt("imageManagerListSize") : System.Convert.ToInt32(base.Request["size"]));
     }
     catch (System.FormatException)
     {
         this.State = ListFileManager.ResultState.InvalidParam;
         this.WriteResult();
         return;
     }
     System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>();
     try
     {
         string localPath = base.Server.MapPath(this.PathToList);
         list.AddRange(from x in System.IO.Directory.GetFiles(localPath, "*", System.IO.SearchOption.AllDirectories)
                       where this.SearchExtensions.Contains(System.IO.Path.GetExtension(x).ToLower())
                       select this.PathToList + x.Substring(localPath.Length).Replace("\\", "/"));
         this.Total    = list.Count;
         this.FileList = (from x in list
                          orderby x
                          select x).Skip(this.Start).Take(this.Size).ToArray <string>();
     }
     catch (System.UnauthorizedAccessException)
     {
         this.State = ListFileManager.ResultState.AuthorizError;
     }
     catch (System.IO.DirectoryNotFoundException)
     {
         this.State = ListFileManager.ResultState.PathNotFound;
     }
     catch (System.IO.IOException)
     {
         this.State = ListFileManager.ResultState.IOError;
     }
     finally
     {
         this.WriteResult();
     }
 }
Пример #3
0
    public override void Process()
    {
        try
        {
            this.Start = string.IsNullOrEmpty(this.Request["start"]) ? 0 : Convert.ToInt32(this.Request["start"]);
            this.Size  = string.IsNullOrEmpty(this.Request["size"]) ? Config.GetInt("imageManagerListSize") : Convert.ToInt32(this.Request["size"]);
        }
        catch (FormatException ex)
        {
            this.State = ListFileManager.ResultState.InvalidParam;
            this.WriteResult();
            return;
        }
        List <string> source = new List <string>();

        try
        {
            string localPath = this.Server.MapPath(this.PathToList);
            source.AddRange(((IEnumerable <string>)Directory.GetFiles(localPath, "*", SearchOption.AllDirectories)).Where <string>((Func <string, bool>)(x => ((IEnumerable <string>) this.SearchExtensions).Contains <string>(Path.GetExtension(x).ToLower()))).Select <string, string>((Func <string, string>)(x => this.PathToList + x.Substring(localPath.Length).Replace("\\", "/"))));
            this.Total    = source.Count;
            this.FileList = source.OrderBy <string, string>((Func <string, string>)(x => x)).Skip <string>(this.Start).Take <string>(this.Size).ToArray <string>();
        }
        catch (UnauthorizedAccessException ex)
        {
            this.State = ListFileManager.ResultState.AuthorizError;
        }
        catch (DirectoryNotFoundException ex)
        {
            this.State = ListFileManager.ResultState.PathNotFound;
        }
        catch (IOException ex)
        {
            this.State = ListFileManager.ResultState.IOError;
        }
        finally
        {
            this.WriteResult();
        }
    }