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);
        }
    public void UserUpdate(string userUpdate)
    {
        try {
            Dictionary <string, object>             o  = (Dictionary <string, object>)Json.Deserialize(userUpdate);
            Dictionary <string, string>             _o = new Dictionary <string, string>();
            Dictionary <string, object> .Enumerator it = o.GetEnumerator();

            while (it.MoveNext())
            {
                _o[it.Current.Key] = string.Format("{0}", it.Current.Value);
            }

            SDK.UserUpdate(_o);
        } catch (System.Exception e) {
            SwrveLog.LogError(e.ToString(), "userUpdate");
        }
    }
Example #3
0
        /// <summary>
        /// Attempts to deduce the WWW error
        /// </summary>
        /// <returns>
        /// The deduced error.
        /// </returns>
        /// <param name='request'>
        /// The request to check.
        /// </param>
        /// <param name='expectedResponse'>
        /// The expected response.
        /// </param>
        public static WwwDeducedError DeduceWwwError(WWW request)
        {
            // Check response headers for X-Swrve-Error
            if (request.responseHeaders.Count > 0)
            {
                string errorKey = null;

                Dictionary <string, string> .Enumerator enumerator = request.responseHeaders.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    string headerKey = enumerator.Current.Key;
                    if (string.Equals(headerKey, "X-Swrve-Error", StringComparison.OrdinalIgnoreCase))
                    {
                        request.responseHeaders.TryGetValue(headerKey, out errorKey);
                        break;
                    }
                }

                if (errorKey != null)
                {
                    SwrveLog.LogError(@"Request response headers [""X-Swrve-Error""]: " + errorKey + " at " + request.url);
                    try {
                        if (!string.IsNullOrEmpty(request.text))
                        {
                            SwrveLog.LogError(@"Request response headers [""X-Swrve-Error""]: " +
                                              ((IDictionary <string, object>)Json.Deserialize(request.text))["message"]);
                        }
                    }
                    catch (Exception e) {
                    }
                    return(WwwDeducedError.ApplicationErrorHeader);
                }
            }

            // Check WWW error- accessing www.bytes can barf if this is set.
            // Unity 3.4 webplayer has error/nohdr/nobody for non-200 http response
            // - actually an application error, but treated here as a network error
            //   hence 'NetworkOrApplicationError'
            if (!string.IsNullOrEmpty(request.error))
            {
                SwrveLog.LogError("Request error: " + request.error + " in " + request.url);
                return(WwwDeducedError.NetworkError);
            }

            return(WwwDeducedError.NoError);
        }
Example #4
0
 protected void ProcessResponse(UnityWebRequest www, long wwwTime, string url, Action <RESTResponse> listener)
 {
     try
     {
         if (!www.isNetworkError || !www.isHttpError)
         {
             string decodedString = null;
             bool   flag          = ResponseBodyTester.TestUTF8(www.downloadHandler.data, out decodedString);
             Dictionary <string, string> dictionary = new Dictionary <string, string>();
             string text = null;
             if (www.GetResponseHeaders() != null)
             {
                 Dictionary <string, string> .Enumerator enumerator = www.GetResponseHeaders().GetEnumerator();
                 while (enumerator.MoveNext())
                 {
                     KeyValuePair <string, string> current = enumerator.Current;
                     dictionary.Add(current.Key.ToUpper(), current.Value);
                 }
                 if (dictionary.ContainsKey("CONTENT-ENCODING"))
                 {
                     text = dictionary["CONTENT-ENCODING"];
                 }
             }
             if (flag)
             {
                 AddMetrics(url, wwwTime, error: false);
                 listener(new RESTResponse(decodedString, dictionary));
             }
             else
             {
                 AddMetrics(url, wwwTime, error: true);
                 listener(new RESTResponse(decodedString, dictionary));
             }
         }
         else
         {
             AddMetrics(url, wwwTime, error: true);
             listener(new RESTResponse(www.responseCode));
         }
     }
     catch (Exception message)
     {
         SwrveLog.LogError(message);
     }
 }
