Exemple #1
0
        public void TestSessionTimeout()
        {
            MobileAnalyticsManagerConfig maConfig = new MobileAnalyticsManagerConfig();

            Console.WriteLine("session delta is " + maConfig.SessionTimeout);

            string appID = Guid.NewGuid().ToString();

            // create AmazonMobileAnayticsManager instance
            MobileAnalyticsManager.GetOrCreateInstance(appID, Credentials, RegionEndpoint.USEast1, maConfig);
            Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.Session session = new Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.Session(appID, new MobileAnalyticsManagerConfig());
            session.Start();
            DateTime startTime1 = session.StartTime;
            string   sessionId1 = session.SessionId;

            // sleep for a while but wake up before session expires
            session.Pause();
            Thread.Sleep(Convert.ToInt32((maConfig.SessionTimeout - 1) * 1000));
            session.Resume();

            // make sure session is not expired
            DateTime startTime2 = session.StartTime;
            string   sessionId2 = session.SessionId;

            Assert.IsTrue(startTime1 == startTime2 && sessionId1 == sessionId2);

            // sleep longer until session expires
            session.Pause();
            Thread.Sleep(Convert.ToInt32((maConfig.SessionTimeout + 1) * 1000));
            session.Resume();

            // make sure session is expired
            DateTime startTime3 = session.StartTime;
            string   sessionId3 = session.SessionId;

            Assert.IsTrue(startTime3 > startTime2 && sessionId2 != sessionId3);

            // sleep for a while but wake up before session expires
            session.Pause();
            Thread.Sleep(Convert.ToInt32((maConfig.SessionTimeout - 1) * 1000));
            session.Resume();

            // make sure session is not expired
            DateTime startTime4 = session.StartTime;
            string   sessionId4 = session.SessionId;

            Assert.IsTrue(startTime4 == startTime3 && sessionId4 == sessionId3);

            // sleep longer until session expires
            session.Pause();
            Thread.Sleep(Convert.ToInt32((maConfig.SessionTimeout + 1) * 1000));
            session.Resume();

            // make sure session is expired
            DateTime startTime5 = session.StartTime;
            string   sessionId5 = session.SessionId;

            Assert.IsTrue(startTime5 > startTime4 && sessionId5 != sessionId4);
        }
