/// <summary> /// 发送PutOid请求,并返回获得的回应 /// </summary> /// <param name="oid">Wos对象标识</param> /// <returns>返回HttpWosPutOidResponse对象</returns> public HttpSeaFileGetUpdateLinkResponse ExecuteSeaFileGetUpdateLinkRequest(String strToken, String strRepoId) { LogTrace.TraceInfo("ExecuteSeaFileGetUpdateLinkRequest"); HttpSeaFileGetUpdateLinkResponse rsp = new HttpSeaFileGetUpdateLinkResponse(); try { HttpWebRequest req = CreateSeaFileGetUpdateLinkRequest(strToken, strRepoId); if (req != null) { HttpWebResponse res = (HttpWebResponse)req.GetResponse(); LogTrace.TraceInfo("Response code for GetUpdateLink is {0}", res.StatusCode); Stream rStream = res.GetResponseStream(); StreamReader sr = new StreamReader(rStream); rsp.URL = sr.ReadToEnd(); req.Abort(); res.Close(); return(rsp); } return(null); } catch (Exception ept) { LogTrace.TraceException(ept); return(null); } }
/// <summary> /// 开始上传附件到OBS云端存储 /// </summary> private void bgwUploadFile_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { if (m_bRegisterWindowClose == false) { ((Outlook.ItemEvents_10_Event)(dynamic) Globals.ThisAddIn.Application.ActiveInspector().CurrentItem).Close += new Microsoft.Office.Interop.Outlook.ItemEvents_10_CloseEventHandler(MailItem_Close); m_bRegisterWindowClose = true; } Outlook.Application objApplication = Globals.ThisAddIn.Application; Outlook.Inspector objInspector = objApplication.ActiveInspector(); //获取入参 Object[] objArray = (Object[])e.Argument; String[] strArrFilePath = (String[])objArray[0]; String[] strArrFileName = (String[])objArray[1]; if (!SeafileLogon()) { LogTrace.TraceError("Seafile Logon failed."); return; } UploadInProgress = true; for (int i = 0; i < strArrFilePath.Count <String>(); i++) { String strFilePath = strArrFilePath[i]; String strFileName = strArrFileName[i]; LogTrace.TraceInfo("Start upload file {0} : {1}", strFileName, strFilePath); //获取文件信息 FileInfo fInfo = new FileInfo(strFileName, strFilePath); if (fInfo.FileLength > Globals.ThisAddIn.GetMaxFileSize() * 1024 * 1024) { MessageBox.Show("文件" + strFileName + "大小超过管理员规定(" + Globals.ThisAddIn.GetMaxFileSize().ToString() + ")", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } if (uploadProgressBar.InvokeRequired) { uploadProgressBar.Invoke(new MethodInvoker(delegate { uploadProgressBar.Minimum = 0; uploadProgressBar.Maximum = CaculateProgressBarMaxSize(fInfo.FileLength); uploadProgressBar.Value = 0; LogTrace.TraceInfo("Reset ProgressBar bar, Min {0} Max {1} value {2}", uploadProgressBar.Minimum, uploadProgressBar.Maximum, uploadProgressBar.Value); })); } if (!m_bUploadFolder) { HttpSeaFileGetDirectoryEntriesResponse gdeRsp = httpClient.ExecuteSeaFileGetDirectoryEntriesRequest(m_strToken, m_strRepoID, "/" + m_strDefaultUploadFolder); if (gdeRsp == null) { m_bUploadFolder = httpClient.ExecuteCreateSeaFileCreateNewDirectoryRequest(m_strToken, m_strRepoID, "/" + m_strDefaultUploadFolder); } } HttpSeaFileGetUpdateLinkResponse gulDlg = httpClient.ExecuteSeaFileGetUpdateLinkRequest(m_strToken, m_strRepoID); if (gulDlg != null) { //upload File to ShareFile httpClient.AttachFile(strFilePath, strFileName); String strResult = httpClient.ExecuteBackGroundShareFileUploadFileStream(m_bgwUploadFile, m_strToken, gulDlg.URL, "/" + m_strDefaultUploadFolder); if (strResult == null || strResult == String.Empty) { MessageBox.Show("上传文件 " + strFileName + " 失败!"); LogTrace.TraceError("Upload file {0} failed.", strFileName); } else { String strDownloadLink = httpClient.ExecuteCreateSeaFileCreateDownloadLinkRequest(m_strToken, m_strRepoID, "/" + m_strDefaultUploadFolder + "/" + strFileName, "", 0); if (strDownloadLink != null && strDownloadLink != "" && strDownloadLink != String.Empty) { LogTrace.TraceInfo("Replace attachment {0} with Link {1}", strFileName, strDownloadLink); ReplceAttachment(strFileName, strDownloadLink); } else { MessageBox.Show("文件(" + strFileName + ")下载链接获取失败"); LogTrace.TraceError("Get Download Link for file {0} is empty", strFileName); } } } else { LogTrace.TraceError("Retrieve Upload URL failed."); } } UploadInProgress = false; }