Validate method

void Validate()
override
Validates this instance.

Implementation

void Validate() {
  // Validate all added attachments
  bool contactPhotoFound = false;

  for (int attachmentIndex = 0;
      attachmentIndex < this.AddedItems.length;
      attachmentIndex++) {
    Attachment attachment = this.AddedItems[attachmentIndex];
    if (attachment.IsNew) {
      // At the server side, only the last attachment with IsContactPhoto is kept, all other IsContactPhoto
      // attachments are removed. CreateAttachment will generate AttachmentId for each of such attachments (although
      // only the last one is valid).
      //
      // With E14 SP2 CreateItemWithAttachment, such request will only return 1 AttachmentId; but the client
      // expects to see all, so let us prevent such "invalid" request in the first place.
      //
      // The IsNew check is to still let CreateAttachmentRequest allow multiple IsContactPhoto attachments.
      //
      if (this._owner!.IsNew &&
          this._owner!.Service.RequestedServerVersion.index >=
              ExchangeVersion.Exchange2010_SP2.index) {
        FileAttachment fileAttachment = attachment as FileAttachment;

        if (fileAttachment != null && fileAttachment.IsContactPhoto!) {
          if (contactPhotoFound) {
            throw new ServiceValidationException(
                "Strings.MultipleContactPhotosInAttachment");
          }

          contactPhotoFound = true;
        }
      }

      attachment.ValidateWithIndex(attachmentIndex);
    }
  }
}