Pregunta

tengo una aplicación de sincronización con las citas de sincronización con Exchange 2010, y tengo algunas preguntas.

  1. UsuarioA crea una cita y añadir el usuario B como asistente, significa esto Usuario A es el organizador de la cita y el usuario B calendario de Outlook tendrá una entrada de cita creado.
  2. Usuario A Usuario B y cita del calendario tendrá sus propias identificaciones (UniqueID).
  3. Si, por ejemplo, yo sólo soy dado el ID (UniqueID) de cita del calendario del usuario b, que es un método para recuperar cita del calendario del usuario A? Porque creo que deberían haber alguna relación entre el organizador y el nombramiento asistentes, sólo que no sé cómo.
¿Fue útil?

Solución

Para cualquiera que venga después de mí - aquí es los detalles sobre cómo funciona este. También voy posterior referencia a mi blog con archivos de origen.

En pocas palabras - citas están vinculados entre sí mediante la propiedad UID. Esta propiedad también se denomina como la CleanUniqueIdentifier. Si bien este código de ejemplo podría ser ajustado en base a una solución "error" se hace referencia en la entrada del blog a continuación, el código fuente se hace porque los requisitos son para trabajar con => 2007 SP1.

Esto supone que usted tiene algún conocimiento previo de lo que el sistema de alerta temprana es y cómo usarlo ( EWS API ). Esto también está construyendo fuera de la entrada del blog " EWS: UID no siempre el mismo para las instancias huérfanos de la misma reunión" y post " búsqueda en una reunión con un UID específico utilizando servicios web de Exchange 2007 "

Configuración necesaria para que esto funcione:

        
  1. Cuenta de usuario que puede ser un "delegado" o tiene privilegios "suplantación" de las cuentas respectivas.

Problema: Cada "cita" a cambio tiene un identificador único (Appointment.Id) que es el identificador de instancia exacta. Tener esta identificación, ¿cómo se puede encontrar todas las instancias relacionadas (recurrentes o asistentes solicitudes) en un calendario?

El código siguiente describe cómo esto se puede lograr.

[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 );
  }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top