4

我正在使用 ExchangeService(ExchangeVersion.Exchange2010_SP1)

我想接受并将类别添加到RequiredAttendees 约会。为此,我需要找到这些约会。

我在 EWS 中的理解是,在保存具有RequiredAttendees 的约会时,会为每个“必需的与会者”创建一个新的会议请求。

如何访问为“必需的与会者”自动创建的约会?这些在所需的与会者日历中显示为约会,以及会议请求。

我设法对主题进行了粗略的发现(以下步骤)

  1. 作为 Organizer 连接到服务器
  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 赶上约会。在我看来,这样做的一个好方法是同时运行 Organizer 和 Attendee,并赶上他们之间的约会。要查看示例,我已经发布了对上一个问题Multiple impersonation-threads in Exchange Web Service (EWS)的答案。如果您发现我的答案很有用,请为这两个帖子的答案(这里和那里)投票。

我不想让你害怕,但是一旦你解决了你当前的问题;如果你想继续它会变得更复杂。我可以写下我是如何解决会议问题的,但我根本看不出来,所以如果你自己写可能会更好。

干杯

于 2013-02-15T08:39:26.430 回答