本文整理汇总了C#中ModelBuilder.CreatePipeline方法的典型用法代码示例。如果您正苦于以下问题:C# ModelBuilder.CreatePipeline方法的具体用法?C# ModelBuilder.CreatePipeline怎么用?C# ModelBuilder.CreatePipeline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelBuilder
的用法示例。
在下文中一共展示了ModelBuilder.CreatePipeline方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunJob
/// <summary>
/// Runs the job.
/// </summary>
/// <returns></returns>
public async Task<string> RunJob(CancellationToken token)
{
var logEntry = new PledgeLog();
var client = new HttpClient();
try
{
client.BaseAddress = new Uri(ApiAddress);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//Check if the credentials provided for the remote job are vaild.
var content = new StringContent($"grant_type=password&username={UserName}&password={Password}",
Encoding.UTF8, "application/x-www-form-urlencoded");
var response = await client.PostAsync("Token", content, token);
if (!response.IsSuccessStatusCode)
{
return response.ReasonPhrase;
}
//Once authenticated, add access token as header
var login = await response.Content.ReadAsAsync<AuthenticationResponse>(token);
var accessToken = login.AccessToken;
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");
//Get the config object attached to the JobId
response = await client.GetAsync($"api/jobs/get/{JobId}", token);
if (!response.IsSuccessStatusCode)
{
return response.ReasonPhrase;
}
var jobData = await response.Content.ReadAsAsync<JobData>(token);
if (jobData == null)
{
return "Object Deserialization error";
}
//Add LogEntry details
logEntry.JobId = JobId;
logEntry.ConfigId = jobData.PledgeConfiguration.Id.ToString();
logEntry.ConfigName = jobData.PledgeConfiguration.Name;
logEntry.UserName = UserName;
logEntry.Type = LogType.Regular;
logEntry.Subject = $"Process Job: {JobId}";
logEntry.DateCreated = DateTime.UtcNow;
logEntry.StartTime = DateTime.UtcNow;
//Run pledge pipeline
var activeJob = jobData.Job;
var jobName = jobData.Job.JobName;
var builder = new ModelBuilder();
var pipeline = builder.CreatePipeline(activeJob, jobData.PledgeConfiguration);
var payload = pipeline.Run(token);
//Add remaining LogEntry details on successful run of the job
logEntry.EndTime = DateTime.UtcNow;
logEntry.TotalRows = payload.PledgeResult.TotalRecordsProcessed;
logEntry.PassedRows = payload.PledgeResult.TotalPassedRecordsCount;
logEntry.FailedRows = payload.PledgeResult.TotalFailedRecordsCount;
//Cleanup(activeJob, payload);
return $"Execution of {jobName} complete";
}
catch (Exception error)
{
//Add remaining LogEntry details on failure of the job
logEntry.EndTime = DateTime.UtcNow;
logEntry.Write(error);
return error.Message;
}
finally
{
//Fire and Forget : Post log entry to the Audit (Web API) End-point
await client.PostAsJsonAsync("api/audit/post/", logEntry);
// Logging - END
}
}