private void TrackEventInternal(AdjustEvent adjustEvent) { if (!IsEnabled()) { return; } if (!CheckEvent(adjustEvent)) { return; } var now = DateTime.Now; ActivityState.EventCount++; UpdateActivityState(now); var packageBuilder = new PackageBuilder(AdjustConfig, DeviceInfo, ActivityState, now); ActivityPackage eventPackage = packageBuilder.BuildEventPackage(adjustEvent); PackageHandler.AddPackage(eventPackage); if (AdjustConfig.EventBufferingEnabled) { Logger.Info("Buffered event {0}", eventPackage.Suffix); } else { PackageHandler.SendFirstPackage(); } WriteActivityStateInternal(); }
private void OpenUrlInternal(Uri uri) { if (uri == null) { return; } var sUri = Uri.UnescapeDataString(uri.ToString()); var windowsPhone80Protocol = "/Protocol?"; if (sUri.StartsWith(windowsPhone80Protocol)) { sUri = sUri.Substring(windowsPhone80Protocol.Length); } var queryStringIdx = sUri.IndexOf("?"); // check if '?' exists and it's not the last char if (queryStringIdx == -1 || queryStringIdx + 1 == sUri.Length) { return; } var queryString = sUri.Substring(queryStringIdx + 1); // remove any possible fragments var fragmentIdx = queryString.LastIndexOf("#"); if (fragmentIdx != -1) { queryString = queryString.Substring(0, fragmentIdx); } var queryPairs = queryString.Split('&'); var extraParameters = new Dictionary <string, string>(queryPairs.Length); var attribution = new AdjustAttribution(); bool hasAdjustTags = false; foreach (var pair in queryPairs) { if (ReadQueryString(pair, extraParameters, attribution)) { hasAdjustTags = true; } } if (!hasAdjustTags) { return; } var clickPackage = GetDeeplinkClickPackage(extraParameters, attribution); PackageHandler.AddPackage(clickPackage); PackageHandler.SendFirstPackage(); }
private void TransferSessionPackage() { // build Session Package var sessionBuilder = new PackageBuilder(AdjustConfig, DeviceInfo, ActivityState, DateTime.Now); var sessionPackage = sessionBuilder.BuildSessionPackage(); // send Session Package PackageHandler.AddPackage(sessionPackage); PackageHandler.SendFirstPackage(); }
private void EndInternal() { PackageHandler.PauseSending(); AttributionHandler.PauseSending(); StopTimer(); if (UpdateActivityState(DateTime.Now)) { WriteActivityStateInternal(); } }
private void UpdatePackageHandlerStatus() { if (Paused()) { PackageHandler.PauseSending(); } else { PackageHandler.ResumeSending(); } }
public override void SetUp() { base.SetUp(); MockRequestHandler = new MockRequestHandler(MockLogger); MockActivityHandler = new MockActivityHandler(MockLogger); AdjustFactory.Logger = MockLogger; AdjustFactory.SetRequestHandler(MockRequestHandler); AdjustFactory.SetActivityHandler(MockActivityHandler); ActivityHandler = GetActivityHandler(); PackageHandler = StartPackageHandler(); }
private void TimerFiredInternal() { if (Paused()) { StopTimer(); return; } Logger.Debug("Session timer fired"); PackageHandler.SendFirstPackage(); if (UpdateActivityState(DateTime.Now)) { WriteActivityStateInternal(); } }
private void PackageSent(Task <SendResponse> SendTask) { // status needs to be tested before reading the result. // section "Passing data to a continuation" of // http://msdn.microsoft.com/en-us/library/ee372288(v=vs.110).aspx var successRunning = !SendTask.IsFaulted && !SendTask.IsCanceled; if (successRunning && SendTask.Result.JsonDict != null) { PackageHandler.FinishedTrackingActivity(SendTask.Result.JsonDict); } //Logger.Debug("SendTask.Result.WillRetry {0}", SendTask.Result.WillRetry); if (successRunning && !SendTask.Result.WillRetry) { PackageHandler.SendNextPackage(); } else { PackageHandler.CloseFirstPackage(); } }
private PackageHandler StartPackageHandler() { // delete package queue for fresh start var packageQueueDeleted = Util.DeleteFile("AdjustIOPackageQueue"); MockLogger.Test("Was PackageQueue deleted? " + packageQueueDeleted); PackageHandler packageHandler = new PackageHandler( activityHandler:MockActivityHandler, startPaused: false); DeviceUtil.Sleep(1000); Assert.Verbose("Package queue file not found"); return packageHandler; }
private PackageHandler AddSecondPackageTest(PackageHandler packageHandler) { if (packageHandler == null) { packageHandler = new PackageHandler( activityHandler: MockActivityHandler, startPaused: false); DeviceUtil.Sleep(1000); // check that it can read the previously saved package Assert.Debug("Package handler read 1 packages"); } ActivityPackage secondActivityPackage = CreateUnknowPackage("SecondPackage"); packageHandler.AddPackage(secondActivityPackage); DeviceUtil.Sleep(1000); AddPackageTests(packageNumber: 2, packageString: "unknownSecondPackage"); return packageHandler; }
private void AddAndSendFirstPackageTest(PackageHandler packageHandler) { // add a package ActivityPackage activityPackage = CreateUnknowPackage("FirstPackage"); // send the first package packageHandler.AddPackage(activityPackage); packageHandler.SendFirstPackage(); DeviceUtil.Sleep(2000); AddPackageTests(1, "unknownFirstPackage"); SendFirstTests(SendFirstState.SEND, "unknownFirstPackage"); }
public void TestSendFirst() { PackageHandler.SendFirstPackage(); DeviceUtil.Sleep(1000); SendFirstTests(SendFirstState.EMPTY_QUEUE); AddAndSendFirstPackageTest(PackageHandler); // try to send when it is still sending PackageHandler.SendFirstPackage(); DeviceUtil.Sleep(1000); SendFirstTests(SendFirstState.IS_SENDING); // try to send paused PackageHandler.PauseSending(); PackageHandler.SendFirstPackage(); DeviceUtil.Sleep(1000); SendFirstTests(SendFirstState.PAUSED); // unpause, it's still sending PackageHandler.ResumeSending(); PackageHandler.SendFirstPackage(); DeviceUtil.Sleep(1000); SendFirstTests(SendFirstState.IS_SENDING); // verify that both paused and isSending are reset with a new session PackageHandler secondSessionPackageHandler = new PackageHandler( activityHandler: MockActivityHandler, startPaused: false); secondSessionPackageHandler.SendFirstPackage(); DeviceUtil.Sleep(1000); // send the package to request handler SendFirstTests(SendFirstState.SEND, "unknownFirstPackage"); }