/// <summary> /// 지정된 경로에서 리소스를 읽어오는 Task{byte[]}를 빌드합니다. /// </summary> private static Task <byte[]> ReadFileTask(HttpContext context, string virtualPath) { virtualPath.ShouldNotBeWhiteSpace("virtualPath"); Task <byte[]> task = null; if (IsDebugEnabled) { log.Debug("지정된 경로에서 리소스를 읽어오는 Task<byte[]>를 빌드합니다. virtualPath=[{0}]", virtualPath); } // 외부경로의 리소스라면, 다운로드 받는다. if (IsWebResource(virtualPath)) { var webClient = new WebClient(); task = webClient.DownloadDataTask(virtualPath); task.ContinueWith(_ => webClient.Dispose(), TaskContinuationOptions.ExecuteSynchronously); } else { var path = FileTool.GetPhysicalPath(virtualPath); task = path.FileExists() ? FileAsync.ReadAllBytes(FileTool.GetPhysicalPath(virtualPath)) : Task.Factory.FromResult(new byte[0]); } return(task); }
/// <summary> /// 지정된 파일을 비동기적으로 읽습니다. /// </summary> /// <param name="context"></param> /// <param name="physicalPath">파일의 물리적 경로</param> /// <returns></returns> private static Task <byte[]> ReadFile(HttpContext context, string physicalPath) { if (IsDebugEnabled) { log.Debug("Static File을 비동기 방식으로 읽습니다. physicalPath=[{0}]", physicalPath); } if (File.Exists(physicalPath)) { return(FileAsync.ReadAllBytes(physicalPath)); } if (log.IsWarnEnabled) { log.Warn("파일 정보가 없습니다. 길이가 0인 byte 배열을 반환합니다. physicalPath=[{0}]", physicalPath); } return(Task.Factory.FromResult(new byte[0])); }
private async void LoadImageAsync(FileStream fileStream, Action <byte[]> result) { var bytes = await FileAsync.ReadAllBytes(fileStream); DispathToMainThread(() => result?.Invoke(bytes)); }