当前位置: 首页>>代码示例>>C#>>正文


C# ModelBuilder.CreatePipeline方法代码示例

本文整理汇总了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
            }
        }
开发者ID:tuvoksg1,项目名称:RulesEngine,代码行数:82,代码来源:Invoker.cs


注:本文中的ModelBuilder.CreatePipeline方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。