Exemplo n.º 1
0
        public void OnSharedPreferenceChanged(ISharedPreferences sharedPreferences, string key)
        {
            switch (key)
            {
            case ConfigurationParameters.WeatherUpdateFrequency:
                int interval_minutes = int.Parse(sharedPreferences.GetString(ConfigurationParameters.WeatherUpdateFrequency, "-1"));
                if (interval_minutes != -1)
                {
                    ListPreference weatherUpdateFrequency = FindPreference("weatherupdatefrequency") as ListPreference;
                    weatherUpdateFrequency.Value   = interval_minutes.ToString();
                    weatherUpdateFrequency.Summary = weatherUpdateFrequency.Entry;

                    PeriodicWorkRequest weatherPeriodicWorkRequest = PeriodicWorkRequest.Builder.From <GrabWeatherJob>(TimeSpan.FromMinutes(interval_minutes)).Build();
                    WorkManager.GetInstance(this.Activity).Enqueue(weatherPeriodicWorkRequest);
                }
                else
                {
                    WorkManager.GetInstance(this.Activity).CancelAllWork();
                }

                break;

            case ConfigurationParameters.WeatherCity:

                Preference weatherCity = FindPreference("weathercity");
                weatherCity.Summary = configurationManager.RetrieveAValue(ConfigurationParameters.WeatherCity, string.Empty);
                break;
            }
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            CreateNotificationChannel();

            var button = FindViewById <Button>(Resource.Id.MyButton);

            button.Click += ButtonOnClick;

            PeriodicWorkRequest taxWorkRequest = PeriodicWorkRequest.Builder.From <NotificationWorker>(TimeSpan.FromMinutes(10)).Build();

            WorkManager.Instance.Enqueue(taxWorkRequest);

            WebClient client = new WebClient();
            string    url;

            try
            {
                url = "https://www.dba.dk/boliger/lejebolig/lejelejlighed/reg-koebenhavn-og-omegn/?reg=nordsjaelland&sort=listingdate-desc&pris=(0-7000)";

                url_string = client.DownloadString(url);

                url_string = url_string.Substring(url_string.IndexOf("Product"));
                url_string = url_string.Substring(url_string.IndexOf("url") + 7, (url_string.IndexOf("offers") - 18) - (url_string.IndexOf("url") + 7));
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Exemplo n.º 3
0
        private void StartBackgroundCheck()
        {
            // Minimum time for periodic work is 15 min
            PeriodicWorkRequest periodicWork = PeriodicWorkRequest.Builder.From <NotificationWorker>(1, Java.Util.Concurrent.TimeUnit.Seconds).Build();

            WorkManager.GetInstance(this).EnqueueUniquePeriodicWork(expiration_work_id, ExistingPeriodicWorkPolicy.Replace, periodicWork);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            Xamarin.FormsMaps.Init(this, savedInstanceState);


            Constraints constraints = new Constraints();

            constraints.SetRequiresStorageNotLow(true);
            constraints.SetRequiresBatteryNotLow(true);
            constraints.RequiredNetworkType = NetworkType.Connected;

            PeriodicWorkRequest taxWorkRequest = PeriodicWorkRequest
                                                 .Builder.From <locationBrain>(TimeSpan.FromMinutes(16))
                                                 .SetConstraints(constraints).Build();

            String TAG = "locationWork";

            WorkManager.Instance.EnqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.Keep, taxWorkRequest);



            LoadApplication(new App());

            Common.IsUserOnline = true;
        }
Exemplo n.º 5
0
        public static void ScheduleBackgroundFetch()
        {
            //The interval has to be minimum 15 minutes.
            //Note that execution may be delayed because WorkManager is subject to OS battery optimizations,
            //such as doze mode.
            PeriodicWorkRequest.Builder periodicWorkRequestBuilder = new PeriodicWorkRequest.Builder(
                typeof(BackgroundFetchWorker),
                Conf.BACKGROUND_FETCH_REPEAT_INTERVAL_ANDROID);

            periodicWorkRequestBuilder
            //Start time is when the first time will be
            .SetPeriodStartTime(TimeSpan.FromSeconds(1))
            //If Result.InvokeRetry() is called it will linearly double the amount of time specified below before it tries again.
            .SetBackoffCriteria(BackoffPolicy.Linear, TimeSpan.FromSeconds(10))
            .SetConstraints(new Constraints.Builder()
                            //Only run if connected to the internet
                            .SetRequiredNetworkType(NetworkType.Connected)
                            .Build());

            PeriodicWorkRequest periodicWorkRequest = periodicWorkRequestBuilder.Build();

            WorkManager workManager = WorkManager.GetInstance(Platform.AppContext);

            workManager.EnqueueUniquePeriodicWork("exposurenotification",
                                                  ExistingPeriodicWorkPolicy.Keep,
                                                  periodicWorkRequest);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            FFImageLoading.Forms.Platform.CachedImageRenderer.Init(enableFastRenderer: true);



            String TAG = "WallpaperWork";

            Constraints constraints = new Constraints();

            constraints.SetRequiresStorageNotLow(true);
            constraints.SetRequiresBatteryNotLow(true);
            constraints.RequiredNetworkType = NetworkType.Connected;

            PeriodicWorkRequest taxWorkRequest = PeriodicWorkRequest
                                                 .Builder.From <DownloadBrain>(TimeSpan.FromHours(1))
                                                 .SetConstraints(constraints).Build();

            WorkManager.GetInstance(Application.Context).EnqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.Keep, taxWorkRequest);

            LoadApplication(new App());
        }