Example #5
0
 public void UserUpdate(string userUpdate)
 {
     try
     {
         Dictionary <string, object>             dictionary  = (Dictionary <string, object>)Json.Deserialize(userUpdate);
         Dictionary <string, string>             dictionary2 = new Dictionary <string, string>();
         Dictionary <string, object> .Enumerator enumerator  = dictionary.GetEnumerator();
         while (enumerator.MoveNext())
         {
             dictionary2[enumerator.Current.Key] = $"{enumerator.Current.Value}";
         }
         SDK.UserUpdate(dictionary2);
     }
     catch (Exception ex)
     {
         SwrveLog.LogError(ex.ToString(), "userUpdate");
     }
 }
        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 virtual string Load(string tag, string userId = null)
        {
            string result = null;

            try
            {
                string fileName = GetFileName(tag, userId);
                if (CrossPlatformFile.Exists(fileName))
                {
                    result = CrossPlatformFile.LoadText(fileName);
                }
            }
            catch (Exception ex)
            {
                SwrveLog.LogError(ex.ToString(), "storage");
            }
            return(result);
        }
        public void TriggerFailure(string eventName, string globalReason)
        {
            try {
                if (CanMakeTriggerRequest())
                {
                    string endpoint = getEndpoint("talk/game/" + swrve.ApiKey + "/user/" + swrve.UserId + "/trigger");
                    Dictionary <string, object> triggerJson = new Dictionary <string, object> ();
                    triggerJson.Add("trigger_name", eventName);
                    triggerJson.Add("displayed", false);
                    triggerJson.Add("reason", globalReason);
                    triggerJson.Add("campaigns", new List <object> ());

                    MakeRequest(endpoint, triggerJson);
                }
            } catch (Exception exp) {
                SwrveLog.LogError("QA request talk session failed: " + exp.ToString());
            }
        }
Example #9
0
 public static IEnumerable <SwrveTrigger> LoadFromJson(List <object> triggers)
 {
     try
     {
         if (SwrveTrigger.< > f__mg$cache0 == null)
         {
             SwrveTrigger.< > f__mg$cache0 = new Func <object, SwrveTrigger>(SwrveTrigger.LoadFromJson);
         }
         return(from dict in triggers.Select(SwrveTrigger.< > f__mg$cache0)
                where dict != null
                select dict);
     }
     catch (Exception arg)
     {
         SwrveLog.LogError(string.Format("Error creating a list of SwrveTriggers, ex: {0}", arg));
     }
     return(null);
 }
Example #10
0
 public static WwwDeducedError DeduceWwwError(UnityWebRequest request)
 {
     if (request.isNetworkError)
     {
         SwrveLog.LogError("Request network error: " + request.error + " in " + request.url);
         return(WwwDeducedError.NetworkError);
     }
     if (request.GetResponseHeaders() != null)
     {
         string value = null;
         Dictionary <string, string> .Enumerator enumerator = request.GetResponseHeaders().GetEnumerator();
         while (enumerator.MoveNext())
         {
             string key = enumerator.Current.Key;
             if (string.Equals(key, "X-Swrve-Error", StringComparison.OrdinalIgnoreCase))
             {
                 request.GetResponseHeaders().TryGetValue(key, out value);
                 break;
             }
         }
         if (value != null)
         {
             SwrveLog.LogError("Request response headers [\"X-Swrve-Error\"]: " + value + " at " + request.url);
             try
             {
                 if (!string.IsNullOrEmpty(request.downloadHandler.text))
                 {
                     SwrveLog.LogError("Request response headers [\"X-Swrve-Error\"]: " + ((IDictionary <string, object>)Json.Deserialize(request.downloadHandler.text))["message"]);
                 }
             }
             catch (Exception ex)
             {
                 SwrveLog.LogError(ex.Message);
             }
             return(WwwDeducedError.ApplicationErrorHeader);
         }
     }
     if (!string.IsNullOrEmpty(request.error))
     {
         SwrveLog.LogError("Request network error: " + request.error + " in " + request.url);
         return(WwwDeducedError.NetworkError);
     }
     return(WwwDeducedError.NoError);
 }
