Exemple #1
0
        public void Log(string type, ToastLogLevel level, string message, IDictionary <string, string> userFields = null)
        {
            if (string.IsNullOrEmpty(type))
            {
                type = "NORMAL";
            }

            var uri        = ToastUri.Create("logger", new ToastUri.VariableSegment(_appKey), "log");
            var methodCall = MethodCall.CreateSyncCall(uri);

            methodCall.AddParameter("level", level.ToString())
            .AddParameter("type", type)
            .AddParameter("message", message);

            if (userFields != null)
            {
                foreach (var items in userFields)
                {
                    if (string.IsNullOrEmpty(items.Key))
                    {
                        ToastLog.Error("20002 : key is null or empty string");
                        return;
                    }
                }

                methodCall.AddParameter("userFields", userFields);
            }

            var response = ToastNativeSender.SyncSendMessage(methodCall);

            ToastLog.Debug("InstanceLogger.Log.Response={0}", response);
        }
        public static bool TrySelectJsonArray(JSONNode jsonNode, out JSONArray outArray, params string[] paths)
        {
            outArray = null;

            if (!jsonNode.IsObject)
            {
                ToastLog.Error("Json is not object type : {0}", jsonNode);
                return(false);
            }

            var jsonObject = jsonNode.AsObject;
            var cursor     = jsonObject;

            foreach (var path in paths)
            {
                if (!cursor.ContainsKey(path))
                {
                    ToastLog.Error("Json doesn't contain ({0}) path", path);
                    return(false);
                }

                var node = cursor[path];
                if (!node.IsArray)
                {
                    return(false);
                }

                outArray = node.AsArray;
            }

            return(outArray != null);
        }
Exemple #3
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));
        }
Exemple #4
0
        public static void Log(ToastLogLevel logLevel, string message, Dictionary <string, string> userFields = null)
        {
            if (!IsInitialized())
            {
                return;
            }

            if (userFields != null)
            {
                foreach (var items in userFields)
                {
                    if (string.IsNullOrEmpty(items.Key))
                    {
                        int    errorCode    = ToastLoggerErrorCode.InvalidUserKey.Code;
                        string errroMessage = "key is null or empty string";
                        ToastLog.Error(errorCode + " : " + errroMessage);
                        return;
                    }
                }
            }

            string     methodName = MethodBase.GetCurrentMethod().Name;
            string     uri        = ToastUri.Create(SERVICE_NAME, methodName.ToLower());
            MethodCall methodCall = MethodCall.CreateSyncCall(uri);

            methodCall.AddParameter("level", logLevel.ToString().ToUpper());
            methodCall.AddParameter("message", message);
            if (userFields != null)
            {
                methodCall.AddParameter("userFields", userFields);
            }

            Dispatcher.Instance.Post(() => ToastNativeSender.SyncSendMessage(methodCall));
        }
        public void OnLogError(string jsonString)
        {
            ToastLog.Debug("[OnLogError] {0}", jsonString);

            LogEntry log;

            if (TryParseLog(jsonString, out log))
            {
                JSONObject body;
                if (TryParseBody(jsonString, out body))
                {
                    if (log.LogType == ToastLoggerType.CRASH_FROM_UNITY)
                    {
                        InvokeCrashListener(false, log);
                    }
                    else
                    {
                        if (_listenerLogger != null)
                        {
                            _listenerLogger.OnError(log,
                                                    body.ContainsKey("errorMessage") ? (string)body["errorMessage"] : "Unknown error");
                        }
                    }
                }
            }
        }
        public static NativeResponse SyncSendMessage(MethodCall methodCall)
        {
            try
            {
                ToastLog.Debug(methodCall.ToJsonString());
                var retMessage = ToastNativePlugin.Instance.NativePlugin.SyncSendMessage(methodCall);
                if (string.IsNullOrEmpty(retMessage))
                {
                    return(null);
                }

                ToastLog.Debug(retMessage);
                var response = NativeResponse.FromJson(retMessage);
                LogResponse(response);
                return(response);
            }
            catch (Exception e)
            {
                ToastLog.Error("ToastNativePlugin.Instance.NativePlugin.sendMessage Failed!");
                ToastLog.Exception(e);
                ToastLog.Developer("Raise exception when calling a method : {0}\n{1}", e.Message, e.StackTrace);
            }

            return(null);
        }
