Validate method

  1. @override
void Validate()
override
Validates this instance.

Implementation

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

  for (
    int attachmentIndex = 0;
    attachmentIndex < AddedItems.length;
    attachmentIndex++
  ) {
    Attachment attachment = 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 (_owner!.IsNew &&
          _owner!.Service.RequestedServerVersion.index >=
              ExchangeVersion.Exchange2010_SP2.index) {
        FileAttachment fileAttachment = attachment as FileAttachment;

        if (fileAttachment.IsContactPhoto!) {
          if (contactPhotoFound) {
            throw ServiceValidationException(
              "Strings.MultipleContactPhotosInAttachment",
            );
          }

          contactPhotoFound = true;
        }
      }

      attachment.ValidateWithIndex(attachmentIndex);
    }
  }
}