Example #11
0
        public virtual string Load(string tag, string userId = null)
        {
            string result = null;

            try
            {
                string key = tag + ((userId != null) ? userId : string.Empty);
                if (PlayerPrefs.HasKey(key))
                {
                    SwrveLog.Log("Got " + tag + " from PlayerPrefs", "storage");
                    result = PlayerPrefs.GetString(key);
                }
            }
            catch (PlayerPrefsException ex)
            {
                SwrveLog.LogError(ex.ToString(), "storage");
            }
            return(result);
        }
Example #12
0
 protected bool _CheckArguments(string name, long quantity, string type)
 {
     if (string.IsNullOrEmpty(name))
     {
         SwrveLog.LogError("IapRewards illegal argument: reward name cannot be empty");
         return(false);
     }
     if (quantity <= 0)
     {
         SwrveLog.LogError("IapRewards illegal argument: reward amount must be greater than zero");
         return(false);
     }
     if (string.IsNullOrEmpty(type))
     {
         SwrveLog.LogError("IapRewards illegal argument: type cannot be empty");
         return(false);
     }
     return(true);
 }
Example #13
0
 public void UpdateDeviceInfo()
 {
     try {
         if (CanMakeRequest())
         {
             String endpoint = getEndpoint("talk/game/" + swrve.ApiKey + "/user/" + swrve.UserId + "/device_info");
             Dictionary <string, object>             deviceJson     = new Dictionary <string, object> ();
             Dictionary <string, string>             deviceData     = swrve.GetDeviceInfo();
             Dictionary <string, string> .Enumerator deviceDataEnum = deviceData.GetEnumerator();
             while (deviceDataEnum.MoveNext())
             {
                 deviceJson.Add(deviceDataEnum.Current.Key, deviceDataEnum.Current.Value);
             }
             MakeRequest(endpoint, deviceJson);
         }
     } catch (Exception exp) {
         SwrveLog.LogError("QA request talk device info update failed: " + exp.ToString());
     }
 }
        protected void ProcessResponse(UnityWebRequest www, long wwwTime, string url, Action <RESTResponse> listener)
        {
#if SWRVE_SUPPORTED_PLATFORM
            try {
                if (!www.isNetworkError)
                {
                    // - made it there and it was ok
                    string responseBody = null;
                    bool   success      = ResponseBodyTester.TestUTF8(www.downloadHandler.data, out responseBody);
                    Dictionary <string, string> headers = new Dictionary <string, string> ();

                    if (www.GetResponseHeaders() != null)
                    {
                        Dictionary <string, string> .Enumerator headersEnum = www.GetResponseHeaders().GetEnumerator();
                        while (headersEnum.MoveNext())
                        {
                            KeyValuePair <string, string> header = headersEnum.Current;
                            headers.Add(header.Key.ToUpper(), header.Value);
                        }
                    }

                    if (success)
                    {
                        AddMetrics(url, wwwTime, false);
                        listener.Invoke(new RESTResponse(error: UnityWwwHelper.DeduceWwwError(www), responseCode: www.responseCode, responseBody: responseBody, headers: headers));
                    }
                    else
                    {
                        AddMetrics(url, wwwTime, true);
                        listener.Invoke(new RESTResponse(error: WwwDeducedError.ApplicationErrorBody, responseCode: www.responseCode, responseBody: responseBody, headers: headers));
                    }
                }
                else
                {
                    AddMetrics(url, wwwTime, true);
                    listener.Invoke(new RESTResponse(error: UnityWwwHelper.DeduceWwwError(www)));
                }
            } catch (Exception exp) {
                SwrveLog.LogError(exp);
            }
#endif
        }
Example #15
0
        public virtual void Save(string tag, string data, string userId = null)
        {
            bool flag = false;

            try
            {
                string text = tag + ((userId != null) ? userId : string.Empty);
                SwrveLog.Log("Setting " + text + " in PlayerPrefs", "storage");
                PlayerPrefs.SetString(text, data);
                flag = true;
            }
            catch (PlayerPrefsException ex)
            {
                SwrveLog.LogError(ex.ToString(), "storage");
            }
            if (!flag)
            {
                SwrveLog.LogWarning(tag + " not saved!", "storage");
            }
        }
