Exemple #1
0
        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);
            }
        }
Exemple #2
0
        public override async Task Schedule(JobInfo jobInfo)
        {
            await base.Schedule(jobInfo);

            CrossJobs.StartJobService();
        }
Exemple #3
0
 public static void SetValue(this JobInfo job, string key, object value)
 {
     job.Parameters[key] = value;
 }
Exemple #4
0
 protected override bool CheckCriteria(JobInfo job) => job.IsEligibleToRun();
Exemple #5
0
 protected override bool CheckCriteria(JobInfo job) => true;
Exemple #6
0
 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));
 }
Exemple #7
0
 protected abstract bool CheckCriteria(JobInfo job);
Exemple #8
0
 public JobRunResult(JobInfo jobInfo, Exception exception)
 {
     this.Job       = jobInfo;
     this.Exception = exception;
 }
Exemple #9
0
        public override async Task Schedule(JobInfo jobInfo)
        {
            await base.Schedule(jobInfo);

            this.TryRegUwpJob();
        }