Exemplo n.º 7
0
        private static void EnqueueUniquePeriodicWork(PeriodicWorkRequest workRequest)
        {
            var workManager = WorkManager.GetInstance(Essentials.Platform.AppContext);

            workManager.EnqueueUniquePeriodicWork(CurrentWorkName,
                                                  ExistingPeriodicWorkPolicy.Keep,
                                                  workRequest);
        }
Exemplo n.º 8
0
 private void InitMessagingCenterSubcription()
 {
     MessagingCenter.Subscribe <CalculatorWorkerRequested>(this, nameof(CalculatorWorkerRequested), message =>
     {
         WorkManager workManager            = WorkManager.GetInstance(Xamarin.Essentials.Platform.AppContext);
         PeriodicWorkRequest taxWorkRequest = PeriodicWorkRequest.Builder.From <CalculatorWorker>(TimeSpan.FromMinutes(15)).Build();
         workManager.EnqueueUniquePeriodicWork(nameof(CalculatorWorker), ExistingPeriodicWorkPolicy.Replace, taxWorkRequest);
     });
 }
        public bool SetAlarmAt(string medicineName, TimeSpan medicationTime)
        {
            PeriodicWorkRequest alarmRequest = PeriodicWorkRequest.Builder
                                               .From <AlarmWorker>(1, TimeUnit.Days)
                                               .Build();

            WorkManager.Instance.Enqueue(alarmRequest);

            return(true);
        }
Exemplo n.º 10
0
        public void StartService()
        {
            PeriodicWorkRequest taxWorkRequest = PeriodicWorkRequest
                                                 .Builder
                                                 .From <LocationUpdatesService>(TimeSpan.FromMinutes(5)
                                                                                ).Build();

            WorkManager.Instance.Enqueue(taxWorkRequest);
            _workId = taxWorkRequest.Id;
        }
Exemplo n.º 11
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());

            PeriodicWorkRequest taxWorkRequest = PeriodicWorkRequest.Builder.From <CalculatorWorker>(TimeSpan.FromMinutes(20)).Build();

            WorkManager.Instance.Enqueue(taxWorkRequest);
        }
Exemplo n.º 12
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App(new AndroidInitializer()));
            CreateNotificationFromIntent(Intent);

            PeriodicWorkRequest testWorkRequest = PeriodicWorkRequest.Builder.From <TestWorker>(TimeSpan.FromMinutes(16)).Build();

            WorkManager.GetInstance(Xamarin.Essentials.Platform.AppContext).Enqueue(testWorkRequest);
        }
        public Task RunTask(Action callback)
        {
            Constraints constraints = new Constraints.Builder()
                                      .SetRequiredNetworkType(NetworkType.Connected)
                                      .Build();

            PeriodicWorkRequest taxWorkRequest = PeriodicWorkRequest.Builder
                                                 .From <RunTaskWorker>(15, TimeUnit.Minutes)
                                                 .SetConstraints(constraints)
                                                 .Build();

            WorkManager.Instance.Enqueue(taxWorkRequest);

            return(Task.FromResult(true));
        }
Exemplo n.º 14
0
        public override void Schedule()
        {
            LoggerService.StartMethod();

            WorkManager workManager = WorkManager.GetInstance(Platform.AppContext);

            PeriodicWorkRequest periodicWorkRequest = CreatePeriodicWorkRequest();

            workManager.EnqueueUniquePeriodicWork(
                CURRENT_WORK_NAME,
                ExistingPeriodicWorkPolicy.Keep,
                periodicWorkRequest
                );

            LoggerService.EndMethod();
        }
Exemplo n.º 15
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());

            PeriodicWorkRequest request =
                PeriodicWorkRequest.Builder
                .From <OfficialJournalWorker>(15, TimeUnit.Minutes)
                .Build();

            WorkManager.Instance.Enqueue(request);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());

            CreateNotificationFromIntent(Intent);

            PeriodicWorkRequest taxWorkRequest = PeriodicWorkRequest.Builder.From <SampleBackgroundService>(TimeSpan.FromMinutes(15), TimeSpan.FromMinutes(10)).Build();

            var worker = WorkManager.GetInstance(this.ApplicationContext);

            worker.EnqueueUniquePeriodicWork("myWork", ExistingPeriodicWorkPolicy.Keep, taxWorkRequest);
        }
