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);
                }
            }
        }
Example #2
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);
 }
Example #3
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++;
            }
        }
Example #4
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);
                }
            }
        }