Beispiel #1
0
            public void Handle(UpdateProcessCommand message)
            {
                var acDomain          = _set._acDomain;
                var processRepository = _set._acDomain.RetrieveRequiredService <IRepository <Process, Guid> >();

                if (!acDomain.NodeHost.Processs.ContainsProcess(message.Input.Id))
                {
                    throw new NotExistException();
                }
                var entity = processRepository.GetByKey(message.Input.Id);

                if (entity == null)
                {
                    throw new NotExistException();
                }
                var bkState = _set._dic[entity.Id];

                entity.Update(message.Input);

                var  newState     = new ProcessDescriptor(acDomain, ProcessState.Create(entity), entity.Id);
                bool stateChanged = newState != bkState;

                lock (Locker)
                {
                    if (stateChanged)
                    {
                        Update(newState);
                    }
                }
                try
                {
                    processRepository.Update(entity);
                    processRepository.Context.Commit();
                }
                catch
                {
                    if (stateChanged)
                    {
                        Update(bkState);
                    }
                    processRepository.Context.Rollback();
                    throw;
                }
                if (stateChanged)
                {
                    _set._acDomain.PublishEvent(new ProcessUpdatedEvent(message.AcSession, entity));
                    _set._acDomain.CommitEventBus();
                }
            }
Beispiel #2
0
            public void Handle(AddProcessCommand message)
            {
                var acDomain          = _set._acDomain;
                var processRepository = _set._acDomain.RetrieveRequiredService <IRepository <Process, Guid> >();

                if (!message.Input.Id.HasValue)
                {
                    throw new ValidationException("标识是必须的");
                }
                if (acDomain.NodeHost.Processs.ContainsProcess(message.Input.Id.Value))
                {
                    throw new ValidationException("给定标识标识的记录已经存在");
                }

                var entity = Process.Create(message.Input);

                lock (Locker)
                {
                    if (!_set._dic.ContainsKey(entity.Id))
                    {
                        _set._dic.Add(entity.Id, new ProcessDescriptor(acDomain, ProcessState.Create(entity), entity.Id));
                    }
                    try
                    {
                        processRepository.Add(entity);
                        processRepository.Context.Commit();
                    }
                    catch
                    {
                        if (_set._dic.ContainsKey(entity.Id))
                        {
                            _set._dic.Remove(entity.Id);
                        }
                        processRepository.Context.Rollback();
                        throw;
                    }
                }
                _set._acDomain.PublishEvent(new ProcessAddedEvent(message.AcSession, entity));
                _set._acDomain.CommitEventBus();
            }
Beispiel #3
0
 private void Init()
 {
     if (_initialized)
     {
         return;
     }
     lock (Locker)
     {
         if (_initialized)
         {
             return;
         }
         _acDomain.MessageDispatcher.DispatchMessage(new MemorySetInitingEvent(this));
         _dic.Clear();
         var processes = _acDomain.RetrieveRequiredService <INodeHostBootstrap>().GetProcesses();
         foreach (var process in processes)
         {
             _dic.Add(process.Id, new ProcessDescriptor(_acDomain, ProcessState.Create(process), process.Id));
         }
         _initialized = true;
         _acDomain.MessageDispatcher.DispatchMessage(new MemorySetInitializedEvent(this));
     }
 }