/// <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);
        }
Exemple #2
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);
        }
        /// <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);
        }
 private SwrveMessage(ISwrveAssetController assetController, SwrveMessagesCampaign campaign)
 {
     this.assetController = assetController;
     this.Campaign        = campaign;
     this.Formats         = new List <SwrveMessageFormat> ();
 }