//return !string.IsNullOrWhiteSpace(input) ? Regex.Match(input, @"http://\w*\.directupload\.net/images/\d*/\w*\.[a-z]{3}").Value : null; /// <summary> /// 断点续传方式提交批次,通信两次,第一次提交批次和文件信息,第二次提交文件数据 /// </summary> /// <param name="batchInfo"></param> /// <returns></returns> public static void BroekUpload(NBatchInfo batchInfo) { batchInfo.Status = EBatchStatus.NEW; string url = HttpUtil.GetHttpBrokeUploadBatchURL(); byte[] batchBytes = batchInfo.ToPbMsgWithoutData().ToByteArray(); //提交批次信息 byte[] resultBytes = PostWithContent(url, batchBytes, batchInfo.BatchNO).Result; NResultInfo resultInfo = NResultInfo.FromNetMsg(MsgResultInfo.ParseFrom(resultBytes)); resultInfo.EnsureResultSuccess(); IList <string> processingFileIds = resultInfo.ProcessingFileIds; //List<NFileInfo> processingFileInfos = batchInfo.FileInfos.Where(x => processingFileIds.Contains(x.FileNO)).ToList(); //选出处理中的文件继续提交 batchInfo.FileInfos = batchInfo.FileInfos.Where(x => processingFileIds.Contains(x.FileNO)).ToList(); //选出处理中的文件继续提交 foreach (NFileInfo fileInfo in batchInfo.FileInfos) //提交剩余文件 { batchInfo.Status = EBatchStatus.PROCESSING; //url = HttpUtil.GetHttpBrokeUploadFileURL(); batchBytes = batchInfo.ToPbMsgWithData().ToByteArray(); resultBytes = PostWithContent(url, batchBytes, batchInfo.BatchNO).Result; resultInfo = NResultInfo.FromNetMsg(MsgResultInfo.ParseFrom(resultBytes)); resultInfo.EnsureResultSuccess(); } //发送批次完成请求 url = HttpUtil.GetHttpFinishBrokeBatchURL(batchInfo.BatchNO); resultBytes = Post(url, batchInfo.BatchNO).Result; resultInfo = NResultInfo.FromNetMsg(MsgResultInfo.ParseFrom(resultBytes)); resultInfo.EnsureResultSuccess(); }
public static NBatchInfo GetBatch(string batchNo) { string url = HttpUtil.GetHttpGetBatchURL(batchNo); //提交批次信息 byte[] resultBytes = Post(url, batchNo).Result; NResultInfo resultInfo = NResultInfo.FromNetMsg(MsgResultInfo.ParseFrom(resultBytes)); resultInfo.EnsureResultSuccess(); NBatchInfo batchInfo = resultInfo.BatchInfo; IList <NFileInfo> fileInfos = batchInfo.FileInfos; string tmpDir = AppContext.GetInstance().Config.GetConfigParamValue("AppSetting", "TmpFileDir"); string batchDir = Path.Combine(tmpDir, batchInfo.BatchNO); Directory.CreateDirectory(batchDir); TmpDirMgr.AddTmpDir(batchDir); foreach (NFileInfo fileInfo in fileInfos) { string filePath = Path.Combine(batchDir, fileInfo.FileNO); fileInfo.LocalPath = filePath; File.WriteAllBytes(filePath, fileInfo.Data); TmpFileMgr.AddTmpFile(filePath); } return(batchInfo); }
public void UploadBatch(NBatchInfo batch) { NResultInfo nResultInfo = new NResultInfo(); nResultInfo.Status = EResultStatus.eSuccess; NResultInfo result; try { string transMode = AppContext.GetInstance().Config.GetConfigParamValue("NetSetting", "TransMode"); //batch.TransMode = (ETransMode)Enum.Parse(typeof(ETransMode), transMode); if (transMode.Equals(ConstString.TRANSMODE_FULL)) { HttpClientManager.FullUpload(batch); //完全方式提交 } else if (transMode.Equals(ConstString.TRANSMODE_BROKE)) { HttpClientManager.BroekUpload(batch); //断点方式提交 } this.ReportMsg(ENetTransferStatus.Success, batch.BatchNO, "", 0.0, 0.0); } //catch (WebException ex) //{ // this.ReportMsg(ENetTransferStatus.Error, batch.BatchNO, ExceptionHelper.GetFirstException(ex).Message, 0.0, 0.0); //} catch (Exception e) { this.ReportMsg(ENetTransferStatus.Error, batch.BatchNO, ExceptionHelper.GetFirstException(e).Message, 0.0, 0.0); } //this._uploadresult = nResultInfo; //result = nResultInfo; //return result; }
/// <summary> /// 全批次上传,只通信一次,批次信息+批次数据 /// </summary> /// <param name="batchInfo"></param> public static void FullUpload(NBatchInfo batchInfo) { string url = HttpUtil.GetHttpFullUploadBatchURL(); byte[] batchBytes = batchInfo.ToPbMsgWithData().ToByteArray(); //提交批次信息 byte[] resultBytes = PostWithContent(url, batchBytes, batchInfo.BatchNO).Result; NResultInfo resultInfo = NResultInfo.FromNetMsg(MsgResultInfo.ParseFrom(resultBytes)); }
void INetTransfer.UploadBatch(NBatchInfo info) { this.ReportMsg(ENetTransferStatus.Start, info.BatchNO, "", 0.0, 0.0); string fileName = this.GetFileName(info.BatchNO); info.ToPBFile(fileName, AppContext.GetInstance().Config.GetConfigParamValue("NetSetting", "TransModel")); AppContext.GetInstance().MS.LogDebug("localserver mode save to " + fileName); this.ReportMsg(ENetTransferStatus.Success, info.BatchNO, "", 0.0, 0.0); NResultInfo nResultInfo = new NResultInfo(); nResultInfo.Status = EResultStatus.eSuccess; this._uploadresult = nResultInfo; //return nResultInfo; }
public static NResultInfo ParseWebResponse(HttpWebResponse resp) { NResultInfo result; try { MsgResultInfo info = MsgResultInfo.ParseFrom(resp.GetResponseStream()); NResultInfo nResultInfo = NResultInfo.FromNetMsg(info); result = nResultInfo; } catch (Exception ex) { result = new NResultInfo { Status = EResultStatus.eFailed, Msg = ex.ToString() }; } return(result); }
public NBatchInfo DownloadBatch(NQueryBatchInfo queryinfo) { NResultInfo resultInfo = new NResultInfo(); this._downloadresult = null; string url = HttpUtil.GetHttpGetBatchURL(queryinfo.BatchNO); this.ReportMsg(ENetTransferStatus.Start, queryinfo.BatchNO, "", 0.0, 0.0); try { NBatchInfo batchInfo = HttpClientManager.GetBatch(queryinfo.BatchNO); //HTTP请求获取批次信息 this._downloadresult = batchInfo; this.ReportMsg(ENetTransferStatus.Success, queryinfo.BatchNO, "", 0.0, 0.0); } catch (Exception ex) { this.ReportMsg(ENetTransferStatus.Error, queryinfo.BatchNO, ExceptionHelper.GetFirstException(ex).Message, 0.0, 0.0); } return(null); }