עבודה עם תצורת משתמש בשרת
ניהול תצורת משתמש
ניתן להשתמש ב‑Aspose.Email API כדי לנהל תצורת משתמש ב‑Exchange Server עם ה‑ EWSClient מחלקה. מחלקה זו משתמשת ב‑Exchange Web Services, הזמינות רק ב‑Exchange Server 2007 ומאוחר יותר. במאמר זה נסתכל איך לקרוא, ליצור, לעדכן ולמחוק קונפיגורציות משתמש ב‑Exchange Server 2010. נדרש Microsoft Exchange Server 2010 Service Pack 1 לכל הפיצ’רים המתוארים כאן.
קונפיגורציית משתמש היא קבוצת הגדרות בשם שהיישום שומר בתיקייה של תיבת הדואר. היא מיוצגת על‑ידי UserConfiguration אובייקט, שה‑dictionary שלו מכיל את ההגדרות כמפתחות‑ערך, ומזוהה על‑ידי UserConfigurationName - שם הקונפיגורציה וה‑URI של התיקייה.
הדוגמאות במאמר זה משתמשות בכותרות ובמרחבי שם אלה:
#include <Clients/Exchange/WebService/EWSClient/EWSClient.h>
#include <Clients/Exchange/WebService/EWSClient/IEWSClient.h>
#include <Clients/Exchange/WebService/UserConfiguration/UserConfiguration.h>
#include <Clients/Exchange/WebService/UserConfiguration/UserConfigurationName.h>
#include <Clients/Exchange/ExchangeMailboxInfo.h>
#include <system/collections/dictionary.h>
#include <system/object_ext.h>
using namespace System;
using namespace Aspose::Email::Clients::Exchange;
using namespace Aspose::Email::Clients::Exchange::WebService;
כל הדוגמאות במאמר זה מתחברות לשרת כך:
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://your.exchange.server/ews/Exchange.asmx", u"username", u"password", u"domain");
client->Dispose();
קריאת תצורת משתמש
כדי לקבל את מידע תצורת המשתמש של תיקייה ספציפית מה‑Exchange Server:
- התחבר ל‑Exchange Server באמצעות IEWSClient.
- הפעל את GetUserConfiguration() שיטה לקבל את תצורת המשתמש עבור תיקייה.
- הצג את תכונות תצורת המשתמש כגון מזהה (ID), שם ופריטי מילון כזוגות מפתח‑ערך.
המפתחות והערכים של המילון הם אובייקטים; המחרוזות שמאוחסנות בו ארוזות.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
try
{
SharedPtr<UserConfigurationName> userConfigName = MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri());
SharedPtr<UserConfiguration> userConfig = client->GetUserConfiguration(userConfigName);
Console::WriteLine(u"Configuration Id: " + userConfig->get_Id());
Console::WriteLine(u"Configuration Name: " + userConfig->get_UserConfigurationName()->get_Name());
Console::WriteLine(u"Key value pairs:");
for (auto entry : userConfig->get_Dictionary())
{
Console::WriteLine(ObjectExt::ToString(entry.get_Key()) + u": " + ObjectExt::ToString(entry.get_Value()));
}
}
catch (System::Exception& ex)
{
Console::WriteLine(ex->get_Message());
}
client->Dispose();
יצירת תצורות משתמש
ליצירת תצורת המשתמש עבור תיקייה ספציפית ב‑Exchange Server:
- התחבר ל‑Exchange Server באמצעות IEWSClient.
- צור UserConfiguration עם השם והתיקייה שלה ומלא את המילון שלה.
- הפעל את CreateUserConfiguration() שיטה ליצור את תצורת המשתמש עבור תיקייה.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
SharedPtr<UserConfigurationName> userConfigName = MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri());
SharedPtr<UserConfiguration> userConfig = MakeObject<UserConfiguration>(userConfigName);
userConfig->get_Dictionary()->Add(ObjectExt::Box<String>(u"key1"), ObjectExt::Box<String>(u"value1"));
userConfig->get_Dictionary()->Add(ObjectExt::Box<String>(u"key2"), ObjectExt::Box<String>(u"value2"));
userConfig->get_Dictionary()->Add(ObjectExt::Box<String>(u"key3"), ObjectExt::Box<String>(u"value3"));
try
{
client->CreateUserConfiguration(userConfig);
}
catch (System::Exception& ex)
{
Console::WriteLine(ex->get_Message());
}
client->Dispose();
עדכון תצורת משתמש
כדי לעדכן את תצורת המשתמש עבור תיקייה ספציפית ב‑Exchange Server:
- התחבר ל‑Exchange Server באמצעות IEWSClient.
- קרא את הקונפיגורציה עם GetUserConfiguration() ומשנה את המילון שלה.
- הפעל את UpdateUserConfiguration() שיטה לעדכן את תצורת המשתמש עבור תיקייה.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
SharedPtr<UserConfigurationName> userConfigName = MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri());
SharedPtr<UserConfiguration> userConfig = client->GetUserConfiguration(userConfigName);
userConfig->get_Dictionary()->idx_set(ObjectExt::Box<String>(u"key1"), ObjectExt::Box<String>(u"new-value1"));
client->UpdateUserConfiguration(userConfig);
client->Dispose();
מחיקת תצורת משתמש
כדי למחוק את תצורת המשתמש עבור תיקייה ספציפית ב‑Exchange Server:
- התחבר ל‑Exchange Server באמצעות IEWSClient.
- הפעל את DeleteUserConfiguration() שיטה למחוק את תצורת המשתמש עבור תיקייה.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
SharedPtr<UserConfigurationName> userConfigName = MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri());
try
{
client->DeleteUserConfiguration(userConfigName);
}
catch (System::Exception& ex)
{
Console::WriteLine(ex->get_Message());
}
client->Dispose();