public Message FindMessage(OpDataRecord dataRecord) { using (var dbContext = _dbContextProvider.CreateDbContext()) { dbContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; if (dataRecord.XRequestId != null) { var result = dbContext.Messages.FirstOrDefault(it => it.XRequestId == dataRecord.XRequestId); if (result != null) { return(result); } } var searchInProducerRecords = dataRecord.SecurityServerType.Equals("Client"); var targetMessageState = searchInProducerRecords ? MessageState.MergedProducer : MessageState.MergedConsumer; var messageIdFilter = PredicateBuilder.New <Message>() .And(it => it.MessageState.Equals(targetMessageState)) .And(it => it.MessageId == dataRecord.MessageId) .And(it => it.ConsumerInstance == dataRecord.ClientXRoadInstance) .And(it => it.ConsumerMemberClass == dataRecord.ClientMemberClass) .And(it => it.ConsumerSubSystemCode == dataRecord.ClientSubsystemCode) .And(it => it.ProducerInstance == dataRecord.ServiceXRoadInstance) .And(it => it.ProducerMemberClass == dataRecord.ServiceMemberClass) .And(it => it.ProducerMemberCode == dataRecord.ServiceMemberCode) .And(it => it.ProducerServiceCode == dataRecord.ServiceCode); return(dbContext.Messages.FirstOrDefault(messageIdFilter)); } }
public void ProcessRecords(int batchSize) { var dbContext = _dbContextProvider.CreateDbContext(); dbContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; var clientDataRecords = dbContext.OpDataRecords .Where(it => it.SecurityServerType.Equals("Client") && !it.IsProcessed) .OrderBy(it => it.Id) .ToPagedList(1, batchSize); var producerDataRecords = dbContext.OpDataRecords .Where(it => it.SecurityServerType.Equals("Producer") && !it.IsProcessed) .OrderBy(it => it.Id) .ToPagedList(1, batchSize); dbContext.Dispose(); clientDataRecords.AsParallel().ForAll(ProcessRecord); producerDataRecords.AsParallel().ForAll(ProcessRecord); }
public void Collect() { List <Server> servers; using (var dbContext = _dbContextProvider.CreateDbContext()) { servers = dbContext.Servers.ToList(); } servers.AsParallel().ForAll(server => { try { Collect(server); } catch (Exception exception) { Console.WriteLine(exception.Message); Console.WriteLine(exception.StackTrace); } }); }
public IUnitOfWork BeginUnitOfWork() { return(new UnitOfWork(_dbContextProvider.CreateDbContext())); }
public IUnitOfWork BeginUnitOfWork(bool enableLogging = false) { var dbContext = _dbContextProvider.CreateDbContext(enableLogging ? _loggerFatory : null); return(new UnitOfWork(dbContext)); }