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); }
protected void LogAndAddReason(string reason, bool displayed, List <SwrveQaUserCampaignInfo> qaCampaignInfoList) { if (SwrveQaUser.Instance.loggingEnabled && qaCampaignInfoList != null) { SwrveQaUserCampaignInfo campaignInfo = null; if (this is SwrveConversationCampaign) { SwrveConversationCampaign conversationCampaign = (SwrveConversationCampaign)this; campaignInfo = new SwrveQaUserCampaignInfo(Id, conversationCampaign.Conversation.Id, conversationCampaign.GetCampaignType(), displayed, reason); } else if (this is SwrveInAppCampaign) { SwrveInAppCampaign inAppCampaign = (SwrveInAppCampaign)this; campaignInfo = new SwrveQaUserCampaignInfo(Id, inAppCampaign.Messages[0].Id, inAppCampaign.GetCampaignType(), displayed, reason); } else if (this is SwrveEmbeddedCampaign) { SwrveEmbeddedCampaign embeddedCampaign = (SwrveEmbeddedCampaign)this; campaignInfo = new SwrveQaUserCampaignInfo(Id, embeddedCampaign.Message.Id, embeddedCampaign.GetCampaignType(), displayed, reason); } if (campaignInfo != null) { qaCampaignInfoList.Add(campaignInfo); } } SwrveLog.Log(string.Format("{0} {1}", this, reason)); }
public bool ResolveTemplating(SwrveInAppCampaign campaign, Dictionary <string, string> properties) { for (int i = 0; i < campaign.Messages.Count; i++) { if (!ResolveTemplating(campaign.Messages[i], properties)) { return(false); } } return(true); }
public static SwrveInAppCampaign LoadFromJSON(ISwrveAssetsManager swrveAssetsManager, Dictionary <string, object> campaignData, int id, DateTime initialisedTime, Color?defaultBackgroundColor, List <SwrveQaUserCampaignInfo> qaUserCampaignInfoList) { SwrveInAppCampaign campaign = new SwrveInAppCampaign(initialisedTime); object _messages = null; campaignData.TryGetValue("messages", out _messages); IList <object> messages = null; try { messages = (IList <object>)_messages; } catch (Exception e) { string reason = "Campaign [" + id + "] invalid messages found, skipping. Error: " + e; campaign.LogAndAddReason(reason, false, qaUserCampaignInfoList); } if (messages == null) { string reason = "Campaign [" + id + "] JSON messages are null, skipping."; campaign.LogAndAddReason(reason, false, qaUserCampaignInfoList); return(null); } for (int k = 0, t = messages.Count; k < t; k++) { Dictionary <string, object> messageData = (Dictionary <string, object>)messages [k]; SwrveMessage message = SwrveMessage.LoadFromJSON(swrveAssetsManager, campaign, messageData, defaultBackgroundColor); if (message.Formats.Count > 0) { campaign.AddMessage(message); } } if (campaign.Messages.Count == 0) { string reason = "Campaign [" + id + "] no messages found, skipping."; campaign.LogAndAddReason(reason, false, qaUserCampaignInfoList); } return(campaign); }
/// <summary> /// Load an in-app message from a JSON response. /// </summary> /// <param name="campaign"> /// Parent in-app campaign. /// </param> /// <param name="messageData"> /// JSON object with the individual message data. /// </param> /// <returns> /// Parsed in-app message. /// </returns> public static SwrveMessage LoadFromJSON(ISwrveAssetsManager swrveAssetsManager, SwrveInAppCampaign campaign, Dictionary <string, object> messageData, Color?defaultBackgroundColor) { SwrveMessage message = new SwrveMessage(swrveAssetsManager, campaign); message.Id = MiniJsonHelper.GetInt(messageData, "id"); message.Name = (string)messageData ["name"]; if (messageData.ContainsKey("priority")) { message.Priority = MiniJsonHelper.GetInt(messageData, "priority"); } Dictionary <string, object> template = (Dictionary <string, object>)messageData ["template"]; IList <object> jsonFormats = (List <object>)template ["formats"]; for (int i = 0, j = jsonFormats.Count; i < j; i++) { Dictionary <string, object> messageFormatData = (Dictionary <string, object>)jsonFormats [i]; SwrveMessageFormat messageFormat = SwrveMessageFormat.LoadFromJSON(swrveAssetsManager, message, messageFormatData, defaultBackgroundColor); message.Formats.Add(messageFormat); } return(message); }
private SwrveMessage(ISwrveAssetsManager swrveAssetsManager, SwrveInAppCampaign campaign) { this.SwrveAssetsManager = swrveAssetsManager; this.Campaign = campaign; this.Formats = new List <SwrveMessageFormat> (); }