internal override void ProcessMessageHeadersFromQueryString(Message request)
        {
            OwaServiceMessage owaServiceMessage = request as OwaServiceMessage;
            HttpRequest       httpRequest       = owaServiceMessage.HttpRequest;
            bool flag = false;

            foreach (object obj in httpRequest.QueryString.Keys)
            {
                string text = (string)obj;
                string a;
                if ((a = text) != null)
                {
                    if (!(a == "ManagementRole"))
                    {
                        if (a == "RequestServerVersion")
                        {
                            base.RequestVersion = JsonMessageHeaderProcessor.ReadRequestVersionHeader(httpRequest.QueryString.Get(text));
                        }
                    }
                    else
                    {
                        base.QueryStringXmlDictionaryReaderAction(httpRequest.QueryString.Get(text), delegate(XmlDictionaryReader reader)
                        {
                            base.ManagementRoleType = JsonMessageHeaderProcessor.ReadManagementRoleHeader(reader);
                        });
                        flag = true;
                    }
                }
            }
            if (flag)
            {
                base.ProcessRequestVersion(request);
            }
        }
        internal override ProxyRequestType?ProcessRequestTypeHeader(Message request)
        {
            OwaServiceMessage owaServiceMessage = request as OwaServiceMessage;

            if (owaServiceMessage != null)
            {
                return(base.ParseProxyRequestType(owaServiceMessage.HttpRequest.Headers["RequestType"]));
            }
            return(null);
        }
        internal override void ProcessHttpHeaders(Message request, ExchangeVersion defaultVersion)
        {
            OwaServiceMessage owaServiceMessage = request as OwaServiceMessage;
            HttpRequest       httpRequest       = owaServiceMessage.HttpRequest;

            if (httpRequest == null)
            {
                return;
            }
            string text = httpRequest.Headers["X-MailboxCulture"];

            if (!string.IsNullOrEmpty(text))
            {
                base.MailboxCulture = text;
            }
            string text2 = httpRequest.Headers["X-TimeZoneContext"];

            if (!string.IsNullOrEmpty(text2))
            {
                base.TimeZoneContext = new TimeZoneContextType
                {
                    TimeZoneDefinition = new TimeZoneDefinitionType
                    {
                        Id = text2
                    }
                };
            }
            string value = httpRequest.Headers["X-DateTimePrecision"];

            if (!string.IsNullOrEmpty(value))
            {
                base.DateTimePrecision = new DateTimePrecision?(JsonMessageHeaderProcessor.ReadDateTimePrecisionHeader(value));
            }
            string value2 = httpRequest.Headers["X-BackgroundLoad"];

            if (!string.IsNullOrEmpty(value2))
            {
                base.IsBackgroundLoad = bool.Parse(value2);
            }
            ExchangeVersion ewsVersionFromHttpHeaders = this.GetEwsVersionFromHttpHeaders(request, httpRequest);

            if (ewsVersionFromHttpHeaders != null)
            {
                base.RequestVersion = ewsVersionFromHttpHeaders;
            }
            else
            {
                string text3 = httpRequest.Headers["X-RequestServerVersion"];
                base.RequestVersion = (string.IsNullOrEmpty(text3) ? defaultVersion : JsonMessageHeaderProcessor.ReadRequestVersionHeader(text3));
            }
            base.ProcessRequestVersion(request);
        }
        internal override void ProcessMessageHeaders(Message request)
        {
            OwaServiceMessage owaServiceMessage = request as OwaServiceMessage;
            BaseJsonRequest   baseJsonRequest   = owaServiceMessage.Request as BaseJsonRequest;

            if (baseJsonRequest != null && baseJsonRequest.Header != null)
            {
                base.RequestVersion     = JsonMessageHeaderProcessor.ReadRequestVersionHeader(baseJsonRequest.Header.RequestServerVersion.ToString());
                base.MailboxCulture     = baseJsonRequest.Header.MailboxCulture;
                base.TimeZoneContext    = baseJsonRequest.Header.TimeZoneContext;
                base.DateTimePrecision  = new DateTimePrecision?(baseJsonRequest.Header.DateTimePrecision);
                base.IsBackgroundLoad   = baseJsonRequest.Header.BackgroundLoad;
                base.ManagementRoleType = baseJsonRequest.Header.ManagementRole;
            }
            base.ProcessRequestVersion(request);
        }
        internal override void ProcessEwsVersionFromHttpHeaders(Message request)
        {
            OwaServiceMessage owaServiceMessage = request as OwaServiceMessage;
            HttpRequest       httpRequest       = owaServiceMessage.HttpRequest;

            if (httpRequest == null)
            {
                return;
            }
            ExchangeVersion ewsVersionFromHttpHeaders = this.GetEwsVersionFromHttpHeaders(request, httpRequest);

            if (ewsVersionFromHttpHeaders != null)
            {
                base.RequestVersion = ewsVersionFromHttpHeaders;
                base.ProcessRequestVersion(request);
            }
        }
        private void InternalAfterReceiveRequest(HttpRequest httpRequest, string methodName, object request)
        {
            try
            {
                ExTraceGlobals.CommonAlgorithmTracer.TraceDebug <string>((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] called for method name: {0}", methodName);
                CallContext.ClearCallContextForCurrentThread();
                Globals.UpdateErrorTracingConfiguration();
                OwaApplication.GetRequestDetailsLogger.ActivityScope.SetProperty(ExtensibleLoggerMetadata.EventId, methodName);
                OwaServiceMessage message = new OwaServiceMessage(httpRequest, request);
                message.Headers.Action = methodName;
                message.Properties["HttpOperationName"] = methodName;
                OwaMessageHeaderProcessor messageHeaderProcessor = new OwaMessageHeaderProcessor();
                bool flag  = OWAMessageInspector.RequestNeedsHeaderProcessing(methodName);
                bool flag2 = OWAMessageInspector.RequestNeedsQueryStringProcessing(methodName);
                bool flag3 = OWAMessageInspector.RequestNeedsHttpHeaderProcessing(methodName);
                ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] processing message headers");
                if (flag || flag2 || flag3)
                {
                    if (flag)
                    {
                        messageHeaderProcessor.ProcessMessageHeaders(message);
                        messageHeaderProcessor.ProcessEwsVersionFromHttpHeaders(message);
                    }
                    else if (flag2)
                    {
                        messageHeaderProcessor.ProcessMessageHeadersFromQueryString(message);
                    }
                    else if (flag3)
                    {
                        messageHeaderProcessor.ProcessHttpHeaders(message, ExchangeVersion.Exchange2013);
                    }
                }
                message.Properties["MessageHeaderProcessor"] = messageHeaderProcessor;
                message.Properties["ConnectionCostType"]     = 0;
                WebMethodEntry jsonWebMethodEntry;
                if (!OWAMessageInspector.MethodNameToWebMethodEntryMap.Member.TryGetValue(methodName, out jsonWebMethodEntry))
                {
                    jsonWebMethodEntry = WebMethodEntry.JsonWebMethodEntry;
                }
                message.Properties["WebMethodEntry"] = jsonWebMethodEntry;
                ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] creating CallContext");
                CallContext callContext = OwaApplication.GetRequestDetailsLogger.TrackLatency <CallContext>(ServiceLatencyMetadata.CallContextInitLatency, () => CallContextUtilities.CreateCallContext(message, messageHeaderProcessor, true, ""));
                callContext.IsOwa = true;
                ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] CallContext created");
                callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsMowaClient, OfflineClientRequestUtilities.IsRequestFromMOWAClient(callContext.HttpContext.Request, callContext.HttpContext.Request.UserAgent) ? 1 : 0);
                bool?flag4 = new bool?(OfflineClientRequestUtilities.IsRequestFromOfflineClient(callContext.HttpContext.Request));
                if (flag4 != null)
                {
                    callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsOfflineEnabled, flag4.Value ? 1 : 0);
                }
                callContext.OwaExplicitLogonUser = UserContextUtilities.GetExplicitLogonUser(HttpContext.Current);
                if (string.IsNullOrEmpty(callContext.OwaExplicitLogonUser))
                {
                    OWAMessageInspector.CheckThatUserProvisionedDevice(methodName, callContext);
                    OWAMessageInspector.CheckMowaRemoteWipe(methodName, callContext);
                    OWAMessageInspector.CheckClientVersion(callContext);
                    OWAMessageInspector.CheckMowaDisabled(callContext);
                    OWAMessageInspector.CheckMobileDevicePolicyIsCorrect(methodName, callContext);
                }
                OWAMessageInspector.MarkResponseNonCacheable(methodName);
                callContext.WorkloadType       = WorkloadType.Owa;
                callContext.UsingWcfDispatcher = false;
                callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.UsingWcfHttpHandler, 0);
                if (ExchangeVersion.Current == ExchangeVersion.Exchange2007)
                {
                    ExchangeVersion.Current = ExchangeVersion.Exchange2013;
                }
                if (OWAMessageInspector.ShouldCreateUserContext(callContext))
                {
                    UserContext userContext = UserContextManager.GetMailboxContext(callContext.HttpContext, callContext.EffectiveCaller, true) as UserContext;
                    if (userContext != null)
                    {
                        callContext.OwaCulture = userContext.UserCulture;
                        if (userContext.FeaturesManager != null)
                        {
                            callContext.FeaturesManager = userContext.FeaturesManager;
                            if (userContext.FeaturesManager.ServerSettings.OwaMailboxSessionCloning.Enabled)
                            {
                                callContext.OwaUserContextKey = userContext.Key.ToString();
                            }
                        }
                    }
                }
            }
            catch (LocalizedException ex)
            {
                ExTraceGlobals.CommonAlgorithmTracer.TraceError <string, LocalizedException>((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] Caught localized exception trying to process message. Type: {0} Exception: {1}", ex.GetType().Name, ex);
                OwaServerTraceLogger.AppendToLog(new TraceLogEvent("OWAMessageInspector", null, "InternalAfterReceiveRequest", string.Format("OwaServiceFaultException_InnerException - {0}", ex)));
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeLogRequestException(OwaApplication.GetRequestDetailsLogger, ex, "OwaServiceFaultException_InnerException");

                throw OwaFaultExceptionUtilities.CreateFault(ex);
            }
            catch (Exception ex2)
            {
                ExTraceGlobals.CommonAlgorithmTracer.TraceError <string, Exception>((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] Caught exception trying to process message. Type: {0} Exception: {1}", ex2.GetType().Name, ex2);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeLogRequestException(OwaApplication.GetRequestDetailsLogger, ex2, "OwaServiceFaultException_InnerException");

                throw;
            }
            ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] completed");
        }