IDictionary <string, string> GetRequiredPayloadData(string hitType, bool isNonInteractive, SessionControl sessionControl)
        {
            var result = new Dictionary <string, string>();

            result.Add("v", "1");
            result.Add("tid", PropertyId);
            result.Add("cid", AnonymousClientId);
            result.Add("an", AppName);
            result.Add("av", AppVersion);
            result.Add("t", hitType);
            if (ScreenName != null)
            {
                result.Add("cd", ScreenName);
            }
            if (isNonInteractive)
            {
                result.Add("ni", "1");
            }
            if (AnonymizeIP)
            {
                result.Add("aip", "1");
            }
            if (sessionControl != SessionControl.None)
            {
                result.Add("sc", sessionControl == SessionControl.Start ? "start" : "end");
            }
            if (ScreenResolution.HasValue)
            {
                result.Add("sr", string.Format("{0}x{1}", ScreenResolution.Value.Width, ScreenResolution.Value.Height));
            }
            if (ViewportSize.HasValue)
            {
                result.Add("vp", string.Format("{0}x{1}", ViewportSize.Value.Width, ViewportSize.Value.Height));
            }
            if (UserLanguage != null)
            {
                result.Add("ul", UserLanguage.ToLowerInvariant());
            }
            if (ScreenColorDepthBits.HasValue)
            {
                result.Add("sd", string.Format("{0}-bits", ScreenColorDepthBits.Value));
            }
            if (DocumentEncoding != null)
            {
                result.Add("de", DocumentEncoding);
            }
            foreach (var dimension in CustomDimensions)
            {
                result.Add(string.Format("cd{0}", dimension.Key), dimension.Value);
            }
            foreach (var metric in CustomMetrics)
            {
                result.Add(string.Format("cm{0}", metric.Key), metric.Value.ToString(CultureInfo.InvariantCulture));
            }
            CustomDimensions.Clear();
            CustomMetrics.Clear();

            return(result);
        }
示例#2
0
        //*****************************************************************************************

        //*****************************************************************************************
        // Prototype   : public void SendViewInternal ( string ViewName )
        // Description : Informe le service qu'une vue a été chargée
        //*****************************************************************************************
        /// <summary>
        /// Informe le service qu'une vue a été chargée.
        /// </summary>
        /// <param name="ViewName">Nom de la vue.</param>
        //-----------------------------------------------------------------------------------------
        private void SendViewInternal(string ViewName)
        {
            //-------------------------------------------------------------------------------------
            Size Sr = ScreenResolution;

            var PayloadData = new Dictionary <string, string>();

            PayloadData.Add("v", "1");
            PayloadData.Add("tid", this.PropertyId);
            PayloadData.Add("cid", this.ClientID);
            PayloadData.Add("an", this.AppName);
            PayloadData.Add("av", this.AppVersion.ToString());
            PayloadData.Add("t", "appview");
            PayloadData.Add("cd", ViewName);
            PayloadData.Add("sr", string.Format("{0}x{1}", Sr.Width, Sr.Height));
            PayloadData.Add("vp", string.Format("{0}x{1}", Sr.Width, Sr.Height));
            PayloadData.Add("ul", UserLanguage.ToLowerInvariant());
            //-------------------------------------------------------------------------------------

            //-------------------------------------------------------------------------------------
            foreach (KeyValuePair <int, string> Cd in this.CustomDimentions)
            {
                PayloadData.Add(string.Format("cd{0}", Cd.Key), Cd.Value);
            }
            //-------------------------------------------------------------------------------------

            //-------------------------------------------------------------------------------------
            SendOrPostCallback Event = ( object Args ) =>
            {
                //---------------------------------------------------------------------------------
                Dictionary <string, string> Data = (Dictionary <string, string>)Args;

                var    EndPoint = this.UseSecure ? EndPointSecure : EndPointUnsecure;
                byte[] Content  = Encoding.UTF8.GetBytes(GetUrlEncodedString(Data));
                //---------------------------------------------------------------------------------

                //---------------------------------------------------------------------------------
                try
                {
                    //-----------------------------------------------------------------------------
                    HttpWebRequest http = (HttpWebRequest)HttpWebRequest.Create(EndPoint);

                    http.Method      = "POST";
                    http.ContentType = "application/x-www-form-urlencoded";
                    http.UserAgent   = DeviceInfos.UserAgent;

                    http.BeginGetRequestStream(( IAsyncResult A ) =>
                    {
                        //-------------------------------------------------------------------------
                        try
                        {
                            //---------------------------------------------------------------------
                            HttpWebRequest Request_A = (HttpWebRequest)A.AsyncState;

                            Stream Stream = Request_A.EndGetRequestStream(A);

                            Stream.Write(Content, 0, Content.Length);

                            Stream.Close();
                            //---------------------------------------------------------------------

                            //---------------------------------------------------------------------
                            Request_A.BeginGetResponse(( IAsyncResult B ) =>
                            {
                                //-----------------------------------------------------------------
                                try
                                {
                                    //-------------------------------------------------------------
                                    HttpWebRequest Request_B = (HttpWebRequest)B.AsyncState;

                                    WebResponse Response = Request_B.EndGetResponse(B);

                                    HttpWebResponse HttpResponse = Response as HttpWebResponse;

                                    using (Stream S = HttpResponse.GetResponseStream()) {}
                                    //-------------------------------------------------------------
                                }
                                //-----------------------------------------------------------------
                                catch {}
                                //-----------------------------------------------------------------
                            }, Request_A);
                            //---------------------------------------------------------------------
                        }
                        //-------------------------------------------------------------------------
                        catch {}
                        //-------------------------------------------------------------------------
                    }, http);
                    //-----------------------------------------------------------------------------
                }
                //---------------------------------------------------------------------------------
                catch {}
                //---------------------------------------------------------------------------------
            };

            //-------------------------------------------------------------------------------------

            //-------------------------------------------------------------------------------------
            AsyncOperationManager.CreateOperation(null).PostOperationCompleted
                (Event, PayloadData);
            //-------------------------------------------------------------------------------------
        }