public Object AttachCompleter(CallbackToFutureAdapter.Completer p0) { Log.Debug(TAG, $"Executing."); //Switch to background thread. Task.Run(async() => { //Perform a process here, simulated by a delay for 5 seconds. var delaySeconds = 5; var progress = 0; var progressIncrement = 100 / delaySeconds; var dataBuilder = new Data.Builder(); for (int i = 0; i < delaySeconds + 1; i++) { await Task.Delay(1000); progress += progressIncrement; dataBuilder.PutInt("Progress", progress); SetProgressAsync(dataBuilder.Build()); } Log.Debug(TAG, "Completed."); //Set a Success Result on the completer and return it. return(p0.Set(Result.InvokeSuccess())); }); return(TAG); }
public override void OnMessageReceived(RemoteMessage message) { //Log.Debug(TAG, "From: " + message.From); //var body = message.GetNotification().Body; //Log.Debug(TAG, "Notification Message Body: " + body); Log.Info(TAG, $"Received a firebase request from {message.From}."); if (message.From == $"/topics/{MainActivity.CHANNEL_ID}") { Log.Debug(TAG, "Received an announcement."); SendNotification(message.GetNotification().Body, message.GetNotification().Title, message.Data); } else if (message.From == $"/topics/{MainActivity.UPDATE_CHANNEL_NAME}" && !Preferences.ContainsKey("DisableAutoUpdate")) { Log.Debug(TAG, "Received an update request."); if (!message.Data.ContainsKey("region") || !int.TryParse(message.Data["region"], out var region)) { Log.Warn(TAG, "Firebase message missing region."); return; } if (region < 1 || region > 2) { Log.Warn(TAG, "Invalid region for update request."); return; } string preferencesKey = ""; switch (region) { case 1: preferencesKey = $"InstalledScript_{FGORegion.Jp}"; break; case 2: preferencesKey = $"InstalledScript_{FGORegion.Na}"; break; } if (Preferences.Get(preferencesKey, null) == null) { Log.Warn(TAG, "User hasn't installed any script for this region."); return; } var data = new Data.Builder(); data.PutInt("region", region); data.PutString("preferencesKey", preferencesKey); var finalData = data.Build(); var builder = OneTimeWorkRequest.Builder.From <RayshiftTranslationUpdateWorker>(); builder.SetInputData(finalData); OneTimeWorkRequest request = builder.Build(); WorkManager.Instance.Enqueue(request); } }
public bool SetNewFutureWork(int workId) { var logger = new OurLoggerService(); logger.LogInformation($"Setting new service worker for ${workId} started"); var workData = new Data.Builder(); workData.PutInt("WORK_NO", workId); Random random = new Random(); OneTimeWorkRequest someWork = new OneTimeWorkRequest .Builder(typeof(FutureWorker)) .SetInputData(workData.Build()) .SetInitialDelay(random.Next(1, 30), timeUnit: TimeUnit.Seconds) .Build(); WorkManager.Instance.Enqueue(someWork); logger.LogInformation($"Setting new service worker for ${workId} complete"); return(true); }
private void UpdateProgress(Data.Builder progressDataBuilder, double progress, bool visible) { progressDataBuilder.PutInt(ProgressPercentTag, (int)progress); progressDataBuilder.PutBoolean(ProgressVisibleTag, visible); SetProgressAsync(progressDataBuilder.Build()); }