public AnnotationServiceProvider(IOptions <ProxyServerSettings> proxySettings, ILogger <AnnotationServiceProvider> logger, IOptions <AnnotationServiceConfiguration> serviceConnectionConfiguration) { this.proxySettings = proxySettings.Value; this.serviceConnectionConfiguration = serviceConnectionConfiguration.Value; this.logger = logger; initialized = true; }
private static async Task <string> GetJsonData(string uri, ProxyServerSettings proxySettings) { var proxyUri = string.Format("{0}:{1}", proxySettings.Address, proxySettings.Port); var proxy = new WebProxy(proxyUri); var httpClientHandler = new HttpClientHandler { Proxy = proxy }; using (var client = new HttpClient(httpClientHandler)) { var response = await client.GetAsync(uri); var body = await response.Content.ReadAsStringAsync(); return(body); } }
public HealthChecker(IOptions <ProxyServerSettings> proxySettings, IOptions <TestAccessUrlConfiguration> testAccessUrlConfiguration, MapServiceProvider mapServiceProvider, AnnotationServiceProvider annotationServiceProvider, IContextManager contextManager, ILogger <HealthChecker> logger) { initialized = true; this.proxySettings = proxySettings.Value; this.testAccessUrlConfiguration = testAccessUrlConfiguration.Value; this.mapServiceProvider = mapServiceProvider; this.annotationServiceProvider = annotationServiceProvider; this.contextManager = contextManager; this.logger = logger; if (!string.IsNullOrEmpty(this.proxySettings.Address) && !string.IsNullOrEmpty(this.proxySettings.Port)) { try { string address = this.proxySettings.Address.ToLower(); string httpPrefix = "http://"; string httpsPrefix = "https://"; if (address.StartsWith(httpPrefix)) { address = address.Remove(0, httpPrefix.Length); } else if (address.StartsWith(httpsPrefix)) { address = address.Remove(0, httpsPrefix.Length); } if (address.EndsWith("/")) { address = address.Remove(address.Length - 1, 1); } proxyPureAddress = address; int.TryParse(this.proxySettings.Port, out proxyPort); proxyFullUri = string.Format("{0}:{1}", this.proxySettings.Address, this.proxySettings.Port); var testProxy = new WebProxy(proxyFullUri); } catch (Exception e) { initialized = false; logger.LogError(e.Message); } } proxyConfigured = !string.IsNullOrEmpty(proxyPureAddress) && (proxyPort != 0); }
public MapServiceProvider(IHostingEnvironment env, ApplicationConfiguration configuration, IOptions <ProxyServerSettings> proxySettings, ILogger <MapServiceProvider> logger) { this.configuration = configuration; this.proxySettings = proxySettings.Value; try { //requestBody = XDocument.Load(env.GetFilePath(frameworkProjectPath, requestBodyFileName)); using (var streamBodyContent = new MemoryStream(Convert.FromBase64String(requestBodyContent))) { requestBody = XDocument.Load(streamBodyContent); } } catch (Exception e) { logger.LogCritical(CoreExtensions.ExtractAllInnerExceptions(e)); return; } query = requestBody.Descendants(wfs + "Query").First(); query.Remove(); initialized = true; }
public UrlService(ApplicationConfiguration configuration, IOptions <ProxyServerSettings> proxySettings) { this.configuration = configuration; this.proxySettings = proxySettings.Value; }
protected void ExecuteInternal(Action action, IJobExecutionContext context) { if (context.Scheduler == null) { throw new Exception("Scheduler of context is not set."); } var jobSchedulingConfiguration = QuartzScheduler.GetJobSchedulingConfiguration(context.JobDetail); var countOfExceptionFires = CountOfExecutionFires(context); var isForced = IsForced(context); var regularFire = countOfExceptionFires == 0 && !isForced; proxySettings = context.Scheduler.Context.Get(QuartzScheduler.PROXY_SERVER_SETTINGS) as ProxyServerSettings; var executionType = isForced ? JobExecutionTypeEnum.Forced : regularFire ? JobExecutionTypeEnum.Regular : JobExecutionTypeEnum.RunAfterFail; try { LogTaskStarted(executionType, countOfExceptionFires, jobSchedulingConfiguration.RetriesOnFail); var sw = new Stopwatch(); sw.Start(); action(); sw.Stop(); LogTaskExecuted(sw.Elapsed, executionType); // reschedule after re-fire, if its needed if (!regularFire && !isForced) { SetRegularScheduling(context, jobSchedulingConfiguration.Scheduler); } // reschedule to "regular" scheduling when job was forced on paused trigger if (isForced) { var trigger = GetTriggerForJob(context); var triggerState = context.Scheduler.GetTriggerState(trigger.Key).Result; if (triggerState == TriggerState.Paused && trigger.CronExpressionString == jobSchedulingConfiguration.SchedulerOnFail) { SetRegularScheduling(context, jobSchedulingConfiguration.Scheduler); } } } catch (Exception e) { var retriesOnFail = jobSchedulingConfiguration.RetriesOnFail; context.JobDetail.JobDataMap.Put(QuartzScheduler.COUNT_OF_FAILED_EXECUTIONS, ++countOfExceptionFires); LogTaskFailed(executionType, $"Job '{JobType}' has failed.", e); if (regularFire) { SetExceptionalScheduling(context, jobSchedulingConfiguration.SchedulerOnFail); } if (countOfExceptionFires > retriesOnFail && !isForced) { PauseTrigger(context); // ClearCountOfFails(context); } throw new JobExecutionException(e) { RefireImmediately = false }; } }
/// <summary> /// Quartz scheduler initializer /// </summary> /// <param name="serviceProvider"></param> public static void Initialize(IServiceProvider serviceProvider) { if (_isRunning) { throw new Exception("Scheduler is already running."); } if (_scheduler != null) { throw new Exception("Scheduler is already initialized!"); } if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } var jobConfigurationBuilder = new ConfigurationBuilder() .SetBasePath(AppContext.BaseDirectory) .AddJsonFile("jobsettings.json", optional: false, reloadOnChange: true); _configuration = jobConfigurationBuilder.Build(); var applicationConfiguration = serviceProvider.GetRequiredService <IConfigurationRoot>(); var properties = new NameValueCollection { ["quartz.serializer.type"] = "json", ["quartz.scheduler.instanceName"] = "PtvScheduler", ["quartz.scheduler.instanceId"] = "ptv_quartz_instance", ["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz", ["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz", ["quartz.jobStore.useProperties"] = "false", ["quartz.jobStore.dataSource"] = "default", ["quartz.jobStore.tablePrefix"] = "QRTZ_", ["quartz.jobStore.maxMisfiresToHandleAtATime"] = "1", ["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz", ["quartz.dataSource.default.connectionString"] = applicationConfiguration.GetConnectionString("QuartzConnection"), ["quartz.dataSource.default.provider"] = "Npgsql", ["quartz.threadPool.threadCount"] = "5", // Allows only 5 Thread in parallel // ["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz", // ["quartz.threadPool.threadPriority"] = "2", // ["quartz.jobStore.misfireThreshold"] = "600000" //// Amount of milliseconds that may pass till a trigger that couldn't start in time counts as misfired (600000 ms => 10 minutes) }; try { var schedulerFactory = new StdSchedulerFactory(properties); _scheduler = schedulerFactory.GetScheduler().Result; _scheduler.Context.Put(SERVICE_PROVIDER, serviceProvider); // proxy server settings var pss = new ProxyServerSettings(); applicationConfiguration.GetSection("ProxyServerSettings").Bind(pss); _scheduler.Context.Put(PROXY_SERVER_SETTINGS, pss); // _scheduler.Clear().Wait(); // TaskSchedulerLogger.ClearAllLogs(); ConfigureJobs(); _logger.Info("QuartzScheduler has been initialized"); } catch (Exception e) { _logger.Error(e); throw; } }