public static async Task Run() { Console.WriteLine("Creating employee target seed...."); using (var context = new AuditorDbContext(ContextProvider.ContextOptions)) { List <EmployeeTarget> sources = new List <EmployeeTarget>() { new EmployeeTarget() { SocialSecurityNumber = "01010101", FirstName = "Kari", LastName = "Nordman", Department = "Support" }, new EmployeeTarget() { SocialSecurityNumber = "0101004", FirstName = "Esther", LastName = "Doe", Department = "Support" }, new EmployeeTarget() { SocialSecurityNumber = "01010102", FirstName = "Nils", LastName = "Nilsen", Department = "Sales" }, }; foreach (var source in sources) { var employeeTarget = await context.EmployeeTargets.FirstOrDefaultAsync(x => x.SocialSecurityNumber == source.SocialSecurityNumber); if (employeeTarget == null) { context.EmployeeTargets.Add(source); } else { employeeTarget.FirstName = source.FirstName; employeeTarget.LastName = source.LastName; employeeTarget.Department = source.Department; context.EmployeeTargets.Update(employeeTarget); } } await context.SaveChangesAsync(); } }
public static async Task Main(string[] args) { //setup SettingsHelper.ConfigurationProvider = new ConfigurationProvider(); LogHelper.WriteLine("Initialising Database..."); await AuditorDbContext.InitializeAsync(); LogHelper.WriteLine("Setting up Nuget Search Service Api..."); await NugetServiceIndex.SetupSearchApiAsync(); LogHelper.WriteLine("Processing feed..."); await NugetAuditRobot.ProcessAsync(); }
public static async Task Run() { Console.WriteLine("Creating student target seed...."); using (var context = new AuditorDbContext(ContextProvider.ContextOptions)) { List <StudentTarget> sources = new List <StudentTarget>() { new StudentTarget() { StudentId = "01010101", Name = "Kari Nordman", Course = "Algorithm" }, new StudentTarget() { StudentId = "0101004", Name = "Esther Doe", Course = "Data Structure" }, new StudentTarget() { StudentId = "01010102", Name = "Nils Nilsen", Course = "Structure Programming Language" }, }; foreach (var source in sources) { var employeeTarget = await context.StudentTargets.FirstOrDefaultAsync(x => x.StudentId == source.StudentId); if (employeeTarget == null) { context.StudentTargets.Add(source); } else { employeeTarget.Name = source.Name; employeeTarget.Course = source.Course; context.StudentTargets.Update(employeeTarget); } } await context.SaveChangesAsync(); } }
public static async Task Run() { Console.WriteLine("Creating student source seed...."); using (var context = new AuditorDbContext(ContextProvider.ContextOptions)) { List <StudentSource> sources = new List <StudentSource>() { new StudentSource() { StudentId = "01010101", Name = "Kari Nordmann", Course = "C#" }, new StudentSource() { StudentId = "01010102", Name = "Jack Jackson", Course = "Javascript" }, new StudentSource() { StudentId = "01010103", Name = "Nils Nilsen", Course = "SQL Server" }, }; foreach (var source in sources) { var studentSource = await context.StudentSources.FirstOrDefaultAsync(x => x.StudentId == source.StudentId); if (studentSource == null) { context.StudentSources.Add(source); } else { studentSource.Name = source.Name; studentSource.Course = source.Course; context.StudentSources.Update(studentSource); } } await context.SaveChangesAsync(); } }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log, ExecutionContext context) { SettingsHelper.ConfigurationProvider = new ConfigurationProvider(); LogHelper.Logger = new LoggerProvider(log); var config = SettingsHelper.ConfigurationProvider.GetConnectionString("dbConn"); LogHelper.WriteLine("Initialising Database..."); await AuditorDbContext.InitializeAsync(); LogHelper.WriteLine("Setting up Nuget Search Service Api..."); await NugetServiceIndex.SetupSearchApiAsync(); LogHelper.WriteLine("Processing feed..."); await NugetAuditRobot.ProcessAsync(); return(req.CreateResponse(HttpStatusCode.OK, "Boom!")); }
public async Task <MatchTableResponse> FindMatch(Type sourceTable, Type targetTable, string primaryKey) { var response = new MatchTableResponse(); using (var context = new AuditorDbContext(ContextProvider.ContextOptions)) { context.ChangeTracker.AutoDetectChangesEnabled = false; var sourceDbSet = context.Set(sourceTable); var targetDbSet = context.Set(targetTable); var sourceCount = await sourceDbSet.CountAsync(); var targetCount = await targetDbSet.CountAsync(); Console.WriteLine($"{sourceCount} source items found and {targetCount} target items found\n\n"); var max = Math.Max(sourceCount, targetCount); for (int i = 0; i < (max / BatchSize) + 1; i++) { var skip = BatchSize * i; var sources = await sourceDbSet.OrderByDynamic(x => $"x.{primaryKey}").Skip(skip).Take(BatchSize).ToListAsync(); var targets = await targetDbSet.OrderByDynamic(x => $"x.{primaryKey}").Skip(skip).Take(BatchSize).ToListAsync(); foreach (var item in targets) { var type = item.GetType(); var propertyInfo = type.GetProperty(primaryKey); if (propertyInfo != null) { var value = propertyInfo.GetValue(item)?.ToString(); var expression = propertyInfo.PropertyType.Name == nameof(System.Int32) || propertyInfo.PropertyType.Name == nameof(System.Int64) ? $"x.{primaryKey}=={value}" : $"x.{primaryKey}==\"{value}\""; var targetItem = sources.SingleOrDefaultDynamic(x => expression); if (targetItem != null) { var compare = targetItem.DeepCompare(item); if (!compare.IsEqual) { foreach (var changeProperty in compare.ChangeProperties) { response.Changes.Add(new MatchItem(value, $"{value} {changeProperty.Name.Name} changed from {changeProperty.OldValue} to {changeProperty.NewValue}")); } } } } } var sourceKeys = sources.SelectDynamic(x => $"x.{primaryKey}").ToList(); var targetKeys = targets.SelectDynamic(x => $"x.{primaryKey}").ToList(); var removedItems = sourceKeys.Except(targetKeys).ToList(); foreach (var item in removedItems) { var @dynamic = sources.FirstDynamic(x => $"x.{primaryKey}==\"{item}\""); response.Removed.Add(new MatchItem(item.ToString(), $"{@dynamic}")); } var addedItems = targetKeys.Except(sourceKeys).ToList(); foreach (var item in addedItems) { var @dynamic = targets.FirstDynamic(x => $"x.{primaryKey}==\"{item}\""); response.Added.Add(new MatchItem(item.ToString(), $"{@dynamic}")); } } } return(response); }