private ICollection <string> ExtractSmtpAddresses(OwaIdentity requestor)
        {
            if (requestor == null)
            {
                return(Array <string> .Empty);
            }
            OWAMiniRecipient owaminiRecipient = requestor.OwaMiniRecipient ?? requestor.GetOWAMiniRecipient();

            if (owaminiRecipient == null)
            {
                this.tracer.TraceDebug((long)this.GetHashCode(), "OwaPhotoRequestorWriter:  cannot extract SMTP addresses because recipient information has NOT been initialized or computed for requestor.");
                return(Array <string> .Empty);
            }
            HashSet <string> hashSet            = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            SmtpAddress      primarySmtpAddress = requestor.PrimarySmtpAddress;

            hashSet.Add(requestor.PrimarySmtpAddress.ToString());
            if (owaminiRecipient.EmailAddresses != null && owaminiRecipient.EmailAddresses.Count > 0)
            {
                hashSet.UnionWith(from a in owaminiRecipient.EmailAddresses
                                  where OwaPhotoRequestorWriter.IsNonBlankSmtpAddress(a)
                                  select a.ValueString);
            }
            return(hashSet);
        }
        public DispatchStepResult Dispatch(RequestContext context)
        {
            if (context == null || context.HttpContext == null || context.HttpContext.Request == null || context.HttpContext.Response == null)
            {
                return(DispatchStepResult.Continue);
            }
            if (!context.HttpContext.Request.Path.EndsWith("/GetUserPhoto", StringComparison.OrdinalIgnoreCase))
            {
                return(DispatchStepResult.Continue);
            }
            HttpContext httpContext = new OwaPhotoRequestorWriter(NullPerformanceDataLogger.Instance, this.tracer).Write(context.HttpContext, context.HttpContext);

            if (!GetUserPhotoRequestDispatcher.IsRequestorInPhotoStackV2Flight(httpContext))
            {
                return(DispatchStepResult.Continue);
            }
            DispatchStepResult result;

            try
            {
                new PhotoRequestHandler(OwaApplication.GetRequestDetailsLogger).ProcessRequest(httpContext);
                context.HttpStatusCode = (HttpStatusCode)context.HttpContext.Response.StatusCode;
                result = DispatchStepResult.EndResponseWithPrivateCaching;
            }
            catch (TooComplexPhotoRequestException arg)
            {
                this.tracer.TraceDebug <TooComplexPhotoRequestException>((long)this.GetHashCode(), "[GetUserPhotoRequestDispatcher::DispatchIfGetUserPhotoRequest] too complex photo request.  Exception: {0}", arg);
                result = DispatchStepResult.Continue;
            }
            return(result);
        }
        public HttpContext Write(HttpContext authenticatedUserContext, HttpContext output)
        {
            ArgumentValidator.ThrowIfNull("authenticatedUserContext", authenticatedUserContext);
            ArgumentValidator.ThrowIfNull("output", output);
            HttpContext result;

            try
            {
                using (new StopwatchPerformanceTracker("PhotoRequestorWriterResolveIdentity", this.perfLogger))
                {
                    using (new ADPerformanceTracker("PhotoRequestorWriterResolveIdentity", this.perfLogger))
                    {
                        using (OwaIdentity owaIdentity = OwaIdentity.ResolveLogonIdentity(authenticatedUserContext, null))
                        {
                            if (owaIdentity == null)
                            {
                                this.tracer.TraceDebug((long)this.GetHashCode(), "OwaPhotoRequestorWriter:  requestor could NOT be resolved.");
                                return(output);
                            }
                            OrganizationId organization = OwaPhotoRequestorWriter.GetOrganization(owaIdentity);
                            if (organization == null)
                            {
                                this.tracer.TraceError((long)this.GetHashCode(), "OwaPhotoRequestorWriter:  could NOT determine requestor's organization.");
                                return(output);
                            }
                            output.Items["Photo.Requestor"] = new PhotoPrincipal
                            {
                                OrganizationId = organization,
                                EmailAddresses = this.ExtractSmtpAddresses(owaIdentity)
                            };
                            output.Items["Photo.Requestor.EnabledInFasterPhotoFlightHttpContextKey"] = OwaPhotoRequestorWriter.InPhotoFasterPhotoFlight(owaIdentity.OwaMiniRecipient);
                        }
                    }
                }
                result = output;
            }
            catch (OwaADObjectNotFoundException arg)
            {
                this.tracer.TraceError <OwaADObjectNotFoundException>((long)this.GetHashCode(), "OwaPhotoRequestorWriter:  requestor NOT found.  Exception: {0}", arg);
                result = output;
            }
            catch (TransientException arg2)
            {
                this.tracer.TraceError <TransientException>((long)this.GetHashCode(), "OwaPhotoRequestorWriter:  failed to resolve requestor with a transient error.  Exception: {0}", arg2);
                result = output;
            }
            catch (ADOperationException arg3)
            {
                this.tracer.TraceError <ADOperationException>((long)this.GetHashCode(), "OwaPhotoRequestorWriter:  failed to resolve requestor with permanent directory error.  Exception: {0}", arg3);
                result = output;
            }
            return(result);
        }