예제 #1
0
        /// <summary>
        /// Creates an instance of <see cref="MixpanelClient"/>. This constructor is usually used
        /// when you want to call only 'Send' and 'SendAsync' methods, because in this case
        /// token is already specified in each <see cref="MixpanelMessage"/>.
        /// </summary>
        /// <param name="config">
        /// Configuration for this particular client. Set properties from this class will override global properties.
        /// </param>
        /// <param name="superProperties">
        /// Object with properties that will be attached to every message for the current mixpanel client.
        /// If some of the properties are not valid mixpanel properties they will be ignored. Check documentation
        /// on project page https://github.com/eealeivan/mixpanel-csharp for valid property types.
        /// </param>
        public MixpanelClient(MixpanelConfig config = null, object superProperties = null)
        {
            this.config = config;
            UtcNow      = () => DateTime.UtcNow;

            // Parse super properties only one time
            this.superProperties = PropertiesDigger.Get(superProperties, PropertyOrigin.SuperProperty).ToList();
        }
예제 #2
0
        private void ProcessRawProperties(object rawProperties)
        {
            if (rawProperties == null)
            {
                return;
            }

            foreach (ObjectProperty objectProperty in PropertiesDigger.Get(rawProperties, PropertyOrigin.RawProperty))
            {
                ProcessObjectProperty(objectProperty);
            }
        }
        public void Given_Class_When_MixpanelNameAndDataMemberAttributes_Then_MixpanelNameUsed()
        {
            var obj = new Class5
            {
                DecimalProperty = DecimalPropertyValue2,
            };

            var properties = PropertiesDigger.Get(obj, PropertyOrigin.RawProperty).ToArray();

            Assert.That(properties.Count, Is.EqualTo(1));
            CheckProperty(
                DecimalPropertyName2, PropertyNameSource.MixpanelName, DecimalPropertyValue2, properties);
        }
        public void Given_StringObjectDic_When_ValidInput_Then_AllParsed()
        {
            var dic = new Dictionary <string, object>
            {
                { DecimalPropertyName, DecimalPropertyValue },
                { StringPropertyName, StringPropertyValue },
                { DateTimePropertyName, DateTimePropertyValue }
            };

            var properties = PropertiesDigger.Get(dic, PropertyOrigin.RawProperty).ToArray();

            CheckProperties(properties);
        }
        public void Given_Class_When_ValidInput_Then_AllParsed()
        {
            var obj = new Class1
            {
                DecimalProperty  = DecimalPropertyValue,
                StringProperty   = StringPropertyValue,
                DateTimeProperty = DateTimePropertyValue
            };

            var properties = PropertiesDigger.Get(obj, PropertyOrigin.RawProperty).ToArray();

            CheckProperties(properties);
        }
        public void Given_ExpandoObject_When_ValidInput_Then_AllParsed()
        {
            dynamic expando = new ExpandoObject();

            expando.DecimalProperty  = DecimalPropertyValue;
            expando.StringProperty   = StringPropertyValue;
            expando.DateTimeProperty = DateTimePropertyValue;

            var properties =
                ((IEnumerable <ObjectProperty>)PropertiesDigger.Get(expando, PropertyOrigin.RawProperty))
                .ToArray();

            CheckProperties(properties);
        }
        public void Given_Hashtable_When_MixedInput_Then_OnlyValidParsed()
        {
            var hashtable = new Hashtable
            {
                { 1, IntPropertyValue },
                { DecimalPropertyName, DecimalPropertyValue },
                { StringPropertyName, StringPropertyValue },
                { DateTimePropertyName, DateTimePropertyValue }
            };

            var properties = PropertiesDigger.Get(hashtable, PropertyOrigin.RawProperty).ToArray();

            CheckProperties(properties);
        }
        public void Given_Dynamic_When_ValidInput_Then_AllParsed()
        {
            dynamic dyn = new
            {
                DecimalProperty  = DecimalPropertyValue,
                StringProperty   = StringPropertyValue,
                DateTimeProperty = DateTimePropertyValue
            };

            var properties =
                ((IEnumerable <ObjectProperty>)PropertiesDigger.Get(dyn, PropertyOrigin.RawProperty))
                .ToArray();

            CheckProperties(properties);
        }
        public void Given_StringDecimalDic_When_ValidInput_Then_AllParsed()
        {
            var dic = new Dictionary <string, decimal>
            {
                { DecimalPropertyName, DecimalPropertyValue },
                { DecimalPropertyName2, DecimalPropertyValue2 }
            };

            var properties = PropertiesDigger.Get(dic, PropertyOrigin.RawProperty).ToArray();

            Assert.That(properties.Count, Is.EqualTo(2));

            CheckProperty(DecimalPropertyName, PropertyNameSource.Default, DecimalPropertyValue, properties);
            CheckProperty(DecimalPropertyName2, PropertyNameSource.Default, DecimalPropertyValue2, properties);
        }
        public void Given_Class_When_DataContractAttribute_Then_DataMemberParsed()
        {
            var obj = new Class3
            {
                DecimalProperty  = DecimalPropertyValue2,
                StringProperty   = StringPropertyValue2,
                DateTimeProperty = DateTimePropertyValue,
                IgnoredProperty  = StringPropertyValue
            };

            var properties = PropertiesDigger.Get(obj, PropertyOrigin.RawProperty).ToArray();

            Assert.That(properties.Count, Is.EqualTo(1));
            CheckProperty(StringPropertyName2, PropertyNameSource.DataMember, StringPropertyValue2, properties);
        }