Example #16
0
        protected static void AssignCampaignTriggers(SwrveBaseCampaign campaign, Dictionary <string, object> campaignData)
        {
            IList <object> list  = (IList <object>)campaignData["triggers"];
            int            i     = 0;
            int            count = list.Count;

            while (i < count)
            {
                object obj = list[i];
                if (obj.GetType() == typeof(string))
                {
                    obj = new Dictionary <string, object>
                    {
                        {
                            "event_name",
                            obj
                        },
                        {
                            "conditions",
                            new Dictionary <string, object>()
                        }
                    };
                }
                try
                {
                    SwrveTrigger item = SwrveTrigger.LoadFromJson((IDictionary <string, object>)obj);
                    campaign.GetTriggers().Add(item);
                }
                catch (Exception ex)
                {
                    SwrveLog.LogError(string.Concat(new object[]
                    {
                        "Unable to parse SwrveTrigger from json ",
                        Json.Serialize(obj),
                        ", ",
                        ex
                    }));
                }
                i++;
            }
        }
Example #17
0
        public static void CampaignButtonClicked(int campaignId, int variantId, string buttonName, string actionType, string actionValue)
        {
            if (!CanLog())
            {
                return;
            }

            try {
                Dictionary <string, object> logDetails = new Dictionary <string, object>();
                logDetails.Add("campaign_id", campaignId);
                logDetails.Add("variant_id", variantId);
                logDetails.Add("button_name", buttonName);
                logDetails.Add("action_type", actionType);
                logDetails.Add("action_value", actionValue);

                SwrveQaUser qaUser = SwrveQaUser.Instance;
                qaUser.QueueQaLogEvent("campaign-button-clicked", logDetails);
            } catch (Exception ex) {
                SwrveLog.LogError("SwrveQaUser: CampaignButtonClicked exception:" + ex.ToString());
            }
        }
 public virtual void Remove(string tag, string userId = null)
 {
     try
     {
         string fileName = GetFileName(tag, userId);
         if (CrossPlatformFile.Exists(fileName))
         {
             SwrveLog.Log("Removing: " + fileName, "storage");
             CrossPlatformFile.Delete(fileName);
         }
         string path = fileName + "_SGT";
         if (CrossPlatformFile.Exists(path))
         {
             CrossPlatformFile.Delete(path);
         }
     }
     catch (Exception ex)
     {
         SwrveLog.LogError(ex.ToString(), "storage");
     }
 }
Example #19
0
 /// <summary>
 /// Buffer the event of a purchase using real currency, where any in-app
 /// currencies were purchased, or where multiple items were purchased as part of a bundle.
 /// The receipt provided will be validated against the iTunes Store.
 /// </summary>
 /// <remarks>
 /// See the REST API documentation for the "iap" event.
 /// Note that this method is currently only supported for the Apple App Store,
 /// and a valid receipt needs to be provided for verification.
 /// </remarks>
 /// <param name="quantity">
 /// Quantity purchased.
 /// </param>
 /// <param name="productId">
 /// Unique product identifier for the item bought. This should match the Swrve resource name.
 /// </param>
 /// <param name="productPrice">
 /// Price of the product purchased in real money. Note that this is the price
 /// per product, not the total price of the transaction (when quantity > 1).
 /// </param>
 /// <param name="currency">
 /// Real world currency used for this transaction. This must be an ISO currency code.
 /// </param>
 /// <param name="rewards">
 /// SwrveIAPRewards object containing any in-app currency and/or additional items
 /// included in this purchase that need to be recorded.
 /// This parameter is optional.
 /// </param>
 /// <param name="receipt">
 /// The receipt sent back from the iTunes Store upon successful purchase - this receipt will be verified by Swrve.
 /// Use either Base64EncodedReceipt or RawReceipt depending on what is offered by your plugin.
 /// </param>
 /// <param name="transactionId">
 /// The transaction id identifying the purchase iOS7+ (see SKPaymentTransaction::transactionIdentifier).
 /// </param>
 public void IapApple(int quantity, string productId, double productPrice, string currency, IapRewards rewards, IapReceipt receipt, string transactionId)
 {
     if (config.AppStore != "apple")
     {
         throw new Exception("This function can only be called to validate IAP events from Apple");
     }
     else
     {
         string encodedReceipt = null;
         if (receipt != null)
         {
             encodedReceipt = receipt.GetBase64EncodedReceipt();
         }
         if (String.IsNullOrEmpty(encodedReceipt))
         {
             SwrveLog.LogError("IAP event not sent: receipt cannot be empty for Apple Store verification");
             return;
         }
         _Iap(quantity, productId, productPrice, currency, rewards, encodedReceipt, string.Empty, transactionId, config.AppStore);
     }
 }
        public virtual string Load(string tag, string userId = null)
        {
            string result = null;

            try {
                // Read from file
                string loadFileName = GetFileName(tag, userId);
                if (CrossPlatformFile.Exists(loadFileName))
                {
                    result = CrossPlatformFile.LoadText(loadFileName);
                }
                else
                {
                    // Skipping file load, doesn't exist
                }
            } catch (Exception e) {
                SwrveLog.LogError(e.ToString(), "storage");
            }

            return(result);
        }