Exemple #2
0
        /// <summary>
        /// Converts to mobile analytics model event. <see cref="Amazon.MobileAnalytics.Model.Event"/>
        /// </summary>
        /// <returns>The to mobile analytics model event.</returns>
        /// <param name="session">Session. <see cref="Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.Session"/></param>
        internal virtual Amazon.MobileAnalytics.Model.Event ConvertToMobileAnalyticsModelEvent(Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.Session session)
        {
            Amazon.MobileAnalytics.Model.Event modelEvent = new Amazon.MobileAnalytics.Model.Event();

            this.StartTimestamp = session.StartTime;
            this.SessionId      = session.SessionId;


            // assign session info from custom event to model event
            modelEvent.EventType  = this.EventType;
            modelEvent.Session    = new Amazon.MobileAnalytics.Model.Session();
            modelEvent.Session.Id = session.SessionId;
            modelEvent.Session.StartTimestampUtc = session.StartTime;
            if (session.StopTime != null)
            {
                modelEvent.Session.StopTimestampUtc = session.StopTime.Value;
            }


            if (this.EventType == Constants.SESSION_STOP_EVENT_TYPE)
            {
                modelEvent.Session.StopTimestampUtc = this.StopTimestamp.Value;
                modelEvent.Session.Duration         = this.Duration;
            }

            lock (_globalLock)
            {
                AddDict(_globalAttributes, modelEvent.Attributes);
                if (_eventTypeGlobalAttributes.ContainsKey(EventType))
                {
                    AddDict(_eventTypeGlobalAttributes[EventType], modelEvent.Attributes);
                }

                AddDict(_globalMetrics, modelEvent.Metrics);
                if (_eventTypeGlobalMetrics.ContainsKey(EventType))
                {
                    AddDict(_eventTypeGlobalMetrics[EventType], modelEvent.Metrics);
                }
            }

            lock (_lock)
            {
                AddDict(_attributes, modelEvent.Attributes);
                AddDict(_metrics, modelEvent.Metrics);
            }

            modelEvent.TimestampUtc = Timestamp;
            modelEvent.Version      = "v2.0";

            return(modelEvent);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Amazon.MobileAnalytics.MobileAnalyticsManager.MobileAnalyticsManager"/> class.
        /// </summary>
        /// <param name="clientContextConfig">Client context config.</param>
        /// <param name="regionEndpoint">Region endpoint.</param>
        /// <param name="credentials">AWS Credentials.</param>
        private MobileAnalyticsManager(string appId, AWSCredentials credentials, RegionEndpoint regionEndpoint)
        {
            _appId = appId;

            ClientContext = new Amazon.Runtime.Internal.ClientContext(appId);

            if (credentials == null)
                throw new ArgumentNullException("credentials");

            BackgroundDeliveryClient = new DeliveryClient(AWSConfigsMobileAnalytics.AllowUseDataNetwork, ClientContext, credentials, regionEndpoint);

            Session = new Session(_appId);
        }
Exemple #4
0
        /// <summary>
        /// Converts to mobile analytics model event. <see cref="Amazon.MobileAnalytics.Model.Event"/>
        /// </summary>
        /// <returns>The to mobile analytics model event.</returns>
        /// <param name="session">Session.</param>
        public virtual Amazon.MobileAnalytics.Model.Event ConvertToMobileAnalyticsModelEvent(Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.Session session)
        {
            Amazon.MobileAnalytics.Model.Event modelEvent = new Amazon.MobileAnalytics.Model.Event();

            // get session info
            string startTimestamp = null, stopTimestamp = null, sessionId = null; long duration = 0;

            session.GetSessionInfo(out startTimestamp, out stopTimestamp, out sessionId, out duration);

            if (string.IsNullOrEmpty(this.StartTimestamp))
            {
                this.StartTimestamp = startTimestamp;
            }
            if (string.IsNullOrEmpty(this.SessionId))
            {
                this.SessionId = sessionId;
            }



            // assign session info from manager event to model event
            modelEvent.EventType              = this._eventType;
            modelEvent.Session                = new Amazon.MobileAnalytics.Model.Session();
            modelEvent.Session.Id             = this.SessionId;
            modelEvent.Session.StartTimestamp = DateTime.ParseExact(this.StartTimestamp, AWSSDKUtils.ISO8601DateFormat, CultureInfo.InvariantCulture);

            if (_eventType == "_session.stop")
            {
                modelEvent.Session.StopTimestamp = DateTime.ParseExact(stopTimestamp, AWSSDKUtils.ISO8601DateFormat, CultureInfo.InvariantCulture);
                modelEvent.Session.Duration      = this.Duration;
            }

            lock (_globalLock)
            {
                AddDict(_globalAttributes, modelEvent.Attributes);
                if (_eventTypeGlobalAttributes.ContainsKey(_eventType))
                {
                    AddDict(_eventTypeGlobalAttributes[_eventType], modelEvent.Attributes);
                }

                AddDict(_globalMetrics, modelEvent.Metrics);
                if (_eventTypeGlobalMetrics.ContainsKey(_eventType))
                {
                    AddDict(_eventTypeGlobalMetrics[_eventType], modelEvent.Metrics);
                }
            }

            lock (_lock)
            {
                AddDict(_attributes, modelEvent.Attributes);
                AddDict(_metrics, modelEvent.Metrics);
            }

            modelEvent.Timestamp = DateTime.ParseExact(this.Timestamp, AWSSDKUtils.ISO8601DateFormat, CultureInfo.InvariantCulture);
            modelEvent.Version   = "v2.0";

            return(modelEvent);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Amazon.MobileAnalytics.MobileAnalyticsManager.MobileAnalyticsManager"/> class.
        /// </summary>
        /// <param name="clientContextConfig">Client context config.</param>
        /// <param name="regionEndpoint">Region endpoint.</param>
        /// <param name="credentials">AWS Credentials.</param>
        private MobileAnalyticsManager(ClientContextConfig clientContextConfig,RegionEndpoint regionEndpoint,AWSCredentials credentials)
        {        
            if(clientContextConfig == null)
                throw new ArgumentNullException("clientContextConfig");
            ClientContext = new ClientContext(clientContextConfig);
            
            if(string.IsNullOrEmpty(clientContextConfig.AppId))
                throw new ArgumentNullException("application id");
            _appId = clientContextConfig.AppId;
            
            if(credentials == null)
                throw new ArgumentNullException("credentials");

            BackgroundDeliveryClient = new DeliveryClient(AWSConfigsMobileAnalytics.AllowUseDataNetwork, ClientContext, credentials, regionEndpoint);
            
            Session = new Session(_appId);
        }
        public void TestSessionTimeout()
        {
            MobileAnalyticsManagerConfig maConfig = new MobileAnalyticsManagerConfig();

            Console.WriteLine("session delta is " + maConfig.SessionTimeout);

            string appID = Guid.NewGuid().ToString();

            // create AmazonMobileAnayticsManager instance
            MobileAnalyticsManager.GetOrCreateInstance(appID, CommonTests.Framework.TestRunner.Credentials, RegionEndpoint.USEast1, maConfig);
            Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.Session session = new Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.Session(appID, new MobileAnalyticsManagerConfig());
            session.Start();
            DateTime startTime1 = session.StartTime;
            string   sessionId1 = session.SessionId;

            // sleep for a while but wake up before session expires
            session.Pause();
            Task.Delay(TimeSpan.FromSeconds(maConfig.SessionTimeout - 1)).Wait();
            session.Resume();

            // make sure session is not expired
            DateTime startTime2 = session.StartTime;
            string   sessionId2 = session.SessionId;

            Assert.IsTrue(startTime1 == startTime2);
            Assert.IsTrue(sessionId1 == sessionId2);

            // sleep longer until session expires
            session.Pause();
            Task.Delay(TimeSpan.FromSeconds(maConfig.SessionTimeout + 1)).Wait();
            session.Resume();

            // make sure session is expired
            DateTime startTime3 = session.StartTime;
            string   sessionId3 = session.SessionId;

            Assert.IsTrue(startTime3 > startTime2);
            Assert.IsTrue(sessionId2 != sessionId3);

            // sleep for a while but wake up before session expires
            session.Pause();
            Task.Delay(TimeSpan.FromSeconds(maConfig.SessionTimeout - 1)).Wait();
            session.Resume();

            // make sure session is not expired
            DateTime startTime4 = session.StartTime;
            string   sessionId4 = session.SessionId;

            Assert.IsTrue(startTime4 == startTime3);
            Assert.IsTrue(sessionId4 == sessionId3);

            // sleep longer until session expires
            session.Pause();
            Task.Delay(TimeSpan.FromSeconds(maConfig.SessionTimeout + 1)).Wait();
            session.Resume();

            // make sure session is expired
            DateTime startTime5 = session.StartTime;
            string   sessionId5 = session.SessionId;

            Assert.IsTrue(startTime5 > startTime4);
            Assert.IsTrue(sessionId5 != sessionId4);
        }
Exemple #7
0
        /// <summary>
        /// Converts to mobile analytics model event. <see cref="Amazon.MobileAnalytics.Model.Event"/>
        /// </summary>
        /// <returns>The to mobile analytics model event.</returns>
        /// <param name="session">Session.</param>
        public override Amazon.MobileAnalytics.Model.Event ConvertToMobileAnalyticsModelEvent(Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.Session session)
        {
            if (Quantity != null)
            {
                this.AddMetric(PURCHASE_EVENT_QUANTITY_METRIC, Convert.ToDouble(Quantity));
            }

            if (ItemPrice != null)
            {
                this.AddMetric(PURCHASE_EVENT_ITEM_PRICE_METRIC, Convert.ToDouble(ItemPrice));
            }

            if (!string.IsNullOrEmpty(ProductId))
            {
                this.AddAttribute(PURCHASE_EVENT_PRODUCT_ID_ATTR, ProductId);
            }

            if (!string.IsNullOrEmpty(ItemPriceFormatted))
            {
                this.AddAttribute(PURCHASE_EVENT_ITEM_PRICE_FORMATTED_ATTR, ItemPriceFormatted);
            }

            if (!string.IsNullOrEmpty(Store))
            {
                this.AddAttribute(PURCHASE_EVENT_STORE_ATTR, Store);
            }

            if (!string.IsNullOrEmpty(TransactionId))
            {
                this.AddAttribute(PURCHASE_EVENT_TRANSACTION_ID_ATTR, TransactionId);
            }

            if (!string.IsNullOrEmpty(Currency))
            {
                this.AddAttribute(PURCHASE_EVENT_CURRENCY_ATTR, Currency);
            }

            return(base.ConvertToMobileAnalyticsModelEvent(session));
        }