2013-02-11 57 views
3

我需要每次預約時保存指導。 我試着使用PolicyTagArchiveTag,卻得到了一個,EWS每日預約保存指南

「的屬性PolicyTag僅供交流Exchange2013或 更高版本有效。」,

例外。

我們對Exchange 2010有類似的東西嗎? 據我瞭解,有appointment.ID包含自我生成的ID。 我不喜歡使用它。 謝謝。

回答

4

來處理這個問題的方法是創建一個擴展屬性,把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; 
} 

此解決方案在單一約會和使用On Premises Exchange的情況下工作得非常好。這裏的問題是在聯機Web訪問(OWA)中的會議(如Office 365)中,約會的屬性從組織者的原約會中複製而來,其中屬性是AppoinmentID在其中的擴展屬性。 因此,爲了避免這種麻煩,我們使與會者的預約ID與組織者中的原始預約ID類似,併爲服務所有者(生成通知的服務)添加電子郵件地址。 如果沒有此解決方案,內部系統中的約會將與原始預訂具有相似的AppointmentID,並且它將被視爲一個,或者您可能具有不同的兩個具有相同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's 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's 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 
      } 

     } 
+0

感謝此代碼。我試過了,它工作得很好。這是否意味着我不能使用約會uniqueId更新,取消約會,因爲它會在一段時間後改變?我可以使用此GUID綁定到會議,然後更新它,取消它嗎? – Morano88 2013-06-05 05:44:16

+1

關於唯一的ID,是的,你可以使用它,但是很難跟蹤它,尤其是如果約會移動到另一個文件夾,例如,如果它被刪除,儘管你得到的通知來自同一約會,但是UniqueID將會改變,因此如果你將uniqueID作爲主鍵映射,你將有兩行用於同一約會 – BraveHeart 2013-06-05 08:37:21

+2

在會議中,它是不同且棘手的部分。一旦組織者創建會議並將其發送給與會者,它實際上會將相同約會對象的副本發送給與會者。 約會創建後,當然擴展屬性(「AppointmentID」)將爲空,然後將被髮送給與會者。在這種情況下(在新創建的情況下)可以,因爲參與者將約會視爲新約會並放置自己的GUID。但!一旦組織者改變了會議,它將覆蓋剩下的所有屬性,包括我們的「AppointmentID」! – BraveHeart 2013-06-05 09:01:26