예제 #11
0
        public MessageData(
            IDictionary <string, string> specialPropsBindings,
            IDictionary <string, string> distinctIdPropsBindings,
            MessagePropetiesRules messagePropetiesRules,
            SuperPropertiesRules superPropertiesRules,
            MixpanelConfig config = null)
        {
            _specialPropsBindings    = specialPropsBindings ?? new Dictionary <string, string>();
            _distinctIdPropsBindings = distinctIdPropsBindings ?? new Dictionary <string, string>();
            _messagePropetiesRules   = messagePropetiesRules;
            _superPropertiesRules    = superPropertiesRules;
            _valueParser             = new ValueParser();
            _nameFormatter           = new PropertyNameFormatter(config);
            _propertiesDigger        = new PropertiesDigger();

            SpecialProps = new Dictionary <string, object>();
            Props        = new Dictionary <string, object>();
        }
예제 #12
0
        public MessageData(
            IDictionary<string, string> specialPropsBindings,
            IDictionary<string, string> distinctIdPropsBindings,
            MessagePropetiesRules messagePropetiesRules,
            SuperPropertiesRules superPropertiesRules,
            MixpanelConfig config = null)
        {
            _specialPropsBindings = specialPropsBindings ?? new Dictionary<string, string>();
            _distinctIdPropsBindings = distinctIdPropsBindings ?? new Dictionary<string, string>();
            _messagePropetiesRules = messagePropetiesRules;
            _superPropertiesRules = superPropertiesRules;
            _valueParser = new ValueParser();
            _nameFormatter = new PropertyNameFormatter(config);
            _propertiesDigger = new PropertiesDigger();

            SpecialProps = new Dictionary<string, object>();
            Props = new Dictionary<string, object>();
        }
        public void Given_Class_When_MixpanelNameAttribute_Then_MixpanelNameUsed()
        {
            var obj = new Class2
            {
                DecimalProperty  = DecimalPropertyValue2,
                StringProperty   = StringPropertyValue2,
                DateTimeProperty = DateTimePropertyValue
            };

            var properties = PropertiesDigger.Get(obj, PropertyOrigin.RawProperty).ToArray();

            Assert.That(properties.Count, Is.EqualTo(3));

            CheckProperty(
                DecimalPropertyName2, PropertyNameSource.MixpanelName, DecimalPropertyValue2, properties);
            CheckProperty(
                StringPropertyName2, PropertyNameSource.MixpanelName, StringPropertyValue2, properties);
            CheckProperty(
                DateTimePropertyName, PropertyNameSource.Default, DateTimePropertyValue, properties);
        }
 public void SetUp()
 {
     _digger = new PropertiesDigger();
     _now = DateTime.Now;
 }
예제 #15
0
 public void SetUp()
 {
     _digger = new PropertiesDigger();
 }
 public void SetUp()
 {
     _digger = new PropertiesDigger();
 }