Esempio 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!");
            }
        }
Esempio 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");
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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);
            }
        }