/// <summary> /// Performs validation on the RunInfo /// if validation fails an Exception is thrown. /// </summary> protected virtual void ValidateRunInfo(IRunInfo runInfo) { if (!runInfo.GetIsValid(out string exMsg)) { throw new Exception(exMsg); } }
public async Task Run(IRunInfo runInfo, IMetaData metaData) { try { Logger?.Write(LogLevels.Information, $"{Name} Started"); MetaData = metaData; RunInfo = await Initialize(runInfo); await BuildInitialStages(); if (runInfo.Type != RunType.Build) { await RunStage(StagePath.Root, GetStage(StagePath.Root)); } Logger?.Write(LogLevels.Information, $"{Name} Finished"); } catch (OperationCanceledException) { Logger?.Write(LogLevels.Warning, $"{Name} Cancelled"); } catch (Exception ex) { Logger?.Write(LogLevels.Fatal, $"{Name} threw an exception"); Logger?.Write(LogLevels.Fatal, ex); } finally { await RunFinally(); } }
public String GetData(IRunInfo runInfo) { String responseUrlString = ""; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(runInfo.RequestString); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { responseUrlString = response.ResponseUri.ToString(); if (Debug) { Console.WriteLine(responseUrlString); } } } catch (WebException we) { Console.WriteLine("Caught WebException" + we.Message); responseUrlString = null; } String resStr = runInfo.FormatResponse(responseUrlString); return(resStr); }
/// <summary> /// Takes the run info, validates it and returns it with a job and request id if none existed. /// </summary> /// <param name="runInfo"></param> /// <returns>The updated run info</returns> private async Task <IRunInfo> Initialize(IRunInfo runInfo) { if (HasRunBeenCalled) { throw new Exception("A job instance can only be run once"); } HasRunBeenCalled = true; ValidateRunInfo(runInfo); if (DataLayer.GetIsNewJob(runInfo)) { runInfo = await DataLayer.CreateJob(this, runInfo, GetCancellationToken()); } else { await DataLayer.ValidateExistingJob(runInfo, Version, GetCancellationToken()); } runInfo = await DataLayer.CreateRequest(runInfo, MetaData, GetCancellationToken()); return(runInfo); }
public StageBuilder(IDataLayer dataLayer, IRunInfo runInfo, StagePath stagePath) { DataLayer = dataLayer; RunInfo = runInfo; StagePath = stagePath; }
public async Task <IRunInfo> CreateRequest(IRunInfo runInfo, CancellationToken cancellationToken) { return(await Task.FromResult(new RunInfo <string>(runInfo.Type, (runInfo as RunInfo <string>).JobId, "Test Request ID", runInfo.Path))); }
public async Task ValidateExistingJob(IRunInfo runInfo, string version, CancellationToken cancellationToken) { await Task.CompletedTask; }
public async Task <IRunInfo> CreateJob(IKernel kernel, IRunInfo runInfo, CancellationToken cancellationToken) { return(await Task.FromResult(new RunInfo <string>(runInfo.Type, "Test Job ID", (runInfo as RunInfo <string>).RequestId, runInfo.Path))); }
public bool GetIsNewJob(IRunInfo runInfo) { return(string.IsNullOrWhiteSpace((runInfo as RunInfo <string>).JobId)); }