Example #1
0
        // Token: 0x06000935 RID: 2357 RVA: 0x000367A0 File Offset: 0x000349A0
        public ADABContact(ABSession ownerSession, ADRecipient recipient) : base(ownerSession)
        {
            if (recipient == null)
            {
                throw new ArgumentNullException("recipient");
            }
            if (recipient.Id == null)
            {
                throw new ArgumentException("recipient.Id can't be null.", "recipient.Id");
            }
            switch (recipient.RecipientType)
            {
            case RecipientType.MailUniversalDistributionGroup:
            case RecipientType.MailUniversalSecurityGroup:
            case RecipientType.MailNonUniversalGroup:
            case RecipientType.DynamicDistributionGroup:
                throw new ArgumentException("RecipientType " + recipient.RecipientType.ToString() + " shouldn't be wrapped in an ADABContact.", "recipient");

            default:
                this.recipient = recipient;
                return;
            }
        }
        public void Execute()
        {
            Command.CurrentCommand.ProtocolLogger.SetValue(ProtocolLoggerData.SearchQueryLength, this.searchQuery.Length);
            if (this.user.IsConsumerOrganizationUser)
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "GalSearch command not supported for consumer users");
                return;
            }
            if (this.minRange >= GlobalSettings.MaxGALSearchResults)
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "GalSearch command min range specified is outside our configured maximum. No results will be returned");
                return;
            }
            UnicodeCategory unicodeCategory = char.GetUnicodeCategory(this.searchQuery, 0);

            if (this.searchQuery.Length < GlobalSettings.MinGALSearchLength && unicodeCategory != UnicodeCategory.OtherLetter)
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "GalSearch search string is shorter than MinGALSearchLength. No results will be returned");
                Command.CurrentCommand.ProtocolLogger.SetValueIfNotSet(ProtocolLoggerData.Error, "SearchStringTooShort");
                return;
            }
            OperationRetryManagerResult operationRetryManagerResult = GalSearchProvider.retryManager.TryRun(delegate
            {
                IABSessionSettings sessionSettings = ABDiscoveryManager.GetSessionSettings(this.user.ExchangePrincipal, new int?(this.lcid), null, GlobalSettings.SyncLog, this.user.ClientSecurityContextWrapper.ClientSecurityContext);
                using (ABSession absession = ADABSession.Create(sessionSettings))
                {
                    this.addressBookObjects = absession.FindByANR(this.searchQuery, GlobalSettings.MaxGALSearchResults);
                }
            });

            if (operationRetryManagerResult.Succeeded)
            {
                if (this.pictureOptions != null && this.user.Features.IsEnabled(EasFeature.HDPhotos) && this.user.Context.Request.Version >= 160)
                {
                    this.photoRetriever = new AirSyncPhotoRetriever(this.user.Context);
                    List <string> list = new List <string>();
                    int           num  = this.minRange;
                    while (this.addressBookObjects != null && num <= this.maxRange && num < this.addressBookObjects.Count)
                    {
                        ABObject abobject = this.addressBookObjects[num];
                        if (abobject == null)
                        {
                            AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "ABSession.FindByAnr returned null  addresBookObject. Continue.");
                        }
                        else
                        {
                            ABContact abcontact = abobject as ABContact;
                            if (abcontact == null)
                            {
                                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "ABSession.FindByAnr returned object that is not a \"ABContact\". Continue.");
                            }
                            else
                            {
                                list.Add(abcontact.EmailAddress);
                            }
                        }
                        num++;
                    }
                    this.photoRetriever.BeginGetThumbnailPhotoFromMailbox(list, this.pictureOptions.PhotoSize);
                }
                return;
            }
            if (operationRetryManagerResult.Exception is ABSubscriptionDisabledException)
            {
                throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, operationRetryManagerResult.Exception, false)
                      {
                          ErrorStringForProtocolLogger = "ABSubsDisabled"
                      };
            }
            if (operationRetryManagerResult.Exception is DataValidationException)
            {
                throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, operationRetryManagerResult.Exception, false)
                      {
                          ErrorStringForProtocolLogger = "BadADDataInGalSearch"
                      };
            }
            if (operationRetryManagerResult.Exception is DataSourceOperationException)
            {
                throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, operationRetryManagerResult.Exception, false)
                      {
                          ErrorStringForProtocolLogger = "BadADDataSource"
                      };
            }
            if (operationRetryManagerResult.Exception != null)
            {
                throw operationRetryManagerResult.Exception;
            }
            throw new InvalidOperationException("GalSearch failed with result code: " + operationRetryManagerResult.ResultCode);
        }