Exemplo n.º 1
0
        public void testInitSelfDescribing()
        {
            var sdj = new SelfDescribingJson("iglu:com.acme/some_event/jsonschema/1-0-0", new Dictionary <string, string>
            {
                { "hello", "world" }
            });

            var sd = new SelfDescribing()
                     .SetEventData(sdj)
                     .SetTrueTimestamp(123456789123)
                     .Build();

            Assert.IsNotNull(sd);
            Assert.AreEqual(Constants.EVENT_UNSTRUCTURED, sd.GetPayload().Payload[Constants.EVENT]);
            Assert.AreEqual(@"{""schema"":""iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0"",""data"":{""schema"":""iglu:com.acme/some_event/jsonschema/1-0-0"",""data"":{""hello"":""world""}}}", sd.GetPayload().Payload[Constants.UNSTRUCTURED]);

            sd.SetBase64Encode(true);

            Assert.AreEqual("eyJzY2hlbWEiOiJpZ2x1OmNvbS5zbm93cGxvd2FuYWx5dGljcy5zbm93cGxvdy91bnN0cnVjdF9ldmVudC9qc29uc2NoZW1hLzEtMC0wIiwiZGF0YSI6eyJzY2hlbWEiOiJpZ2x1OmNvbS5hY21lL3NvbWVfZXZlbnQvanNvbnNjaGVtYS8xLTAtMCIsImRhdGEiOnsiaGVsbG8iOiJ3b3JsZCJ9fX0=", sd.GetPayload().Payload[Constants.UNSTRUCTURED_ENCODED]);

            Assert.IsNotNull(sd.GetContexts());
            Assert.IsTrue(sd.GetPayload().Payload.ContainsKey(Constants.EID));
            Assert.IsTrue(sd.GetPayload().Payload.ContainsKey(Constants.TIMESTAMP));
            Assert.IsTrue(sd.GetPayload().Payload.ContainsKey(Constants.TRUE_TIMESTAMP));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Figures out what kind of event is being tracked and
        /// then processes it accordingly.
        /// </summary>
        /// <param name="newEvent"></param>
        private void ProcessEvent(IEvent newEvent)
        {
            List <IContext> contexts = newEvent.GetContexts();
            string          eventId  = newEvent.GetEventId();
            Type            eType    = newEvent.GetType();

            if (eType == typeof(PageView) || eType == typeof(Structured))
            {
                CompleteAndTrackPayload((Payload)newEvent.GetPayload(), contexts, eventId);
            }
            else if (eType == typeof(EcommerceTransaction))
            {
                CompleteAndTrackPayload((Payload)newEvent.GetPayload(), contexts, eventId);
                EcommerceTransaction ecommerceTransaction = (EcommerceTransaction)newEvent;
                foreach (EcommerceTransactionItem item in ecommerceTransaction.GetItems())
                {
                    item.SetItemId(ecommerceTransaction.GetOrderId());
                    item.SetCurrency(ecommerceTransaction.GetCurrency());
                    item.SetDeviceCreatedTimestamp(ecommerceTransaction.GetDeviceCreatedTimestamp());
                    item.SetTrueTimestamp(ecommerceTransaction.GetTrueTimestamp());
                    CompleteAndTrackPayload((Payload)item.GetPayload(), item.GetContexts(), item.GetEventId());
                }
            }
            else if (eType == typeof(SelfDescribing))
            {
                SelfDescribing selfDescribing = (SelfDescribing)newEvent;
                selfDescribing.SetBase64Encode(_encodeBase64);
                CompleteAndTrackPayload((Payload)selfDescribing.GetPayload(), contexts, eventId);
            }
            else if (eType == typeof(ScreenView) || eType == typeof(Timing))
            {
                ProcessEvent(new SelfDescribing()
                             .SetEventData((SelfDescribingJson)newEvent.GetPayload())
                             .SetCustomContext(newEvent.GetContexts())
                             .SetDeviceCreatedTimestamp(newEvent.GetDeviceCreatedTimestamp())
                             .SetTrueTimestamp(newEvent.GetTrueTimestamp())
                             .SetEventId(newEvent.GetEventId())
                             .Build());
            }
        }
Exemplo n.º 3
0
 public static string asString(SelfDescribing selfDescribing)
 {
   return StringDescription.toString(selfDescribing);
 }
Exemplo n.º 4
0
 public static string toString(SelfDescribing value)
 {
   return Object.instancehelper_toString((object) new StringDescription().appendDescriptionOf(value));
 }
Exemplo n.º 5
0
 public virtual Description appendDescriptionOf(SelfDescribing value)
 {
   value.describeTo((Description) this);
   return (Description) this;
 }