protected void SetNormalProperties(IDictionary<string, object> obj, MessageData messageData)
 {
     foreach (var prop in messageData.Props)
     {
         obj[prop.Key] = prop.Value;
     }
 }
        public override IDictionary<string, object> GetMessageObject(MessageData messageData)
        {
            IDictionary<string, object> msg = GetCoreMessageObject(messageData);

            // $ip, $time and $ignore_time
            SetSpecialProperties(msg, messageData, new Dictionary<string, Func<object, object>>
            {
                { MixpanelProperty.PeopleIp, null },
                { MixpanelProperty.PeopleTime, ConvertToUnixTime },
                { MixpanelProperty.PeopleIgnoreTime, null }
            });

            // $set
            var set = new Dictionary<string, object>();
            msg[MixpanelProperty.PeopleSet] = set;

            SetSpecialProperties(set, messageData, new Dictionary<string, Func<object, object>>
            {
                { MixpanelProperty.PeopleFirstName, null },
                { MixpanelProperty.PeopleLastName, null },
                { MixpanelProperty.PeopleName, null },
                { MixpanelProperty.PeopleCreated, null },
                { MixpanelProperty.PeopleEmail, null },
                { MixpanelProperty.PeoplePhone, null },
            });

            SetNormalProperties(set, messageData);

            return msg;
        }
 protected void SetSpecialProperties(
     IDictionary<string, object> obj, MessageData messageData,
     IDictionary<string, Func<object, object>> propNames)
 {
     foreach (var propName in propNames)
     {
         SetSpecialProperty(obj, messageData, propName.Key, propName.Value);
     }
 }
        public override IDictionary<string, object> GetMessageObject(MessageData messageData)
        {
            IDictionary<string, object> msg = GetCoreMessageObject(messageData, 3);

            // $unset
            SetSpecialRequiredProperty(msg, messageData, MixpanelProperty.PeopleUnset);

            return msg;
        }
 protected void SetSpecialProperty(
     IDictionary<string, object> obj, MessageData messageData, string propName,
     Func<object, object> convertFn = null)
 {
     var val = messageData.GetSpecialProp(propName, convertFn);
     if (val != null)
     {
         obj[propName] = val;
     }
 }
        public override IDictionary<string, object> GetMessageObject(MessageData messageData)
        {
            IDictionary<string, object> msg = GetCoreMessageObject(messageData, 3);

            var add = new Dictionary<string, object>();
            msg[MixpanelProperty.PeopleAdd] = add;

            SetNormalProperties(add, messageData);

            return msg;
        }
        public override IDictionary<string, object> GetMessageObject(MessageData messageData)
        {
            IDictionary<string, object> msg = GetCoreMessageObject(messageData, 3);

            var union = new Dictionary<string, object>();
            msg[MixpanelProperty.PeopleUnion] = union;

            SetNormalProperties(union, messageData);

            return msg;
        }
        public override IDictionary<string, object> GetMessageObject(MessageData messageData)
        {
            IDictionary<string, object> msg = GetCoreMessageObject(messageData);

            var append = new Dictionary<string, object>(1);
            msg[MixpanelProperty.PeopleAppend] = append;

            var transactions = new Dictionary<string, object>(2);
            append[MixpanelProperty.PeopleTransactions] = transactions;

            SetSpecialRequiredProperty(transactions, messageData, MixpanelProperty.PeopleTime);
            SetSpecialRequiredProperty(transactions, messageData, MixpanelProperty.PeopleAmount);

            return msg;
        }
        public override IDictionary<string, object> GetMessageObject(MessageData messageData)
        {
            var msg = GetCoreMessageObject(messageData);
            var properties = (IDictionary<string, object>)msg[MixpanelProperty.TrackProperties];

            // distinct_id, ip and time
            SetSpecialProperties(properties, messageData, new Dictionary<string, Func<object, object>>
            {
                { MixpanelProperty.TrackDistinctId, x => x.ToString() },
                { MixpanelProperty.TrackIp, x => x.ToString() },
                { MixpanelProperty.TrackTime, ConvertToUnixTime }
            });

            SetNormalProperties(properties, messageData);

            return msg;
        }
        public override IDictionary<string, object> GetMessageObject(MessageData messageData)
        {
            IDictionary<string, object> msg = GetCoreMessageObject(messageData);

            // $ignore_time
            SetSpecialProperties(msg, messageData, new Dictionary<string, Func<object, object>>
            {
                { MixpanelProperty.PeopleIgnoreTime, null }
            });

            // $set_once
            var setOnce = new Dictionary<string, object>();
            msg[MixpanelProperty.PeopleSetOnce] = setOnce;

            SetNormalProperties(setOnce, messageData);

            return msg;
        }
        /// <summary>
        /// Creates core people message object that can be used as base for
        /// building other people messages. Sets $token and $distinct_id properties.
        /// </summary>
        /// <param name="messageData">Parsed message data.</param>
        /// <param name="messageItemsCount">
        /// If set then message dictionary will be initialized with this value as capacity.
        /// </param>
        protected IDictionary<string, object> GetCoreMessageObject(
            MessageData messageData, int? messageItemsCount = null)
        {
            var msg = messageItemsCount == null
                ? new Dictionary<string, object>()
                : new Dictionary<string, object>(messageItemsCount.Value);

            // $token
            SetSpecialRequiredProperty(msg, messageData, MixpanelProperty.PeopleToken,
                x => ThrowIfPropertyIsNullOrEmpty(x, MixpanelProperty.PeopleToken),
                x => x.ToString());

            // $distinct_id
            SetSpecialRequiredProperty(msg, messageData, MixpanelProperty.PeopleDistinctId,
                x => ThrowIfPropertyIsNullOrEmpty(x, MixpanelProperty.PeopleDistinctId),
                x => x.ToString());

            return msg;
        }
        protected IDictionary<string, object> GetCoreMessageObject(MessageData messageData)
        {
            var msg = new Dictionary<string, object>(2);

            // event
            SetSpecialRequiredProperty(msg, messageData, MixpanelProperty.TrackEvent,
                x => ThrowIfPropertyIsNullOrEmpty(x, MixpanelProperty.TrackEvent),
                x => x.ToString());

            var properties = new Dictionary<string, object>();
            msg[MixpanelProperty.TrackProperties] = properties;

            // token
            SetSpecialRequiredProperty(properties, messageData, MixpanelProperty.TrackToken,
                x => ThrowIfPropertyIsNullOrEmpty(x, MixpanelProperty.TrackToken),
                x => x.ToString());

            return msg;
        }
        public override IDictionary<string, object> GetMessageObject(MessageData messageData)
        {
            messageData.SetProperty(MixpanelProperty.TrackEvent, MixpanelProperty.TrackCreateAlias);

            var msg = GetCoreMessageObject(messageData);
            var properties = (IDictionary<string, object>)msg[MixpanelProperty.TrackProperties];

            // distinct_id
            SetSpecialRequiredProperty(properties, messageData, MixpanelProperty.TrackDistinctId,
                x => ThrowIfPropertyIsNullOrEmpty(x, MixpanelProperty.TrackDistinctId),
                x => x.ToString());

            // alias
            SetSpecialRequiredProperty(properties, messageData, MixpanelProperty.TrackAlias,
                x => ThrowIfPropertyIsNullOrEmpty(x, MixpanelProperty.TrackAlias),
                x => x.ToString());

            return msg;
        }
 public void SetUp()
 {
     MixpanelConfig.Global.Reset();
     _builder = new PeopleSetMessageBuilder();
     _od = new MessageData(_builder.SpecialPropsBindings);
 }
 public override IDictionary<string, object> GetMessageObject(MessageData messageData)
 {
     IDictionary<string, object> msg = GetCoreMessageObject(messageData, 3);
     msg[MixpanelProperty.PeopleDelete] = string.Empty;
     return msg;
 }
 public void SetUp()
 {
     MixpanelConfig.Global.Reset();
     _builder = new PeopleSetMessageBuilder();
     _md = new MessageData(
         _builder.SpecialPropsBindings,
         _builder.DistinctIdPropsBindings,
         _builder.MessagePropetiesRules,
         _builder.SuperPropertiesRules);
 }
        /// <summary>
        /// Returns dictionary that contains Mixpanel message and is ready to be serialized. 
        /// </summary>
        /// <param name="builder">
        /// An override of <see cref="MessageBuilderBase"/> to use to generate message data.
        /// </param>
        /// <param name="userProperties">Object that contains user defined properties.</param>
        /// <param name="extraProperties">
        /// Object created by calling method. Usually contains properties that are passed to calling method
        /// as arguments.
        /// </param>
        private IDictionary<string, object> GetMessageObject(
            MessageBuilderBase builder, object userProperties, object extraProperties)
        {
            var md = new MessageData(
                builder.SpecialPropsBindings,
                builder.DistinctIdPropsBindings,
                builder.MessagePropetiesRules,
                builder.SuperPropertiesRules,
                _config);
            md.SetProperty(MixpanelProperty.Token, _token);
            md.ParseAndSetSuperProperties(_superProperties);
            md.ParseAndSetProperties(userProperties);
            md.ParseAndSetPropertiesIfNotNull(extraProperties);

            return builder.GetMessageObject(md);
        }
 public abstract IDictionary<string, object> GetMessageObject(MessageData messageData);
 protected void SetSpecialRequiredProperty(
     IDictionary<string, object> obj, MessageData messageData, string propName,
     Action<object> validateFn = null, Func<object, object> convertFn = null)
 {
     obj[propName] = messageData.GetSpecialRequiredProp(propName, validateFn, convertFn);
 }