Example #21
0
 public void TriggerFailure(string eventName, string globalReason)
 {
     try
     {
         if (this.CanMakeTriggerRequest())
         {
             string endpoint = this.getEndpoint(string.Concat(new string[]
             {
                 "talk/game/",
                 this.swrve.ApiKey,
                 "/user/",
                 this.swrve.UserId,
                 "/trigger"
             }));
             this.MakeRequest(endpoint, new Dictionary <string, object>
             {
                 {
                     "trigger_name",
                     eventName
                 },
                 {
                     "displayed",
                     false
                 },
                 {
                     "reason",
                     globalReason
                 },
                 {
                     "campaigns",
                     new List <object>()
                 }
             });
         }
     }
     catch (Exception ex)
     {
         SwrveLog.LogError("QA request talk session failed: " + ex.ToString());
     }
 }
Example #22
0
 public static WwwDeducedError DeduceWwwError(WWW request)
 {
     if (request.responseHeaders.Count > 0)
     {
         string text = null;
         Dictionary <string, string> .Enumerator enumerator = request.responseHeaders.GetEnumerator();
         while (enumerator.MoveNext())
         {
             KeyValuePair <string, string> current = enumerator.Current;
             string key = current.Key;
             if (string.Equals(key, "X-Swrve-Error", StringComparison.OrdinalIgnoreCase))
             {
                 request.responseHeaders.TryGetValue(key, out text);
                 break;
             }
         }
         if (text != null)
         {
             SwrveLog.LogError("Request response headers [\"X-Swrve-Error\"]: " + text + " at " + request.url);
             try
             {
                 if (!string.IsNullOrEmpty(request.text))
                 {
                     SwrveLog.LogError("Request response headers [\"X-Swrve-Error\"]: " + ((IDictionary <string, object>)Json.Deserialize(request.text))["message"]);
                 }
             }
             catch (Exception ex)
             {
                 SwrveLog.LogError(ex.Message);
             }
             return(WwwDeducedError.ApplicationErrorHeader);
         }
     }
     if (!string.IsNullOrEmpty(request.error))
     {
         SwrveLog.LogError("Request error: " + request.error + " in " + request.url);
         return(WwwDeducedError.NetworkError);
     }
     return(WwwDeducedError.NoError);
 }
