Exchange ユーザーの上司の空き時間情報を取得する
この例では、ユーザーの上司の予定表で次に空いている 60 分時間枠を表示します。
例
次のコード サンプルでは、現在のユーザーが Exchange ユーザーかどうかを調べます。 Exchange ユーザーであり、現在のユーザーに上司がいる場合は、AddressEntry オブジェクトの GetExchangeUser メソッドおよび ExchangeUser オブジェクトの GetExchangeUserManager メソッドを呼び出して、上司の情報を取得します。 上司の情報は ExchangeUser オブジェクトに格納されています。これには上司の空き時間スケジュールが含まれます。
Visual Studio を使用してこのコード例をテストする場合、Microsoft.Office.Interop.Outlook 名前空間をインポートするときに、まず Microsoft Outlook 15.0 オブジェクト ライブラリ コンポーネントへの参照を追加し、Outlook 変数を指定します。 Imports または using ステートメントは、コード例の関数の前に直接置くことはできません。パブリック Class 宣言の前に追加する必要があります。 次のコード行は、Visual Basic および C# でインポートおよび割り当てを行う方法を示しています。
Imports Outlook = Microsoft.Office.Interop.Outlook
using Outlook = Microsoft.Office.Interop.Outlook;
Private Sub GetManagerOpenInterval()
Const slotLength As Integer = 60
Dim addrEntry As Outlook.AddressEntry = _
Application.Session.CurrentUser.AddressEntry
If addrEntry.Type = "EX" Then
Dim manager As Outlook.ExchangeUser = _
Application.Session.CurrentUser. _
AddressEntry.GetExchangeUser(). _
GetExchangeUserManager()
If Not (manager Is Nothing) Then
Dim freeBusy As String = _
manager.GetFreeBusy(DateTime.Now, slotLength, True)
For i As Integer = 1 To freeBusy.Length - 1
If (freeBusy.Substring(i, 1) = "0") Then
' Get number of minutes into
' the day for free interval
Dim busySlot As Double = (i - 1) * slotLength
' Get an actual date/time
Dim dateBusySlot As DateTime = _
DateTime.Now.Date.AddMinutes(busySlot)
If (dateBusySlot.TimeOfDay >= _
DateTime.Parse("8:00 AM").TimeOfDay And _
dateBusySlot.TimeOfDay <= _
DateTime.Parse("5:00 PM").TimeOfDay And _
Not (dateBusySlot.DayOfWeek = _
DayOfWeek.Saturday Or _
dateBusySlot.DayOfWeek = DayOfWeek.Sunday))Then
Dim sb As StringBuilder = New StringBuilder()
sb.AppendLine( _
manager.Name & " first open interval:")
sb.AppendLine(dateBusySlot.ToString("f"))
Debug.WriteLine(sb.ToString())
End If
End If
Next
End If
End If
End Sub
private void GetManagerOpenInterval()
{
const int slotLength = 60;
Outlook.AddressEntry addrEntry =
Application.Session.CurrentUser.AddressEntry;
if (addrEntry.Type == "EX")
{
Outlook.ExchangeUser manager =
Application.Session.CurrentUser.
AddressEntry.GetExchangeUser().GetExchangeUserManager();
if (manager != null)
{
string freeBusy = manager.GetFreeBusy(
DateTime.Now, slotLength, true);
for (int i = 1; i < freeBusy.Length; i++)
{
if (freeBusy.Substring(i, 1) == "0")
{
// Get number of minutes into
// the day for free interval
double busySlot = (i - 1) * slotLength;
// Get an actual date/time
DateTime dateBusySlot =
DateTime.Now.Date.AddMinutes(busySlot);
if (dateBusySlot.TimeOfDay >=
DateTime.Parse("8:00 AM").TimeOfDay &
dateBusySlot.TimeOfDay <=
DateTime.Parse("5:00 PM").TimeOfDay &
!(dateBusySlot.DayOfWeek ==
DayOfWeek.Saturday |
dateBusySlot.DayOfWeek == DayOfWeek.Sunday))
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(manager.Name
+ " first open interval:");
sb.AppendLine(dateBusySlot.ToString("f"));
Debug.WriteLine(sb.ToString());
}
}
}
}
}
}