Obtenez le rendez-vous du calendrier de l'organisateur en utilisant SAP pour Exchange 2010

StackOverflow https://stackoverflow.com/questions/3829039

Question

J'ai une application de synchronisation avec des rendez-vous de synchronisation avec Exchange 2010, et j'ai quelques questions.

  1. UserA crée un rendez-vous et ajoutez UtilisateurB comme participant, ce moyen UserA est l'organisateur du rendez-vous et le calendrier des perspectives UtilisateurB auront une entrée de rendez-vous créé.
  2. UserA et rendez-vous de calendrier UtilisateurB auront leurs propres ID (ID unique).
  3. Si, par exemple je ne suis donné l'ID (ID unique) de la nomination de calendrier UtilisateurB, est qu'une méthode pour récupérer le rendez-vous du calendrier de UserA? Parce que je pense qu'ils devraient avoir un lien entre l'organisateur et la nomination des participants, je ne sais pas comment.
Était-ce utile?

La solution

Pour ceux qui viennent après moi - voici les détails sur la façon dont cela fonctionne. Je vais aussi référence après sur mon blog avec des fichiers source.

En bref - rendez-vous sont attachés ensemble en utilisant la propriété UID. Cette propriété est aussi appelée la CleanUniqueIdentifier. Bien que ce code exemple pourrait être ajustée en fonction d'une solution « bug » référencé dans le blog ci-dessous, ce code source est fait parce que les exigences sont de travailler avec => 2007 SP1.

Cela suppose que vous avez une certaine connaissance préalable de ce que le SAP est et comment l'utiliser ( EWS API ). Ceci est également hors de la construction de blog « EWS: UID pas toujours les mêmes pour les cas orphelins de la même réunion " et après " Recherche d'une réunion avec un UID spécifique en utilisant des services Web Exchange 2007 "

Configuration requise pour que cela fonctionne:

        
  1. Compte d'utilisateur qui peut être un « délégué » ou a des privilèges « Usurpation » pour les comptes respectifs.

Problème: Chaque « rendez-vous » en échange est un identifiant unique (Appointment.Id) qui est l'identificateur d'instance exacte. Ayant cette id, comment peut-on trouver tous les cas connexes (récurrents ou Prsence demandes) dans un calendrier?

Le code ci-dessous décrit comment cela peut être accompli.

[TestFixture]
public class BookAndFindRelatedAppoitnmentTest
{
  public const string ExchangeWebServiceUrl = "https://contoso.com/ews/Exchange.asmx";

  [Test]
  public void TestThatAppointmentsAreRelated()
  {
    ExchangeService service = GetExchangeService();

    //Impersonate the user who is creating the Appointment request
    service.ImpersonatedUserId = new ImpersonatedUserId( ConnectingIdType.PrincipalName, "Test1" );
    Appointment apptRequest = CreateAppointmentRequest( service, new Attendee( "Test2@contoso.com" ) );

    //After the appointment is created, we must rebind the data for the appointment in order to set the Unique Id
    apptRequest = Appointment.Bind( service, apptRequest.Id );

    //Impersonate the Attendee and locate the appointment on their calendar
    service.ImpersonatedUserId = new ImpersonatedUserId( ConnectingIdType.PrincipalName, "Test2" );
    //Sleep for a second to let the meeting request propogate YMMV so you may need to increase the sleep for this test
    System.Threading.Thread.Sleep( 1000 );
    Appointment relatedAppt = FindRelatedAppointment( service, apptRequest );

    Assert.AreNotEqual( apptRequest.Id, relatedAppt.Id );
    Assert.AreEqual( apptRequest.ICalUid, relatedAppt.ICalUid );
  }

  private static Appointment CreateAppointmentRequest( ExchangeService service, params Attendee[] attendees )
  {
    // Create the appointment.
    Appointment appointment = new Appointment( service )
    {
      // Set properties on the appointment.
      Subject = "Test Appointment",
      Body = "Testing Exchange Services and Appointment relationships.",
      Start = DateTime.Now,
      End = DateTime.Now.AddHours( 1 ),
      Location = "Your moms house",
    };

    //Add the attendess
    Array.ForEach( attendees, a => appointment.RequiredAttendees.Add( a ) );

    // Save the appointment and send out invites
    appointment.Save( SendInvitationsMode.SendToAllAndSaveCopy );

    return appointment;
  }

  /// <summary>
  /// Finds the related Appointment.
  /// </summary>
  /// <param name="service">The service.</param>
  /// <param name="apptRequest">The appt request.</param>
  /// <returns></returns>
  private static Appointment FindRelatedAppointment( ExchangeService service, Appointment apptRequest )
  {
    var filter = new SearchFilter.IsEqualTo
    {
      PropertyDefinition = new ExtendedPropertyDefinition
        ( DefaultExtendedPropertySet.Meeting, 0x03, MapiPropertyType.Binary ),
      Value = GetObjectIdStringFromUid( apptRequest.ICalUid ) //Hex value converted to byte and base64 encoded
    };

    var view = new ItemView( 1 ) { PropertySet = new PropertySet( BasePropertySet.FirstClassProperties ) };

    return service.FindItems( WellKnownFolderName.Calendar, filter, view ).Items[ 0 ] as Appointment;
  }

  /// <summary>
  /// Gets the exchange service.
  /// </summary>
  /// <returns></returns>
  private static ExchangeService GetExchangeService()
  {
    //You can use AutoDiscovery also but in my scenario, I have it turned off      
    return new ExchangeService( ExchangeVersion.Exchange2007_SP1 )
    {
      Credentials = new System.Net.NetworkCredential( "dan.test", "Password1" ),
      Url = new Uri( ExchangeWebServiceUrl )
    };
  }

  /// <summary>
  /// Gets the object id string from uid.
  /// <remarks>The UID is formatted as a hex-string and the GlobalObjectId is displayed as a Base64 string.</remarks>
  /// </summary>
  /// <param name="id">The uid.</param>
  /// <returns></returns>
  private static string GetObjectIdStringFromUid( string id )
  {
    var buffer = new byte[ id.Length / 2 ];
    for ( int i = 0; i < id.Length / 2; i++ )
    {
      var hexValue = byte.Parse( id.Substring( i * 2, 2 ), System.Globalization.NumberStyles.AllowHexSpecifier );
      buffer[ i ] = hexValue;
    }
    return Convert.ToBase64String( buffer );
  }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top