4

ExchangeService(ExchangeVersion.Exchange2010_SP1) を使用しています

RequiredAttendees Appointments にカテゴリを承認して追加したいです。これを行うには、これらの予定を見つける必要があります。

EWS での私の理解では、RequiredAttendees を持つ予定を保存すると、「必要な出席者」ごとに新しい会議出席依頼が作成されます。

「必要な出席者」のために自動的に作成された予定にアクセスするにはどうすればよいですか? これらは、会議出席依頼とともに、必要な出席者の予定表に予定として表示されます。

件名で大まかな検索を行うことができました(以下の手順)

  1. オーガナイザーとしてサーバーに接続する
  2. 予約を作成する
  3. 件名を設定
  4. 必須出席者を追加
  5. 予約を保存

  6. 手順 4 の必須参加者としてサーバーに接続します。

  7. 手順 3 で件名を持つ予定を検索します。
  8. ステップ 7 で予定にカテゴリを追加する
  9. ステップ 7 で予定を更新する
  10. ステップ7で予約を受け入れる

これは機能しますが、関係するユーザーは件名を変更します。

開催者によって作成された予定に拡張プロパティと値を追加してから、必須出席者として接続された予定の拡張プロパティ値の FindItems を追加しようとしました。これは動作しません。

私が達成しようとしていることに対する好ましい方法はありますか?

ありがとうございました

Private Shared ReadOnly m_organiserEmailAddress As String = "Organiser@test.com"
Private Shared ReadOnly m_eventIdExtendedPropertyDefinition As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Meeting, "EventId", MapiPropertyType.Long)

'--> start here
Public Shared Function SaveToOutlookCalendar(eventCalendarItem As EventCalendarItem) As String

    If eventCalendarItem.Id Is Nothing Then
        'new
        Dim newAppointment = EventCalendarItemMapper.SaveNewAppointment(eventCalendarItem)
        'set the Id
        eventCalendarItem.Id = newAppointment.Id.UniqueId.ToString()
        'accept the calendar item on behalf of the Attendee
        EventCalendarItemMapper.AcceptAppointmentAsAttendees(newAppointment)
        Return eventCalendarItem.Id
    Else
        'update existing appointment
        Return EventCalendarItemMapper.UpdateAppointment(eventCalendarItem)
    End If


End Function

Private Shared Sub ConnectToServer(Optional autoUser As String = "")

    If autoUser = "" Then
        _service.Url = New Uri(ExchangeWebServicesUrl)
    Else
        _service.AutodiscoverUrl(autoUser)
    End If

End Sub

Private Shared Sub ImpersonateUser(userEmail As String)

    _service.Credentials = New NetworkCredential(ImpersonatorUsername, ImpersonatorPassword, Domain)
    _service.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, userEmail)

End Sub

Private Shared Function SaveNewAppointment(eventCalendarItem As EventCalendarItem) As Appointment

    Try
        ConnectToServer(m_organiserEmailAddress)
        ImpersonateUser(m_organiserEmailAddress)

        Dim appointment As New Appointment(_service) With {
                   .Subject = eventCalendarItem.Subject}

        'add attendees
        For Each attendee In eventCalendarItem.Attendees
            appointment.RequiredAttendees.Add(attendee.Email)
        Next

        'add categories
        For Each category In eventCalendarItem.Categories
            appointment.Categories.Add(Globals.GetEnumDescription(category))
        Next

        'add EventId = 5059 as an extended property of the appointment
        appointment.SetExtendedProperty(m_eventIdExtendedPropertyDefinition, 5059)

        appointment.Save(SendInvitationsMode.SendOnlyToAll)

        Return appointment
    Catch
        Throw New Exception("Can't save appointment")
    End Try


End Function

Private Shared Sub AcceptAppointmentAsAttendees(appointment As Appointment)

    For Each attendee In appointment.RequiredAttendees
        Try
            ConnectToServer(attendee.Address.ToString())
            ImpersonateUser(attendee.Address.ToString())

            For Each a In FindRelatedAppiontments(appointment)
                a.Categories.Add(Globals.GetEnumDescription(CalendarItemCategory.Workshop))
                a.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone)
                a.Accept(True)
            Next

        Catch
            Throw
        End Try
    Next
End Sub

Private Shared Function FindRelatedAppiontments(appointment As Appointment) As List(Of Appointment)

    Dim view As New ItemView(1000)
    Dim foundAppointments As New List(Of Appointment)

    view.PropertySet =
        New PropertySet(New PropertyDefinitionBase() {m_eventIdExtendedPropertyDefinition})

    'Extended Property value = 5059
    Dim searchFilter = New SearchFilter.IsEqualTo(m_eventIdExtendedPropertyDefinition, 5059)

    For Each a In _service.FindItems(WellKnownFolderName.Calendar, searchFilter, view)
        If a.ExtendedProperties.Count > 0 Then
            foundAppointments.Add(appointment.Bind(_service, CType(a.Id, ItemId)))
        End If
    Next

    Return foundAppointments

End Function
4

1 に答える 1

2

確かに、EWSには単純なものは何もありません。正直に言うと、今のところ、内部カレンダーからExchangeカレンダーへの統合には取り組んでいませんでした。私の経験は逆で、交換で内部カレンダーに何を取得するかということです。

とにかくあなたのコードを読んだ後、私はあなたがほとんどそこにいると思います。ただし、ストリーミング通知を使用して出席者に届く予定をキャッチすることをお勧めします。それほど難しくはありません。だから私はステップがこのようになるべきだと思います

  1. 予定を作成する
  2. 次のように拡張プロパティを適用します(ハードコードされた番号の代わりにGUIDを使用することをお勧めします)

拡張プロパティを作成し、予定のGUIDを配置します。別の予定からコピーを作成しない限り、変更されません(結局のところ、これは単なるプロパティです)

private static readonly PropertyDefinitionBase AppointementIdPropertyDefinition = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "AppointmentID", MapiPropertyType.String);
public static PropertySet PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, AppointementIdPropertyDefinition);


//Setting the property for the appointment 
 public static void SetGuidForAppointement(Appointment appointment)
{
    try
    {
        appointment.SetExtendedProperty((ExtendedPropertyDefinition)AppointementIdPropertyDefinition, Guid.NewGuid().ToString());
        appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone);
    }
    catch (Exception ex)
    {
        // logging the exception
    }
}

//Getting the property for the appointment
 public static string GetGuidForAppointement(Appointment appointment)
{
    var result = "";
    try
    {
        appointment.Load(PropertySet);
        foreach (var extendedProperty in appointment.ExtendedProperties)
        {
            if (extendedProperty.PropertyDefinition.Name == "AppointmentID")
            {
                result = extendedProperty.Value.ToString();
            }
        }
    }
    catch (Exception ex)
    {
     // logging the exception
    }
    return result;
} 
  1. StreamingNotificationEventで予定をキャッチします。私の意見では、それを行うための良い方法は、オーガナイザーと参加者の両方を同時に実行し、それらの間の予定をキャッチすることです。例を示すために、前の質問に対する回答を投稿しました。ExchangeWebサービス(EWS)の複数の偽装スレッド。私の回答が役に立ったと思ったら、両方の投稿(こことそこ)の回答に投票してください。

私はあなたを怖がらせたくはありませんが、あなたが現在の問題を解決したら、続行したい場合は、より複雑になります。会議の問題をどのように解決したかを書き留めることはできますが、それがまったくわかりにくいので、自分で書いた方がよいかもしれません。

乾杯

于 2013-02-15T08:39:26.430 に答える