public async Task Run(Plugin.Jobs.JobInfo jobInfo, CancellationToken cancelToken) { string response = string.Empty; try { var currentConnectivity = Connectivity.NetworkAccess; var networkProfiles = Connectivity.ConnectionProfiles; if (currentConnectivity == NetworkAccess.Internet && networkProfiles.Contains(ConnectionProfile.WiFi)) { string term = "background"; var url = $"https://mashape-community-urban-dictionary.p.rapidapi.com/define?term=" + term; APIResponseRoot results; using (var httpClient = new HttpClient()) { var uri = new Uri(url); httpClient.DefaultRequestHeaders.Add("X-RapidAPI-Host", "mashape-community-urban-dictionary.p.rapidapi.com"); httpClient.DefaultRequestHeaders.Add("X-RapidAPI-Key", _apiKey); response = await httpClient.GetStringAsync(uri); results = JsonConvert.DeserializeObject <APIResponseRoot>(response); } CrossLocalNotifications.Current.Show("Objetos recebidos", $"{results.list.Count} objetos recebidos da API"); } else { CrossLocalNotifications.Current.Show("Conectividade", $"Habilite o WiFi para realizar as tarefas em Background."); } } catch (Exception ex) { Log.WriteLine(LogPriority.Error, "[Job Log Error]", ex.Message); } finally { Log.WriteLine(LogPriority.Error, "[Job Log]", response); } }
public override async Task Schedule(JobInfo jobInfo) { await base.Schedule(jobInfo); CrossJobs.StartJobService(); }
public static void SetValue(this JobInfo job, string key, object value) { job.Parameters[key] = value; }
protected override bool CheckCriteria(JobInfo job) => job.IsEligibleToRun();
protected override bool CheckCriteria(JobInfo job) => true;
public static void Schedule <TJob>(this ContainerBuilder builder, JobInfo jobInfo) where TJob : IJob { jobInfo.Type = typeof(TJob); builder.RegisterJob <TJob>(); builder.RegisterBuildCallback(_ => CrossJobs.Current.Schedule(jobInfo)); }
protected abstract bool CheckCriteria(JobInfo job);
public JobRunResult(JobInfo jobInfo, Exception exception) { this.Job = jobInfo; this.Exception = exception; }
public override async Task Schedule(JobInfo jobInfo) { await base.Schedule(jobInfo); this.TryRegUwpJob(); }