public JobController()
        {
            GeresEventSource.Log.WebApiControllerInitializing(RoleEnvironment.CurrentRoleInstance.Id, RoleEnvironment.DeploymentId, "JobController");

            _jobController = EngineFactory.CreateController();

            GeresEventSource.Log.WebApiControllerInitialized(RoleEnvironment.CurrentRoleInstance.Id, RoleEnvironment.DeploymentId, "JobController");
        }
 public SelectBuildServerViewModel(IJobRepository jobRepository, IJobController jobController, 
     IJobProviderFactory jobProviderFactory, INavigationService navigationService, 
     ISchedulerAccessor schedulerAccessor, IMessageBoxFacade messageBoxFacade)
 {
     this.jobRepository = jobRepository;
     this.navigationService = navigationService;
     this.schedulerAccessor = schedulerAccessor;
     this.messageBoxFacade = messageBoxFacade;
     this.jobController = jobController;
 }
 public AddJobsViewModel(INavigationService navigationService, IJobController jobController,
     IJobProviderFactory jobProviderFactory, IJobRepository jobRepository, ISchedulerAccessor schedulerAccessor,
     IApplicationInformation applicationInformation, IMessageBoxFacade messageBoxFacade)
 {
     this.navigationService = navigationService;
     this.jobController = jobController;
     this.jobProviderFactory = jobProviderFactory;
     this.jobRepository = jobRepository;
     this.schedulerAccessor = schedulerAccessor;
     this.applicationInformation = applicationInformation;
     this.messageBoxFacade = messageBoxFacade;
 }
 public ViewJobViewModel(INavigationService navigationService, IJobRepository jobRepository, 
     ISchedulerAccessor schedulerAccessor, IApplicationTileService applicationTileService, 
     IWebBrowserTaskFacade webBrowserTask, IMessageBoxFacade messageBoxFacade,
     IJobController jobController)
 {
     this.navigationService = navigationService;
     this.jobRepository = jobRepository;
     this.schedulerAccessor = schedulerAccessor;
     this.applicationTileService = applicationTileService;
     this.webBrowserTask = webBrowserTask;
     this.messageBoxFacade = messageBoxFacade;
     this.jobController = jobController;
 }
Example #5
0
        /// <summary>
        /// Gets the Job section settings of the app.config
        /// </summary>
        public static IJobController CreateJobController()
        {
            JobSection section = (JobSection)ConfigurationManager.GetSection(SECTION_NAME);

            if (!string.IsNullOrEmpty(section.JobControllerProviderType))
            {
                IJobController customController = Activator.CreateInstance(Type.GetType(section.JobControllerProviderType)) as IJobController;
                if (customController != null)
                {
                    return(customController.CreateJobControllerInstance());
                }
            }

            return(section);
        }
