Beispiel #1
0
        public static SwrveTrigger LoadFromJson(object json)
        {
            IDictionary <string, object> dict = null;

            try {
                dict = (IDictionary <string, object>)json;
            } catch (Exception e) {
                SwrveLog.LogError(string.Format("Invalid object passed in to LoadFromJson, expected Dictionary<string, object>, received {0}", json));
                return(null);
            }

            string          eventName  = null;
            SwrveConditions conditions = null;

            try {
                eventName = (string)dict [EVENT_NAME_KEY];
                if (dict.ContainsKey(CONDITIONS_KEY))
                {
                    conditions = SwrveConditions.LoadFromJson((IDictionary <string, object>)dict [CONDITIONS_KEY], true);
                }
            } catch (Exception e) {
                SwrveLog.LogError(string.Format("Error parsing a SwrveTrigger from json {0}, ex: {1}", dict, e));
            }

            if (string.IsNullOrEmpty(eventName) || (conditions == null))
            {
                return(null);
            }

            SwrveTrigger trigger = new SwrveTrigger();

            trigger.eventName  = eventName;
            trigger.conditions = conditions;
            return(trigger);
        }
        protected static void AssignCampaignTriggers(SwrveBaseCampaign campaign, Dictionary <string, object> campaignData)
        {
            IList <object> list = (IList <object>)campaignData["triggers"];
            int            i    = 0;

            for (int count = list.Count; i < count; i++)
            {
                object obj = list[i];
                if (obj.GetType() == typeof(string))
                {
                    Dictionary <string, object> dictionary = new Dictionary <string, object>();
                    dictionary.Add("event_name", obj);
                    dictionary.Add("conditions", new Dictionary <string, object>());
                    obj = dictionary;
                }
                try
                {
                    SwrveTrigger item = SwrveTrigger.LoadFromJson((IDictionary <string, object>)obj);
                    campaign.GetTriggers().Add(item);
                }
                catch (Exception ex)
                {
                    SwrveLog.LogError("Unable to parse SwrveTrigger from json " + Json.Serialize(obj) + ", " + ex);
                }
            }
        }
Beispiel #3
0
 public static IEnumerable <SwrveTrigger> LoadFromJson(string json)
 {
     try
     {
         object obj = Json.Deserialize(json);
         return(SwrveTrigger.LoadFromJson((List <object>)obj));
     }
     catch (Exception arg)
     {
         SwrveLog.LogError(string.Format("Error parsing a SwrveTrigger from json {0}, ex: {1}", json, arg));
     }
     return(null);
 }
Beispiel #4
0
        protected static void AssignCampaignTriggers(SwrveBaseCampaign campaign, Dictionary <string, object> campaignData)
        {
            IList <object> list  = (IList <object>)campaignData["triggers"];
            int            i     = 0;
            int            count = list.Count;

            while (i < count)
            {
                object obj = list[i];
                if (obj.GetType() == typeof(string))
                {
                    obj = new Dictionary <string, object>
                    {
                        {
                            "event_name",
                            obj
                        },
                        {
                            "conditions",
                            new Dictionary <string, object>()
                        }
                    };
                }
                try
                {
                    SwrveTrigger item = SwrveTrigger.LoadFromJson((IDictionary <string, object>)obj);
                    campaign.GetTriggers().Add(item);
                }
                catch (Exception ex)
                {
                    SwrveLog.LogError(string.Concat(new object[]
                    {
                        "Unable to parse SwrveTrigger from json ",
                        Json.Serialize(obj),
                        ", ",
                        ex
                    }));
                }
                i++;
            }
        }
Beispiel #5
0
        public static SwrveTrigger LoadFromJson(object json)
        {
            IDictionary <string, object> dictionary = null;

            try
            {
                dictionary = (IDictionary <string, object>)json;
            }
            catch (Exception ex)
            {
                SwrveLog.LogError(string.Format("Invalid object passed in to LoadFromJson, expected Dictionary<string, object>, received {0}, exception: {1}", json, ex.Message));
                SwrveTrigger result = null;
                return(result);
            }
            string          value           = null;
            SwrveConditions swrveConditions = null;

            try
            {
                value = (string)dictionary["event_name"];
                if (dictionary.ContainsKey("conditions"))
                {
                    swrveConditions = SwrveConditions.LoadFromJson((IDictionary <string, object>)dictionary["conditions"], true);
                }
            }
            catch (Exception arg)
            {
                SwrveLog.LogError(string.Format("Error parsing a SwrveTrigger from json {0}, ex: {1}", dictionary, arg));
            }
            if (string.IsNullOrEmpty(value) || swrveConditions == null)
            {
                return(null);
            }
            return(new SwrveTrigger
            {
                eventName = value,
                conditions = swrveConditions
            });
        }
Beispiel #6
0
        public static SwrveTrigger LoadFromJson(object json)
        {
            IDictionary <string, object> dictionary = null;

            try
            {
                dictionary = (IDictionary <string, object>)json;
            }
            catch (Exception ex)
            {
                SwrveLog.LogError($"Invalid object passed in to LoadFromJson, expected Dictionary<string, object>, received {json}, exception: {ex.Message}");
                return(null);
            }
            string          value           = null;
            SwrveConditions swrveConditions = null;

            try
            {
                value = (string)dictionary["event_name"];
                if (dictionary.ContainsKey("conditions"))
                {
                    swrveConditions = SwrveConditions.LoadFromJson((IDictionary <string, object>)dictionary["conditions"], isRoot: true);
                }
            }
            catch (Exception ex)
            {
                SwrveLog.LogError($"Error parsing a SwrveTrigger from json {dictionary}, ex: {ex}");
            }
            if (string.IsNullOrEmpty(value) || swrveConditions == null)
            {
                return(null);
            }
            SwrveTrigger swrveTrigger = new SwrveTrigger();

            swrveTrigger.eventName  = value;
            swrveTrigger.conditions = swrveConditions;
            return(swrveTrigger);
        }
Beispiel #7
0
        protected static void AssignCampaignTriggers(SwrveBaseCampaign campaign, Dictionary <string, object> campaignData)
        {
            IList <object> jsonTriggers = (IList <object>)campaignData [TRIGGERS_KEY];

            for (int i = 0, j = jsonTriggers.Count; i < j; i++)
            {
                object jsonTrigger = jsonTriggers [i];
                if (jsonTrigger.GetType() == typeof(string))
                {
                    jsonTrigger = new Dictionary <string, object> {
                        { EVENT_NAME_KEY, jsonTrigger },
                        { CONDITIONS_KEY, new Dictionary <string, object>() }
                    };
                }

                try {
                    SwrveTrigger trigger = SwrveTrigger.LoadFromJson((IDictionary <string, object>)jsonTrigger);
                    campaign.GetTriggers().Add(trigger);
                } catch (Exception e) {
                    SwrveLog.LogError("Unable to parse SwrveTrigger from json " + Json.Serialize(jsonTrigger) + ", " + e);
                }
            }
        }