internal Stream DownloadToStream(FileDownloadInput input) { string json = JsonConvert.SerializeObject(input); var res = HwApiHelper.HuaweiPostSync(baseUrl, downloadUri, token.Access_token, json, null); Stream stream = res.GetResponseStream(); return(stream); }
public bool DownloadToFile(string file, FileDownloadInput input) { Stream stream = dal.DownloadToStream(input); if (stream == null) { return(false); } FileStream fs = new FileStream(file, FileMode.OpenOrCreate); byte[] data = new byte[1024]; while (stream.Read(data, 0, data.Length) > 0) { fs.Write(data, 0, data.Length); fs.Flush(); } fs.Close(); return(true); }
/// <summary> /// 下载订单的PDF文件 /// </summary> /// <param name="outFile">输出文件名</param> /// <param name="showPrice">是否显示价格</param> /// <param name="lang">语言版本</param> /// <param name="erpId">ERPID,默认1</param> /// <param name="poNums">待输出的PO行 PoLineToDownload</param> /// <returns></returns> public bool DownloadPoPdf(string outFile, bool showPrice, ELang lang = ELang.zh_CN, EInstanceId erpId = EInstanceId.Huawei, params string[] poNums) { List <PoLineToDownload> poLines = new List <PoLineToDownload>(); foreach (var p in poNums) { poLines.Add(new PoLineToDownload { instanceId = erpId, poNumber = p }); } bool ret = false; GenPoPdfInput input = new GenPoPdfInput { lang = lang.ToString(), queryHistoryDB = 0, showPriceFlag = showPrice, lines = poLines.ToArray() }; var res = dal.GenPoPdfDAL(input); if (res != null) { if (res.Success) { string fileKey = res.PreUrl; DownloadBLL downloadBLL = new DownloadBLL(); FileDownloadInput downLoadParam = new FileDownloadInput { downloadType = "1", downloadKey = res.PreUrl }; ret = downloadBLL.DownloadToFile(outFile, downLoadParam); } } return(ret); }