public async Task <string> ThumbnailUrl(string WIDTH_x_HEIGHT, ExtEnum Ext, bool Crop) { var parameters = new AuthDictionary() { { "fileid", FileID.ToString() }, { "size", WIDTH_x_HEIGHT }, { "type", Ext.ToString() }, { "crop", Crop ? "1" : null } }; using (HtpClient localHttpClient = new HtpClient(new HCHandler())) { HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getthumblink")); HtpReqMessage.Content = new FormUrlEncodedContent(parameters.RemoveEmptyValues()); using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false)) { string result = await response.Content.ReadAsStringAsync(); if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0)) { return(string.Format("https://{0}{1}", JObject.Parse(result).SelectToken("hosts[0]").ToString(), JObject.Parse(result).SelectToken("path").ToString().Replace(@"\", string.Empty))); } else { ShowError(result); return(null); } } } }
public static IWorkbook GetIWorkbook(ExtEnum ext) { if (ext == ExtEnum.XLSX) { return(new XSSFWorkbook()); } else if (ext == ExtEnum.XLS) { return(new HSSFWorkbook()); } else { throw new Exception("excel格式无法解析"); } }
public static IWorkbook GetIWorkbook(Stream fileStream, ExtEnum ext) { if (ext == ExtEnum.Xlsx) { return(new XSSFWorkbook(fileStream)); } else if (ext == ExtEnum.Xls) { return(new HSSFWorkbook(fileStream)); } else { throw new Exception("excel格式无法解析"); } }
/// <summary> /// 导入Excel /// </summary> /// <param name="fileStream">excel文件流</param> /// <param name="ext">excel后缀</param> /// <param name="importBook">导入模型</param> /// <param name="outPutErrorStream">错误输出流</param> /// <returns>导入结果</returns> public ImportResult ImportExcel(Stream fileStream, ExtEnum ext, ImportBook importBook, Stream outPutErrorStream = null) { var ret = new ImportResult(); var sheets = importBook.Sheets.Select(m => this.CreateResultSheetInstance(m.GetType().GenericTypeArguments[0], m)).ToArray(); ret.SetSheets(sheets); IWorkbook workbook; try { workbook = WorkbookGenerator.GetIWorkbook(fileStream, ext); } catch (Exception ex) { ret.SetBookFormatErrorMessage(ex.Message, ex); return(ret); } var errorStyleGenerator = new ImporterErrorStyleGenerator(workbook, importBook.DataErrorForegroundColor, importBook.RepeatedErrorForegroundColor, importBook.DefaultForegroundColor); for (var i = 0; i < workbook.NumberOfSheets; i++) { var sheet = workbook.GetSheetAt(i); var sheetModel = ret.Sheets.FirstOrDefault(m => m.SheetIndex == i || m.SheetName == sheet.SheetName); if (sheetModel == null) { continue; } sheetModel.SheetIndex = i; sheetModel.SheetName = sheet.SheetName; this.ParseSheetToModel(sheet, sheetModel); if (outPutErrorStream != null) { errorStyleGenerator.InitStyle(sheet, sheetModel.HeaderRowIndex); errorStyleGenerator.SetErrorStyle(sheet, sheetModel); } } if (outPutErrorStream != null) { workbook.Write(outPutErrorStream); } return(ret); }
public async Task <byte[]> Thumbnail(string WIDTH_x_HEIGHT, ExtEnum Ext, bool Crop) { var parameters = new AuthDictionary() { { "fileid", FileID.ToString() }, { "size", WIDTH_x_HEIGHT }, { "type", Ext.ToString() }, { "crop", Crop ? "1" : null } }; using (HtpClient localHttpClient = new HtpClient(new HCHandler())) { HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getthumb")); HtpReqMessage.Content = new FormUrlEncodedContent(parameters.RemoveEmptyValues()); using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false)) { if (response.StatusCode == HttpStatusCode.OK) { return(await response.Content.ReadAsByteArrayAsync()); } else { throw new pCloudException(response.ReasonPhrase, (int)response.StatusCode); } } } }
public async Task <JSON_FileMetadata> CopyThumbnail(long DestinationFolderID, string WIDTH_x_HEIGHT, ExtEnum Ext, bool Crop, bool AutoRename, string RenameTo = null) { var parameters = new AuthDictionary { { "fileid", FileID.ToString() }, { "tofolderid", DestinationFolderID.ToString() }, { "noover", AutoRename ? "1" : null }, { "toname", RenameTo }, { "type", Ext.ToString() }, { "size", WIDTH_x_HEIGHT }, { "crop", Crop ? "1" : null } }; var encodedContent = new FormUrlEncodedContent(parameters.RemoveEmptyValues()); using (HtpClient localHttpClient = new HtpClient(new HCHandler())) { HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/savethumb")); HtpReqMessage.Content = encodedContent; using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false)) { string result = await response.Content.ReadAsStringAsync(); if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0)) { return(JsonConvert.DeserializeObject <JSON_FileMetadata>(JObject.Parse(result).SelectToken("metadata").ToString(), JSONhandler)); } else { ShowError(result); return(null); } } } }
public async Task <Dictionary <long, string> > ThumbnailUrl(string WIDTH_x_HEIGHT, ExtEnum Ext, bool Crop) { var parameters = new AuthDictionary() { { "fileids", string.Join(",", FileIDs) }, { "size", WIDTH_x_HEIGHT }, { "type", Ext.ToString() } }; if (Crop) { parameters.Add("crop", "1"); } using (HtpClient localHttpClient = new HtpClient(new HCHandler())) { HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getthumbslinks")); HtpReqMessage.Content = new FormUrlEncodedContent(parameters); using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false)) { string result = await response.Content.ReadAsStringAsync(); if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0)) { Dictionary <long, string> addationStatus = new Dictionary <long, string>(); JObject.Parse(result).SelectToken("thumbs").ToList().ForEach(x => addationStatus.Add(x.Value <long>("fileid"), x.Value <int>("result").Equals(0) ? string.Format("https://{0}{1}", x.SelectToken("hosts").ToList().First(), x.Value <string>("path")) : x.Value <string>("error"))); return(addationStatus); } else { ShowError(result); return(null); } } } }