コード例 #1
0
        /// <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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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");
            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;
            }

            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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
 private SwrveMessageFormat(SwrveMessage message)
 {
     this.Message = message;
     this.Buttons = new List <SwrveButton> ();
     this.Images  = new List <SwrveImage> ();
 }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
 protected void AddMessage(SwrveMessage message)
 {
     this.Messages.Add(message);
 }