Exemple #7
0
        public void SetUserField(string key, string value)
        {
            var uri        = ToastUri.Create("logger", new ToastUri.VariableSegment(_appKey), "setUserField");
            var methodCall = MethodCall.CreateSyncCall(uri);

            methodCall.AddParameter("key", key)
            .AddParameter("value", value);
            var response = ToastNativeSender.SyncSendMessage(methodCall);

            ToastLog.Debug("InstanceLogger.SetUserField.Response={0}", response);
        }
        public void OnLogSave(string jsonString)
        {
            ToastLog.Debug("[OnLogSave] {0}", jsonString);

            LogEntry log;

            if (TryParseLog(jsonString, out log))
            {
                if (_listenerLogger != null)
                {
                    _listenerLogger.OnSave(log);
                }
            }
        }
 public ToastAndroidMessenger()
 {
     if (_androidPlugin == null)
     {
         try
         {
             _androidPlugin = new AndroidJavaObject(ToastUnityClassFullName);
         }
         catch (Exception e)
         {
             ToastLog.Exception(e);
         }
     }
 }
        private static void LogResponse(NativeResponse response)
        {
            var isSuccessful = response.Result.IsSuccessful;

            if (isSuccessful)
            {
                ToastLog.Developer("Call : Success");
            }
            else
            {
                ToastLog.Developer("Call : Fail\nCode : {0}\nMessage : {1}",
                                   response.Result.Code,
                                   response.Result.Message);
            }
        }
        public static NativeResponse SendMessage(MethodCall methodCall)
        {
            try
            {
                var retMessage = ToastNativePlugin.Instance.NativePlugin.SendMessage(methodCall);
                var response   = NativeResponse.FromJson(retMessage);
                if (response != null)
                {
                    LogResponse(response);
                }
                return(response);
            }
            catch (Exception e)
            {
                ToastLog.Error("ToastNativePlugin.Instance.NativePlugin.sendMessage Failed!");
                ToastLog.Exception(e);
            }

            return(null);
        }
        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());
            }

            bool debugMode = payload["debugMode"].AsBool;

            ToastLog.Info("ToastCoreSetDebugModeAction : " + debugMode);

            ToastCoreSdk.Instance.NativeCore.SetDebugMode(debugMode);

            return(ToastNativeMessage.CreateSuccessMessage(this.GetUri(),
                                                           this.GetTransactionId()).ToJsonString());
        }
        /// <summary>
        /// Receive callback data from native library
        /// </summary>
        // TODO Not Implementation method
        public void ReceiveFromNative(string message)
        {
            ToastLog.Debug("Receive nativeMethod : " + message);

            var response = NativeResponse.FromJson(message);

            var callbackId = response.Header.TransactionId;
            var callback   = ToastCallbackManager.Instance[callbackId];

            if (callback != null)
            {
                try
                {
                    callback(response.Result, response);
                }
                finally
                {
                    ToastCallbackManager.Instance.RemoveCallback(callbackId);
                }
            }
        }
        public void OnLogSuccess(string jsonString)
        {
            ToastLog.Debug("[OnLogSuccess] {0}", jsonString);

            LogEntry log;

            if (TryParseLog(jsonString, out log))
            {
                if (log.LogType == ToastLoggerType.CRASH_FROM_UNITY)
                {
                    InvokeCrashListener(true, log);
                }
                else
                {
                    if (_listenerLogger != null)
                    {
                        _listenerLogger.OnSuccess(log);
                    }
                }
            }
        }
        public void OnLogFilter(string jsonString)
        {
            ToastLog.Debug("[OnLogFilter] {0}", jsonString);

            LogEntry log;

            if (TryParseLog(jsonString, out log))
            {
                JSONNode filter;
                if (JsonUtils.TrySelectJsonObject(jsonString, out filter, "body", "filter"))
                {
                    if (filter.IsObject)
                    {
                        if (_listenerLogger != null)
                        {
                            _listenerLogger.OnFilter(log, LogFilter.From(filter.AsObject));
                        }
                    }
                }
            }
        }
        public static void Initialize(ToastLoggerConfiguration loggerConfiguration)
        {
            AppKey      = loggerConfiguration.AppKey;
            ServiceZone = loggerConfiguration.ServiceZone;

            if (ServiceZone == ToastServiceZone.ALPHA)
            {
                CollectorUrl = GetCollectorURL(ToastLoggerUrlConstants.COLLECTOR_ALPHA_URL);
                SettingUrl   = GetSettingsURL(ToastLoggerUrlConstants.SETTINGS_ALPHA_URL, AppKey);
            }
            else if (ServiceZone == ToastServiceZone.BETA)
            {
                CollectorUrl = GetCollectorURL(ToastLoggerUrlConstants.COLLECTOR_BETA_URL);
                SettingUrl   = GetSettingsURL(ToastLoggerUrlConstants.SETTINGS_BETA_URL, AppKey);
            }
            else if (ServiceZone == ToastServiceZone.REAL)
            {
                CollectorUrl = GetCollectorURL(ToastLoggerUrlConstants.COLLECTOR_REAL_URL);
                SettingUrl   = GetSettingsURL(ToastLoggerUrlConstants.SETTINGS_REAL_URL, AppKey);
            }
            else
            {
                ToastLog.Error("20003 : ServiceZone is missing!! (LoggerServiceZone is a strange value!!)");
                return;
            }

            ToastLoggerSettings.Instance.LoadToastLoggerSettings(ServiceZone);

            ToastLoggerLogSender.Instance.StartSender();

            if (loggerConfiguration.EnableCrashReporter)
            {
                if (!_isCreateSessionLog)
                {
                    SendSessionData();
                    _isCreateSessionLog = true;
                }
            }
        }