Example #23
0
        public static SwrveTrigger LoadFromJson(object json)
        {
            IDictionary <string, object> dictionary = null;

            try
            {
                dictionary = (IDictionary <string, object>)json;
            }
            catch (Exception ex)
            {
                SwrveLog.LogError(string.Format("Invalid object passed in to LoadFromJson, expected Dictionary<string, object>, received {0}, exception: {1}", json, ex.Message));
                SwrveTrigger result = null;
                return(result);
            }
            string          value           = null;
            SwrveConditions swrveConditions = null;

            try
            {
                value = (string)dictionary["event_name"];
                if (dictionary.ContainsKey("conditions"))
                {
                    swrveConditions = SwrveConditions.LoadFromJson((IDictionary <string, object>)dictionary["conditions"], true);
                }
            }
            catch (Exception arg)
            {
                SwrveLog.LogError(string.Format("Error parsing a SwrveTrigger from json {0}, ex: {1}", dictionary, arg));
            }
            if (string.IsNullOrEmpty(value) || swrveConditions == null)
            {
                return(null);
            }
            return(new SwrveTrigger
            {
                eventName = value,
                conditions = swrveConditions
            });
        }
    /// <summary>
    /// Used internally by the ADM plugin to notify
    /// of a received push notification when the app was opened from it.
    /// </summary>
    /// <param name="notificationJson">
    /// Serialized push notification information.
    /// </param>
    public void OpenedFromPushNotificationADM(string notificationJson)
    {
        Dictionary <string, object> notification = (Dictionary <string, object>)Json.Deserialize(notificationJson);
        string admIdent = (string)notification[ADMIdentKey];

        if (!string.IsNullOrEmpty(admIdent) && (admIdent == LastOpenedNotification))
        {
            return;
        }
        LastOpenedNotification = admIdent;

        string pushId = GetPushId(notification);

        SendPushEngagedEvent(pushId);
        if (pushId != null && androidADMPlugin != null)
        {
            // Acknowledge the opened notification
            androidADMPlugin.CallStatic(AckOpenedNotificationName, pushId);
        }

        // Process push deeplink
        if (notification != null && notification.ContainsKey(PushDeeplinkKey))
        {
            object deeplinkUrl = notification[PushDeeplinkKey];
            if (deeplinkUrl != null)
            {
                OpenURL(deeplinkUrl.ToString());
            }
        }

        if (PushNotificationListener != null)
        {
            try {
                PushNotificationListener.OnOpenedFromPushNotification(notification);
            } catch (Exception exp) {
                SwrveLog.LogError("Error processing the push notification: " + exp.Message);
            }
        }
    }
 /// <summary>
 /// Buffer the event of a purchase using real currency, where any in-app
 /// currencies were purchased, or where multiple items were purchased as part of a bundle.
 /// The receipt provided will be validated against the Google Play Store.
 /// </summary>
 /// <remarks>
 /// See the REST API documentation for the "iap" event.
 /// Note that this method is currently only supported for the Google Play Store,
 /// and a valid receipt and signature need to be provided for verification.
 /// </remarks>
 /// <param name="productId">
 /// Unique product identifier for the item bought. This should match the Swrve resource name.
 /// </param>
 /// <param name="productPrice">
 /// Price of the product purchased in real money. Note that this is the price
 /// per product, not the total price of the transaction (when quantity > 1).
 /// </param>
 /// <param name="currency">
 /// Real world currency used for this transaction. This must be an ISO currency code.
 /// </param>
 /// <param name="rewards">
 /// SwrveIAPRewards object containing any in-app currency and/or additional items
 /// included in this purchase that need to be recorded.
 /// This parameter is optional.
 /// </param>
 /// <param name="purchaseData">
 /// The receipt sent back from the Google Play Store upon successful purchase - this receipt will be verified by Swrve
 /// </param>
 /// <param name="dataSignature">
 /// The receipt signature sent back from the Google Play Store upon successful purchase
 /// </param>
 public void IapGooglePlay(string productId, double productPrice, string currency, IapRewards rewards, string purchaseData, string dataSignature)
 {
     if (config.AppStore != "google")
     {
         throw new Exception("This function can only be called to validate IAP events from Google");
     }
     else
     {
         if (String.IsNullOrEmpty(purchaseData))
         {
             SwrveLog.LogError("IAP event not sent: purchase data cannot be empty for Google Play Store verification");
             return;
         }
         if (String.IsNullOrEmpty(dataSignature))
         {
             SwrveLog.LogError("IAP event not sent: data signature cannot be empty for Google Play Store verification");
             return;
         }
         // Google IAP is always of quantity 1
         _Iap(1, productId, productPrice, currency, rewards, purchaseData, dataSignature, string.Empty, config.AppStore);
     }
 }
 public virtual void Save(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);
             flag = true;
         }
         catch (Exception ex)
         {
             SwrveLog.LogError(ex.ToString(), "storage");
         }
         if (!flag)
         {
             SwrveLog.LogWarning(tag + " not saved!", "storage");
         }
     }
 }
