Beispiel #1
0
 /// <summary>
 /// 添加溯原事件
 /// </summary>
 public void Append(IEnumerable <EventData> events)
 {
     using (var context = _dbContextFactory.CreateDataContext()) {
         events.ForEach(context.Save);
         context.Commit();
     }
 }
        public TDataContext Get <TDataContext>() where TDataContext : DataContext
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("DataContextCollection");
            }

            var requestedType = typeof(TDataContext).ToString();

            if (!_initializedDataContexts.ContainsKey(requestedType))
            {
                // First time we've been asked for this particular DataContext type.
                // Create one, cache it and start its database transaction if needed.
                var dataContext = _dataContextFactory != null
                    ? _dataContextFactory.CreateDataContext <TDataContext>()
                    : Activator.CreateInstance <TDataContext>();

                _initializedDataContexts.Add(requestedType, dataContext);

                if (_readOnly)
                {
                    //TOOD: IS THIS CORRECT?
                    dataContext.ObjectTrackingEnabled = false;
                }

                if (_isolationLevel.HasValue)
                {
                    var tran = dataContext.BeginTransaction(_isolationLevel.Value);
                    _transactions.Add(dataContext, tran);
                }
            }

            return(_initializedDataContexts[requestedType] as TDataContext);
        }
Beispiel #3
0
        public void Add(IEnumerable <MessageData> messages)
        {
            if (!_persistent || messages.IsEmpty())
            {
                return;
            }

            using (var context = _dbContextFactory.CreateDataContext()) {
                messages.ForEach(context.Save);
                context.Commit();
            }
        }
Beispiel #4
0
        /// <summary>
        /// 添加处理程序信息
        /// </summary>
        public override void AddHandlerInfo(HandlerRecordData handlerInfo)
        {
            base.AddHandlerInfo(handlerInfo);

            using (var context = _contextFactory.CreateDataContext()) {
                if (IsHandlerInfoExist(context, handlerInfo))
                {
                    return;
                }

                context.Save(handlerInfo);
                context.Commit();
            }
        }
Beispiel #5
0
        public UnitOfWork(IDataContextFactory dataContextFactory)
        {
            _dataContextFactory = dataContextFactory;

            DataContext  = _dataContextFactory.CreateDataContext();
            _transaction = DataContext.BeginTransaction();
        }
Beispiel #6
0
    public UnitOfWork(IDataContextFactory dataContextFactory)
    {
      _dataContextFactory = dataContextFactory;

      DataContext = _dataContextFactory.CreateDataContext();
      _transaction = DataContext.BeginTransaction();
    }
Beispiel #7
0
        /// <summary>
        /// 获取最新的快照
        /// </summary>
        public override Task <SnapshotData> GetLastestSnapshot(string aggregateRootId, int aggregateRootTypeCode)
        {
            if (!_persistent)
            {
                return(base.GetLastestSnapshot(aggregateRootId, aggregateRootTypeCode));
            }

            return(Task.Factory.StartNew(() => {
                using (var context = _dbContextFactory.CreateDataContext()) {
                    return context.CreateQuery <SnapshotData>()
                    .Where(snapshot => snapshot.AggregateRootId == aggregateRootId &&
                           snapshot.AggregateRootTypeCode == aggregateRootTypeCode)
                    .OrderByDescending(snapshot => snapshot.Version)
                    .FirstOrDefault();
                }
            }));
        }
        public override int GetPublishedVersion(int aggregateRootTypeCode, string aggregateRootId)
        {
            var version = base.GetPublishedVersion(aggregateRootTypeCode, aggregateRootId);

            if (version <= 0)
            {
                using (var context = _contextFactory.CreateDataContext()) {
                    var data = context.Get <EventPublishedVersionData>(aggregateRootTypeCode, aggregateRootId);
                    if (data != null)
                    {
                        version = data.Version;
                    }
                }
            }

            return(version);
        }
Beispiel #9
0
        public bool Authenticate(string loginid, string password)
        {
            Console.WriteLine("Authenticate username and password :" + loginid);

            using (var context = _contextFactory.CreateDataContext()) {
                User user = context.CreateQuery <User>().FirstOrDefault(p => p.LoginId == loginid);

                return(user != null && user.VertifyPassword(password));
            }
        }
Beispiel #10
0
 public IEnumerable <UserDTO> GetAllUsers()
 {
     using (var context = _contextFactory.CreateDataContext()) {
         return(context.CreateQuery <User>().Select(user => new UserDTO {
             LoginId = user.LoginId,
             Password = user.Password,
             UserID = user.Id,
             UserName = user.UserName
         }).ToArray());
     }
 }
Beispiel #11
0
        public void Handle(UserCreated @event)
        {
            var user = _repository.Get <User>(@event.SourceId);

            using (var context = _contextFactory.CreateDataContext()) {
                context.Save(user);
                context.Commit();
            }

            Console.ResetColor();
            Console.WriteLine("Synchorize to Query db");
        }
Beispiel #12
0
 public UnitOfWork(IDataContextFactory dataContextFactory)
 {
     _dataContext  = dataContextFactory.CreateDataContext();
     _repositories = new List <object>();
 }
Beispiel #13
0
 public DataContext CreateContext()
 {
     return(_dbContextFactory.CreateDataContext());
 }
Beispiel #14
0
 public EntityFrameworkSessionScope(IDataContextFactory dbContextFactory)
 {
     Requires.NotNull(dbContextFactory, "dbContextFactory");
     _session     = dbContextFactory.CreateDataContext();
     _transaction = _session.BeginTransaction();
 }
Beispiel #15
0
 /// <summary>
 /// 创建一个仓储上下文实例。
 /// </summary>
 public IRepositoryContext CreateRepositoryContext()
 {
     return(new RepositoryContext(_dbContextFactory.CreateDataContext(), _cache, _eventBus, _logger));
 }