internal void UpdateBindingTable(ComplianceJob job) { try { using (SqlConnection sqlConnection = new SqlConnection(this.GetConnectionString())) { using (DataContext dataContext = new DataContext(sqlConnection)) { Table <TempDatabase.ComplianceJobBindingTable> table = dataContext.GetTable <TempDatabase.ComplianceJobBindingTable>(); IQueryable <TempDatabase.ComplianceJobBindingTable> queryable = from binding in table where binding.JobRunId == job.JobRunId select binding; foreach (TempDatabase.ComplianceJobBindingTable complianceJobBindingTable in queryable) { complianceJobBindingTable.SetRowData(job); } dataContext.SubmitChanges(); } } } catch (Exception ex) { throw ex; } }
internal void UpdateJobTable(ComplianceJob newJob) { try { using (SqlConnection sqlConnection = new SqlConnection(this.GetConnectionString())) { using (DataContext dataContext = new DataContext(sqlConnection)) { Table <TempDatabase.ComplianceJobTable> table = dataContext.GetTable <TempDatabase.ComplianceJobTable>(); IQueryable <TempDatabase.ComplianceJobTable> queryable = from job in table where job.JobId == ((ComplianceJobId)newJob.Identity).Guid select job; if (queryable != null && queryable.Count <TempDatabase.ComplianceJobTable>() > 0) { TempDatabase.ComplianceJobTable complianceJobTable = queryable.First <TempDatabase.ComplianceJobTable>(); complianceJobTable.SetRowData(newJob); dataContext.SubmitChanges(); } } } } catch (Exception ex) { throw ex; } }
private void AddComplianceJob(ComplianceJob job) { job.TenantId = this.organizationId.OrganizationalUnit.ObjectGuid; job.TenantInfo = this.organizationId.GetBytes(Encoding.UTF8); TempDatabase.Instance.InsertIntoTable <TempDatabase.ComplianceJobTable, ComplianceJob>(job); foreach (KeyValuePair <ComplianceBindingType, ComplianceBinding> keyValuePair in job.Bindings) { TempDatabase.Instance.InsertIntoTable <TempDatabase.ComplianceJobBindingTable, ComplianceBinding>(keyValuePair.Value); } }
public void Delete(IConfigurable instance) { ComplianceJob complianceJob = (ComplianceJob)instance; foreach (KeyValuePair <ComplianceBindingType, ComplianceBinding> keyValuePair in complianceJob.Bindings) { TempDatabase.Instance.Delete(keyValuePair.Value); } this.DeleteTasks(complianceJob.TenantId, complianceJob.JobRunId, null); TempDatabase.Instance.Delete(complianceJob); }
private ComplianceJob CreateComplianceJobFromTableRow <T>(TempDatabase.ComplianceJobTable row, DataContext dbContext) where T : IConfigurable, new() { ComplianceJob newJob = (ComplianceJob)((object)((default(T) == null) ? Activator.CreateInstance <T>() : default(T))); newJob.CopyFromRow(row); Table <TempDatabase.ComplianceJobBindingTable> table = dbContext.GetTable <TempDatabase.ComplianceJobBindingTable>(); IQueryable <TempDatabase.ComplianceJobBindingTable> queryable = from binding in table where binding.JobRunId == row.JobRunId && binding.TenantId == newJob.TenantId select binding; foreach (TempDatabase.ComplianceJobBindingTable complianceJobBindingTable in queryable) { newJob.Bindings[complianceJobBindingTable.BindingType].CopyFromRow(complianceJobBindingTable); } newJob.UpdateJobResults(); return(newJob); }
private IEnumerable <ComplianceJob> FindPagedComplianceJobsInternal(Guid tenantId, string jobName, int pageIndex, int pageSize = 100) { using (SqlConnection dbConn = new SqlConnection(this.GetConnectionString())) { using (DataContext dbContext = new DataContext(dbConn)) { Table <TempDatabase.ComplianceJobTable> jobs = dbContext.GetTable <TempDatabase.ComplianceJobTable>(); IQueryable <TempDatabase.ComplianceJobTable> jobQuery = (from job in jobs where job.TenantId == tenantId && (jobName == null || job.DisplayName.Equals(jobName)) select job).Skip(pageIndex * pageSize).Take(pageSize); foreach (TempDatabase.ComplianceJobTable row in jobQuery) { ComplianceJob newObj = this.CreateComplianceJobFromTableRow <ComplianceSearch>(row, dbContext); yield return(newObj); } } } yield break; }
public void Delete(ComplianceJob job) { using (SqlConnection sqlConnection = new SqlConnection(this.GetConnectionString())) { using (DataContext dataContext = new DataContext(sqlConnection)) { Table <TempDatabase.ComplianceJobTable> table = dataContext.GetTable <TempDatabase.ComplianceJobTable>(); IQueryable <TempDatabase.ComplianceJobTable> queryable = from jobRow in table where jobRow.JobId == ((ComplianceJobId)job.Identity).Guid select jobRow; if (queryable != null && queryable.Count <TempDatabase.ComplianceJobTable>() > 0) { TempDatabase.ComplianceJobTable entity = queryable.First <TempDatabase.ComplianceJobTable>(); table.DeleteOnSubmit(entity); dataContext.SubmitChanges(); } } } }
internal IEnumerable <ComplianceJob> FindComplianceJob(Guid tenantId, Guid jobRunId) { using (SqlConnection dbConn = new SqlConnection(this.GetConnectionString())) { using (DataContext dbContext = new DataContext(dbConn)) { Table <TempDatabase.ComplianceJobTable> jobs = dbContext.GetTable <TempDatabase.ComplianceJobTable>(); IQueryable <TempDatabase.ComplianceJobTable> jobQuery = from job in jobs where job.TenantId == tenantId && job.JobRunId == jobRunId select job; foreach (TempDatabase.ComplianceJobTable row in jobQuery) { ComplianceJob newObj = this.CreateComplianceJobFromTableRow <ComplianceSearch>(row, dbContext); yield return(newObj); } } } yield break; }
internal IEnumerable <T> ReadComplianceJobByName <T>(string jobName, Guid tenantId) where T : IConfigurable, new() { using (SqlConnection dbConn = new SqlConnection(this.GetConnectionString())) { using (DataContext dbContext = new DataContext(dbConn)) { Table <TempDatabase.ComplianceJobTable> jobs = dbContext.GetTable <TempDatabase.ComplianceJobTable>(); IQueryable <TempDatabase.ComplianceJobTable> jobQuery = from job in jobs where job.DisplayName.Equals(jobName) && job.TenantId == tenantId select job; foreach (TempDatabase.ComplianceJobTable row in jobQuery) { ComplianceJob newJob = this.CreateComplianceJobFromTableRow <T>(row, dbContext); yield return((T)((object)newJob)); } } } yield break; }
public void SaveComplianceJob(ComplianceJob job) { if (job.ObjectState == ObjectState.New) { this.AddComplianceJob(job); } else if (job.ObjectState == ObjectState.Changed) { if (job.NewRunId) { ComplianceJob instance = (ComplianceJob)this.Read <ComplianceSearch>(job.Identity); this.Delete(instance); this.AddComplianceJob(job); } else { TempDatabase.Instance.UpdateJobTable(job); TempDatabase.Instance.UpdateBindingTable(job); } } job.NewRunId = false; job.ResetChangeTracking(true); }
public void SetRowData(ComplianceJob job) { this.SetRowData(job.Bindings[this.BindingType]); }