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(); } }
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); }
public void CheckLogon(/*object source, System.Timers.ElapsedEventArgs e*/) { RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\MICROSOFT\OFFICE\OUTLOOK\ADDINS\PinganAttachment.OutlookAddin", true); String strDesKey = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress.Substring(0, 8); String m_strToken = String.Empty; if (regKey != null) { try { m_strToken = Decrypt(regKey.GetValue("token").ToString(), strDesKey); } catch (Exception ept) { LogTrace.TraceException(ept); pbLogon.Image = global::FileToUpload.Properties.Resources.off; return; } } else { pbLogon.Image = global::FileToUpload.Properties.Resources.off; return; } if (m_strToken == null || m_strToken == String.Empty) { pbLogon.Image = global::FileToUpload.Properties.Resources.off; } else { WosHttpClient httpClient = null; 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, turn logon off"); pbLogon.Image = global::FileToUpload.Properties.Resources.off; return; } try { Boolean bCheckLogon = httpClient.ExecuteSeaFilePingRequest(m_strToken); if (bCheckLogon) { LogTrace.TraceInfo("Turn logon on (1)"); pbLogon.Image = global::FileToUpload.Properties.Resources.on; } else { LogTrace.TraceInfo("Turn logon off (1)"); pbLogon.Image = global::FileToUpload.Properties.Resources.off; } } catch (Exception ept) { LogTrace.TraceInfo("Turn logon off (1)"); pbLogon.Image = global::FileToUpload.Properties.Resources.off; LogTrace.TraceException(ept); } } }