Exemple #1
0
        private void ShareFileSelectDialog_Load(object sender, EventArgs e)
        {
            lstPreviousfolder.Add("/");

            string strUrl = Globals.ThisAddIn.GetSeafileURL();

            if (strUrl != null && strUrl != "" && strUrl != String.Empty)
            {
                httpClient = new WosHttpClient(strUrl);
                LogTrace.TraceVerbose("Connect to fileshare with URL {0}", strUrl);
            }
            else
            {
                LogTrace.TraceError("Got fileshare URL failed.");
                this.Close();
                return;
            }

            strToken = SeafileLogon();

            if (strToken == null)
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
                return;
            }

            HttpSeaFileGetDefaultLibraryResponse gdlRsp = httpClient.ExecuteSeaFileGetDefaultLibraryRequest(strToken);

            if (gdlRsp != null)
            {
                strRepoID = gdlRsp.RepoId;
                LogTrace.TraceVerbose("Retrieve Repro Id [{0}]", strRepoID);
            }
            else
            {
                LogTrace.TraceError("Retrieve Repro ID failed.");
                this.DialogResult = DialogResult.Abort;
                this.Close();
                return;
            }

            HttpSeaFileGetDirectoryEntriesResponse gdresp =
                httpClient.ExecuteSeaFileGetDirectoryEntriesRequest(strToken, strRepoID, strCurrentFolder);

            if (gdresp != null)
            {
                ListDirectory(gdresp);
            }
            else
            {
                LogTrace.TraceError("Get Default Directory list failed.");
                this.DialogResult = DialogResult.Abort;
                this.Close();
            }
        }
Exemple #2
0
        /// <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;
        }