internal UserPhotoQueryResult(LocalizedException exception, ITracer upstreamTracer) : base(exception)
        {
            this.tracer = ExTraceGlobals.UserPhotosTracer.Compose(upstreamTracer);
            HttpStatusCode httpStatusCode = UserPhotoQueryResult.TranslateExceptionToHttpStatusCode(exception);

            this.tracer.TraceDebug <HttpStatusCode, string>((long)this.GetHashCode(), "Translated exception in query to HTTP {0}.  Exception: {1}", httpStatusCode, (exception != null) ? exception.Message : string.Empty);
            this.StatusCode = httpStatusCode;
            this.Expires    = null;
            HttpStatusCode httpStatusCode2 = httpStatusCode;

            if (httpStatusCode2 <= HttpStatusCode.NotModified)
            {
                if (httpStatusCode2 == HttpStatusCode.OK || httpStatusCode2 == HttpStatusCode.NotModified)
                {
                    return;
                }
            }
            else if (httpStatusCode2 != HttpStatusCode.NotFound && httpStatusCode2 != HttpStatusCode.InternalServerError)
            {
            }
            if (this.FallbackToADPhoto(exception))
            {
                return;
            }
            this.CacheId        = null;
            this.UserPhotoBytes = Array <byte> .Empty;
        }
 private static HttpStatusCode GetHttpStatusCodeFromProxyWebRequestProcessingException(ProxyWebRequestProcessingException e)
 {
     if (e == null)
     {
         return(HttpStatusCode.InternalServerError);
     }
     if (e.InnerException is WebException)
     {
         return(UserPhotoQueryResult.GetHttpStatusCodeFromWebException((WebException)e.InnerException));
     }
     if (e.InnerException is AddressSpaceNotFoundException)
     {
         return(HttpStatusCode.NotFound);
     }
     return(HttpStatusCode.InternalServerError);
 }
 private static HttpStatusCode TranslateExceptionToHttpStatusCode(Exception e)
 {
     if (e == null)
     {
         return(HttpStatusCode.InternalServerError);
     }
     if (e is UserPhotoNotFoundException)
     {
         return(HttpStatusCode.NotFound);
     }
     if (e is MailRecipientNotFoundException)
     {
         return(HttpStatusCode.NotFound);
     }
     if (e is ProxyServerWithMinimumRequiredVersionNotFound)
     {
         return(HttpStatusCode.NotFound);
     }
     if (e is AccessDeniedException)
     {
         return(HttpStatusCode.Forbidden);
     }
     if (e is NoFreeBusyAccessException)
     {
         return(HttpStatusCode.Forbidden);
     }
     if (e is WebException)
     {
         return(UserPhotoQueryResult.GetHttpStatusCodeFromWebException((WebException)e));
     }
     if (e is ProxyWebRequestProcessingException)
     {
         return(UserPhotoQueryResult.GetHttpStatusCodeFromProxyWebRequestProcessingException((ProxyWebRequestProcessingException)e));
     }
     return(HttpStatusCode.InternalServerError);
 }
예제 #4
0
 private UserPhotoQuery(RecipientData recipientData, UserPhotoQueryResult result) : base(recipientData, result)
 {
 }
예제 #5
0
        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);
        }