Пример #1
0
        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);
        }
Пример #2
0
        protected static void AssignCampaignDates(SwrveBaseCampaign campaign, Dictionary <string, object> campaignData)
        {
            DateTime unixEpoch = SwrveHelper.UnixEpoch;

            campaign.StartDate = unixEpoch.AddMilliseconds(MiniJsonHelper.GetLong(campaignData, "start_date"));
            campaign.EndDate   = unixEpoch.AddMilliseconds(MiniJsonHelper.GetLong(campaignData, "end_date"));
        }
Пример #3
0
        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);
                }
            }
        }
Пример #4
0
        protected static void AssignCampaignDates(SwrveBaseCampaign campaign, Dictionary <string, object> campaignData)
        {
            DateTime initDate = SwrveHelper.UnixEpoch;

            campaign.StartDate = initDate.AddMilliseconds(MiniJsonHelper.GetLong(campaignData, START_DATE_KEY));
            campaign.EndDate   = initDate.AddMilliseconds(MiniJsonHelper.GetLong(campaignData, END_DATE_KEY));
        }
        public static SwrveBaseCampaign LoadFromJSONWithNoValidation(ISwrveAssetsManager swrveAssetsManager, Dictionary <string, object> campaignData, DateTime initialisedTime, UnityEngine.Color?defaultBackgroundColor, List <SwrveQaUserCampaignInfo> qaUserCampaignInfoList = null)
        {
            int id = MiniJsonHelper.GetInt(campaignData, ID_KEY);
            SwrveBaseCampaign campaign = null;

            if (campaignData.ContainsKey(CONVERSATION_KEY))
            {
                campaign = SwrveConversationCampaign.LoadFromJSON(swrveAssetsManager, campaignData, id, initialisedTime);
            }
            else if (campaignData.ContainsKey(MESSAGES_KEY))
            {
                campaign = SwrveInAppCampaign.LoadFromJSON(swrveAssetsManager, campaignData, id, initialisedTime, defaultBackgroundColor, qaUserCampaignInfoList);
            }
            else if (campaignData.ContainsKey(EMBEDDED_MESSAGE_KEY))
            {
                campaign = SwrveEmbeddedCampaign.LoadFromJSON(campaignData, initialisedTime, qaUserCampaignInfoList);
            }

            if (campaign == null)
            {
                return(null);
            }
            campaign.Id = id;
            return(campaign);
        }
        /// <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);
        }
Пример #7
0
        protected static void AssignCampaignRules(SwrveBaseCampaign campaign, Dictionary <string, object> campaignData)
        {
            Dictionary <string, object> dictionary = (Dictionary <string, object>)campaignData["rules"];

            campaign.RandomOrder = ((string)dictionary["display_order"]).Equals("random");
            if (dictionary.ContainsKey("dismiss_after_views"))
            {
                int num = (campaign.maxImpressions = MiniJsonHelper.GetInt(dictionary, "dismiss_after_views"));
            }
            if (dictionary.ContainsKey("delay_first_message"))
            {
                campaign.delayFirstMessage       = MiniJsonHelper.GetInt(dictionary, "delay_first_message");
                campaign.showMessagesAfterLaunch = campaign.swrveInitialisedTime + TimeSpan.FromSeconds(campaign.delayFirstMessage);
            }
            if (dictionary.ContainsKey("min_delay_between_messages"))
            {
                int num2 = (campaign.minDelayBetweenMessage = MiniJsonHelper.GetInt(dictionary, "min_delay_between_messages"));
            }
        }
Пример #8
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++;
            }
        }
Пример #9
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);
        }
Пример #10
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);
                }
            }
        }
Пример #11
0
        protected static void AssignCampaignRules(SwrveBaseCampaign campaign, Dictionary <string, object> campaignData)
        {
            Dictionary <string, object> rules = (Dictionary <string, object>)campaignData [RULES_KEY];

            campaign.RandomOrder = ((string)rules [DISPLAY_ORDER_KEY]).Equals(RANDOM_KEY);

            if (rules.ContainsKey(DISMISS_AFTER_VIEWS_KEY))
            {
                int totalImpressions = MiniJsonHelper.GetInt(rules, DISMISS_AFTER_VIEWS_KEY);
                campaign.maxImpressions = totalImpressions;
            }

            if (rules.ContainsKey(DELAY_FIRST_MESSAGE_KEY))
            {
                campaign.delayFirstMessage       = MiniJsonHelper.GetInt(rules, DELAY_FIRST_MESSAGE_KEY);
                campaign.showMessagesAfterLaunch = campaign.swrveInitialisedTime + TimeSpan.FromSeconds(campaign.delayFirstMessage);
            }

            if (rules.ContainsKey(MIN_DELAY_BETWEEN_MESSAGES_KEY))
            {
                int minDelay = MiniJsonHelper.GetInt(rules, MIN_DELAY_BETWEEN_MESSAGES_KEY);
                campaign.minDelayBetweenMessage = minDelay;
            }
        }