Ejemplo n.º 1
0
        /// <summary>
        /// Запуск задачи.
        /// </summary>
        public static void StartTracking()
        {
            Log.Debug(TAG, "Starting Tracking");

            // This is the "Java" way to create a FirebaseJobDispatcher object
            IDriver driver = new GooglePlayDriver(Application.Context);

            dispatcher = new FirebaseJobDispatcher(driver);

            //RetryStrategy retry = dispatcher.NewRetryStrategy(RetryStrategy.RetryPolicyLinear, retryTime, deadline);
            JobTrigger myTrigger = Trigger.ExecutionWindow(10, 15);

            // FirebaseJobDispatcher dispatcher = context.CreateJobDispatcher();
            Job myJob = dispatcher.NewJobBuilder()
                        .SetService <WebService>("demo-job-tag")
                        .SetTrigger(myTrigger)
                        .AddConstraint(Constraint.OnAnyNetwork)
                        .Build();

            // This method will not throw an exception; an integer result value is returned
            int scheduleResult = dispatcher.Schedule(myJob);

            Log.Debug(TAG, "Scheduling LocationJobService...");

            if (scheduleResult != FirebaseJobDispatcher.ScheduleResultSuccess)
            {
                Log.Warn(TAG, "Job Scheduler failed to schedule job!");
            }
        }
Ejemplo n.º 2
0
        public void ScheduleMeasurement(int minutes)
        {
            dispatcher = MainActivity.instance.CreateJobDispatcher();
            JobTrigger.ExecutionWindowTrigger trigger = Firebase.JobDispatcher.Trigger.ExecutionWindow(minutes * 60, minutes * 60 + 10);

            var job = dispatcher.NewJobBuilder()
                      .SetTag("MeasurementService")           //unique tag
                      .SetService <MeasurementJob>("measurement-service")
                      .SetRecurring(true)
                      .SetTrigger(trigger)
                      .SetLifetime(Lifetime.Forever)
                      .SetReplaceCurrent(true)           //replace previous defined job
                      .Build();

            int result = dispatcher.Schedule(job);

            if (result == FirebaseJobDispatcher.ScheduleResultSuccess)
            {
                Console.WriteLine("Job succeeded");
            }
            else
            {
                Console.WriteLine("Job failed");
            }
        }
Ejemplo n.º 3
0
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            var driver     = new GooglePlayDriver(this);
            var dispatcher = new FirebaseJobDispatcher(driver);

            dispatcher.Cancel("my-job-service-tag");

            var myJob = dispatcher.NewJobBuilder()
                        .SetService <BackgroundJobService>("my-job-service-tag")
                        .SetTrigger(Trigger.ExecutionWindow(2, 5))
                        .SetLifetime(Lifetime.Forever)
                        .SetRecurring(true)
                        .Build();

            dispatcher.MustSchedule(myJob);

            global::Xamarin.Forms.Forms.Init(this, bundle);

            LoadApplication(new App());
        }
Ejemplo n.º 4
0
        private void startJob()
        {
            IDriver driver = new GooglePlayDriver(this);
            FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver);

            JobTrigger myTrigger = Trigger.ExecutionWindow(30, 60);
            Job        myJob     = dispatcher.NewJobBuilder()
                                   .SetService <DemoJob>("demo-job-tag")
                                   .SetLifetime(Lifetime.Forever)
                                   .SetRecurring(true)
                                   .SetTrigger(myTrigger)
                                   .Build();

            dispatcher.MustSchedule(myJob);
        }
Ejemplo n.º 5
0
        private void ScheduleNotificationCheck()
        {
            try
            {
                FirebaseJobDispatcher dispatcher = this.CreatJobDispatcher();
                Job job = dispatcher.NewJobBuilder()
                          .SetService <PusteraScheduler>("notifJob")
                          .SetRecurring(true)
                          .SetLifetime(Lifetime.Forever)
                          .SetRetryStrategy(dispatcher.NewRetryStrategy(RetryStrategy.RetryPolicyLinear, 30, 360))
                          .SetReplaceCurrent(false)
                          .SetTrigger(Trigger.ExecutionWindow(Utils.HoursToSeconds(1), Utils.HoursToSeconds(1.5)))
                          .Build();

                dispatcher.Schedule(job);
            }
            catch (Exception bug)
            {
                Log.Debug("PUSTERA_LOG", bug.Message);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Schedules a job to run on the JobService subclass.
        /// </summary>
        /// <param name="context">The context that is request the job.</param>
        /// <typeparam name="T">A <code>JobService</code> subclass.</typeparam>
        internal void SubmitJob <T>(Context context) where T : JobService
        {
            if (!initialized)
            {
                throw new InvalidOperationException(
                          "Must initialize the parameters with JobFormScheduler.WithParametersFrom before trying to schedule the job!");
            }

            FirebaseJobDispatcher dispatcher = context.CreateJobDispatcher();

            RetryStrategy retryStrategy = BuildRetryStrategy(dispatcher);

            if (retryStrategy == null)
            {
                throw new InvalidCastException("Cannot create a RetryStrategy!");
            }

            JobTrigger trigger = Trigger.ExecutionWindow(winStartSeconds, winEndSeconds);


            var jobParameters = new Bundle();

            jobParameters.PutInt(FibonacciCalculatorJob.FibonacciPositionKey, 25);

            Job.Builder builder = dispatcher.NewJobBuilder()
                                  .SetService <T>(tag)
                                  .SetRecurring(recurring)
                                  .SetLifetime(lifeTime)
                                  .SetRetryStrategy(retryStrategy)
                                  .SetTrigger(trigger)
                                  .SetExtras(jobParameters)
                                  .SetReplaceCurrent(replaceCurrent);

            if (constrainDeviceCharging)
            {
                builder.SetConstraints(Constraint.DeviceCharging);
            }

            if (constrainOnAnyNetwork)
            {
                builder.SetConstraints(Constraint.OnAnyNetwork);
            }

            if (constrainOnUnmeteredNewtwork)
            {
                builder.SetConstraints(Constraint.OnUnmeteredNetwork);
            }

            int    scheduleResult = dispatcher.Schedule(builder.Build());
            string message        =
                $"Scheduled new job `{tag}` for the service `{typeof(T).Name}`. SCHEDULE_RESULT = {scheduleResult}.";

            if (scheduleResult == FirebaseJobDispatcher.ScheduleResultSuccess)
            {
                Log.Info(TAG, message);
            }
            else
            {
                Log.Error(TAG, message);
            }
        }