EWS Save Guid for calendar appointment

I need to keep the Manual for each Assignment. I tried using PolicyTag

and ArchiveTag

but got

"Property PolicyTag is only valid for Exchange Exchange 2013 or later.",

an exception.

Do we have something similar for Exchange 2010? As I understand it, there is appointment.ID

one that contains a self-generated id. I prefer not to use it. Thank.

+3


source to share


1 answer


The way around this problem is to create an extended property and assign a pointer to the assignment, and this won't change unless you made a copy from another appointment (after all, it's just a property)

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;
} 

      



This solution works very well for single meetings and for On Premises Exchange. The problem here is in the case of online access (OWA) appointments such as Office 365, the appointment properties are copied from the original meeting organizer, among these properties are extended properties, among which is AppoinmentID.Therefore, to avoid this problem, we assign the meeting ID of the attendee. similar to the original in the organizer, and just add the email address for the owner of the service (the service that issued the notification). Without this solution, the destination in the internal system will have the same destination ID for the original booking and it will be treated as one, or you may have two different destinations with the same ID.

 private static void SetGuidForMeetingAppiontment(Appointment appointment)
        {
            var log = "";

            try
            {
                if (!appointment.IsMeeting) return;
                if (appointment.Service.ImpersonatedUserId == null) return;

                /*
                 * The only tricky case is that if the appointment is created at the attendee with no Guid.
                 * In this case the application should look for the original appointment from the organizer side, and get its guid, to paste it in the new booking 
                 * from the attendee side, and add the attendee emailAddress. 
                 */
                if (GetGuidForMeetingAppointement(appointment).Length <= 36)
                {
                    // If it was an attendee, then look for the original appointment from the organizer service
                    if (appointment.Service.ImpersonatedUserId.Id != appointment.Organizer.Address)
                    {

                        log += "1/5 Getting the original event of the meeting\n";
                        if (ExchangeLiteService.Services.ContainsKey(appointment.Organizer.Address))
                        {
                            //  FindItemsResults<Appointment> originalAppointments;
                            var originalAppointments = ExchangeLiteService.Services[appointment.Organizer.Address].FindAppointments(WellKnownFolderName.Calendar, new CalendarView(appointment.Start, appointment.End, 1));
                            if (originalAppointments == null) return; //there must be an original appointment. 
                            if (!originalAppointments.Any()) return; //there must be an original appointment. 
                            var originalAppointment = originalAppointments.First(); // there should be only one appointment at a specifict time and date. 

                            log += "2/5 Getting the Guid for the original event of the meeting\n";
                            var originalAppointmentID = GetGuidForMeetingAppointement(originalAppointment);
                            if (string.IsNullOrEmpty(originalAppointmentID)) return; // the original appointment must have a guid already.

                            var orignalAppointmentIDGuid = originalAppointmentID.Substring(0, 36);

                            log += "3/5 Attaching the email address to the guid extracted\n";
                            var newAppointmentID = orignalAppointmentIDGuid + "_" + appointment.Service.ImpersonatedUserId.Id;

                            log += "4/5 Setting the new Guid to the meeting appointment\n";
                            appointment.SetExtendedProperty((ExtendedPropertyDefinition)AppointementIdPropertyDefinition, newAppointmentID);

                            log += "5/5 Updateing the meeting appointment\n";
                            appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone);
                        }
                        else //Then the user is invited from an organizer outside the system.
                        {
                            // Delete if there are anything similar 
                            ExchangeLiteService.OnCallDeleteBookingFromInternal(appointment.Service.ImpersonatedUserId.Id, appointment.Start, appointment.End);

                            //Assign a new 
                            var appointmentIDGuid = Guid.NewGuid().ToString();
                            var newAppointmentID = appointmentIDGuid + "_" + appointment.Service.ImpersonatedUserId.Id;
                            appointment.SetExtendedProperty((ExtendedPropertyDefinition)AppointementIdPropertyDefinition, newAppointmentID);
                            appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone);

                        }
                        //Get only the guid part of it (without the address of the organizer) 
                    }
                    else // if he was the organizer 
                    {
                        log += "If it was new meeting appointment and the notification from the organizer\n";
                        var appointmentIDGuid = Guid.NewGuid().ToString();
                        var newAppointmentID = appointmentIDGuid + "_" + appointment.Service.ImpersonatedUserId.Id;
                        appointment.SetExtendedProperty((ExtendedPropertyDefinition)AppointementIdPropertyDefinition, newAppointmentID);
                        appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone);
                    }
                }
                else
                {
                    log += "If it was an updated meeting appointment and has Guid already\n";
                    var appointmentID = GetGuidForMeetingAppointement(appointment);
                    var appointmentIDGuid = appointmentID.Substring(0, 36);
                    var newAppointmentID = appointmentIDGuid + "_" + appointment.Service.ImpersonatedUserId.Id;
                    appointment.SetExtendedProperty((ExtendedPropertyDefinition)AppointementIdPropertyDefinition, newAppointmentID);
                    appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone);
                }
            }
            catch (Exception ex)
            {
                //Logging the exception
            }

        }

      

+4


source







All Articles