Esempio n. 1
0
        private void OnRequestFailed(PreparedTrackingRequest request, IRestResponse response)
        {
            if (response.ResponseStatus != ResponseStatus.Completed || response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                ThreadPool.RegisterWaitForSingleObject(new ManualResetEvent(false), (completed, state) =>
                {
                    RequestQueue.OnNext(request); //Re-queue the item for sending
                }, null, RetryInterval, true);
            }

            Debug.WriteLine("Analytics Request Failed");
            Debug.Indent();
            Debug.WriteLine("{0} {1} {2}", response.ResponseStatus, (int)response.StatusCode, response.StatusCode);
            Debug.WriteLine("{0}", response.Request.Parameters.Select(x => x.Name + "=" + x.Value).Aggregate((x, y) => x + "&" + y));
            if (!response.Content.IsNullOrEmpty())
            {
                Debug.WriteLine("{0}", response.Content);
            }
            Debug.Unindent();
            KeyStore.Invalidate(string.Format("PreparedTrackingRequest_{0}", request.RequestID.ToString()));
        }
Esempio n. 2
0
        private void ProcessRequest(PreparedTrackingRequest request)
        {
            foreach (var finalizer in request.RequiredFinalizations)
            {
                finalizer.FinalizeRequest(request.Request);
            }

            var response = request.Engine.NetworkClient.Execute(request.Request);

            if (response.ResponseStatus != ResponseStatus.Completed)
            {
                OnRequestFailed(request, response);
            }
            else if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                OnRequestFailed(request, response);
            }
            else
            {
                OnRequestTransmitted(request);
            }
        }
        public void Tracking_Serialization()
        {
            var engine  = TrackingEngine.GetEngine(() => Tracking_Serialization()) as UniversalAnalytics;
            var request = new RestRequest()
            {
                Resource = "/collect",
                Method   = Method.POST
            };

            request.AddParameter("q", "Test", ParameterType.GetOrPost);
            request.AddParameter("r", "Yargh!", ParameterType.GetOrPost);
            var pendingRequest = new PreparedTrackingRequest(engine, request, Array.Empty <Implementation.ITrackingFinalize>());
            var formatter      = new BinaryFormatter();

            PreparedTrackingRequest deserialized = null;

            using (var ms = new MemoryStream())
            {
                formatter.Serialize(ms, pendingRequest);
                ms.Seek(0, SeekOrigin.Begin);
                deserialized = formatter.Deserialize(ms) as PreparedTrackingRequest;
            }

            Assert.IsNotNull(deserialized);
            Assert.IsNotNull(deserialized.Request);
            Assert.AreEqual(pendingRequest.Generated, deserialized.Generated);
            Assert.AreEqual(pendingRequest.Engine, deserialized.Engine);

            Assert.AreEqual(pendingRequest.Request.Parameters.Count, request.Parameters.Count);
            for (int i = 0; i < pendingRequest.Request.Parameters.Count; i++)
            {
                var got      = pendingRequest.Request.Parameters[i];
                var expected = request.Parameters[i];
                Assert.AreEqual(expected.Type, got.Type);
                Assert.AreEqual(expected.Name, got.Name);
                Assert.AreEqual(expected.Value, got.Value);
            }
        }
Esempio n. 4
0
 private void OnRequestTransmitted(PreparedTrackingRequest request)
 {
     KeyStore.Invalidate(string.Format("PreparedTrackingRequest_{0}", request.RequestID.ToString()));
 }
Esempio n. 5
0
 private void OnStoredRequestLoaded(PreparedTrackingRequest request)
 {
     RequestQueue.OnNext(request);
 }
Esempio n. 6
0
        private void OnRequestPrepared(PreparedTrackingRequest request)
        {
            KeyStore.InsertObject($"PreparedTrackingRequest_{request.RequestID}", request, new DateTimeOffset(DateTime.Now.Add(QueueLifeSpan)));

            RequestQueue.OnNext(request);
        }