private static void AddClientLoadTimeDataPoint(Dictionary <string, string> rawKeyValuePairs, Dictionary <string, string> calculatedKeyValuePairs, string contextId, string ipAddress, string clientVersion, bool isMowa, string userName, UserContext userContext, string clientIdCookieValue = null)
        {
            List <string> list  = new List <string>();
            List <string> list2 = new List <string>();

            foreach (string text in rawKeyValuePairs.Keys)
            {
                if (!Plt1WebHandler.ShouldIgnoreKey(text))
                {
                    list.Add(text);
                    list2.Add(rawKeyValuePairs[text]);
                }
            }
            foreach (string text2 in calculatedKeyValuePairs.Keys)
            {
                if (!Plt1WebHandler.ShouldIgnoreKey(text2))
                {
                    list.Add(text2);
                    list2.Add(calculatedKeyValuePairs[text2]);
                }
            }
            Datapoint      datapoint = new Datapoint(DatapointConsumer.Analytics, "ClientLoadTime", DateTime.UtcNow.ToString("o"), list.ToArray(), list2.ToArray());
            ClientLogEvent logEvent  = new ClientLogEvent(datapoint, contextId, ipAddress, userName, clientVersion, Globals.ApplicationVersion ?? string.Empty, isMowa, clientIdCookieValue);

            Plt1WebHandler.UpdateLogEventCommonData(logEvent, userContext);
            OwaClientLogger.AppendToLog(logEvent);
        }
        private static void AddCalculatedClientLoadTimeDataPoint(Dictionary <string, string> rawKeyValuePairs, Dictionary <string, string> calculatedKeyValuePairs, string contextId, string ipAddress, string clientVersion, bool isMowa, string userName, string clientIdCookieValue = null)
        {
            List <string> list  = new List <string>();
            List <string> list2 = new List <string>();

            if (rawKeyValuePairs.ContainsKey("brn"))
            {
                list.Add("brn");
                list2.Add(rawKeyValuePairs["brn"]);
            }
            if (rawKeyValuePairs.ContainsKey("brv"))
            {
                list.Add("brv");
                list2.Add(rawKeyValuePairs["brv"]);
            }
            if (rawKeyValuePairs.ContainsKey("tg"))
            {
                list.Add("tg");
                list2.Add(rawKeyValuePairs["tg"]);
            }
            if (rawKeyValuePairs.ContainsKey("domL"))
            {
                list.Add("domL");
                list2.Add(rawKeyValuePairs["domL"]);
            }
            if (rawKeyValuePairs.ContainsKey("pE"))
            {
                list.Add("DPT");
                list2.Add(rawKeyValuePairs["pE"]);
            }
            if (rawKeyValuePairs.ContainsKey("rpo"))
            {
                list.Add("RPO");
                list2.Add(rawKeyValuePairs["rpo"]);
            }
            if (rawKeyValuePairs.ContainsKey("te"))
            {
                list.Add("te");
                list2.Add(rawKeyValuePairs["te"]);
            }
            foreach (string text in calculatedKeyValuePairs.Keys)
            {
                if (!Plt1WebHandler.ShouldIgnoreKey(text))
                {
                    list.Add(text);
                    list2.Add(calculatedKeyValuePairs[text]);
                }
            }
            Datapoint      datapoint = new Datapoint(DatapointConsumer.Analytics, "CalculatedClientLoadTime", DateTime.UtcNow.ToString("o"), list.ToArray(), list2.ToArray());
            ClientLogEvent logEvent  = new ClientLogEvent(datapoint, contextId, ipAddress, userName, clientVersion, Globals.ApplicationVersion ?? string.Empty, isMowa, clientIdCookieValue);

            OwaClientLogger.AppendToLog(logEvent);
        }
        public void ProcessRequest(HttpContext context)
        {
            string      userContextId           = Plt1WebHandler.GetUserContextId(context);
            bool        isMowa                  = OfflineClientRequestUtilities.IsRequestFromMOWAClient(context.Request, context.Request.UserAgent);
            HttpRequest request                 = context.Request;
            string      clientAddressWithoutPII = this.GetClientAddressWithoutPII(request);
            UserAgent   userAgent               = OwaUserAgentUtilities.CreateUserAgentWithLayoutOverride(context);
            string      userName                = string.Empty;
            string      cookieValueAndSetIfNull = ClientIdCookie.GetCookieValueAndSetIfNull(context);
            UserContext userContext             = UserContextManager.GetUserContext(context, false);

            if (userContext != null && userContext.LogonIdentity != null)
            {
                SmtpAddress primarySmtpAddress = userContext.LogonIdentity.PrimarySmtpAddress;
                userName = userContext.LogonIdentity.PrimarySmtpAddress.ToString();
            }
            if (Plt1WebHandler.IsPlt1PerformanceRequest(request))
            {
                string text = "";
                if (context.Request.HttpMethod == "POST")
                {
                    using (StreamReader streamReader = new StreamReader(context.Request.InputStream))
                    {
                        text = streamReader.ReadToEnd();
                        context.Response.AppendToLog(text);
                    }
                }
                string clientVersion = context.Request.QueryString.Get("cver") ?? string.Empty;
                Uri    uri;
                string refererQueryString = request.TryParseUrlReferrer(out uri) ? uri.Query : "noRefUrl";
                Dictionary <string, string> dictionary  = new Dictionary <string, string>();
                Dictionary <string, string> dictionary2 = new Dictionary <string, string>();
                Plt1WebHandler.GetPlt1PerformanceEventData(userAgent, refererQueryString, request.QueryString, text, dictionary, dictionary2);
                Plt1WebHandler.AddClientLoadTimeDataPoint(dictionary, dictionary2, userContextId, clientAddressWithoutPII, clientVersion, isMowa, userName, userContext, cookieValueAndSetIfNull);
                if (dictionary2.Count > 0 && dictionary.ContainsKey("msg") && dictionary["msg"].Contains("success"))
                {
                    Plt1WebHandler.AddCalculatedClientLoadTimeDataPoint(dictionary, dictionary2, userContextId, clientAddressWithoutPII, clientVersion, isMowa, userName, cookieValueAndSetIfNull);
                }
                if (userContext != null && userContext.FeaturesManager != null && userContext.FeaturesManager.ServerSettings.OwaServerLogonActivityLogging.Enabled)
                {
                    this.AddtoActivityLog(userContext, dictionary, userName, clientAddressWithoutPII, userAgent.RawString);
                }
            }
            else
            {
                string         clientVersion2  = context.Request.QueryString.Get("v") ?? string.Empty;
                ClientLogEvent plt1AccessEvent = Plt1WebHandler.GetPlt1AccessEvent(userContextId, request.UserAgent, clientAddressWithoutPII, clientVersion2, isMowa, cookieValueAndSetIfNull);
                OwaClientLogger.AppendToLog(plt1AccessEvent);
            }
            Plt1WebHandler.SetResponseHeaders(context.Response);
            Plt1WebHandler.WriteImage(context.Response);
        }