/// <summary> /// Records the custom event to the local persistent storage. Background thread will deliver the event later. /// </summary> /// <param name="customEvent">The Mobile Analytics event.</param> public void RecordEvent(CustomEvent customEvent) { if (null == customEvent) throw new ArgumentNullException("customEvent"); customEvent.Timestamp = DateTime.UtcNow; Amazon.MobileAnalytics.Model.Event modelEvent = customEvent.ConvertToMobileAnalyticsModelEvent(this.Session); BackgroundDeliveryClient.EnqueueEventsForDelivery(modelEvent); }
/// <summary> /// Records the custom event to the local persistent storage. Background thread will deliver the event later. /// </summary> /// <param name="customEvent">The event.</param> public void RecordEvent(CustomEvent customEvent) { customEvent.Timestamp = DateTime.UtcNow.ToString(AWSSDKUtils.ISO8601DateFormat); Amazon.MobileAnalytics.Model.Event modelEvent = customEvent.ConvertToMobileAnalyticsModelEvent(this.Session); BackgroundDeliveryClient.EnqueueEventsForDelivery(modelEvent); }
public void TestCustomEventConcurrency() { // event type const string EVENT_TYPE = "MyEventType"; // attribute config string ATTR1 = "ATTR1"; string ATTR1_VAL_T0 = "dshjadfhjdfa132`23jj`23jh1k2h3h21hg3h21j2gh"; string ATTR1_VAL_T1 = "gfhfdhgvkfdkgljfdgjfdsj;l34t43jj4erjerb"; string ATTR1_VAL_T2 = "7t32674tgdfjehkjdksjs;akfdshfjdsafkadsfdsljfa"; string ATTR2 = "ATTR2"; string ATTR2_VAL_T0 = "343hjfdshdfjklsafj0913432jh4"; string ATTR2_VAL_T1 = "378t43y21ggdhsgdahshfdjsfafd"; string ATTR2_VAL_T2 = "48ry42378tfhsfkds;kfl;dsdfk;ldslks"; string ATTR3 = "ATTR3"; string ATTR3_VAL_T0 = "321432g4ghjfjshdggfjhsdgfdskgfjdsjgfsd"; string ATTR3_VAL_T1 = "76432tgrsgerhjkfgshdfdssfgjdssaf"; string ATTR3_VAL_T2 = "87549353hjtkgdk;sfgfdgf;kfl;dshfjdsjkhfjs"; string ATTR_EMPTY1 = "ATTR_EMPTY1"; string ATTR_EMPTY2 = "ATTR_EMPTY2"; string ATTR_EMPTY3 = "ATTR_EMPTY3"; // metric config System.Random randObj = new System.Random(); const string METRIC1 = "METRIC1"; double METRIC1_VAL_T0 = randObj.Next(); double METRIC1_VAL_T1 = randObj.Next(); double METRIC1_VAL_T2 = randObj.Next(); const string METRIC2 = "METRIC2"; double METRIC2_VAL_T0 = randObj.Next(); double METRIC2_VAL_T1 = randObj.Next(); double METRIC2_VAL_T2 = randObj.Next(); const string METRIC3 = "METRIC3"; double METRIC3_VAL_T0 = randObj.Next(); double METRIC3_VAL_T1 = randObj.Next(); double METRIC3_VAL_T2 = randObj.Next(); CustomEvent customEvent = new CustomEvent(EVENT_TYPE); const int LOOP_COUNT = 999; Task task0 = new Task(() => { for (int i = 0; i < LOOP_COUNT; i++) { customEvent.AddAttribute(ATTR1, ATTR1_VAL_T0); customEvent.AddGlobalAttribute(ATTR2, ATTR2_VAL_T0); customEvent.AddGlobalAttribute(EVENT_TYPE, ATTR3, ATTR3_VAL_T0); customEvent.AddMetric(METRIC1, METRIC1_VAL_T0); customEvent.AddGlobalMetric(METRIC2, METRIC2_VAL_T0); customEvent.AddGlobalMetric(EVENT_TYPE, METRIC3, METRIC3_VAL_T0); customEvent.AddAttribute(ATTR_EMPTY1, ""); customEvent.AddGlobalAttribute(ATTR_EMPTY2, ""); customEvent.AddGlobalAttribute(EVENT_TYPE, ATTR_EMPTY3, ""); } }); Task task1 = new Task(() => { for (int i = 0; i < LOOP_COUNT; i++) { customEvent.AddAttribute(ATTR1, ATTR1_VAL_T1); customEvent.AddGlobalAttribute(ATTR2, ATTR2_VAL_T1); customEvent.AddGlobalAttribute(EVENT_TYPE, ATTR3, ATTR3_VAL_T1); customEvent.AddMetric(METRIC1, METRIC1_VAL_T1); customEvent.AddGlobalMetric(METRIC2, METRIC2_VAL_T1); customEvent.AddGlobalMetric(EVENT_TYPE, METRIC3, METRIC3_VAL_T1); } }); Task task2 = new Task(() => { for (int i = 0; i < LOOP_COUNT; i++) { customEvent.AddAttribute(ATTR1, ATTR1_VAL_T1); customEvent.AddGlobalAttribute(ATTR2, ATTR2_VAL_T1); customEvent.AddGlobalAttribute(EVENT_TYPE, ATTR3, ATTR3_VAL_T1); customEvent.AddMetric(METRIC1, METRIC1_VAL_T1); customEvent.AddGlobalMetric(METRIC2, METRIC2_VAL_T1); customEvent.AddGlobalMetric(EVENT_TYPE, METRIC3, METRIC3_VAL_T1); } }); task0.Start(); task1.Start(); task2.Start(); // wait all task complete Task.WaitAll(new[] { task0, task1, task2 }); // Get Model event. Amazon.MobileAnalytics.Model.Event modelEvent = customEvent.ConvertToMobileAnalyticsModelEvent(GetMobileAnalyticsManager("TestCustomEventConcurrency").Session); // check attribute value if (!modelEvent.Attributes.ContainsKey(ATTR1) || !modelEvent.Attributes.ContainsKey(ATTR2) || !modelEvent.Attributes.ContainsKey(ATTR3)) { Assert.Fail(); return; } if (modelEvent.Attributes[ATTR1] != ATTR1_VAL_T0 && modelEvent.Attributes[ATTR1] != ATTR1_VAL_T1 && modelEvent.Attributes[ATTR1] != ATTR1_VAL_T2) { Assert.Fail(); return; } if (modelEvent.Attributes[ATTR2] != ATTR2_VAL_T0 && modelEvent.Attributes[ATTR2] != ATTR2_VAL_T1 && modelEvent.Attributes[ATTR2] != ATTR2_VAL_T2) { Assert.Fail(); return; } if (modelEvent.Attributes[ATTR3] != ATTR3_VAL_T0 && modelEvent.Attributes[ATTR3] != ATTR3_VAL_T1 && modelEvent.Attributes[ATTR3] != ATTR3_VAL_T2) { Assert.Fail(); return; } if (modelEvent.Attributes[ATTR_EMPTY1] != "" || modelEvent.Attributes[ATTR_EMPTY2] != "" || modelEvent.Attributes[ATTR_EMPTY3] != "") { Assert.Fail(); return; } // check metric value if (!modelEvent.Metrics.ContainsKey(METRIC1) || !modelEvent.Metrics.ContainsKey(METRIC2) || !modelEvent.Metrics.ContainsKey(METRIC3)) { Assert.Fail(); return; } if (modelEvent.Metrics[METRIC1] != METRIC1_VAL_T0 && modelEvent.Metrics[METRIC1] != METRIC1_VAL_T1 && modelEvent.Metrics[METRIC1] != METRIC1_VAL_T2) { Assert.Fail(); return; } if (modelEvent.Metrics[METRIC2] != METRIC2_VAL_T0 && modelEvent.Metrics[METRIC2] != METRIC2_VAL_T1 && modelEvent.Metrics[METRIC2] != METRIC2_VAL_T2) { Assert.Fail(); return; } if (modelEvent.Metrics[METRIC3] != METRIC3_VAL_T0 && modelEvent.Metrics[METRIC3] != METRIC3_VAL_T1 && modelEvent.Metrics[METRIC3] != METRIC3_VAL_T2) { Assert.Fail(); return; } }