static int _m_FlushAsync(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); System.IO.MemoryStream gen_to_be_invoked = (System.IO.MemoryStream)translator.FastGetCSObj(L, 1); { System.Threading.CancellationToken _cancellationToken; translator.Get(L, 2, out _cancellationToken); System.Threading.Tasks.Task gen_ret = gen_to_be_invoked.FlushAsync( _cancellationToken); translator.Push(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
public async Task <string> CacheImage(byte[] bytes) { var outputFile = CreateTempFile(); System.IO.MemoryStream s = new System.IO.MemoryStream(bytes); using (System.IO.FileStream fileStream = System.IO.File.OpenWrite(outputFile.AbsolutePath)) { await s.CopyToAsync(fileStream); await s.FlushAsync(); await fileStream.FlushAsync(); } return(outputFile.AbsolutePath); }
public async Task <byte[]> ToCsvAsync() { var branches = await _siteService.GetAllBranches(); using var memoryStream = new System.IO.MemoryStream(); using var writer = new System.IO.StreamWriter(memoryStream); using var csv = new CsvHelper.CsvWriter(writer, new CsvConfiguration(CultureInfo.InvariantCulture)); csv.Context.RegisterClassMap <Maps.BranchMap>(); await csv.WriteRecordsAsync(branches.OrderBy(_ => _.SystemName).ThenBy(_ => _.Name)); await csv.FlushAsync(); await writer.FlushAsync(); await memoryStream.FlushAsync(); return(memoryStream.ToArray()); }
static StackObject *FlushAsync_4(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Threading.CancellationToken @cancellationToken = (System.Threading.CancellationToken) typeof(System.Threading.CancellationToken).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 2); System.IO.MemoryStream instance_of_this_method = (System.IO.MemoryStream) typeof(System.IO.MemoryStream).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.FlushAsync(@cancellationToken); object obj_result_of_this_method = result_of_this_method; if (obj_result_of_this_method is CrossBindingAdaptorType) { return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance)); } return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method)); }
public async Task <bool> ExtractCover(LibraryModel library, ComicFile comicFile) { try { // VALIDATE if (Xamarin.Essentials.Connectivity.NetworkAccess != Xamarin.Essentials.NetworkAccess.Internet) { return(false); } // RETRIEVE THE DOWNLOAD URL var downloadUrl = await this.Connector.GetDownloadUrlAsync(new FileData { id = comicFile.Key }); if (string.IsNullOrEmpty(downloadUrl)) { return(false); } // OPEN REMOTE STREAM using (var zipStream = new System.IO.Compression.HttpZipStream(downloadUrl)) { // STREAM SIZE var streamSizeValue = comicFile.GetKeyValue("StreamSize"); if (!string.IsNullOrEmpty(streamSizeValue)) { long streamSize; if (long.TryParse(streamSizeValue, out streamSize)) { zipStream.SetContentLength(streamSize); } } // FIRST ENTRY var entryList = await zipStream.GetEntriesAsync(); var entry = entryList .Where(x => x.FileName.ToLower().EndsWith(".jpg") || x.FileName.ToLower().EndsWith(".jpeg") || x.FileName.ToLower().EndsWith(".png")) .OrderBy(x => x.FileName) .FirstOrDefault(); if (entry == null) { return(false); } // RETRIEVE REMOTE IMAGE CONTENT var imageByteArray = await zipStream.ExtractAsync(entry); if (imageByteArray == null || imageByteArray.Length == 0) { return(false); } // SAVE CACHE FILE using (var imageStream = new System.IO.MemoryStream(imageByteArray)) { await imageStream.FlushAsync(); imageStream.Position = 0; await this.FileSystem.SaveThumbnail(imageStream, comicFile.CoverPath); imageStream.Close(); System.IO.File.SetLastWriteTime(comicFile.CoverPath, comicFile.ReleaseDate); } } return(System.IO.File.Exists(comicFile.CoverPath)); } catch (Exception ex) { Helpers.AppCenter.TrackEvent(ex); return(false); } }
public async Task <IActionResult> Upload([FromForm] IFormFile uploadFile) { var nowStamp = DateTime.Now; var rootPath = _env.ContentRootPath; if (uploadFile == null) { return(NoContent()); } // 根据现有信息创建文件实体 var file = new File { FileName = uploadFile.FileName, Type = uploadFile.ContentType, UploadDate = nowStamp }; if (uploadFile.Length > 0) { using (var stream = new System.IO.MemoryStream()) { // 读取上传文件计算 MD5 await uploadFile.CopyToAsync(stream); stream.Position = 0; var md5Arr = MD5.Create().ComputeHash(stream); StringBuilder sBuilder = new StringBuilder(); for (int i = 0; i < md5Arr.Length; i++) { // x2 代表转为 16 进制长度为 2 的 string sBuilder.Append(md5Arr[i].ToString("x2")); } file.MD5 = sBuilder.ToString(); // 将文件内容转为字节数组并写入实体 file.FileContent = stream.ToArray(); var extension = ""; // 处理特定的文档预览 switch (file.Type) { case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": extension = ".docx"; break; case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": extension = ".xlsx"; break; case "application/vnd.openxmlformats-officedocument.presentationml.presentation": extension = ".pptx"; break; case "application/msword": extension = ".doc"; break; case "application/vnd.ms-excel": extension = ".xls"; break; case "application/vnd.ms-powerpoint": extension = ".ppt"; break; case "application/pdf": extension = ".pdf"; break; } if (extension != "") { // 进行预览图片的生成并写入到实体中 var resultImage = CovertFile.Covert(rootPath, file.MD5, extension, stream); if (System.IO.File.Exists(resultImage)) { using (var previewStream = new System.IO.FileStream(resultImage, System.IO.FileMode.Open)) { await stream.FlushAsync(); stream.Position = 0; await previewStream.CopyToAsync(stream); file.PreviewImage = stream.ToArray(); } // 删除临时生成的图片 System.IO.File.Delete(resultImage); } } } // 将生成的实体添加到 Model 中并与数据库同步 await _context.File.AddAsync(file); _context.SaveChanges(); return(Ok(new FileReturnInfo(file))); } else { return(NoContent()); } }