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);
                }
            }
        }
        public static SwrveBaseCampaign LoadFromJSON(ISwrveAssetsManager swrveAssetsManager, Dictionary <string, object> campaignData, DateTime initialisedTime, SwrveQAUser qaUser, Color?defaultBackgroundColor)
        {
            int @int = MiniJsonHelper.GetInt(campaignData, "id");
            SwrveBaseCampaign swrveBaseCampaign = null;

            if (campaignData.ContainsKey("conversation"))
            {
                swrveBaseCampaign = SwrveConversationCampaign.LoadFromJSON(swrveAssetsManager, campaignData, @int, initialisedTime);
            }
            else if (campaignData.ContainsKey("messages"))
            {
                swrveBaseCampaign = SwrveMessagesCampaign.LoadFromJSON(swrveAssetsManager, campaignData, @int, initialisedTime, qaUser, defaultBackgroundColor);
            }
            if (swrveBaseCampaign == null)
            {
                return(null);
            }
            swrveBaseCampaign.Id = @int;
            AssignCampaignTriggers(swrveBaseCampaign, campaignData);
            swrveBaseCampaign.MessageCenter = campaignData.ContainsKey("message_center") && (bool)campaignData["message_center"];
            if (!swrveBaseCampaign.MessageCenter && swrveBaseCampaign.GetTriggers().Count == 0)
            {
                swrveBaseCampaign.LogAndAddReason("Campaign [" + swrveBaseCampaign.Id + "], has no triggers. Skipping this campaign.", qaUser);
                return(null);
            }
            AssignCampaignRules(swrveBaseCampaign, campaignData);
            AssignCampaignDates(swrveBaseCampaign, campaignData);
            swrveBaseCampaign.Subject = (campaignData.ContainsKey("subject") ? ((string)campaignData["subject"]) : "");
            if (swrveBaseCampaign.MessageCenter)
            {
                SwrveLog.Log($"message center campaign: {swrveBaseCampaign.GetType()}, {swrveBaseCampaign.subject}");
            }
            return(swrveBaseCampaign);
        }
        /// <summary>
        /// Load an in-app campaign from a JSON response.
        /// </summary>
        /// <param name="campaignData">
        /// JSON object with the individual campaign data.
        /// </param>
        /// <param name="initialisedTime">
        /// Time that the SDK was initialised. Used for rules checking.
        /// </param>
        /// <param name="assetPath">
        /// Path to the folder that will store all the assets.
        /// </param>
        /// <returns>
        /// Parsed in-app campaign.
        /// </returns>
        public static SwrveBaseCampaign LoadFromJSON(ISwrveAssetsManager swrveAssetsManager, Dictionary <string, object> campaignData, DateTime initialisedTime, UnityEngine.Color?defaultBackgroundColor, List <SwrveQaUserCampaignInfo> qaUserCampaignInfoList)
        {
            SwrveBaseCampaign campaign = LoadFromJSONWithNoValidation(swrveAssetsManager, campaignData, initialisedTime, defaultBackgroundColor, qaUserCampaignInfoList);

            if (campaign == null)
            {
                return(null);
            }

            AssignCampaignTriggers(campaign, campaignData);
            campaign.MessageCenter = campaignData.ContainsKey(MESSAGE_CENTER_KEY) && (bool)campaignData[MESSAGE_CENTER_KEY];

            if (!campaign.MessageCenter && (campaign.GetTriggers().Count == 0))
            {
                string reason = "Campaign [" + campaign.Id + "], has no triggers. Skipping this campaign.";
                campaign.LogAndAddReason(reason, false, qaUserCampaignInfoList);
                return(null);
            }

            AssignCampaignRules(campaign, campaignData);
            AssignCampaignDates(campaign, campaignData);
            campaign.Subject = campaignData.ContainsKey(SUBJECT_KEY) ? (string)campaignData[SUBJECT_KEY] : "";

            return(campaign);
        }
Exemple #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++;
            }
        }
Exemple #5
0
        /// <summary>
        /// Load an in-app campaign from a JSON response.
        /// </summary>
        /// <param name="campaignData">
        /// JSON object with the individual campaign data.
        /// </param>
        /// <param name="initialisedTime">
        /// Time that the SDK was initialised. Used for rules checking.
        /// </param>
        /// <param name="assetPath">
        /// Path to the folder that will store all the assets.
        /// </param>
        /// <returns>
        /// Parsed in-app campaign.
        /// </returns>
        public static SwrveBaseCampaign LoadFromJSON(SwrveSDK sdk, Dictionary <string, object> campaignData, DateTime initialisedTime, SwrveQAUser qaUser)
        {
            int id = MiniJsonHelper.GetInt(campaignData, ID_KEY);
            SwrveBaseCampaign campaign = null;

            if (campaignData.ContainsKey(CONVERSATION_KEY))
            {
                campaign = SwrveConversationCampaign.LoadFromJSON(sdk, campaignData, id, initialisedTime);
            }
            else if (campaignData.ContainsKey(MESSAGES_KEY))
            {
                campaign = SwrveMessagesCampaign.LoadFromJSON(sdk, campaignData, id, initialisedTime, qaUser);
            }

            if (campaign == null)
            {
                return(null);
            }
            campaign.Id = id;

            AssignCampaignTriggers(campaign, campaignData);
            campaign.MessageCenter = campaignData.ContainsKey(MESSAGE_CENTER_KEY) && (bool)campaignData[MESSAGE_CENTER_KEY];

            if ((!campaign.MessageCenter) && (campaign.GetTriggers().Count == 0))
            {
                campaign.LogAndAddReason("Campaign [" + campaign.Id + "], has no triggers. Skipping this campaign.", qaUser);
                return(null);
            }

            AssignCampaignRules(campaign, campaignData);
            AssignCampaignDates(campaign, campaignData);
            campaign.Subject = campaignData.ContainsKey(SUBJECT_KEY) ? (string)campaignData[SUBJECT_KEY] : "";

            if (campaign.MessageCenter)
            {
                SwrveLog.Log(string.Format("message center campaign: {0}, {1}", campaign.GetType(), campaign.subject));
            }

            return(campaign);
        }
Exemple #6
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);
                }
            }
        }