private void SubUserCenterProc(IRepositoryContext <Transfer> contextTo, IDictionary <string, IDictionary <string, object> > usersFrom) { TimeOutTryAgain(() => { string sql; int count = 0; foreach (var item in usersFrom) { var account = item.Value["UE_account"].ToTLower(); var drpd = item.Value["UE_drpd"].ToTLower(); if (!_usersTo.TryGetValue(account, out IDictionary <string, object> user)) { this.Log($"SubUserCenterProc UE_account:{account}不存在于目标库中"); continue; } if (!_usersTo.TryGetValue(drpd, out IDictionary <string, object> userCenter)) { this.Log($"SubUserCenterProc UE_drpd:{drpd}不存在于目标库中"); continue; } if (count == 0) { contextTo.BeginTransaction(); } sql = $"UPDATE User_User SET ServiceCenterUserId={userCenter["Id"]} WHERE Id={user["Id"]}"; contextTo.Execute(sql); try { count++; if (count == 1000) { SubRelationAllProcSubmitTransaction(contextTo); count = 0; } } catch (Exception ex) { this.Log($"SubUserCenterProc({sql}, {user["Id"]}); exception:", ex); contextTo.RollbackTransaction(); contextTo.DisposeTransaction(); contextTo.Close(); } this.Log($"SubUserCenterProc:{sql}"); } if (count > 0) { SubRelationAllProcSubmitTransaction(contextTo); } this.Log($"SubUserCenterProc execute ({Thread.CurrentThread.ManagedThreadId}) finish {usersFrom.Count()} records."); }); }
private void Initialize([NotNull] IRepositoryOptions options) { Guard.NotNull(options, nameof(options)); var contextFactory = Guard.EnsureNotNull(options.ContextFactory, "No context provider has been configured for this unit of work."); _context = contextFactory.Create(); _transactionManager = _context.BeginTransaction(); // Re-configures the options and adds a shared context for the repositories to use _options = new RepositoryOptions(options).With(new RepositoryContextFactory(_context)); }
private void SubRelationAllProc(IRepositoryContext <Transfer> contextFrom, IRepositoryContext <Transfer> contextTo, IDictionary <string, IDictionary <string, object> > usersFrom) { TimeOutTryAgain(() => { string sql; int count = 0; foreach (var item in usersFrom) { sql = $"CALL getParentPlace({item.Value["UE_ID"]})"; if (!_usersTo.TryGetValue(item.Value["UE_account"].ToTLower(), out IDictionary <string, object> user)) { continue; } //var user = _usersTo.FirstOrDefault(d => d["UserName"].Equals(item["UE_account"])); //if (user == null) // continue; if (count == 0) { contextTo.BeginTransaction(); } DealRelation(contextFrom, contextTo, sql, user["Id"], item.Value["tree_position"], item.Value["UE_ID"]); try { count++; if (count == 1000) { SubRelationAllProcSubmitTransaction(contextTo); count = 0; } } catch (Exception ex) { this.Log($"DealRelation({sql}, {user["Id"]}); exception:", ex); contextTo.RollbackTransaction(); contextTo.DisposeTransaction(); contextTo.Close(); } this.Log($"ExecuteRelation:{sql}"); } if (count > 0) { SubRelationAllProcSubmitTransaction(contextTo); } this.Log($"SubRelationAllProc execute ({Thread.CurrentThread.ManagedThreadId}) finish {usersFrom.Count()} records."); }); }
/// <summary> /// Begins the transaction. /// </summary> /// <returns>The transaction.</returns> public ITransactionManager BeginTransaction() { return(_context.BeginTransaction()); }
public ITransactionManager BeginTransaction() { return(_underlyingContext.BeginTransaction()); }