protected virtual IEnumerator DownloadAsset(SwrveAssetsQueueItem item) { string cdn = (item.IsImage ? CdnImages : CdnFonts); string url = cdn + item.Name; SwrveLog.Log("Downloading asset: " + url); WWW www = new WWW(url); yield return(www); WwwDeducedError err = UnityWwwHelper.DeduceWwwError(www); if (www != null && err == WwwDeducedError.NoError && www.isDone) { if (item.IsImage) { SaveImageAsset(item, www); } else { SaveBinaryAsset(item, www); } } TaskFinished("SwrveAssetsManager.DownloadAsset"); }
protected virtual IEnumerator DownloadAsset(SwrveAssetsQueueItem item) { string str = (!item.IsImage) ? this.CdnFonts : this.CdnImages; string text = str + item.Name; SwrveLog.Log("Downloading asset: " + text); WWW wWW = new WWW(text); yield return(wWW); WwwDeducedError wwwDeducedError = UnityWwwHelper.DeduceWwwError(wWW); if (wWW != null && wwwDeducedError == WwwDeducedError.NoError && wWW.isDone) { if (item.IsImage) { this.SaveImageAsset(item, wWW); } else { this.SaveBinaryAsset(item, wWW); } } this.TaskFinished("SwrveAssetsManager.DownloadAsset"); yield break; }
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 virtual void SaveSecure(string tag, string data, string userId = null) { if (string.IsNullOrEmpty(data)) { return; } bool saved = false; try { string saveFileName = GetFileName(tag, userId); SwrveLog.Log("Saving: " + saveFileName, "storage"); CrossPlatformFile.SaveText(saveFileName, data); string signatureFileName = saveFileName + SIGNATURE_SUFFIX; string signature = SwrveHelper.CreateHMACMD5(data, uniqueKey); CrossPlatformFile.SaveText(signatureFileName, signature); saved = true; } catch (Exception e) { SwrveLog.LogError(e.ToString(), "storage"); } if (!saved) { SwrveLog.LogWarning(tag + " not saved!", "storage"); } }
protected virtual IEnumerator DownloadAsset(SwrveAssetsQueueItem item) { string cdn = item.IsImage ? CdnImages : CdnFonts; string url = cdn + item.Name; SwrveLog.Log("Downloading asset: " + url); UnityWebRequest www = (item.IsImage)? UnityWebRequestTexture.GetTexture(url) : new UnityWebRequest(url); if (!item.IsImage) { DownloadHandlerBuffer dH = new DownloadHandlerBuffer(); www.downloadHandler = dH; } yield return(www.SendWebRequest()); if (!www.isNetworkError && !www.isHttpError) { if (item.IsImage) { SaveImageAsset(item, www); } else { SaveBinaryAsset(item, www); } } else { MissingAssetsQueue.Add(item); } TaskFinished("SwrveAssetsManager.DownloadAsset"); }
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); }
public virtual void SaveSecure(string tag, string data, string userId = null) { if (!string.IsNullOrEmpty(data)) { bool flag = false; try { string fileName = GetFileName(tag, userId); SwrveLog.Log("Saving: " + fileName, "storage"); CrossPlatformFile.SaveText(fileName, data); string path = fileName + "_SGT"; string data2 = SwrveHelper.CreateHMACMD5(data, uniqueKey); CrossPlatformFile.SaveText(path, data2); flag = true; } catch (Exception ex) { SwrveLog.LogError(ex.ToString(), "storage"); } if (!flag) { SwrveLog.LogWarning(tag + " not saved!", "storage"); } } }
protected void LogAndAddReason(string reason, SwrveQAUser qaUser) { if (qaUser != null && !qaUser.campaignReasons.ContainsKey(this.Id)) { qaUser.campaignReasons.Add(this.Id, reason); } SwrveLog.Log(string.Format("{0} {1}", this, reason)); }
protected void LogAndAddReason(string reason, SwrveQAUser qaUser) { if (!(qaUser?.campaignReasons.ContainsKey(Id) ?? true)) { qaUser.campaignReasons.Add(Id, reason); } SwrveLog.Log($"{this} {reason}"); }
private void setNativeAppVersion() { try { config.AppVersion = _swrveiOSGetAppVersion(); SwrveLog.Log("got iOS version name " + config.AppVersion); } catch (Exception exp) { SwrveLog.LogWarning("Couldn't get the device app version, make sure you have the iOS plugin inside your project and you are running on a iOS device: " + exp.ToString()); } }
public virtual void Remove(string tag, string userId = null) { try { string prefPath = tag + ((userId == null) ? string.Empty : userId); SwrveLog.Log("Setting " + prefPath + " to null", "storage"); PlayerPrefs.SetString(prefPath, null); } catch (PlayerPrefsException ppe) { SwrveLog.LogError(ppe.ToString()); } }
public void HandleNotificationToCampaign(string campaignID) { if (String.IsNullOrEmpty(campaignID)) { SwrveLog.Log("campaignID was nil or an empty string. Campaign will not be displayed"); return; } string getRequest = CreateCampaignUrl(campaignID); container.StartCoroutine(GetExternalCampaign_Coroutine(getRequest)); }
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) { #if UNITY_5 if (target == BuildTarget.iOS) #else if (target == BuildTarget.iPhone) #endif { SwrveLog.Log("SwrveIOSPostProcess"); CorrectXCodeProject(pathToBuiltProject, true); } }
public virtual void Remove(string tag, string userId = null) { try { string text = tag + ((userId != null) ? userId : string.Empty); SwrveLog.Log("Setting " + text + " to null", "storage"); PlayerPrefs.SetString(text, null); } catch (PlayerPrefsException ex) { SwrveLog.LogError(ex.ToString()); } }
/// <summary> /// Obtain the Swrve identifier from a received push notification. /// </summary> /// <param name="notification"> /// Push notification received by the app. /// </param> private string GetPushId(Dictionary <string, object> notification) { if (notification != null && notification.ContainsKey(PushTrackingKey)) { return(notification[PushTrackingKey].ToString()); } else { SwrveLog.Log("Got unidentified notification"); } return(null); }
protected static string ExecuteCommand(string workingDirectory, string filename, string arguments) { string resp = ""; if ("." == workingDirectory) { workingDirectory = new DirectoryInfo(".").FullName; } Process proc = new Process(); proc.StartInfo.WorkingDirectory = workingDirectory; proc.StartInfo.FileName = filename; proc.StartInfo.Arguments = arguments; SwrveLog.Log(string.Format("Executing {0} command: {1} (in: {2} )\n(cd {2}; {0} {1})", filename, arguments, workingDirectory )); proc.StartInfo.CreateNoWindow = true; proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardOutput = true; try { proc.Start(); proc.StandardError.ReadToEnd(); resp = proc.StandardOutput.ReadToEnd(); string errorOutput = proc.StandardError.ReadToEnd(); if ("" != resp) { SwrveLog.Log(resp); } if ("" != errorOutput) { SwrveLog.LogError(errorOutput); } if (proc.ExitCode == 0) { UnityEngine.Debug.Log(filename + " " + arguments + " successfull"); } } catch (Exception e) { throw new Exception(string.Format("Encountered unexpected error while running {0}", filename), e); } return(resp); }
public SwrveMessage GetMessageForEvent(string triggerEvent, IDictionary <string, string> payload, SwrveQAUser qaUser) { int count = this.Messages.Count; if (count == 0) { base.LogAndAddReason("No messages in campaign " + this.Id, qaUser); return(null); } if (base.checkCampaignLimits(triggerEvent, payload, qaUser)) { SwrveLog.Log(string.Format("[{0}] {1} matches a trigger in {2}", this, triggerEvent, this.Id)); return(this.GetNextMessage(count, qaUser)); } return(null); }
public SwrveEmbeddedMessage GetMessageForEvent(string triggerEvent, IDictionary <string, string> payload, List <SwrveQaUserCampaignInfo> qaCampaignInfoList) { if (Message == null) { string reason = "No embedded message in campaign " + Id; LogAndAddReason(reason, false, qaCampaignInfoList); return(null); } if (CheckCampaignLimits(triggerEvent, payload, qaCampaignInfoList)) { SwrveLog.Log(string.Format("[{0}] {1} matches a trigger in {2}", this, triggerEvent, Id)); return(Message); } return(null); }
public void MessageWasShownToUser(SwrveMessageFormat messageFormat) { WasShownToUser(); if (Messages.Count > 0) { if (!RandomOrder) { int num2 = (base.Next = (base.Next + 1) % Messages.Count); SwrveLog.Log("Round Robin: Next message in campaign " + Id + " is " + num2); } else { SwrveLog.Log("Next message in campaign " + Id + " is random"); } } }
public SwrveMessage GetMessageForEvent(string triggerEvent, IDictionary <string, string> payload, SwrveQAUser qaUser) { int count = Messages.Count; if (count == 0) { LogAndAddReason("No messages in campaign " + Id, qaUser); return(null); } if (CheckCampaignLimits(triggerEvent, payload, qaUser)) { SwrveLog.Log($"[{this}] {triggerEvent} matches a trigger in {Id}"); return(GetNextMessage(count, qaUser)); } return(null); }
/// <summary> /// Search for a conversation related to the given trigger event at the given /// time. This function will return null if too many conversations were dismissed, /// the campaign start is in the future, the campaign end is in the past or /// the given event is not contained in the trigger set. /// </summary> /// <param name="triggerEvent"> /// Event triggered. Must be a trigger for the campaign. /// </param> /// <param name="campaignReasons"> /// At the exit of the function will include the reasons why a campaign the campaigns /// in memory were not shown or chosen. /// </param> /// <returns> /// SwrveConversation that contains the given event in its trigger list and satisfies all the /// rules. /// </returns> public SwrveConversation GetConversationForEvent(string triggerEvent, IDictionary <string, string> payload, SwrveQAUser qaUser) { if (null == Conversation) { LogAndAddReason("No conversation in campaign " + Id, qaUser); return(null); } if (checkCampaignLimits(triggerEvent, payload, qaUser)) { SwrveLog.Log(string.Format("[{0}] {1} matches a trigger in {2}", this, triggerEvent, Id)); return(Conversation); } return(null); }
protected virtual void SaveBinaryAsset(SwrveAssetsQueueItem item, WWW www) { byte[] bytes = www.bytes; string text = SwrveHelper.sha1(bytes); if (text == item.Digest) { string temporaryPathFileName = this.GetTemporaryPathFileName(item.Name); SwrveLog.Log("Saving to " + temporaryPathFileName); CrossPlatformFile.SaveBytes(temporaryPathFileName, bytes); this.AssetsOnDisk.Add(item.Name); } else { SwrveLog.Log("Error downloading binary assetItem:" + item.Name + ". Did not match digest:" + text); } }
public virtual string Load(string tag, string userId = null) { string result = null; try { string prefPath = tag + ((userId == null) ? string.Empty : userId); if (PlayerPrefs.HasKey(prefPath)) { SwrveLog.Log("Got " + tag + " from PlayerPrefs", "storage"); result = PlayerPrefs.GetString(prefPath); } } catch (PlayerPrefsException ppe) { SwrveLog.LogError(ppe.ToString(), "storage"); } return(result); }
/// <summary> /// Processe remote notifications and clear them. /// </summary> public void ProcessRemoteNotifications() { if (config.PushNotificationEnabled) { // Process push notifications int notificationCount = NotificationServices.remoteNotificationCount; if (notificationCount > 0) { SwrveLog.Log("Got " + notificationCount + " remote notifications"); for (int i = 0; i < notificationCount; i++) { ProcessRemoteNotification(NotificationServices.remoteNotifications[i]); } NotificationServices.ClearRemoteNotifications(); } } }
public SwrveConversation GetConversationForEvent(string triggerEvent, IDictionary <string, string> payload, SwrveQAUser qaUser) { if (null == Conversation) { LogAndAddReason("No conversation in campaign " + Id, qaUser); return(null); } if (CheckCampaignLimits(triggerEvent, payload, qaUser)) { SwrveLog.Log($"[{this}] {triggerEvent} matches a trigger in {Id}"); if (AreAssetsReady()) { return(Conversation); } LogAndAddReason("Assets not downloaded to show conversation in campaign " + Id, qaUser); } return(null); }
protected virtual void SaveBinaryAsset(SwrveAssetsQueueItem item, UnityWebRequest www) { byte[] bytes = www.downloadHandler.data; string sha1 = SwrveHelper.sha1(bytes); if (sha1 == item.Digest) { string filePath = GetTemporaryPathFileName(item.Name); SwrveLog.Log("Saving to " + filePath); CrossPlatformFile.SaveBytes(filePath, bytes); bytes = null; AssetsOnDisk.Add(item.Name); } else { SwrveLog.Log("Error downloading binary assetItem:" + item.Name + ". Did not match digest:" + sha1); } }
private void QueueDeeplinkGenericEvent(string adSource, string campaignID, string campaignName, string actionType) { if (String.IsNullOrEmpty(adSource)) { SwrveLog.Log("DeeplinkCampaign adSource was nil or an empty string. Generic event not queued"); return; } adSource = "external_source_" + adSource; Dictionary <string, object> eventData = new Dictionary <string, object>(); eventData.Add("campaignType", adSource); eventData.Add("actionType", actionType); eventData.Add("campaignId", campaignID); eventData.Add("contextId", campaignName); eventData.Add("id", -1); this.sdk.QueueGenericCampaignEvent(eventData); }
/// <summary> /// Notify that the message was shown to the user. This function /// has to be called only once when the message is displayed to /// the user. /// This is automatically called by the SDK and will only need /// to be manually called if you are implementing your own /// in-app message rendering code. /// </summary> public void MessageWasShownToUser(SwrveMessageFormat messageFormat) { base.WasShownToUser(); if (Messages.Count > 0) { if (!RandomOrder) { int nextMessage = (Next + 1) % Messages.Count; Next = nextMessage; SwrveLog.Log("Round Robin: Next message in campaign " + Id + " is " + nextMessage); } else { SwrveLog.Log("Next message in campaign " + Id + " is random"); } } }
public virtual void Save(string tag, string data, string userId = null) { bool saved = false; try { string prefPath = tag + ((userId == null) ? string.Empty : userId); SwrveLog.Log("Setting " + prefPath + " in PlayerPrefs", "storage"); PlayerPrefs.SetString(prefPath, data); saved = true; } catch (PlayerPrefsException ppe) { SwrveLog.LogError(ppe.ToString(), "storage"); } if (!saved) { SwrveLog.LogWarning(tag + " not saved!", "storage"); } }
public SwrveConversation GetConversationForEvent(string triggerEvent, IDictionary <string, string> payload, SwrveQAUser qaUser) { if (this.Conversation == null) { base.LogAndAddReason("No conversation in campaign " + this.Id, qaUser); return(null); } if (base.checkCampaignLimits(triggerEvent, payload, qaUser)) { SwrveLog.Log(string.Format("[{0}] {1} matches a trigger in {2}", this, triggerEvent, this.Id)); if (this.AreAssetsReady()) { return(this.Conversation); } base.LogAndAddReason("Assets not downloaded to show conversation in campaign " + this.Id, qaUser); } return(null); }