Example #6
0
        /// <summary>
        /// Finds and Starts all jobs. Any existing jobs are shutdown first
        /// </summary>
        /// <param name="controller">The controller.</param>
        public void Start(IJobController controller)
        {
            if (_JobList.Count != 0)
            {
                return;
            }

            try { _Interval = controller.Minutes * 60000; }
            catch { _Interval = 15 * 60000; }

            foreach (IJobItem el in controller.JobItems)
            {
                _JobList.Add(new Job(
                                 Type.GetType(el.Type)
                                 , el
                                 , el.Options));
            }

            // run jobs for the first time
            ExecuteFirstRuns();

            bool useGeneralTimerThread = false;

            // Now initialize timer callbacks
            foreach (Job job in _JobList)
            {
                if (job.Enabled &&
                    (job.ExecuteOnOwnThread ||
                     job.ExecuteDaily))
                {
                    job.InitializeTimer();
                }
                else
                {
                    useGeneralTimerThread = true;
                }
            }
            if (useGeneralTimerThread)
            {
                //Create a new timer to iterate over each job
                _SingleTimer = new Timer(new TimerCallback(SingleThreadTimerCallback), null, _Interval, _Interval);
            }
        }
        public async Task AddInstance(Instance instance)
        {
            IJobController instanceController = null;
            var            geofences          = GeofenceController.Instance.GetGeofences(instance.Geofences);

            if (geofences == null)
            {
                // Failed to get geofence, skip?
                _logger.LogError($"[{instance.Name}] Failed to get geofences for instance, make sure it is assign at least one");
                return;
            }
            switch (instance.Type)
            {
            case InstanceType.CirclePokemon:
            case InstanceType.CircleRaid:
            case InstanceType.SmartCircleRaid:
                try
                {
                    var coords = new List <Coordinate>();
                    foreach (var geofence in geofences)
                    {
                        var area = geofence?.Data?.Area;
                        if (area is null)
                        {
                            _logger.LogError($"[{instance.Name}] Failed to get teleport circles, skipping...");
                            continue;
                        }
                        var coordsArray = (List <Coordinate>)
                                          (
                            area is List <Coordinate>
                            ?area
                            : JsonSerializer.Deserialize <List <Coordinate> >(Convert.ToString(area))
                                          );
                        coords.AddRange(coordsArray);
                    }
                    var minLevel = instance.MinimumLevel;
                    var maxLevel = instance.MaximumLevel;
                    switch (instance.Type)
                    {
                    case InstanceType.CirclePokemon:
                        instanceController = new CircleInstanceController(instance.Name, coords, CircleType.Pokemon, instance.Data.CircleRouteType, minLevel, maxLevel, instance.Data.AccountGroup, instance.Data.IsEvent);
                        break;

                    case InstanceType.CircleRaid:
                        instanceController = new CircleInstanceController(instance.Name, coords, CircleType.Raid, CircleRouteType.Default, minLevel, maxLevel, instance.Data.AccountGroup, instance.Data.IsEvent);
                        break;

                    case InstanceType.SmartCircleRaid:
                        // TODO: SmartCircleRaidInstanceController
                        break;
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError($"[{instance.Name}] Error: {ex}");
                }
                break;

            case InstanceType.AutoQuest:
            case InstanceType.PokemonIV:
            case InstanceType.Bootstrap:
            case InstanceType.FindTTH:
                try
                {
                    var multiPolygons = new List <MultiPolygon>();
                    var coordinates   = new List <List <Coordinate> >();
                    foreach (var geofence in geofences)
                    {
                        var area = geofence?.Data?.Area;
                        if (area is null)
                        {
                            _logger.LogError($"[{instance.Name}] Failed to get geofence area, skipping...");
                            continue;
                        }
                        var coordsArray = (List <List <Coordinate> >)
                                          (
                            area is List <List <Coordinate> >
                            ?area
                            : JsonSerializer.Deserialize <List <List <Coordinate> > >(json: Convert.ToString(area))
                                          );
                        coordinates.AddRange(coordsArray);

                        var areaArrayEmptyInner = new List <MultiPolygon>();
                        foreach (var coords in coordsArray)
                        {
                            var        multiPolygon = new MultiPolygon();
                            Coordinate first        = null;
                            for (var i = 0; i < coords.Count; i++)
                            {
                                var coord = coords[i];
                                if (i == 0)
                                {
                                    first = coord;
                                }
                                multiPolygon.Add(new Polygon(coord.Latitude, coord.Longitude));
                            }
                            if (first != null)
                            {
                                multiPolygon.Add(new Polygon(first.Latitude, first.Longitude));
                            }
                            areaArrayEmptyInner.Add(multiPolygon);
                        }
                        multiPolygons.AddRange(areaArrayEmptyInner);
                    }
                    var minLevel = instance.MinimumLevel;
                    var maxLevel = instance.MaximumLevel;
                    switch (instance.Type)
                    {
                    case InstanceType.AutoQuest:
                        var timezone       = instance.Data.Timezone;
                        var timezoneOffset = 0;
                        if (!string.IsNullOrEmpty(timezone))
                        {
                            var tz = TimeZoneService.Instance.Timezones.ContainsKey(timezone) ? TimeZoneService.Instance.Timezones[timezone] : null;
                            if (tz != null)
                            {
                                var tzData = TimeZoneService.Instance.Timezones[timezone];
                                timezoneOffset = instance.Data.EnableDst
                                            ? tzData.Dst * 3600
                                            : tzData.Utc * 3600;
                            }
                        }
                        var spinLimit       = instance.Data.SpinLimit ?? 3500;
                        var retryLimit      = instance.Data.QuestRetryLimit ?? 5;
                        var ignoreBootstrap = instance.Data.IgnoreS2CellBootstrap;
                        instanceController = new AutoInstanceController(instance.Name, multiPolygons, AutoType.Quest, timezoneOffset, minLevel, maxLevel, spinLimit, retryLimit, ignoreBootstrap, instance.Data.AccountGroup, instance.Data.IsEvent);
                        break;

                    case InstanceType.PokemonIV:
                        var ivList       = IVListController.Instance.GetIVList(instance.Data.IVList)?.PokemonIDs ?? new List <uint>();
                        var ivQueueLimit = instance.Data.IVQueueLimit ?? 100;
                        instanceController = new IVInstanceController(instance.Name, multiPolygons, ivList, minLevel, maxLevel, ivQueueLimit, instance.Data.AccountGroup, instance.Data.IsEvent);
                        break;

                    case InstanceType.Bootstrap:
                        var circleSize        = instance.Data.CircleSize ?? 70;
                        var fastBootstrapMode = instance.Data.FastBootstrapMode;
                        instanceController = new BootstrapInstanceController(instance.Name, coordinates, minLevel, maxLevel, circleSize, fastBootstrapMode, instance.Data.AccountGroup, instance.Data.IsEvent);
                        break;

                    case InstanceType.FindTTH:
                        instanceController = new SpawnpointFinderInstanceController(instance.Name, coordinates, minLevel, maxLevel, instance.Data.AccountGroup, instance.Data.IsEvent);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError($"[{instance.Name}] Error: {ex}");
                }
                break;
            }
            lock (_instancesLock)
            {
                _instances[instance.Name] = instanceController;
            }
            await Task.CompletedTask;
        }
Example #8
0
 public void RegisterJob(string jobType, IJobController jobController)
 {
     s_logger.Debug("register job. name:{name} class:{class}", jobType, jobController.GetType().FullName);
     _jobs.Add(jobType, jobController);
 }