Exemplo n.º 17
0
        public AlarmActiveEventArgs StopBirdieLib()
        {
            // Stop the WorkManager.  --Kris
            WorkManager.Instance.CancelAllWork();
            PeriodicWorkRequest = null;

            PendingIntent pendingIntent = PendingIntent.GetBroadcast(Application.Context, 0, AlarmIntent, PendingIntentFlags.UpdateCurrent);
            AlarmManager  alarmManager  = (AlarmManager)Application.Context.GetSystemService(AlarmService);

            try
            {
                alarmManager.Cancel(pendingIntent);
                pendingIntent.Cancel();
            }
            catch (Exception) { }

            Shared.BirdieLib.Stop();

            return(new AlarmActiveEventArgs
            {
                IsScheduled = false
            });
        }
Exemplo n.º 18
0
        public AlarmActiveEventArgs StartBirdieLib()
        {
            AndroidRefreshes.Alarm = DateTime.Now;

            // Set the alarm.  --Kris
            PendingIntent pendingIntent = PendingIntent.GetBroadcast(Application.Context, 0, AlarmIntent, PendingIntentFlags.UpdateCurrent);
            AlarmManager  alarmManager  = (AlarmManager)Application.Context.GetSystemService(AlarmService);

            alarmManager.SetExactAndAllowWhileIdle(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime() + 5000, pendingIntent);

            // Start the WorkManager.  --Kris
            if (PeriodicWorkRequest == null)
            {
                PeriodicWorkRequest = PeriodicWorkRequest.Builder.From <BirdieWorker>(TimeSpan.FromMinutes(20)).Build();
            }
            PeriodicWorkRequest.Tags.Add("BirdieWorker");

            WorkManager.Instance.Enqueue(PeriodicWorkRequest);

            return(new AlarmActiveEventArgs
            {
                IsScheduled = true
            });
        }
Exemplo n.º 19
0
        public static void Create()
        {
            PeriodicWorkRequest alarmWorker = PeriodicWorkRequest.Builder.From <AlarmWorker>(TimeSpan.FromMinutes(15)).Build();

            WorkManager.Instance.Enqueue(alarmWorker);
        }
Exemplo n.º 20
0
        public void CreateUniquePeriodicWorker <T>(TimeSpan repeatInterval) where T : Worker
        {
            PeriodicWorkRequest periodicWorkRequest = PeriodicWorkRequest.Builder.From <T>(repeatInterval).Build();

            WorkManager.GetInstance(Platform.AppContext).EnqueueUniquePeriodicWork(typeof(T).Name, ExistingPeriodicWorkPolicy.Replace, periodicWorkRequest);
        }
        public Task Register(string taskName, string taskEntryPoint, DateTime startDateTime, TimeKind tKind, uint interval)
        {
            if (IsRegistered(taskName))
            {
                return(Task.CompletedTask);
            }

            try
            {
                DateTime nowNoSecond  = DateTime.ParseExact(DateTime.Now.ToString("dd-MM-yyyy HH:mm:00"), "dd-MM-yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                uint     initialDelay = (uint)Math.Round((startDateTime - nowNoSecond).TotalMinutes, 0);

                uint timeInterval = interval;
                Java.Util.Concurrent.TimeUnit unit = Java.Util.Concurrent.TimeUnit.Minutes;
                switch (tKind)
                {
                case TimeKind.Minute:
                    unit = Java.Util.Concurrent.TimeUnit.Minutes;
                    break;

                case TimeKind.Hour:
                    unit = Java.Util.Concurrent.TimeUnit.Hours;
                    break;

                case TimeKind.Day:
                    unit = Java.Util.Concurrent.TimeUnit.Days;
                    break;

                case TimeKind.Month:
                    unit          = Java.Util.Concurrent.TimeUnit.Days;
                    timeInterval *= 30;
                    break;

                case TimeKind.Year:
                    unit          = Java.Util.Concurrent.TimeUnit.Days;
                    timeInterval *= 365;
                    break;

                default:
                    throw new Exception(string.Format("Categoria di tempo {0} non prevista", tKind));
                }

                PeriodicWorkRequest.Builder workRequestedBuilder;
                if (taskName.CompareTo(App.CheckPasswordBackgroundTaskName) == 0)
                {
                    workRequestedBuilder = PeriodicWorkRequest.Builder.From <CheckPasswordWorker>(timeInterval, unit);
                }
                else if (taskName.CompareTo(App.BackupBackgroundTaskName) == 0)
                {
                    workRequestedBuilder = PeriodicWorkRequest.Builder.From <BackupWorker>(timeInterval, unit);
                }
                else
                {
                    throw new Exception("Task not found");
                }

                Data data = new Data.Builder()
                            .PutLong("interval", unit.ToMinutes(timeInterval))
                            .Build();
                PeriodicWorkRequest workRequested = (PeriodicWorkRequest)workRequestedBuilder
                                                    .AddTag(taskName)
                                                    .SetInitialDelay(initialDelay, Java.Util.Concurrent.TimeUnit.Minutes)
                                                    .SetInputData(data)
                                                    .Build();
                AppWorkManager.EnqueueUniquePeriodicWork(taskName, ExistingPeriodicWorkPolicy.Replace, workRequested);
            }
            catch (Exception e)
            {
                Log.Error(Tag, string.Format("Error occurred during scheduling the work with name \"{0}\": {1}", taskName, e.Message));
            }
            return(Task.CompletedTask);
        }