예제 #1
0
        //************************************************************************************************
        //** Execution Functions
        //************************************************************************************************

        /// <summary>
        /// 发送PutOid请求,并返回获得的回应
        /// </summary>
        /// <param name="oid">Wos对象标识</param>
        /// <returns>返回HttpWosPutOidResponse对象</returns>
        public HttpSeaFileTokenResponse ExecuteSeaFileTokenRequest(String strUser, String strPassword)
        {
            LogTrace.TraceInfo("ExecuteSeaFileTokenRequest");

            HttpSeaFileTokenResponse rsp = new HttpSeaFileTokenResponse();

            try
            {
                HttpWebRequest req = CreateSeaFileTokenRequest(strUser, strPassword);
                if (req != null)
                {
                    HttpWebResponse res = (HttpWebResponse)req.GetResponse();

                    LogTrace.TraceInfo("Response code for TokenRequest is {0}", res.StatusCode);

                    String strResponse = String.Empty;

                    Stream       rStream = res.GetResponseStream();
                    StreamReader sr      = new StreamReader(rStream);
                    strResponse = sr.ReadToEnd();

                    JObject jo = (JObject)JsonConvert.DeserializeObject(strResponse);
                    rsp.Token = jo["token"].ToString();

                    req.Abort();
                    res.Close();

                    return(rsp);
                }

                return(null);
            }
            catch (Exception ept)
            {
                LogTrace.TraceException(ept);
                return(null);
            }
        }
