Exemplo n.º 1
0
        protected override string Action(JSONObject payload)
        {
            if (payload == null)
            {
                return(ToastNativeMessage.CreateErrorMessage(this.GetUri(),
                                                             this.GetTransactionId(),
                                                             false,
                                                             ToastNativeCommonErrorCode.InvalidParameter.Code,
                                                             this.GetUri() + " action not found").ToJsonString());
            }

            string projectKey  = payload["projectKey"].Value;
            string serviceZone = payload["serviceZone"].Value;

            if (string.IsNullOrEmpty(projectKey))
            {
                return(ToastNativeMessage.CreateErrorMessage(this.GetUri(),
                                                             this.GetTransactionId(),
                                                             false,
                                                             ToastNativeCommonErrorCode.InvalidParameter.Code,
                                                             "Project key does not exist").ToJsonString());
            }

            ServiceZone zone = (ServiceZone)System.Enum.Parse(typeof(ServiceZone), serviceZone, true);

            ToastInstanceLoggerSdk.Instance.NativeInstanceLogger.Initialize(zone);

            return(ToastNativeMessage.CreateSuccessMessage(this.GetUri(),
                                                           this.GetTransactionId()).ToJsonString());
        }
Exemplo n.º 2
0
        public static string CallMessage(string message)
        {
            if (!_isInitialized)
            {
                Initialize();
            }

            ToastUnityMessage unityMessage = new ToastUnityMessage(message);
            string            uri          = unityMessage.GetUri();

            ToastUnityAction action = ToastActionHandler.GetAction(uri);

            if (action == null)
            {
                ToastLog.Error("Not supported uri: " + uri);

                ToastNativeMessage toastNative =
                    ToastNativeMessage.CreateErrorMessage(uri,
                                                          unityMessage.TransactionId,
                                                          false,
                                                          ToastNativeCommonErrorCode.NotSupportedUri.Code,
                                                          uri + " action not found");

                ToastLog.Debug(toastNative.ToJsonString());
                return(toastNative.ToString());
            }

            return(action.OnMessage(unityMessage));
        }
Exemplo n.º 3
0
        protected override string Action(JSONObject payload)
        {
            if (payload == null)
            {
                return(ToastNativeMessage.CreateErrorMessage(this.GetUri(),
                                                             this.GetTransactionId(),
                                                             false,
                                                             ToastNativeCommonErrorCode.InvalidParameter.Code,
                                                             this.GetUri() + " action not found").ToJsonString());
            }

            string projectKey  = payload["projectKey"].Value;
            string serviceZone = payload["serviceZone"].Value;
            bool   enableCrash = payload["enableCrashReporter"].AsBool;

            if (string.IsNullOrEmpty(projectKey))
            {
                return(ToastNativeMessage.CreateErrorMessage(this.GetUri(),
                                                             this.GetTransactionId(),
                                                             false,
                                                             ToastNativeCommonErrorCode.InvalidParameter.Code,
                                                             "Project key does not exist").ToJsonString());
            }

            ToastLoggerConfiguration loggerConfiguration = new ToastLoggerConfiguration();

            loggerConfiguration.AppKey              = projectKey;
            loggerConfiguration.ServiceZone         = (ToastServiceZone)Enum.Parse(typeof(ToastServiceZone), serviceZone);
            loggerConfiguration.EnableCrashReporter = enableCrash;
            ToastLoggerSdk.Instance.NativeLogger.Initialize(loggerConfiguration);

            return(ToastNativeMessage.CreateSuccessMessage(this.GetUri(),
                                                           this.GetTransactionId()).ToJsonString());
        }
        protected override string Action(JSONObject payload)
        {
            if (payload == null)
            {
                return(ToastNativeMessage.CreateErrorMessage(this.GetUri(),
                                                             this.GetTransactionId(),
                                                             false,
                                                             ToastNativeCommonErrorCode.InvalidParameter.Code,
                                                             this.GetUri() + " action not found").ToJsonString());
            }

            string level   = payload["logLevel"].Value;
            string message = payload["message"].Value;
            string dmpData = payload["dmpData"].ToString();

            JSONObject jsonUserFields = payload["userFields"] as JSONObject;
            Dictionary <string, string> userFields = new Dictionary <string, string>();

            if (jsonUserFields != null)
            {
                foreach (string key in jsonUserFields.Keys)
                {
                    string value = jsonUserFields[key].ToString();
                    userFields.Add(key, value);
                }
            }

            ToastLoggerSdk.Instance.NativeLogger.Report(level, message, dmpData, userFields);

            return(ToastNativeMessage.CreateSuccessMessage(this.GetUri(),
                                                           this.GetTransactionId()).ToJsonString());
        }
        protected override string Action(JSONObject payload)
        {
            if (payload == null)
            {
                return(ToastNativeMessage.CreateErrorMessage(this.GetUri(),
                                                             this.GetTransactionId(),
                                                             false,
                                                             ToastNativeCommonErrorCode.InvalidParameter.Code,
                                                             this.GetUri() + " action not found").ToJsonString());
            }

            string key   = payload["key"].Value;
            string value = payload["value"].Value;

            if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value))
            {
                return(ToastNativeMessage.CreateErrorMessage(this.GetUri(),
                                                             this.GetTransactionId(),
                                                             false,
                                                             ToastNativeCommonErrorCode.InvalidParameter.Code,
                                                             "Invalid Parameter").ToJsonString());
            }

            ToastInstanceLoggerSdk.Instance.NativeInstanceLogger.SetUserField(key, value);

            return(ToastNativeMessage.CreateSuccessMessage(this.GetUri(),
                                                           this.GetTransactionId()).ToJsonString());
        }
