2017-07-28 40 views
2

編寫一個C#的Outlook Addin。這個Addin應該將一些電子郵件中的信息傳遞給Webservice。 im登錄到Webservice後,我得到了一些LoginTokens。 我的問題是,我可以在哪裏保存這些登錄信息,以便每次重新打開Outlook時都不需要再次登錄? 我的令牌30天有效,所以我不需要每次重新打開Outlook新令牌。如何在Outlook的Addin中保存登錄令牌

public interface ILoginHandler 
{ 
    string LoginToken { get; set; } 
    string LoginSessionToken { get; set; } 

    void RequeryCredentials(); 

    bool LastAuthorizationOk { get; set; } 
    bool IsPasswordChangeRequired { get; set; } 

    string TwoFactorAuthSessionToken { get; set; } 
    bool RememberLogin { get; set; } 
    void RequestTwoFactorAuthCode(TwoFactorAuthenticationType type); 

    void AfterSuccessfulTwoFactorAuth(LoginReturn.LoginReturnCode loginReturnCode, bool autoLoginSet); 

    void ClearTokenAndLogin(); 
    void PromptPasswordChange(); 
} 

回答

0

Outlook對象模型爲此提供了StorageItem對象。請閱讀Creating and Saving Data to Solution Storage文章中的更多內容。

Sub StoreData() 
    Dim oInbox As Folder 
    Dim myStorage As StorageItem 
    Dim myPrivateProperty As UserProperty 

    Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox) 
    ' Get an existing instance of StorageItem by subject, or create new if it doesn't exist 
    Set myStorage = oInbox.GetStorage("My Private Storage", olIdentifyBySubject) 

    If myStorage.Size = 0 Then 
    'There was no existing StorageItem by this subject, so created a new one 
    'Create a custom property for Order Number 
    Set myPrivateProperty = myStorage.UserProperties.Add("Order Number", olNumber) 
    Else 
    'Assume that existing storage has the Order Number property already 
    Set myPrivateProperty = myStorage.UserProperties("Order Number") 
    End If 
    myPrivateProperty.Value = lngOrderNumber 
    myStorage.Save 
End Sub 

在一般情況下,你可以把你的C#插件作爲常規管理應用程序,使用.NET提供或任何你喜歡的方式。