private byte[] FallbackToThumbnailIfNecessary(UserPhotoQuery query) { HttpStatusCode statusCode = query.Result.StatusCode; if (statusCode <= HttpStatusCode.NotModified) { if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.NotModified) { goto IL_78; } } else { switch (statusCode) { case HttpStatusCode.Forbidden: break; case HttpStatusCode.NotFound: goto IL_78; default: if (statusCode != HttpStatusCode.InternalServerError) { goto IL_78; } goto IL_78; } } if (query.Result.IsPhotoServedFromADFallback) { this.photoRequest.PerformanceLogger.Log("ADFallbackPhotoServed", string.Empty, 1U); } return(query.Result.UserPhotoBytes); IL_78: if (query.RecipientData == null || query.RecipientData.ThumbnailPhoto == null || query.RecipientData.ThumbnailPhoto.Length == 0) { this.tracer.TraceDebug <HttpStatusCode>((long)this.GetHashCode(), "Photo query: fall-back to thumbnail photo (AD) not possible: no photo. Returning status code: NOT FOUND. Original status code: {0}", this.StatusCode); this.photoRequest.PerformanceLogger.Log("ADFallbackPhotoServed", string.Empty, 0U); this.StatusCode = HttpStatusCode.NotFound; return(query.Result.UserPhotoBytes); } this.tracer.TraceDebug((long)this.GetHashCode(), "Photo query: fall-back to thumbnail photo (AD) successful."); this.photoRequest.PerformanceLogger.Log("ADFallbackPhotoServed", string.Empty, 1U); this.StatusCode = HttpStatusCode.OK; this.ETag = null; this.Expires = this.ComputeExpiresHeader(null, HttpStatusCode.OK); return(query.RecipientData.ThumbnailPhoto); }
protected override byte[] ExecuteInternal() { UserPhotoApplication userPhotoApplication = new UserPhotoApplication(this.photoRequest, this.photosConfiguration, this.photoRequest.Trace, this.upstreamTracer); byte[] result; using (RequestDispatcher requestDispatcher = new RequestDispatcher(base.RequestLogger)) { IList <RecipientData> list = this.LookupTargetUserInDirectory(); if (list.Count == 0) { this.tracer.TraceDebug((long)this.GetHashCode(), "Target user not found in directory."); this.StatusCode = HttpStatusCode.NotFound; this.Expires = this.ComputeExpiresHeader(string.Empty, HttpStatusCode.NotFound); result = null; } else { RecipientData recipientData = list[0]; this.tracer.TraceDebug <SmtpAddress>((long)this.GetHashCode(), "Target user found with PRIMARY SMTP address: '{0}'", recipientData.PrimarySmtpAddress); if (string.IsNullOrEmpty(this.photoRequest.TargetPrimarySmtpAddress) && recipientData.PrimarySmtpAddress.IsValidAddress && recipientData.PrimarySmtpAddress != SmtpAddress.Empty) { this.photoRequest.TargetPrimarySmtpAddress = recipientData.PrimarySmtpAddress.ToString(); } QueryGenerator queryGenerator = new QueryGenerator(userPhotoApplication, base.ClientContext, base.RequestLogger, requestDispatcher, this.queryPrepareDeadline, this.requestProcessingDeadline, list); try { UserPhotoQuery userPhotoQuery = (UserPhotoQuery)queryGenerator.GetQueries()[0]; requestDispatcher.Execute(this.requestProcessingDeadline, base.HttpResponse); this.individualMailboxesProcessed = queryGenerator.UniqueQueriesCount; if (userPhotoQuery.Result == null) { this.tracer.TraceError <ClientContext, string>((long)this.GetHashCode(), "Query result is NULL. Client context: {0}; target: {1}", base.ClientContext, this.photoRequest.TargetSmtpAddress); result = null; } else { byte[] array = userPhotoQuery.Result.UserPhotoBytes; this.ETag = userPhotoQuery.Result.CacheId; this.StatusCode = userPhotoQuery.Result.StatusCode; this.Expires = this.ComputeExpiresHeader(userPhotoQuery.Result.Expires, userPhotoQuery.Result.StatusCode); this.ContentType = userPhotoQuery.Result.ContentType; if (userPhotoQuery.Result.ExceptionInfo != null) { this.tracer.TraceError <LocalizedException>((long)this.GetHashCode(), "Query result has an exception: {0}", userPhotoQuery.Result.ExceptionInfo); base.RequestLogger.AppendToLog <string>("EXP", userPhotoQuery.Result.ExceptionInfo.ToString()); } array = this.FallbackToThumbnailIfNecessary(userPhotoQuery); userPhotoApplication.LogThreadsUsage(base.RequestLogger); result = array; } } catch (Exception arg) { this.tracer.TraceError <Exception>((long)this.GetHashCode(), "Exception at query dispatch: {0}", arg); throw; } finally { requestDispatcher.LogStatistics(base.RequestLogger); } } } return(result); }
internal override BaseQueryResult GetData(BaseQuery query) { this.tracer.TraceDebug((long)this.GetHashCode(), "Executing local photo query."); UserPhotoQuery userPhotoQuery = (UserPhotoQuery)query; BaseQueryResult result; try { using (new StopwatchPerformanceTracker("LocalAuthorization", this.photoRequest.PerformanceLogger)) { using (new ADPerformanceTracker("LocalAuthorization", this.photoRequest.PerformanceLogger)) { new PhotoAuthorization(OrganizationIdCache.Singleton, this.upstreamTracer).Authorize(this.photoRequest.Requestor, new PhotoPrincipal { EmailAddresses = new string[] { userPhotoQuery.ExchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString() }, OrganizationId = userPhotoQuery.ExchangePrincipal.MailboxInfo.OrganizationId }); } } using (MemoryStream memoryStream = new MemoryStream()) { this.CheckDeadline("Retrieving-UserPhoto"); LocalServerPhotoRetrievalPipeline localServerPhotoRetrievalPipeline = new LocalServerPhotoRetrievalPipeline(this.photosConfiguration, "Client=WebServices;Action=UserPhotoTask", this.CreateRecipientSession(userPhotoQuery), XSOFactory.Default, this.upstreamTracer); this.photoRequest.TargetSmtpAddress = userPhotoQuery.ExchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString(); this.photoRequest.TargetPrincipal = userPhotoQuery.ExchangePrincipal; PhotoResponse photoResponse = localServerPhotoRetrievalPipeline.Retrieve(this.photoRequest, memoryStream); this.CheckDeadline("Reading-Image-Bytes"); byte[] array = memoryStream.ToArray(); this.CheckDeadline("Returning-Result"); this.tracer.TraceDebug((long)this.GetHashCode(), "Local query completed. Returned photo is blank? {0}; Status: {1}; ETag: {2}; Content-type: '{3}'", new object[] { array == null || array.Length == 0, photoResponse.Status, photoResponse.ETag, photoResponse.ContentType }); result = new UserPhotoQueryResult(array, photoResponse.ETag, photoResponse.Status, photoResponse.HttpExpiresHeader, photoResponse.ContentType, this.upstreamTracer); } } catch (IOException ex) { result = this.TraceAndReturnQueryResult(ex, new PhotoRetrievalFailedIOException(Strings.PhotoRetrievalFailedIOError(ex.Message), ex)); } catch (Win32Exception ex2) { result = this.TraceAndReturnQueryResult(ex2, new PhotoRetrievalFailedWin32Exception(Strings.PhotoRetrievalFailedWin32Error(ex2.Message), ex2)); } catch (UnauthorizedAccessException ex3) { result = this.TraceAndReturnQueryResult(ex3, new PhotoRetrievalFailedUnauthorizedAccessException(Strings.PhotoRetrievalFailedUnauthorizedAccessError(ex3.Message), ex3)); } catch (AccessDeniedException ex4) { result = this.TraceAndReturnQueryResult(ex4, ex4); } catch (LocalizedException ex5) { result = this.TraceAndReturnQueryResult(ex5, ex5); } return(result); }
private IRecipientSession CreateRecipientSession(UserPhotoQuery query) { return(DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, query.ExchangePrincipal.MailboxInfo.OrganizationId.ToADSessionSettings(), 179, "CreateRecipientSession", "f:\\15.00.1497\\sources\\dev\\infoworker\\src\\common\\UserPhotos\\UserPhotoLocalQuery.cs")); }
public override BaseQuery CreateFromIndividual(RecipientData recipientData, LocalizedException exception) { return(UserPhotoQuery.CreateFromIndividual(recipientData, exception, this.upstreamTracer)); }
public override BaseQuery CreateFromIndividual(RecipientData recipientData) { return(UserPhotoQuery.CreateFromIndividual(recipientData, this.upstreamTracer)); }