/// <summary> /// Get all the assets in the in-app campaign messages. /// </summary> /// <returns> /// All the assets in the in-app campaign. /// </returns> public override List <string> ListOfAssets() { List <string> allAssets = new List <string> (); for (int mi = 0; mi < Messages.Count; mi++) { SwrveMessage message = Messages[mi]; allAssets.AddRange(message.ListOfAssets()); } return(allAssets); }
/// <summary> /// Get a message by its identifier. /// </summary> /// <returns> /// The message with the given identifier if it could be found. /// </returns> public SwrveMessage GetMessageForId(int id) { for (int mi = 0; mi < Messages.Count; mi++) { SwrveMessage message = Messages[mi]; if (message.Id == id) { return(message); } } return(null); }
protected static SwrveButton LoadButtonFromJSON(SwrveMessage message, Dictionary <string, object> buttonData) { SwrveButton button = new SwrveButton(); button.Position.X = IntValueFromAttribute(buttonData, "x"); button.Position.Y = IntValueFromAttribute(buttonData, "y"); button.Size.X = IntValueFromAttribute(buttonData, "w"); button.Size.Y = IntValueFromAttribute(buttonData, "h"); button.Image = StringValueFromAttribute(buttonData, "image_up"); if (buttonData.ContainsKey("text")) { button.Text = StringValueFromAttribute(buttonData, "text"); } button.Message = message; if (buttonData.ContainsKey("name")) { button.Name = (string)buttonData ["name"]; } string actionTypeStr = StringValueFromAttribute(buttonData, "type"); SwrveActionType actionType = SwrveActionType.Dismiss; if (actionTypeStr.ToLower().Equals("install")) { actionType = SwrveActionType.Install; } else if (actionTypeStr.ToLower().Equals("custom")) { actionType = SwrveActionType.Custom; } else if (actionTypeStr.ToLower().Equals("copy_to_clipboard")) { actionType = SwrveActionType.CopyToClipboard; } button.ActionType = actionType; button.Action = StringValueFromAttribute(buttonData, "action"); if (button.ActionType == SwrveActionType.Install) { string appId = StringValueFromAttribute(buttonData, "game_id"); if (appId != null && appId != string.Empty) { button.AppId = int.Parse(appId); } } return(button); }
protected static SwrveImage LoadImageFromJSON(SwrveMessage message, Dictionary <string, object> imageData) { SwrveImage image = new SwrveImage(); image.Position.X = IntValueFromAttribute(imageData, "x"); image.Position.Y = IntValueFromAttribute(imageData, "y"); image.Size.X = IntValueFromAttribute(imageData, "w"); image.Size.Y = IntValueFromAttribute(imageData, "h"); image.File = StringValueFromAttribute(imageData, "image"); return(image); }
public static SwrveMessagesCampaign LoadFromJSON(ISwrveAssetsManager swrveAssetsManager, Dictionary <string, object> campaignData, int id, DateTime initialisedTime, SwrveQAUser qaUser, Color?defaultBackgroundColor) { SwrveMessagesCampaign swrveMessagesCampaign = new SwrveMessagesCampaign(initialisedTime); object obj = null; campaignData.TryGetValue("messages", out obj); IList <object> list = null; try { list = (IList <object>)obj; } catch (Exception ex) { swrveMessagesCampaign.LogAndAddReason(string.Concat(new object[] { "Campaign [", id, "] invalid messages found, skipping. Error: ", ex }), qaUser); } if (list == null) { swrveMessagesCampaign.LogAndAddReason("Campaign [" + id + "] JSON messages are null, skipping.", qaUser); return(null); } int i = 0; int count = list.Count; while (i < count) { Dictionary <string, object> messageData = (Dictionary <string, object>)list[i]; SwrveMessage swrveMessage = SwrveMessage.LoadFromJSON(swrveAssetsManager, swrveMessagesCampaign, messageData, defaultBackgroundColor); if (swrveMessage.Formats.Count > 0) { swrveMessagesCampaign.AddMessage(swrveMessage); } i++; } if (swrveMessagesCampaign.Messages.Count == 0) { swrveMessagesCampaign.LogAndAddReason("Campaign [" + id + "] no messages found, skipping.", qaUser); } return(swrveMessagesCampaign); }
public bool ResolveTemplating(SwrveMessage message, Dictionary <string, string> properties) { try { for (int fi = 0; fi < message.Formats.Count; fi++) { SwrveMessageFormat format = message.Formats[fi]; for (int ii = 0; ii < format.Images.Count; ii++) { SwrveImage image = format.Images[ii]; if (!ResolveWidgetProperty(image, TextResolution, image.Text, properties)) { return(false); } } for (int bi = 0; bi < format.Buttons.Count; bi++) { SwrveButton button = format.Buttons[bi]; if (!ResolveWidgetProperty(button, TextResolution, button.Text, properties)) { return(false); } // Need to personalize action string personalizedButtonAction = button.Action; if ((button.ActionType == SwrveActionType.Custom || button.ActionType == SwrveActionType.CopyToClipboard) && !string.IsNullOrEmpty(personalizedButtonAction)) { if (!ResolveWidgetProperty(button, ActionResolution, personalizedButtonAction, properties)) { return(false); } } else { ActionResolution[button] = personalizedButtonAction; } } } } catch (SwrveSDKTextTemplatingException exp) { UnityEngine.Debug.LogError("Not showing campaign, error with personalization" + exp.Message); 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); }
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); }
new public static SwrveMessagesCampaign LoadFromJSON(SwrveSDK sdk, Dictionary <string, object> campaignData, int id, DateTime initialisedTime, SwrveQAUser qaUser) { SwrveMessagesCampaign campaign = new SwrveMessagesCampaign(initialisedTime); object _messages = null; campaignData.TryGetValue("messages", out _messages); IList <object> messages = null; try { messages = (IList <object>)_messages; } catch (Exception e) { campaign.LogAndAddReason("Campaign [" + id + "] invalid messages found, skipping. Error: " + e, qaUser); } if (messages == null) { campaign.LogAndAddReason("Campaign [" + id + "] JSON messages are null, skipping.", qaUser); 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(sdk, campaign, messageData); if (message.Formats.Count > 0) { campaign.AddMessage(message); } } if (campaign.Messages.Count == 0) { campaign.LogAndAddReason("Campaign [" + id + "] no messages found, skipping.", qaUser); } return(campaign); }
protected static SwrveButton LoadButtonFromJSON(SwrveMessage message, Dictionary <string, object> buttonData) { SwrveButton swrveButton = new SwrveButton(); swrveButton.Position.X = SwrveMessageFormat.IntValueFromAttribute(buttonData, "x"); swrveButton.Position.Y = SwrveMessageFormat.IntValueFromAttribute(buttonData, "y"); swrveButton.Size.X = SwrveMessageFormat.IntValueFromAttribute(buttonData, "w"); swrveButton.Size.Y = SwrveMessageFormat.IntValueFromAttribute(buttonData, "h"); swrveButton.Image = SwrveMessageFormat.StringValueFromAttribute(buttonData, "image_up"); swrveButton.Message = message; if (buttonData.ContainsKey("name")) { swrveButton.Name = (string)buttonData["name"]; } string text = SwrveMessageFormat.StringValueFromAttribute(buttonData, "type"); SwrveActionType actionType = SwrveActionType.Dismiss; if (text.ToLower().Equals("install")) { actionType = SwrveActionType.Install; } else if (text.ToLower().Equals("custom")) { actionType = SwrveActionType.Custom; } swrveButton.ActionType = actionType; swrveButton.Action = SwrveMessageFormat.StringValueFromAttribute(buttonData, "action"); if (swrveButton.ActionType == SwrveActionType.Install) { string text2 = SwrveMessageFormat.StringValueFromAttribute(buttonData, "game_id"); if (text2 != null && text2 != string.Empty) { swrveButton.AppId = int.Parse(text2); } } return(swrveButton); }
/// <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 SwrveMessageFormat(SwrveMessage message) { this.Message = message; this.Buttons = new List <SwrveButton> (); this.Images = new List <SwrveImage> (); }
/// <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); }
protected void AddMessage(SwrveMessage message) { Messages.Add(message); }
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); }
private SwrveMessageFormat(SwrveMessage message) { Message = message; Buttons = new List <SwrveButton>(); Images = new List <SwrveImage>(); }