|
Server : Microsoft-IIS/10.0 System : Windows NT EBS-6136 10.0 build 17763 (Windows Server 2016) i586 User : jxgj ( 0) PHP Version : 7.0.33 Disable Function : passthru,exec,system,shell_exec,proc_open,popen,pcntl_exec,socket_bind,stream_socket_server Directory : D:/tmp_aspnet/root/cae6aa2e/15328683/ |
?#pragma checksum "D:\wwwroot\anlian2025\wwwroot\App_Code\ListFileHandler.cs" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "4D27C8AAF5F0673B9612BAB207608604572BE464"
#line 1 "D:\wwwroot\anlian2025\wwwroot\App_Code\ListFileHandler.cs"
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
/// <summary>
/// FileManager 的提要注明
/// </summary>
public class ListFileManager : Handler
{
enum ResultState
{
Success,
InvalidParam,
AuthorizError,
IOError,
PathNotFound
}
private int Start;
private int Size;
private int Total;
private ResultState State;
private String PathToList;
private String[] FileList;
private String[] SearchExtensions;
public ListFileManager(HttpContext context, string pathToList, string[] searchExtensions)
: base(context)
{
this.SearchExtensions = searchExtensions.Select(x => x.ToLower()).ToArray();
this.PathToList = pathToList;
}
public override void Process()
{
try
{
Start = String.IsNullOrEmpty(Request["start"]) ? 0 : Convert.ToInt32(Request["start"]);
Size = String.IsNullOrEmpty(Request["size"]) ? Config.GetInt("imageManagerListSize") : Convert.ToInt32(Request["size"]);
}
catch (FormatException)
{
State = ResultState.InvalidParam;
WriteResult();
return;
}
var buildingList = new List<String>();
try
{
var localPath = Server.MapPath(PathToList);
buildingList.AddRange(Directory.GetFiles(localPath, "*", SearchOption.AllDirectories)
.Where(x => SearchExtensions.Contains(Path.GetExtension(x).ToLower()))
.Select(x => PathToList + x.Substring(localPath.Length).Replace("\\", "/")));
Total = buildingList.Count;
FileList = buildingList.OrderBy(x => x).Skip(Start).Take(Size).ToArray();
}
catch (UnauthorizedAccessException)
{
State = ResultState.AuthorizError;
}
catch (DirectoryNotFoundException)
{
State = ResultState.PathNotFound;
}
catch (IOException)
{
State = ResultState.IOError;
}
finally
{
WriteResult();
}
}
private void WriteResult()
{
WriteJson(new
{
state = GetStateString(),
list = FileList == null ? null : FileList.Select(x => new { url = x }),
start = Start,
size = Size,
total = Total
});
}
private string GetStateString()
{
switch (State)
{
case ResultState.Success:
return "SUCCESS";
case ResultState.InvalidParam:
return "参数不正确";
case ResultState.PathNotFound:
return "蹊径不存在";
case ResultState.AuthorizError:
return "文件系统权限不及";
case ResultState.IOError:
return "文件系统读取谬误";
}
return "未知谬误";
}
}
#line default
#line hidden