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); }
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(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); }