public void ForEachAccountComponents(AccountInfo account, Action <ForEachComponentData> method, bool withDeleted = false) { try { Logger.Trace("Начинаем обработку компонентов аккаунта; accountId:{0} accountName:{1}", account.Id, account.DisplayName); CancellationToken.ThrowIfCancellationRequested(); using (var accountDbContext = AccountDbContext.CreateFromDatabaseId(account.AccountDatabaseId)) { var componentRepository = accountDbContext.GetComponentRepository(); var components = !withDeleted? componentRepository.QueryAll().ToArray() : componentRepository.QueryAllWithDeleted().ToArray(); Logger.Trace("Найдено компонентов: " + components.Length); var tasks = new ThreadTaskQueue(ComponentsThreads); tasks.ForEach(components, component => { CancellationToken.ThrowIfCancellationRequested(); ForEachAccountComponentsWrapper(account, component, method); }); } } catch (ThreadAbortException) { } catch (OperationCanceledException) { } catch (Exception exception) { SetException(exception); Tools.HandleOutOfMemoryException(exception); Logger.Error(exception); } finally { Logger.Trace("Обработка аккаунта завершена; accountId:{0} accountName:{1}", account.Id, account.DisplayName); } }
public ForEachComponentData( ILogger logger, CancellationToken cancellationToken, AccountInfo account, Component component) { Logger = logger; CancellationToken = cancellationToken; Account = account; AccountDbContext = AccountDbContext.CreateFromDatabaseId(account.AccountDatabaseId); Component = component; }
public AccountDbContext GetAccountDbContextByDataBaseId(Guid databaseId) { AccountDbContext result; if (_accountDbContexts.TryGetValue(databaseId, out result)) { return(result); } if (IsInternalDispatcherContext) { var database = ConfigDbServicesHelper.GetDatabaseService().GetOneById(databaseId); result = AccountDbContext.CreateFromConnectionString(database.ConnectionString); } else { result = AccountDbContext.CreateFromDatabaseId(databaseId); } _accountDbContexts.Add(databaseId, result); return(result); }
public AccountDbContext CreateAccountDbContext() { return(AccountDbContext.CreateFromDatabaseId(AccountDataBaseId)); }