Esempio n. 1
0
        // Token: 0x06000370 RID: 880 RVA: 0x0001410C File Offset: 0x0001230C
        private AnrManager.LookupState GetNamesByAnrFromAD(string name, List <ResolvedRecipient> recipients)
        {
            IList <ABObject>            addressBookObjects          = null;
            OperationRetryManagerResult operationRetryManagerResult = AnrManager.retryManager.TryRun(delegate
            {
                addressBookObjects = this.GetAddressBookSession().FindByANR(name, 1000);
            });

            if (operationRetryManagerResult.Succeeded)
            {
                using (IEnumerator <ABObject> enumerator = addressBookObjects.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ABObject abobject = enumerator.Current;
                        if (abobject.CanEmail)
                        {
                            ResolvedRecipient resolvedRecipient = new ResolvedRecipient(new RecipientAddress
                            {
                                AddressOrigin  = AddressOrigin.Directory,
                                DisplayName    = abobject.DisplayName,
                                RoutingAddress = abobject.LegacyExchangeDN,
                                RoutingType    = "EX",
                                SmtpAddress    = abobject.EmailAddress
                            });
                            ABContact abcontact = abobject as ABContact;
                            if (abcontact != null)
                            {
                                resolvedRecipient.Picture = abcontact.Picture;
                            }
                            recipients.Add(resolvedRecipient);
                        }
                    }
                    goto IL_F7;
                }
            }
            AirSyncDiagnostics.TraceError <Exception>(ExTraceGlobals.RequestTracer, 0, "AnrManager.GetNamesByAnrFromAD(): Exception thrown by FindByANR: {0}", operationRetryManagerResult.Exception);
IL_F7:
            switch (recipients.Count)
            {
            case 0:
                return(AnrManager.LookupState.FoundNone);

            case 1:
                return(AnrManager.LookupState.FoundExact);

            default:
                return(AnrManager.LookupState.FoundMany);
            }
        }
        private static string GetABProperty(ABContact contact, string airSyncPropertyName)
        {
            switch (airSyncPropertyName)
            {
            case "Alias":
                return(contact.Alias);

            case "DisplayName":
                return(contact.DisplayName);

            case "EmailAddress":
                return(contact.EmailAddress);

            case "Company":
                return(contact.CompanyName);

            case "FirstName":
                return(contact.GivenName);

            case "HomePhone":
                return(contact.HomePhoneNumber);

            case "LastName":
                return(contact.Surname);

            case "MobilePhone":
                return(contact.MobilePhoneNumber);

            case "Office":
                return(contact.OfficeLocation);

            case "Phone":
                return(contact.BusinessPhoneNumber);

            case "Title":
                return(contact.Title);
            }
            throw new InvalidOperationException("Unexpected AirSync property name: " + airSyncPropertyName);
        }
 public void BuildResponse(XmlElement responseNode)
 {
     try
     {
         int num = 0;
         this.numberResponses = 0;
         XmlNode xmlNode = responseNode.OwnerDocument.CreateElement("Status", "Search:");
         responseNode.AppendChild(xmlNode);
         xmlNode.InnerText = 1.ToString(CultureInfo.InvariantCulture);
         int num2 = this.minRange;
         while (this.addressBookObjects != null && num2 <= this.maxRange && num2 < this.addressBookObjects.Count)
         {
             ABObject abobject = this.addressBookObjects[num2];
             if (abobject != null)
             {
                 ABContact abcontact = abobject as ABContact;
                 XmlNode   xmlNode2  = responseNode.OwnerDocument.CreateElement("Result", "Search:");
                 XmlNode   xmlNode3  = responseNode.OwnerDocument.CreateElement("Properties", "Search:");
                 xmlNode2.AppendChild(xmlNode3);
                 for (int i = 0; i < GalSearchProvider.schema.Length; i++)
                 {
                     string abproperty;
                     if (abcontact == null)
                     {
                         abproperty = GalSearchProvider.GetABProperty(abobject, GalSearchProvider.schema[i]);
                     }
                     else
                     {
                         abproperty = GalSearchProvider.GetABProperty(abcontact, GalSearchProvider.schema[i]);
                     }
                     if (!string.IsNullOrEmpty(abproperty))
                     {
                         XmlNode xmlNode4 = responseNode.OwnerDocument.CreateElement(GalSearchProvider.schema[i], "Gal:");
                         xmlNode4.InnerText = abproperty;
                         xmlNode3.AppendChild(xmlNode4);
                     }
                 }
                 if (this.pictureOptions != null && abcontact != null)
                 {
                     StatusCode statusCode = StatusCode.Success;
                     byte[]     array      = null;
                     if (this.user.Features.IsEnabled(EasFeature.HDPhotos) && this.user.Context.Request.Version >= 160)
                     {
                         array = this.photoRetriever.EndGetThumbnailPhotoFromMailbox(abcontact.EmailAddress, GlobalSettings.MaxRequestExecutionTime - ExDateTime.Now.Subtract(Command.CurrentCommand.Context.RequestTime), this.pictureOptions.PhotoSize);
                         AirSyncDiagnostics.TraceDebug <bool, int>(ExTraceGlobals.RequestsTracer, this, "GalSearch Requesting user's HD picture. WasRetrived:{0}, size:{1}", array != null, (array == null) ? 0 : array.Length);
                     }
                     if (statusCode != StatusCode.Success || array == null)
                     {
                         AirSyncDiagnostics.TraceDebug <bool, int, StatusCode>(ExTraceGlobals.RequestsTracer, this, "User's HD photo is either null or was not requested, Using contact's picture from AD. :FeatureEnabled:{0}, RequestVersion:{1}, statusCode:{2}", this.user.Features.IsEnabled(EasFeature.HDPhotos), this.user.Context.Request.Version, statusCode);
                         array = abcontact.Picture;
                     }
                     bool    flag;
                     XmlNode newChild = this.pictureOptions.CreatePictureNode(responseNode.OwnerDocument, "Gal:", array, num >= this.pictureOptions.MaxPictures, out flag);
                     xmlNode3.AppendChild(newChild);
                     if (flag)
                     {
                         num++;
                     }
                 }
                 responseNode.AppendChild(xmlNode2);
                 this.numberResponses++;
             }
             num2++;
         }
         if (this.numberResponses == 0)
         {
             XmlNode newChild2 = responseNode.OwnerDocument.CreateElement("Result", "Search:");
             responseNode.AppendChild(newChild2);
         }
         else if (this.rangeSpecified)
         {
             XmlNode xmlNode5 = responseNode.OwnerDocument.CreateElement("Range", "Search:");
             XmlNode xmlNode6 = responseNode.OwnerDocument.CreateElement("Total", "Search:");
             xmlNode5.InnerText = this.minRange.ToString(CultureInfo.InvariantCulture) + "-" + (this.minRange + this.numberResponses - 1).ToString(CultureInfo.InvariantCulture);
             responseNode.AppendChild(xmlNode5);
             AirSyncDiagnostics.Assert(this.addressBookObjects.Count <= GlobalSettings.MaxGALSearchResults);
             xmlNode6.InnerText = this.addressBookObjects.Count.ToString(CultureInfo.InvariantCulture);
             responseNode.AppendChild(xmlNode6);
         }
     }
     finally
     {
         if (this.photoRetriever != null)
         {
             this.photoRetriever.Dispose();
             this.photoRetriever = null;
         }
     }
 }
        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);
        }