/// <summary> /// Initializes a new <see cref="RestZappClient"/>. /// </summary> /// <param name="processController">Controller used for process' lifetime.</param> /// <param name="httpFailurePolicy">Failure policy used to determine http request(s) success.</param> public RestZappClient( IProcessController processController, IHttpFailurePolicy httpFailurePolicy) { this.processController = processController; this.httpFailurePolicy = httpFailurePolicy; var parentPort = Convert.ToInt32(processController.GetVariable <string>( ZappVariables.ParentPortEnvKey)); client = new HttpClient().AsLocalhost(parentPort); }
/// <summary> /// Initializes a new <see cref="FusionProcess"/>. /// </summary> /// <param name="fusionId">Identity of the fusion.</param> /// <param name="logService">Service used for logging.</param> /// <param name="configStore">Store used for loading configuration.</param> /// <param name="fusionCatalogue">Catalogue used to resolve locations of fusions.</param> /// <param name="httpFailurePolicy">Failure policy used for http request(s).</param> public FusionProcess( string fusionId, ILog logService, IConfigStore configStore, IFusionCatalogue fusionCatalogue, IHttpFailurePolicy httpFailurePolicy) { EnsureArg.IsNotNullOrEmpty(fusionId, nameof(fusionId)); FusionId = fusionId; this.logService = logService; this.configStore = configStore; this.fusionCatalogue = fusionCatalogue; this.httpFailurePolicy = httpFailurePolicy; process = new WinProcess(); CpuCounter = new PerformanceCounter("Process", "% Processor Time"); MemoryCounter = new PerformanceCounter("Process", "Working Set - Private"); ChangeState(FusionProcessState.None); }
/// <summary> /// Runs a Http-Get with a <see cref="IHttpFailurePolicy"/> which determines if the request was success or not. /// </summary> /// <param name="client">The client which is used to run the request with.</param> /// <param name="requestUri">The url of the request.</param> /// <param name="failurePolicy">The policy used to determine if the request was success or not.</param> /// <param name="token">The token used to cancel the request.</param> public static async Task GetWithFailurePolicyAsync(this HttpClient client, string requestUri, IHttpFailurePolicy failurePolicy, CancellationToken token) { EnsureArg.IsNotNull(client, nameof(client)); EnsureArg.IsNotNullOrEmpty(requestUri, nameof(requestUri)); EnsureArg.IsNotNull(failurePolicy, nameof(failurePolicy)); try { using (var response = await client.GetAsync(requestUri, token)) { failurePolicy.OnResponse(response); } } catch (Exception ex) { failurePolicy.OnError(ex); } }