Exemple #17
0
        public static void Initialize(ToastLoggerConfiguration loggerConfiguration)
        {
            if (string.IsNullOrEmpty(loggerConfiguration.AppKey))
            {
                int    errorCode    = ToastLoggerErrorCode.InvalidUserKey.Code;
                string errroMessage = "AppKey is null or empty string";
                ToastLog.Error(errorCode + " : " + errroMessage);
                return;
            }

            if (_isInitialized)
            {
                ToastLog.Warn("ToastLogger has already been initialized.");
                return;
            }

            string     methodName = MethodBase.GetCurrentMethod().Name;
            string     uri        = ToastUri.Create(SERVICE_NAME, methodName.ToLower());
            MethodCall methodCall = MethodCall.CreateSyncCall(uri);

            methodCall.AddParameter("projectKey", loggerConfiguration.AppKey);
            methodCall.AddParameter("serviceZone", loggerConfiguration.ServiceZone.ToString().ToUpper());
            methodCall.AddParameter("enableCrashReporter", loggerConfiguration.EnableCrashReporter);
            var result = ToastNativeSender.SyncSendMessage(methodCall);

            if (result == null || !result.Result.IsSuccessful)
            {
                return;
            }
            ToastCrashManager.Instance.Initialize(
                loggerConfiguration.EnableCrashReporter,
                loggerConfiguration.EnableCrashErrorLog);

            _isInitialized = true;

            ToastAuditLog.SendUsageLog();
        }
Exemple #18
0
        public static void SetUserField(string key, string value)
        {
            if (!IsInitialized())
            {
                return;
            }

            if ((key == null) || (key == ""))
            {
                int    errorCode    = ToastLoggerErrorCode.InvalidUserKey.Code;
                string errroMessage = "key is null or empty string";
                ToastLog.Error(errorCode + " : " + errroMessage);
                return;
            }

            string     methodName = MethodBase.GetCurrentMethod().Name;
            string     uri        = ToastUri.Create(SERVICE_NAME, methodName.ToLower());
            MethodCall methodCall = MethodCall.CreateSyncCall(uri);

            methodCall.AddParameter("key", key);
            methodCall.AddParameter("value", value);

            Dispatcher.Instance.Post(() => ToastNativeSender.SyncSendMessage(methodCall));
        }
        public static void Initialize(ServiceZone serviceZone)
        {
            ServiceZone = serviceZone;

            if (ServiceZone == ServiceZone.ALPHA)
            {
                CollectorUrl = GetCollectorURL(LogUrlConstants.COLLECTOR_ALPHA_URL);
            }
            else if (ServiceZone == ServiceZone.BETA)
            {
                CollectorUrl = GetCollectorURL(LogUrlConstants.COLLECTOR_BETA_URL);
            }
            else if (ServiceZone == ServiceZone.REAL)
            {
                CollectorUrl = GetCollectorURL(LogUrlConstants.COLLECTOR_REAL_URL);
            }
            else
            {
                ToastLog.Error("20003 : ServiceZone is missing!! (LoggerServiceZone is a strange value!!)");
                return;
            }

            LogTransfer.Instance.StartSender();
        }