Actualizar una serie periódica mediante EWS
Obtenga información sobre cómo modificar citas en una serie periódica mediante la API administrada ews o EWS en Exchange.
Puede usar la API administrada ews o EWS para actualizar una serie periódica actualizando toda la serie o actualizando una única repetición. En este artículo trataremos cómo actualizar una única repetición.
Modificar una sola cita de una serie es muy similar a modificar una cita de instancia única. Se usan los mismos métodos y operaciones, pero se usa el identificador de elemento de la repetición que desea cambiar.
Cuando se cambia una sola repetición de una serie, esa repetición se agrega a una matriz de citas modificadas asociadas con el patrón periódico de la serie. Puede usar la propiedad DE API administrada EWS Appointment.ModifiedOccurrences o el elemento EWS ModifiedOccurrences para tener acceso a todas las citas de una serie que se han modificado.
Enlazar a la repetición que desea modificar mediante el método Appointment.BindToOccurrence con el valor de índice del elemento o el método Appointment.Bind con el identificador de la repetición. Este identificador se obtiene de la propiedad Id de un objeto Appointment que corresponde a la ocurrencia o de la propiedad ItemId del objeto OccurrenceInfo que corresponde a la repetición.
Actualice las propiedades del objeto Appointment de la ocurrencia.
Guarde los cambios en el objeto de cita de la aparición mediante el método Appointment.Save .
En el ejemplo siguiente se actualiza una cita de una serie periódica y se comprueba que la cita modificada se actualiza en el patrón periódico. En este ejemplo se supone que se ha autenticado en un servidor Exchange y que ha adquirido un objeto ExchangeService denominado servicio. El recurrenceMasterId
parámetro es un identificador asociado con el patrón periódico para la repetición que se va a modificar.
public static ItemId ModifyARecurringSeries(ExchangeService service, ItemId recurrenceMasterId)
{
Appointment calendarItem = Appointment.Bind(service, recurrenceMasterId, new PropertySet(AppointmentSchema.AppointmentType));
Appointment recurrMaster = new Appointment(service);
if (calendarItem.AppointmentType == AppointmentType.RecurringMaster)
{
// Get the recurring master from an occurrence in a recurring series with the properties you need.
recurrMaster = Appointment.Bind(service,
recurrenceMasterId,
new PropertySet(AppointmentSchema.AppointmentType,
AppointmentSchema.Subject,
AppointmentSchema.FirstOccurrence,
AppointmentSchema.LastOccurrence,
AppointmentSchema.ModifiedOccurrences,
AppointmentSchema.DeletedOccurrences));
}
else
{
Console.WriteLine("Item id was not for a recurring master.");
return recurrenceMasterId;
}
// Bind to the second occurrence in the series with the properties to modify.
Appointment occurrenceToModify = Appointment.BindToOccurrence(service,
recurrMaster.Id,
2,
new PropertySet(AppointmentSchema.Location,
AppointmentSchema.Start,
AppointmentSchema.End,
AppointmentSchema.RequiredAttendees,
AppointmentSchema.Subject));
// Update the properties you want to change.
occurrenceToModify.Location = "Helipad of Contoso Bldg 1";
occurrenceToModify.Start = occurrenceToModify.Start.AddDays(1);
occurrenceToModify.End = occurrenceToModify.End.AddDays(1);
occurrenceToModify.RequiredAttendees.Add("Contoso CEO", "sadie@contoso");
occurrenceToModify.RequiredAttendees.Add("Contoso Head of Research", "ronnie@contoso.com");
occurrenceToModify.RequiredAttendees.Add("Contoso Head of Security", "alfred@contoso.com");
occurrenceToModify.Subject = occurrenceToModify.Subject.ToString() + ":Mandatory";
// Update the occurrence in your calendar folder and send meeting update requests to attendees.
// This method call results in an UpdateItem request to EWS.
occurrenceToModify.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);
// View updated and deleted occurrences on the recurring master prior to retrieving updated information.
Console.WriteLine("Modified Occurrences prior to updating recurring master: {0}",
(recurrMaster.ModifiedOccurrences == null ? "None" : recurrMaster.ModifiedOccurrences.Count.ToString()));
// Update the recurring master to view the modified and deleted occurrences.
recurrMaster = Appointment.Bind(service, recurrenceMasterId, new PropertySet(AppointmentSchema.ModifiedOccurrences,
AppointmentSchema.DeletedOccurrences));
// View updated and deleted occurrences on the recurring master after retrieving updated information.
Console.WriteLine("Modified Occurrences after updating recurring master:\t {0}",
(recurrMaster.ModifiedOccurrences == null ? "None" : recurrMaster.ModifiedOccurrences.Count.ToString()));
return recurrMaster.Id;
}
Modificar una sola instancia de una serie es básicamente lo mismo que modificar una cita de instancia única. Puede especificar la repetición que se va a cambiar mediante un elemento ItemId o occurrenceItemId .
En el ejemplo siguiente se muestra el XML de solicitud cuando se usa la operación UpdateItem para actualizar una repetición en una serie periódica de citas. ItemId y ChangeKey se acortan para que sean legibles.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types"
xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010" />
</soap:Header>
<soap:Body>
<m:UpdateItem ConflictResolution="AlwaysOverwrite" SendMeetingInvitationsOrCancellations="SendToAllAndSaveCopy">
<m:ItemChanges>
<t:ItemChange>
<t:ItemId Id="AAMkA" ChangeKey="DwAAAB" />
<t:Updates>
<t:SetItemField>
<t:FieldURI FieldURI="calendar:Location" />
<t:CalendarItem>
<t:Location>Helipad of Contoso Bldg 1</t:Location>
</t:CalendarItem>
</t:SetItemField>
<t:SetItemField>
<t:FieldURI FieldURI="calendar:Start" />
<t:CalendarItem>
<t:Start>2014-03-27T19:33:00.000-07:00</t:Start>
</t:CalendarItem>
</t:SetItemField>
<t:SetItemField>
<t:FieldURI FieldURI="calendar:End" />
<t:CalendarItem>
<t:End>2014-03-27T20:33:00.000-07:00</t:End>
</t:CalendarItem>
</t:SetItemField>
<t:SetItemField>
<t:FieldURI FieldURI="calendar:RequiredAttendees" />
<t:CalendarItem>
<t:RequiredAttendees>
<t:Attendee>
<t:Mailbox>
<t:Name>Mack@contoso.com</t:Name>
<t:EmailAddress>Mack@contoso.com</t:EmailAddress>
<t:RoutingType>SMTP</t:RoutingType>
</t:Mailbox>
</t:Attendee>
<t:Attendee>
<t:Mailbox>
<t:Name>Sadie@contoso.com</t:Name>
<t:EmailAddress>Sadie@contoso.com</t:EmailAddress>
<t:RoutingType>SMTP</t:RoutingType>
</t:Mailbox>
</t:Attendee>
<t:Attendee>
<t:Mailbox>
<t:Name>Magdalena@contoso.com</t:Name>
<t:EmailAddress>Magdalena@contoso.com</t:EmailAddress>
<t:RoutingType>SMTP</t:RoutingType>
</t:Mailbox>
</t:Attendee>
<t:Attendee>
<t:Mailbox>
<t:Name>Contoso CEO</t:Name>
<t:EmailAddress>sadie@contoso</t:EmailAddress>
</t:Mailbox>
</t:Attendee>
<t:Attendee>
<t:Mailbox>
<t:Name>Contoso Head of Research</t:Name>
<t:EmailAddress>ronnie@contoso.com</t:EmailAddress>
</t:Mailbox>
</t:Attendee>
<t:Attendee>
<t:Mailbox>
<t:Name>Contoso Head of Security</t:Name>
<t:EmailAddress>alfred@contoso.com</t:EmailAddress>
</t:Mailbox>
</t:Attendee>
</t:RequiredAttendees>
</t:CalendarItem>
</t:SetItemField>
<t:SetItemField>
<t:FieldURI FieldURI="item:Subject" />
<t:CalendarItem>
<t:Subject>Weekly Update Meeting:Mandatory</t:Subject>
</t:CalendarItem>
</t:SetItemField>
</t:Updates>
</t:ItemChange>
</m:ItemChanges>
</m:UpdateItem>
</soap:Body>
</soap:Envelope>
El servidor responde a la solicitud UpdateItem con un mensaje UpdateItemResponse que incluye un valor ResponseCode de NoError, que indica que la repetición se actualizó correctamente y itemid de la cita actualizada.