Example #27
0
        public static SwrveTrigger LoadFromJson(object json)
        {
            IDictionary <string, object> dictionary = null;

            try
            {
                dictionary = (IDictionary <string, object>)json;
            }
            catch (Exception ex)
            {
                SwrveLog.LogError($"Invalid object passed in to LoadFromJson, expected Dictionary<string, object>, received {json}, exception: {ex.Message}");
                return(null);
            }
            string          value           = null;
            SwrveConditions swrveConditions = null;

            try
            {
                value = (string)dictionary["event_name"];
                if (dictionary.ContainsKey("conditions"))
                {
                    swrveConditions = SwrveConditions.LoadFromJson((IDictionary <string, object>)dictionary["conditions"], isRoot: true);
                }
            }
            catch (Exception ex)
            {
                SwrveLog.LogError($"Error parsing a SwrveTrigger from json {dictionary}, ex: {ex}");
            }
            if (string.IsNullOrEmpty(value) || swrveConditions == null)
            {
                return(null);
            }
            SwrveTrigger swrveTrigger = new SwrveTrigger();

            swrveTrigger.eventName  = value;
            swrveTrigger.conditions = swrveConditions;
            return(swrveTrigger);
        }
Example #28
0
 public void UserUpdate(string userUpdate)
 {
     try
     {
         Dictionary <string, object>             dictionary  = (Dictionary <string, object>)Json.Deserialize(userUpdate);
         Dictionary <string, string>             dictionary2 = new Dictionary <string, string>();
         Dictionary <string, object> .Enumerator enumerator  = dictionary.GetEnumerator();
         while (enumerator.MoveNext())
         {
             Dictionary <string, string>   arg_48_0 = dictionary2;
             KeyValuePair <string, object> current  = enumerator.Current;
             string arg_48_1 = current.Key;
             string arg_43_0 = "{0}";
             KeyValuePair <string, object> current2 = enumerator.Current;
             arg_48_0[arg_48_1] = string.Format(arg_43_0, current2.Value);
         }
         this.SDK.UserUpdate(dictionary2);
     }
     catch (Exception ex)
     {
         SwrveLog.LogError(ex.ToString(), "userUpdate");
     }
 }
    /// <summary>
    /// Used internally by the Google Cloud Messaging plugin to notify
    /// of a received push notification, without any user interaction.
    /// </summary>
    /// <param name="notificationJson">
    /// Serialized push notification information.
    /// </param>
    public void NotificationReceived(string notificationJson)
    {
        Dictionary <string, object> notification = (Dictionary <string, object>)Json.Deserialize(notificationJson);

        if (androidPlugin != null && notification != null)
        {
            string pushId = GetPushId(notification);
            if (pushId != null)
            {
                // Acknowledge the received notification
                androidPlugin.CallStatic("sdkAcknowledgeReceivedNotification", pushId);
            }
        }

        if (PushNotificationListener != null)
        {
            try {
                PushNotificationListener.OnNotificationReceived(notification);
            } catch (Exception exp) {
                SwrveLog.LogError("Error processing the push notification: " + exp.Message);
            }
        }
    }
    private void RequestGooglePlayAdvertisingId(MonoBehaviour container)
    {
        if (SwrveHelper.IsOnDevice())
        {
            try {
                this.googlePlayAdvertisingId = storage.Load(GoogleAdvertisingIdSave);
                using (AndroidJavaClass unityPlayerClass = new AndroidJavaClass(UnityPlayerName)) {
                    string jniPluginClassName = SwrveAndroidPushPluginPackageName.Replace(".", "/");

                    if (AndroidJNI.FindClass(jniPluginClassName).ToInt32() != 0)
                    {
                        androidPlugin = new AndroidJavaClass(SwrveAndroidPushPluginPackageName);
                        if (androidPlugin != null)
                        {
                            androidPlugin.CallStatic <bool>("requestAdvertisingId", container.name);
                        }
                    }
                }
            } catch (Exception exp) {
                SwrveLog.LogError("Could not retrieve the device Registration Id: " + exp.ToString());
            }
        }
    }