예제 #2
0
        private Boolean SeafileLogon()
        {
            Boolean bFoundToken = false;

            string strUrl = Globals.ThisAddIn.GetSeafileURL();

            if (strUrl != null && strUrl != "" && strUrl != String.Empty)
            {
                httpClient = new WosHttpClient(strUrl);
                LogTrace.TraceInfo("Connect to Fileshare with URL: {0}", strUrl);
            }
            else
            {
                LogTrace.TraceError("Sharefile URL is empty.");
                LogTrace.TraceInfo("Turn logon off (3)");
                pbLogon.Image = global::FileToUpload.Properties.Resources.off;
                return(false);
            }

            String      strDesKey = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress.Substring(0, 8);
            RegistryKey regKey    = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\MICROSOFT\OFFICE\OUTLOOK\ADDINS\PinganAttachment.OutlookAddin", true);

            try
            {
                if (regKey != null)
                {
                    m_strToken = Decrypt(regKey.GetValue("token").ToString(), strDesKey);

                    if (m_strToken != null && m_strToken != String.Empty)
                    {
                        Boolean b = httpClient.ExecuteSeaFilePingRequest(m_strToken);

                        if (b)
                        {
                            LogTrace.TraceVerbose("Retrieve Token {0} from register Key.", m_strToken);
                            bFoundToken = true;
                        }
                    }
                }
                else
                {
                    bFoundToken = false;
                }
            }
            catch (Exception ept)
            {
                LogTrace.TraceException(ept);
                bFoundToken = false;
            }

            // Retrieve Token for current user
            if (!bFoundToken)
            {
                String      strLoginUser, strLoginPassword;
                LogonDialog dlg = new LogonDialog();

                DialogResult result = dlg.ShowDialog();

                if (result == DialogResult.OK)
                {
                    strLoginUser     = dlg.EmailAddress;
                    strLoginPassword = dlg.Password;

                    LogTrace.TraceVerbose("Logon user Name is {0}, password is {1}", strLoginUser, "*********");
                }
                else
                {
                    LogTrace.TraceInfo("Cancel logon");
                    LogTrace.TraceInfo("Turn logon off (4)");
                    pbLogon.Image = global::FileToUpload.Properties.Resources.off;
                    return(false);
                }

                HttpSeaFileTokenResponse rsp = httpClient.ExecuteSeaFileTokenRequest(strLoginUser, strLoginPassword);
                if (rsp != null)
                {
                    regKey.SetValue("token", Encrypt(rsp.Token, strDesKey));
                    m_strToken = rsp.Token;
                    LogTrace.TraceVerbose("Save token {0} into register key.", m_strToken);
                }
                else
                {
                    MessageBox.Show("1、如果您已是云盘用户,请输入正确的邮箱密码(开机密码)\n\r2、如果您还不是云盘用户请联系所在机构IT咨询如何申请开通,不要重复尝试登录避免邮箱帐号被锁定", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    LogTrace.TraceInfo("Turn logon off (5)");
                    pbLogon.Image = global::FileToUpload.Properties.Resources.off;
                    return(false);
                }
            }

            HttpSeaFileGetDefaultLibraryResponse gdlRsp = httpClient.ExecuteSeaFileGetDefaultLibraryRequest(m_strToken);

            if (gdlRsp != null)
            {
                m_strRepoID = gdlRsp.RepoId;
                LogTrace.TraceVerbose("Retrieve Repro Id {0}.", m_strRepoID);
                LogTrace.TraceInfo("Turn logon on (6)");
                pbLogon.Image = global::FileToUpload.Properties.Resources.on;
                return(true);
            }
            else
            {
                LogTrace.TraceError("Retrieve Repro Id failed.");
            }

            LogTrace.TraceInfo("Turn logon off (7)");
            pbLogon.Image = global::FileToUpload.Properties.Resources.off;
            return(false);
        }
예제 #3
0
        private String SeafileLogon()
        {
            Boolean bFoundToken = false;

            String      strDesKey = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress.Substring(0, 8);
            RegistryKey regKey    = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\MICROSOFT\OFFICE\OUTLOOK\ADDINS\PinganAttachment.OutlookAddin", true);

            try
            {
                if (regKey != null)
                {
                    strToken = Decrypt(regKey.GetValue("token").ToString(), strDesKey);
                    if (strToken != null && strToken != String.Empty)
                    {
                        Boolean b = httpClient.ExecuteSeaFilePingRequest(strToken);

                        if (b)
                        {
                            LogTrace.TraceVerbose("Retrieve Token {0} from register.", strToken);
                            return(strToken);
                        }
                    }
                }
                else
                {
                    LogTrace.TraceError("Access to Registry key {0} failed.", @"Software\Microsoft\Office\14.0\Outlook\Addins\FileToUpload");
                    bFoundToken = false;
                }
            }
            catch (Exception ept)
            {
                LogTrace.TraceException(ept);
                bFoundToken = false;
            }

            // Retrieve Token for current user
            if (!bFoundToken)
            {
                String      strLoginUser, strLoginPassword;
                LogonDialog dlg = new LogonDialog();

                DialogResult result = dlg.ShowDialog();

                if (result == DialogResult.OK)
                {
                    strLoginUser     = dlg.EmailAddress;
                    strLoginPassword = dlg.Password;

                    LogTrace.TraceVerbose("Retrieve token with user: {0}, password: {1}", strLoginUser, "******");
                }
                else
                {
                    LogTrace.TraceInfo("Cancel logon.");
                    return(null);
                }

                HttpSeaFileTokenResponse rsp = httpClient.ExecuteSeaFileTokenRequest(strLoginUser, strLoginPassword);
                if (rsp != null)
                {
                    regKey.SetValue("token", Encrypt(rsp.Token, strDesKey));
                    strToken = rsp.Token;
                    LogTrace.TraceVerbose("Retrieve Token {0} succeed.", strToken);
                    return(strToken);
                }
                else
                {
                    MessageBox.Show("1、如果您已是云盘用户,请输入正确的邮箱密码(开机密码)\n\r2、如果您还不是云盘用户请联系所在机构IT咨询如何申请开通,不要重复尝试登录避免邮箱帐号被锁定", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    LogTrace.TraceError("Retrieve token failed.");
                    //sdlg.ShowDialog();
                    return(null);
                }
            }
            return(null);
        }