Как записаться на прием в EWS от uniqueId - PullRequest
0 голосов
/ 31 марта 2020

Я создаю встречу, используя EWS без проблем. Я сохраняю уникальный идентификатор как этот

Dim rdvEncours As DevisRdv = GetRdv(ConnectedUser,LesDatas) 
Appointment.Save(New FolderId(WellKnownFolderName.Calendar, rdvEncours.Collaborateur.Mail))
rdvEncours.ExchangeId = Appointment.Id.UniqueId
LesDatas.SaveChange();

После того, как я хочу удалить его. У меня есть рабочая функция, основанная на названии, дне, часе, но она не совсем безопасна. Затем я хочу использовать свой UniqueId. Затем я создаю эту функцию

Public Function FindAppointment(Service As ExchangeService, UnikId As String) As Appointment
    Dim CalendarFolder As CalendarFolder = CalendarFolder.Bind(Service, New FolderId(WellKnownFolderName.Calendar, ml), New PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount))

    ' Set the number of items to the smaller of the number of items in the Contacts folder Or 1000.
    Dim numItems As Integer = If(CalendarFolder.TotalCount < 1000, CalendarFolder.TotalCount, 1000)

    ' Instantiate the item view with the number of items to retrieve from the contacts folder.
    ' To keep the request smaller, send only the display name.
    Dim View As ItemView = New ItemView(numItems) With {.PropertySet = New PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.End, AppointmentSchema.Start)}

    ' Create a searchfilter to check the subject of the tasks.
    Dim searchFilter As SearchFilter.SearchFilterCollection = New SearchFilter.SearchFilterCollection From {New SearchFilter.IsEqualTo(ItemSchema.Id, UnikId)}

    ' Retrieve the items in the Calendar folder with the properties you selected.
    Dim taskItems = Service.FindItems(New FolderId(WellKnownFolderName.Calendar, ml), searchFilter, View)

    If taskItems.Count = 1 AndAlso TypeOf taskItems.Items(0) Is Appointment Then
        Return taskItems.Items(0)
        HelperJournal.WriteEntry("Find Rdv by id") 'TODO:A mettre ne commentaire quand vérifier
    Else
        Return Nothing
    End If

End Function

Я называю это так

Dim FoundTask As Appointment = FindAppointment(ConnectToExchange(), rdvEncours.ExchangeId)
If (FoundTask IsNot Nothing) Then FoundTask.Delete(DeleteMode.HardDelete)

Но произошла ошибка в FindAppointment

Сообщение : Неизведанное. Не имеет смысла для собственности. Исключение: Microsoft.Exchange.WebServices.Data.ServiceResponseException: недопустимо большое значение для собственников. à Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNe необходимое (); Представление ViewBase, Группировка groupBy, ServiceErrorHandling errorHandlingMode) à Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems (FolderId parentFolderId, SearchFilter searchFilter, представление ViewBase) à Maximus.HelperAgendaGerviceHerviceDerviceDervice_Применение_Предприятия_объекту : ligne 50 à Maximus.VisuDevis.PoseInter (SetDevisRDV MesDonnees) dans XXX \ VisuDevis.aspx.vb: ligne 560 Дополнительная информация: Подавление RDV dans calendrier

Ответы [ 2 ]

0 голосов
/ 22 апреля 2020

Комментарии Глена от 6/6/2020 - это правильный ответ. Вот краткое изложение

 Dim Appointment As New Appointment(service) With {
     .Subject = "MySubject",
     .Start = rdvEncours.DteInter,
     .Body = "MyBody",
     .Importance = Importance.High
 }
 Appointment.End = Appointment.Start.AddHours(1)
 Dim MaClef As String = getRandomString(256)
 Appointment.SetExtendedProperty(GetCustomKeyAppointment, MaClef)

 Appointment.Save(New FolderId(WellKnownFolderName.Calendar, rdvEncours.Collaborateur.Mail))
 rdvEncours.ExchangeId = MaClef
 LesDatas.SaveChanges()

И, как и вам, нужно иметь одну ссылку для вашего нового пользовательского ключа в модуле, который я

 ' Get the GUID for the property set.
Private Const MyCustomKeySetId As String = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"

Public Function GetCustomKeyAppointment() As ExtendedPropertyDefinition
    Return New ExtendedPropertyDefinition(New Guid(MyCustomKeySetId), "Mykey", MapiPropertyType.String)
End Function

И, чтобы найти свою встречу

 Public Function FindAppointment(Service As ExchangeService, UnikId As String) As Appointment
    Dim CalendarFolder As CalendarFolder = CalendarFolder.Bind(Service, New FolderId(WellKnownFolderName.Calendar, ml), New PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount))

    ' Set the number of items to the smaller of the number of items in the Contacts folder Or 1000.
    Dim numItems As Integer = If(CalendarFolder.TotalCount < 1000, CalendarFolder.TotalCount, 1000)

    ' Instantiate the item view with the number of items to retrieve from the contacts folder.
    ' To keep the request smaller, send only the display name.
    Dim View As ItemView = New ItemView(numItems) With {.PropertySet = New PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.End, AppointmentSchema.Start)}

    ' Create a searchfilter to check the subject of the tasks.
    Dim searchFilter As SearchFilter = New SearchFilter.IsEqualTo(GetCustomKeyAppointment, UnikId)

    ' Retrieve the items in the Calendar folder with the properties you selected.
    Dim taskItems = Service.FindItems(New FolderId(WellKnownFolderName.Calendar, ml), searchFilter, View)

    If taskItems.Count = 1 AndAlso TypeOf taskItems.Items(0) Is Appointment Then
        Return taskItems.Items(0)

    Else
        Return Nothing
    End If

End Function
0 голосов
/ 01 апреля 2020

Если у вас есть ItemId, вы можете просто привязать его непосредственно к элементу календаря, фактическое свойство не доступно для поиска, поэтому не будет работать в findItems. Но просто используйте

Appointment aptItem = Appointment.Bind(service, ItemId);

То, что указанное хранение и привязка к Itemid может быть проблематичным c см. https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/ews-identifiers-in-exchange, так как эти itemId могут измениться.

...