/// <summary>Initialize a new instance ValidationJobState</summary> /// <param name="ruleEngine">Rule engine</param> /// <param name="jobId">Guid</param> private void InitJobState(RuleEngineWrapper ruleEngine, Guid jobId) { var jobState = new ValidationJobState(); jobState.RuleEngine = ruleEngine; jobState.JobId = jobId; this.jobStates.Add(jobState); }
private JobGroup CreateJobGroupItem(string format, Guid masterJobId, ServiceContext ctx, JobType jobType, List <string> ruleNameList = null, bool insertJobToDB = true) { RuleEngine.IResultProvider resultProvider = new DatabaseResultProvider(ctx.JobId, jobType); ILogger logger = resultProvider as ILogger; RuleEngineWrapper ruleEngine = new RuleEngineWrapper(ctx, resultProvider, logger, ruleNameList); // start the validation workflow on the backend threadpool thread this.InitJobState(ruleEngine, ctx.JobId); if (insertJobToDB) { // insert validation job entry, and insert payload lines, to underlying DB ExtValidationJobs extJob = new ExtValidationJobs(); extJob.ID = ctx.JobId; extJob.Complete = false; extJob.CreatedDate = DateTime.Now; extJob.Uri = ctx.Destination.OriginalString; extJob.Format = format; extJob.RuleCount = ruleEngine.RuleCount; extJob.ResourceType = ctx.PayloadType.ToString(); extJob.ServiceType = ctx.ServiceType.ToString(); foreach (var levelType in ctx.LevelTypes) { extJob.LevelTypes += Enum.GetName(typeof(ConformanceLevelType), levelType).ToString() + ','; } extJob.LevelTypes = extJob.LevelTypes.TrimEnd(','); if (ctx.RequestHeaders != null && ctx.RequestHeaders.Any()) { var headers = ""; foreach (var p in ctx.RequestHeaders) { if (p.Key.Equals("Authorization")) { continue; } headers += p.Key + ":" + p.Value + ";"; } extJob.ReqHeaders = headers; } AddPayloadLinesToJobInImmediateDBEnv(extJob, ctx); LogJobRespHeaders(extJob, ctx); } // populate the data to return JobGroup item = JobGroup.CreateJobGroup(masterJobId, ctx.PayloadType.ToString(), ruleEngine.RuleCount, ctx.Destination.OriginalString); item.DerivativeJobId = ctx.JobId; return(item); }
public void OnInsertJob(ExtValidationJobs job, UpdateOperations op) { if (job == null) { throw new ArgumentNullException("job"); } // ensure only insert ops are allowed ValidateOperationType(op); // limit total size of validation job queue CheckValidationJobQueueSize(); job.Complete = false; job.CreatedDate = DateTime.Now; job.ID = Guid.NewGuid(); // instantiate validation engine var ctx = CreateRuleEngineContext(job); IResultProvider resultProvider = new DatabaseResultProvider(job.ID); ILogger logger = resultProvider as ILogger; RuleEngineWrapper ruleEngine = new RuleEngineWrapper(ctx, resultProvider, logger); // set total # of rules to execute for the given URI & format job.RuleCount = ruleEngine.RuleCount; job.ResourceType = ctx.PayloadType.ToString(); job.ServiceType = ctx.ServiceType.ToString(); foreach (var levelType in ctx.LevelTypes) { job.LevelTypes += Enum.GetName(typeof(ConformanceLevelType), levelType).ToString() + ','; } job.LevelTypes.TrimEnd(','); LogJobRespHeaders(job, ctx); AddPayloadLinesToJob(job, ctx); // state object is used to start the validation workflow on a threadpool thread this.InitJobState(ruleEngine, job.ID); }