public void Run(IBackgroundTaskInstance taskInstance)
        {
#if WNS_PUSH_SERVICE
            Telegram.Logs.Log.WriteSync = true;

            var stopwatch = Stopwatch.StartNew();

            var rawNotification = taskInstance.TriggerDetails as RawNotification;
            var payload         = rawNotification != null ? rawNotification.Content : null;
            var rootObject      = payload != null?PushUtils.GetRootObject(payload) : null;

            var data   = rootObject != null ? rootObject.data : null;
            var locKey = data != null ? data.loc_key : null;

            Log(string.Format("start locKey={0}", locKey));
            if (!_appOpenMutex.WaitOne(0))
            {
                Log("cancel");

                return;
            }
            _appOpenMutex.ReleaseMutex();

            var isAuthorized = SettingsHelper.GetValue <bool>(Constants.IsAuthorizedKey);
            if (!isAuthorized)
            {
                Log(string.Format("cancel isAuthorized=false\npayload={0}", payload));
                return;
            }

            try
            {
                var initConnection = GetInitConnection();
                if (initConnection != null)
                {
                    SystemVersion = initConnection.SystemVersion != null
                        ? initConnection.SystemVersion.ToString()
                        : string.Empty;

                    Log(string.Format(initConnection.ToString()));
                }
                else
                {
                    Log(string.Format("empty init_connection"));
                }
                //string[] supportedLanguages = { "de", "en", "es", "it", "nl", "pt" };
                //var language = initConnection != null ? initConnection.LangCode.ToString() : "en";
                //language = supportedLanguages.Contains(language) ? language : "en";
                Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "";

                PushUtils.UpdateToastAndTiles(taskInstance.TriggerDetails as RawNotification);
            }
            catch (Exception ex)
            {
                Log(string.Format("ex={0}\npayload={1}", ex, payload));
            }

            Log(string.Format("stop elapsed={0}", stopwatch.Elapsed));
#endif
        }
        private void Log(string message, Action callback = null)
        {
            if (!_logEnabled)
            {
                return;
            }

            Telegram.Logs.Log.Write(string.Format("::MessageSchedulerBackgroundTask {0} {1}", _id, message), callback.SafeInvoke);
#if DEBUG
            PushUtils.AddToast("scheduler", message, string.Empty, string.Empty, null, null);
#endif
        }
        public void Run(IBackgroundTaskInstance taskInstance)
        {
#if WNS_PUSH_SERVICE
            Telegram.Logs.Log.WriteSync = true;

            var stopwatch = Stopwatch.StartNew();

            var rawNotification = taskInstance.TriggerDetails as RawNotification;
            var payload         = rawNotification != null ? rawNotification.Content : null;
            var rootObject      = payload != null?PushUtils.GetRootObject(payload) : null;

            var data   = rootObject != null ? rootObject.data : null;
            var locKey = data != null ? data.loc_key : null;

            Log(string.Format("start locKey={0}", locKey));
            if (!_appOpenMutex.WaitOne(0))
            {
                Log("cancel");

                return;
            }
            _appOpenMutex.ReleaseMutex();

            var isAuthorized = SettingsHelper.GetValue <bool>(Constants.IsAuthorizedKey);
            if (!isAuthorized)
            {
                Log(string.Format("cancel isAuthorized=false\npayload={0}", payload));
            }

            //var culture = Utils.CurrentUICulture();
            //var resourceLoader = new ResourceLoader("TelegramClient.Tasks/Resources");
            //var str = resourceLoader.GetString("MESSAGE_TEXT");
            //PushUtils.AddToast("resource", str + " " + culture, string.Empty);
            try
            {
                PushUtils.UpdateToastAndTiles(taskInstance.TriggerDetails as RawNotification);
            }
            catch (Exception ex)
            {
                Log(string.Format("ex={0}\npayload={1}", ex, payload));
            }

            Log(string.Format("stop elapsed={0}", stopwatch.Elapsed));
#endif
        }