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 IEnumerator GetExternalCampaign_Coroutine(string getRequest) { yield return(container.StartCoroutine(this.sdk.restClient.Get(getRequest, delegate(RESTResponse response) { if (response.Error == WwwDeducedError.NoError) { if (!string.IsNullOrEmpty(response.Body)) { Dictionary <string, object> root = (Dictionary <string, object>)Json.Deserialize(response.Body); if (root != null) { if (root.ContainsKey("campaign") && root.ContainsKey("additional_info")) { Dictionary <string, object> campaignData = (Dictionary <string, object>)root["campaign"]; Dictionary <string, object> additionalInfo = (Dictionary <string, object>)root["additional_info"]; this.sdk.UpdateCdnPaths(additionalInfo); int version = MiniJsonHelper.GetInt(additionalInfo, "version"); if (this.sdk.config.MessagingEnabled && version == EXTERNAL_CAMPAIGN_RESPONSE_VERSION) { this.sdk.SaveExternalCampaignCache(response.Body); ProcessCampaignJSON(campaignData); } } } } } else { SwrveLog.LogError("Ad Journey campaign request error: " + response.Error.ToString() + ":" + response.Body); } }))); }
/// <summary> /// Load a conversation from a JSON response. /// </summary> /// <param name="campaign"> /// Parent in-app campaign. /// </param> /// <param name="conversationData"> /// JSON object with the conversation data. /// </param> /// <returns> /// Parsed conversation wrapper for native layer. /// </returns> public static SwrveConversation LoadFromJSON(SwrveSDK sdk, SwrveConversationCampaign campaign, Dictionary <string, object> conversationData) { SwrveConversation conversation = new SwrveConversation(sdk, campaign); conversation.Id = MiniJsonHelper.GetInt(conversationData, "id"); List <object> pages = (List <object>)conversationData ["pages"]; for (int i = 0; i < pages.Count; i++) { Dictionary <string, object> page = (Dictionary <string, object>)pages [i]; List <object> contents = (List <object>)page ["content"]; for (int j = 0; j < contents.Count; j++) { Dictionary <string, object> content = (Dictionary <string, object>)contents[j]; if ("image" == (string)content ["type"]) { conversation.ConversationAssets.Add((string)content ["value"]); } } } conversation.Conversation = Json.Serialize(conversationData); if (conversationData.ContainsKey("priority")) { conversation.Priority = MiniJsonHelper.GetInt(conversationData, "priority"); } return(conversation); }
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 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); }
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")); }
public SwrveCampaignState(int campaignId, Dictionary <string, object> savedStatesJson) { string curKey; // Load next curKey = "Next" + campaignId; if (savedStatesJson.ContainsKey(curKey)) { Next = MiniJsonHelper.GetInt(savedStatesJson, curKey); } // Load impressions curKey = "Impressions" + campaignId; if (savedStatesJson.ContainsKey(curKey)) { Impressions = MiniJsonHelper.GetInt(savedStatesJson, curKey); } // Load cur status curKey = "Status" + campaignId; if (savedStatesJson.ContainsKey(curKey)) { CurStatus = ParseStatus(MiniJsonHelper.GetString(savedStatesJson, curKey)); } else { CurStatus = Status.Unseen; } }
public static SwrveMessageFormat LoadFromJSON(ISwrveAssetsManager swrveAssetsManager, SwrveMessage message, Dictionary <string, object> messageFormatData, Color?defaultBackgroundColor) { SwrveMessageFormat swrveMessageFormat = new SwrveMessageFormat(message); swrveMessageFormat.Name = (string)messageFormatData["name"]; swrveMessageFormat.Language = (string)messageFormatData["language"]; if (messageFormatData.ContainsKey("scale")) { swrveMessageFormat.Scale = MiniJsonHelper.GetFloat(messageFormatData, "scale", 1f); } if (messageFormatData.ContainsKey("orientation")) { swrveMessageFormat.Orientation = SwrveOrientationHelper.Parse((string)messageFormatData["orientation"]); } swrveMessageFormat.BackgroundColor = defaultBackgroundColor; if (messageFormatData.ContainsKey("color")) { string text = (string)messageFormatData["color"]; Color? backgroundColor = swrveMessageFormat.BackgroundColor; if (text.Length == 8) { byte a = byte.Parse(text.Substring(0, 2), NumberStyles.HexNumber); byte r = byte.Parse(text.Substring(2, 2), NumberStyles.HexNumber); byte g = byte.Parse(text.Substring(4, 2), NumberStyles.HexNumber); byte b = byte.Parse(text.Substring(6, 2), NumberStyles.HexNumber); backgroundColor = new Color32(r, g, b, a); } else if (text.Length == 6) { byte r = byte.Parse(text.Substring(0, 2), NumberStyles.HexNumber); byte g = byte.Parse(text.Substring(2, 2), NumberStyles.HexNumber); byte b = byte.Parse(text.Substring(4, 2), NumberStyles.HexNumber); backgroundColor = new Color32(r, g, b, byte.MaxValue); } swrveMessageFormat.BackgroundColor = backgroundColor; } Dictionary <string, object> dictionary = (Dictionary <string, object>)messageFormatData["size"]; swrveMessageFormat.Size.X = MiniJsonHelper.GetInt((Dictionary <string, object>)dictionary["w"], "value"); swrveMessageFormat.Size.Y = MiniJsonHelper.GetInt((Dictionary <string, object>)dictionary["h"], "value"); IList <object> list = (List <object>)messageFormatData["buttons"]; int i = 0; for (int count = list.Count; i < count; i++) { SwrveButton item = LoadButtonFromJSON(message, (Dictionary <string, object>)list[i]); swrveMessageFormat.Buttons.Add(item); } IList <object> list2 = (List <object>)messageFormatData["images"]; int j = 0; for (int count2 = list2.Count; j < count2; j++) { SwrveImage item2 = LoadImageFromJSON(message, (Dictionary <string, object>)list2[j]); swrveMessageFormat.Images.Add(item2); } return(swrveMessageFormat); }
/// <summary> /// Load a conversation from a JSON response. /// </summary> /// <param name="campaign"> /// Parent in-app campaign. /// </param> /// <param name="conversationData"> /// JSON object with the conversation data. /// </param> /// <returns> /// Parsed conversation wrapper for native layer. /// </returns> public static SwrveConversation LoadFromJSON(ISwrveAssetsManager swrveAssetsManager, SwrveConversationCampaign campaign, Dictionary <string, object> conversationData) { SwrveConversation conversation = new SwrveConversation(swrveAssetsManager, campaign); conversation.Id = MiniJsonHelper.GetInt(conversationData, "id"); List <object> pages = (List <object>)conversationData ["pages"]; for (int i = 0; i < pages.Count; i++) { Dictionary <string, object> page = (Dictionary <string, object>)pages [i]; // Add image and font assets to queue from content List <object> contents = (List <object>)page ["content"]; for (int j = 0; j < contents.Count; j++) { Dictionary <string, object> content = (Dictionary <string, object>)contents[j]; string contentType = (string)content ["type"]; switch (contentType) { case "image": conversation.queueImageAsset(content); break; case "html-fragment": case "star-rating": conversation.queueFontAsset(content); break; case "multi-value-input": conversation.queueFontAsset(content); // iterate through options List <object> jsonOptions = (List <object>)content ["values"]; for (int k = 0; k < jsonOptions.Count; k++) { Dictionary <string, object> optionData = (Dictionary <string, object>)jsonOptions [k]; conversation.queueFontAsset(optionData); } break; } } // Add font assets to queue from button control List <object> controls = (List <object>)page ["controls"]; for (int j = 0; j < controls.Count; j++) { Dictionary <string, object> buttonData = (Dictionary <string, object>)controls [j]; conversation.queueFontAsset(buttonData); } } conversation.Conversation = Json.Serialize(conversationData); if (conversationData.ContainsKey("priority")) { conversation.Priority = MiniJsonHelper.GetInt(conversationData, "priority"); } return(conversation); }
public static SwrveConversation LoadFromJSON(ISwrveAssetsManager swrveAssetsManager, SwrveConversationCampaign campaign, Dictionary <string, object> conversationData) { SwrveConversation swrveConversation = new SwrveConversation(swrveAssetsManager, campaign); swrveConversation.Id = MiniJsonHelper.GetInt(conversationData, "id"); List <object> list = (List <object>)conversationData["pages"]; for (int i = 0; i < list.Count; i++) { Dictionary <string, object> dictionary = (Dictionary <string, object>)list[i]; List <object> list2 = (List <object>)dictionary["content"]; for (int j = 0; j < list2.Count; j++) { Dictionary <string, object> dictionary2 = (Dictionary <string, object>)list2[j]; string text = (string)dictionary2["type"]; if (text != null) { if (!(text == "image")) { if (!(text == "html-fragment") && !(text == "star-rating")) { if (text == "multi-value-input") { swrveConversation.queueFontAsset(dictionary2); List <object> list3 = (List <object>)dictionary2["values"]; for (int k = 0; k < list3.Count; k++) { Dictionary <string, object> content = (Dictionary <string, object>)list3[k]; swrveConversation.queueFontAsset(content); } } } else { swrveConversation.queueFontAsset(dictionary2); } } else { swrveConversation.queueImageAsset(dictionary2); } } } List <object> list4 = (List <object>)dictionary["controls"]; for (int l = 0; l < list4.Count; l++) { Dictionary <string, object> content2 = (Dictionary <string, object>)list4[l]; swrveConversation.queueFontAsset(content2); } } swrveConversation.Conversation = Json.Serialize(conversationData); if (conversationData.ContainsKey("priority")) { swrveConversation.Priority = MiniJsonHelper.GetInt(conversationData, "priority"); } return(swrveConversation); }
/// <summary> /// Save the respective SwrveUser in cache /// </summary> /// <param name="swrveUsers"> /// A List of user that will be cached (This method replace the preview list) /// </param> private void SaveSwrveUsers(List <SwrveUser> swrveUsers) { if (swrveUsers == null) { return; } string swrveUsersJsonObj = MiniJsonHelper.ToJson(swrveUsers.ToArray()); PlayerPrefs.SetString(SwrveUsersKey, swrveUsersJsonObj); }
/// <summary> /// Load the List<SwrveUser> from cache. /// </summary> /// <returns> /// List of Swrve users from cache. /// </returns> public List <SwrveUser> GetSwrveUsers() { List <SwrveUser> swrveUsers = new List <SwrveUser>(); string usersJsonObj = PlayerPrefs.GetString(SwrveUsersKey, null); // If find something in cache, return it. if (!string.IsNullOrEmpty(usersJsonObj) || usersJsonObj == "[]") { swrveUsers.AddRange(MiniJsonHelper.FromJson <SwrveUser>(usersJsonObj)); } return(swrveUsers); }
public SwrveQAUser(SwrveSDK swrve, Dictionary <string, object> jsonQa) { this.swrve = swrve; this.ResetDevice = MiniJsonHelper.GetBool(jsonQa, "reset_device_state", false); this.Logging = MiniJsonHelper.GetBool(jsonQa, "logging", false); if (this.Logging) { this.restClient = new RESTClient(); this.loggingUrl = MiniJsonHelper.GetString(jsonQa, "logging_url", null); this.loggingUrl = this.loggingUrl.Replace("http://", "https://"); if (!this.loggingUrl.EndsWith("/")) { this.loggingUrl += "/"; } } this.campaignReasons = new Dictionary <int, string>(); this.campaignMessages = new Dictionary <int, SwrveBaseMessage>(); }
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")); } }
public static SwrveEmbeddedMessage LoadFromJSON(SwrveEmbeddedCampaign campaign, Dictionary <string, object> messageData) { SwrveEmbeddedMessage message = new SwrveEmbeddedMessage(); message.Campaign = campaign; if (messageData.ContainsKey("priority")) { message.Priority = MiniJsonHelper.GetInt(messageData, "priority"); } if (messageData.ContainsKey("id")) { message.Id = MiniJsonHelper.GetInt(messageData, "id"); } if (messageData.ContainsKey("type")) { string typeString = MiniJsonHelper.GetString(messageData, "type"); message.setType(typeString); } if (messageData.ContainsKey("buttons")) { List <object> jsonButtons = (List <object>)messageData ["buttons"]; if (jsonButtons.Count > 0) { message.buttons = new List <string>(); } for (int i = 0; i < jsonButtons.Count; i++) { string buttonName = (string)jsonButtons[i]; message.buttons.Add(buttonName); } } if (messageData.ContainsKey("data")) { message.data = MiniJsonHelper.GetString(messageData, "data"); } return(message); }
public void SetABTestDetailsFromJSON(Dictionary <string, object> abTestDetailsJson) { List <SwrveABTestDetails> list = new List <SwrveABTestDetails>(); Dictionary <string, object> .Enumerator enumerator = abTestDetailsJson.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair <string, object> current = enumerator.Current; if (current.Value is Dictionary <string, object> ) { Dictionary <string, object> dictionary = (Dictionary <string, object>)current.Value; string name = (string)dictionary["name"]; int @int = MiniJsonHelper.GetInt(dictionary, "case_index", 0); SwrveABTestDetails item = new SwrveABTestDetails(current.Key, name, @int); list.Add(item); } } ABTestDetails = list; }
/// <summary> /// Update the AB Test details with the JSON content coming from the Swrve servers. /// </summary> /// <param name="abTestDetailsJson"> /// JSON response coming from the Swrve servers. /// </param> public void SetABTestDetailsFromJSON(Dictionary <string, object> abTestDetailsJson) { List <SwrveABTestDetails> abTestDetails = new List <SwrveABTestDetails> (); Dictionary <string, object> .Enumerator enumerator = abTestDetailsJson.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair <string, object> abTestDetailsPair = enumerator.Current; if (abTestDetailsPair.Value is Dictionary <string, object> ) { Dictionary <string, object> abTestDetailsDic = (Dictionary <string, object>)abTestDetailsPair.Value; string name = (string)abTestDetailsDic ["name"]; int caseIndex = MiniJsonHelper.GetInt(abTestDetailsDic, "case_index", 0); SwrveABTestDetails newDetails = new SwrveABTestDetails(abTestDetailsPair.Key, name, caseIndex); abTestDetails.Add(newDetails); } } ABTestDetails = abTestDetails; }
/// <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); }
public static SwrveMessage LoadFromJSON(ISwrveAssetsManager swrveAssetsManager, SwrveMessagesCampaign campaign, Dictionary <string, object> messageData, Color?defaultBackgroundColor) { SwrveMessage swrveMessage = new SwrveMessage(swrveAssetsManager, campaign); swrveMessage.Id = MiniJsonHelper.GetInt(messageData, "id"); swrveMessage.Name = (string)messageData["name"]; if (messageData.ContainsKey("priority")) { swrveMessage.Priority = MiniJsonHelper.GetInt(messageData, "priority"); } Dictionary <string, object> dictionary = (Dictionary <string, object>)messageData["template"]; IList <object> list = (List <object>)dictionary["formats"]; int i = 0; for (int count = list.Count; i < count; i++) { Dictionary <string, object> messageFormatData = (Dictionary <string, object>)list[i]; SwrveMessageFormat item = SwrveMessageFormat.LoadFromJSON(swrveAssetsManager, swrveMessage, messageFormatData, defaultBackgroundColor); swrveMessage.Formats.Add(item); } return(swrveMessage); }
public SwrveCampaignState(int campaignId, Dictionary <string, object> savedStatesJson) { string key = "Next" + campaignId; if (savedStatesJson.ContainsKey(key)) { this.Next = MiniJsonHelper.GetInt(savedStatesJson, key); } key = "Impressions" + campaignId; if (savedStatesJson.ContainsKey(key)) { this.Impressions = MiniJsonHelper.GetInt(savedStatesJson, key); } key = "Status" + campaignId; if (savedStatesJson.ContainsKey(key)) { this.CurStatus = SwrveCampaignState.ParseStatus(MiniJsonHelper.GetString(savedStatesJson, key)); } else { this.CurStatus = SwrveCampaignState.Status.Unseen; } }
/// <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(SwrveSDK sdk, SwrveMessagesCampaign campaign, Dictionary <string, object> messageData) { SwrveMessage message = new SwrveMessage(sdk, 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(sdk, message, messageFormatData); message.Formats.Add(messageFormat); } return(message); }
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; } }
protected static int IntValueFromAttribute(Dictionary <string, object> data, string attribute) { return(MiniJsonHelper.GetInt(((Dictionary <string, object>)data [attribute]), "value")); }
/// <summary> /// Load an in-app message format from a JSON response. /// </summary> /// <param name="message"> /// Parent in-app message. /// </param> /// <param name="messageFormatData"> /// JSON object with the individual message format data. /// </param> /// <returns> /// Parsed in-app message format. /// </returns> public static SwrveMessageFormat LoadFromJSON(SwrveSDK sdk, SwrveMessage message, Dictionary <string, object> messageFormatData) { SwrveMessageFormat messageFormat = new SwrveMessageFormat(message); messageFormat.Name = (string)messageFormatData ["name"]; messageFormat.Language = (string)messageFormatData ["language"]; if (messageFormatData.ContainsKey("scale")) { messageFormat.Scale = MiniJsonHelper.GetFloat(messageFormatData, "scale", 1); } if (messageFormatData.ContainsKey("orientation")) { messageFormat.Orientation = SwrveOrientationHelper.Parse((string)messageFormatData ["orientation"]); } messageFormat.BackgroundColor = sdk.DefaultBackgroundColor; if (messageFormatData.ContainsKey("color")) { string strColor = (string)messageFormatData ["color"]; Color? c = messageFormat.BackgroundColor; if (strColor.Length == 8) { // RRGGBB byte a = byte.Parse(strColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); byte r = byte.Parse(strColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); byte g = byte.Parse(strColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); byte b = byte.Parse(strColor.Substring(6, 2), System.Globalization.NumberStyles.HexNumber); c = new Color32(r, g, b, a); } else if (strColor.Length == 6) { // AARRGGBB byte r = byte.Parse(strColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); byte g = byte.Parse(strColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); byte b = byte.Parse(strColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); c = new Color32(r, g, b, 255); } messageFormat.BackgroundColor = c; } Dictionary <string, object> sizeJson = (Dictionary <string, object>)messageFormatData ["size"]; messageFormat.Size.X = MiniJsonHelper.GetInt(((Dictionary <string, object>)sizeJson ["w"]), "value"); messageFormat.Size.Y = MiniJsonHelper.GetInt(((Dictionary <string, object>)sizeJson ["h"]), "value"); IList <object> jsonButtons = (List <object>)messageFormatData ["buttons"]; for (int i = 0, j = jsonButtons.Count; i < j; i++) { SwrveButton button = LoadButtonFromJSON(message, (Dictionary <string, object>)jsonButtons [i]); messageFormat.Buttons.Add(button); } IList <object> jsonImages = (List <object>)messageFormatData ["images"]; for (int ii = 0, ji = jsonImages.Count; ii < ji; ii++) { SwrveImage image = LoadImageFromJSON(message, (Dictionary <string, object>)jsonImages [ii]); messageFormat.Images.Add(image); } return(messageFormat); }