Exemplo n.º 6
0
        public static ToastNativeMessage CreateMessage(string uri, string transactionId, bool isSuccess, int code, string message)
        {
            var native = new ToastNativeMessage(uri,
                                                transactionId,
                                                isSuccess,
                                                code,
                                                message);

            return(native);
        }
        protected override string Action(JSONObject payload)
        {
            if (payload == null)
            {
                return(ToastNativeMessage.CreateErrorMessage(this.GetUri(),
                                                             this.GetTransactionId(),
                                                             false,
                                                             ToastNativeCommonErrorCode.InvalidParameter.Code,
                                                             this.GetUri() + " action not found").ToJsonString());
            }

            string type    = payload["type"].Value;
            string level   = payload["level"].Value;
            string message = payload["message"].Value;

            if (string.IsNullOrEmpty(type))
            {
                type = "NORMAL";
            }

            if (string.IsNullOrEmpty(level) || (message == null))
            {
                return(ToastNativeMessage.CreateErrorMessage(this.GetUri(),
                                                             this.GetTransactionId(),
                                                             false,
                                                             ToastNativeCommonErrorCode.InvalidParameter.Code,
                                                             "Log must have loglevel, message parameters").ToJsonString());
            }


            JSONObject jsonUserFields = payload["userFields"] as JSONObject;
            Dictionary <string, string> userFields = new Dictionary <string, string>();

            if (jsonUserFields != null)
            {
                foreach (string key in jsonUserFields.Keys)
                {
                    string value = jsonUserFields[key].Value;
                    userFields.Add(key, value);
                }
            }

            ToastInstanceLoggerSdk.Instance.NativeInstanceLogger.Log(type, level, message, userFields);

            return(ToastNativeMessage.CreateSuccessMessage(this.GetUri(),
                                                           this.GetTransactionId()).ToJsonString());
        }
Exemplo n.º 8
0
        protected override string Action(JSONObject payload)
        {
            var native = ToastNativeMessage.CreateSuccessMessage(this.GetUri(),
                                                                 this.GetTransactionId());

            List <string> properties = new List <string>();
            JSONArray     array      = payload["properties"].AsArray;

            foreach (JSONNode item in array)
            {
                properties.Add(item.ToString());
            }

            ToastCoreSdk.Instance.NativeCore.SetOptionalPolicies(properties);

            return(native.ToJsonString());
        }