示例#20
0
        /// <summary>
        /// Returns dictionary that contains Mixpanel message and is ready to be serialized. 
        /// </summary>
        /// <param name="builder">
        /// An override of <see cref="MessageBuilderBase"/> to use to generate message data.
        /// </param>
        /// <param name="userProperties">Object that contains user defined properties.</param>
        /// <param name="extraProperties">
        /// Object created by calling method. Usually contains properties that are passed to calling method
        /// as arguments.
        /// </param>
        /// <param name="propetyRules">
        /// Additional rules that will be appended to user defined properties.
        /// </param>
        private IDictionary<string, object> GetMessageObject(
            MessageBuilderBase builder, object userProperties, object extraProperties,
            MessagePropetyRules propetyRules = MessagePropetyRules.None)
        {
            var od = new MessageData(builder.SpecialPropsBindings, propetyRules, _config);
            od.ParseAndSetProperties(userProperties);
            od.SetProperty(MixpanelProperty.Token, _token);
            od.ParseAndSetPropertiesIfNotNull(extraProperties);
            od.ParseAndSetProperties(_superProperties);

            return builder.GetMessageObject(od);
        }
 public void SetUp()
 {
     _md = new MessageData(new Dictionary<string, string>
     {
         {MixpanelProperty.Token, MixpanelProperty.Token},
         {MixpanelProperty.DistinctId, MixpanelProperty.DistinctId},
         {"distinctid", MixpanelProperty.DistinctId},
         {MixpanelProperty.Event, MixpanelProperty.Event}
     });
 }