Exemple #1
0
        private void RefreshTokenJob()
        {
            _logger.LogInformation($"Adding refresh token job");
            _schedulerService.AddJob(async() =>
            {
                _logger.LogInformation("Refresh token");

                var res = await _httpClient.PostAsync(TokenAuthUrl,
                                                      HttpClientUtils.BuildFormParams(
                                                          new KeyValuePair <string, string>("grant_type", "refresh_token"),
                                                          new KeyValuePair <string, string>("refresh_token", _config.RefreshToken),
                                                          new KeyValuePair <string, string>("client_id", _config.ClientId),
                                                          new KeyValuePair <string, string>("client_secret", _config.ClientSecret)));
                var st = await res.Content.ReadAsStringAsync();

                var newToken        = st.FromJson <OAuthTokenResult>();
                _config.AccessToken = newToken.AccessToken;
                _config.ExpireOn    = DateTime.Now.AddSeconds(newToken.ExpiresIn);
                _componentsService.SaveComponentConfig(_config);

                _logger.LogInformation($"Token refresh expire on: {_config.ExpireOn}");

                InitSpotifyClient();
            }, "SpotifyRefreshToken", (int)TimeSpan.FromMinutes(30).TotalSeconds, false);
        }
Exemple #2
0
        public Task <bool> Start()
        {
            if (_config.ApiKey != "ChangeMe")
            {
                _darkSkyService = new DarkSkyService(_config.ApiKey);
                _logger.LogInformation("Check Weather every 3 minutes");
                _schedulerService.AddJob(GetWeather, (int)TimeSpan.FromMinutes(3).TotalSeconds, true);
                return(Task.FromResult(true));
            }

            throw new Exception("Configuration Needed");
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,JobGroupId,UnitCollectionId")] JobViewModel model)
        {
            if (ModelState.IsValid)
            {
                var group = await _context.Groups.FindAsync(model.JobGroupId);

                var entity = new JobDefinition
                {
                    Id               = model.Id,
                    Name             = model.Name,
                    Group            = group,
                    UnitCollectionId = model.UnitCollectionId
                };
                _context.Add(entity);
                await _context.SaveChangesAsync();

                await _scheduler.AddJob(entity);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
        public JsonResult PostOperJobState(string fid, string state)
        {
            FapJob fj = _dbContext.Get <FapJob>(fid);

            //禁用
            if (state.EqualsWithIgnoreCase("Disabled"))
            {
                fj.JobState  = "Disabled";
                fj.ExecState = ExecuteStatus.NoExec;
                //移除作业
                _schedule.RemoveJob(fj);
            }
            else if (state.EqualsWithIgnoreCase("Enabled"))
            {//启用
                fj.JobState  = "Enabled";
                fj.ExecState = ExecuteStatus.Execing;
                _schedule.AddJob(fj);
            }
            else if (state.EqualsWithIgnoreCase("Add"))
            {
                fj.ExecState = ExecuteStatus.Execing;
                //执行作业
                _schedule.AddJob(fj);
            }
            else if (state.EqualsWithIgnoreCase("Suspend"))
            {//暂停
                fj.ExecState = ExecuteStatus.Suspend;
                //暂停作业
                _schedule.PauseJob(fj);
            }
            else if (state.EqualsWithIgnoreCase("Resume"))
            {
                fj.ExecState = ExecuteStatus.Execing;
                _schedule.ResumeJob(fj);
            }
            _dbContext.Update <FapJob>(fj);
            return(Json(fj));
        }
 public void AddAlarm(string name, int hours, int minutes, LuaFunction function)
 {
     _schedulerService.AddJob(() => { function.Call(); }, name, hours, minutes);
 }
Exemple #6
0
 public async Task <bool> Start()
 {
     //_config.Devices.ForEach(ConnectDevice);
     _schedulerService.AddJob(async() => { await ScanDevices(); }, 60, true);
     return(true);
 }
Exemple #7
0
 private void RefreshTokenJob()
 {
     Logger.LogInformation($"Adding refresh token job");
     _schedulerService.AddJob(async() => await RefreshToken(), "SpotifyRefreshToken", (int)TimeSpan.FromMinutes(30).TotalSeconds, false);
 }
Exemple #8
0
 public void AddAlarm(string name, int hours, int minutes, Delegate function)
 {
     _schedulerService.AddJob(() => { function.DynamicInvoke(); }, name, hours, minutes);
 }