Exemplo n.º 1
0
 public void ConfirmParticipated()
 {
     DomainEvent.Publish <GrouponParticipatedEvent>(new GrouponParticipatedEvent(this)
     {
         ID = Guid.NewGuid(), TimeStamp = DateTime.Now, ParticipateTime = DateTime.Now
     });
 }
Exemplo n.º 2
0
 public void ShelvedConfirm()
 {
     DomainEvent.Publish(new GoodsShelvedEvent(this)
     {
         ID = Guid.NewGuid(), TimeStamp = DateTime.Now, ShelvedTime = DateTime.Now
     });
 }
Exemplo n.º 3
0
 public void CreatedConfirm()
 {
     DomainEvent.Publish <VerificationCreatedEvent>(new VerificationCreatedEvent(this)
     {
         CreatedTime = DateTime.Now, ID = Guid.NewGuid(), TimeStamp = DateTime.Now, VerificationCode = this.Code, VerificationTo = this.To, BizCode = this.BizCode
     });
 }
Exemplo n.º 4
0
 /// <summary>
 /// 当客户完成收货后,对销售订单进行确认。
 /// </summary>
 public void Confirm()
 {
     DomainEvent.Publish <OrderConfirmedEvent>(new OrderConfirmedEvent(this)
     {
         ConfirmedDate = DateTime.Now, OrderID = this.ID, UserEmailAddress = this.User.Email
     });
 }
        public void NoDispatcher()
        {
            DomainEvent.Assign(null);
            var domainEvent = Substitute.For <IDomainEvent>();

            Assert.Throws <InvalidOperationException>(() => DomainEvent.Publish(domainEvent));
        }
Exemplo n.º 6
0
 /// <summary>
 /// 处理发货。
 /// </summary>
 public void Dispatch()
 {
     DomainEvent.Publish <OrderDispatchedEvent>(new OrderDispatchedEvent(this)
     {
         DispatchedDate = DateTime.Now, OrderID = this.ID, UserEmailAddress = this.User.Email
     });
 }
Exemplo n.º 7
0
 public void ConfirmAppoint()
 {
     DomainEvent.Publish(new AppointmentConfirmedEvent(this)
     {
         ID = Guid.NewGuid(), TimeStamp = DateTime.Now, ConfirmedTime = DateTime.Now
     });
 }
Exemplo n.º 8
0
        /// <summary>
        /// Invoke the command
        /// </summary>
        /// <param name="command">Command to run</param>
        public void Invoke(CreateNote command)
        {
            var note = new Note(command.Title, command.Body);

            _storage.Save(note);
            DomainEvent.Publish(new NoteCreated(note.Id));
        }
Exemplo n.º 9
0
 /// <summary>
 /// 用户权限更新
 /// </summary>
 public void UpdatePermission(Guid WebID)
 {
     DomainEvent.Publish <UserUpdatePermissionEvent>(new UserUpdatePermissionEvent(this)
     {
         UserID = this.ID,
         WebID  = WebID,
     });
 }
Exemplo n.º 10
0
 /// <summary>
 /// 当客户完成收货后,对销售订单进行确认。
 /// </summary>
 public void ChangeEmail(string email)
 {
     Debug.WriteLine("ChangeEmail=>Name:" + Name + " Email:" + Email);
     DomainEvent.Publish <UserChangeEmailDomainEvent>(new UserChangeEmailDomainEvent(this)
     {
         Email = email
     });
 }
Exemplo n.º 11
0
        /// <summary>
        /// 取消
        /// </summary>
        public void Cancel()
        {
            ReservationCanceledEvent evnt = new ReservationCanceledEvent(this);

            evnt.CustomerEmailAddress = this.Customer.Email;
            evnt.CanceledDate         = DateTime.Now;
            DomainEvent.Publish <ReservationCanceledEvent>(evnt);
        }
Exemplo n.º 12
0
 /// <summary>
 /// 用户下线
 /// </summary>
 /// <param name="WebID"></param>
 public void OffLine(Guid WebID)
 {
     DomainEvent.Publish <UserOfflineEvent>(new UserOfflineEvent(this)
     {
         UserID = this.ID,
         WebID  = WebID
     });
 }
Exemplo n.º 13
0
 /// <summary>
 /// 使用站点更新
 /// </summary>
 public void UpdateWeb()
 {
     DomainEvent.Publish <UserWebUpdateEvent>(new UserWebUpdateEvent(this)
     {
         UpdateTime = DateTime.Now,
         Email      = this.Email,
         UserID     = this.ID,
         UserName   = this.RealName
     });
 }
Exemplo n.º 14
0
        public void RegularDispatch()
        {
            var innerDispatcher = Substitute.For <IDomainEventDispatcher>();

            DomainEvent.Assign(innerDispatcher);
            var domainEvent = Substitute.For <IDomainEvent>();

            DomainEvent.Publish(domainEvent);

            innerDispatcher.Received().Dispatch(domainEvent);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Invoke the command
        /// </summary>
        /// <param name="command">Command to run</param>
        public void Invoke(RegisterUser command)
        {
            Console.WriteLine("I would register the user in the DB etc");
            var user = new User(command.DisplayName);

            // fake data layer
            user.GetType().GetProperty("Id").SetValue(user, 1, null);

            // Never include the domain entity, but only info relevant to the actual event.
            DomainEvent.Publish(new UserRegistered(user.Id, user.DisplayName));
        }
Exemplo n.º 16
0
 public void SoldConfirm()
 {
     Stock--;
     if (Stock <= 0)
     {
         DomainEvent.Publish(new GoodsSoldOutEvent(this)
         {
             ID = Guid.NewGuid(), TimeStamp = DateTime.Now, SoldOutTime = DateTime.Now
         });
     }
 }
Exemplo n.º 17
0
        public Word(string stem)
        {
            if (string.IsNullOrWhiteSpace(stem))
            {
                throw new HangerdException("词干不可为空");
            }

            Stem            = stem.Trim().ToLower();
            Interpretations = new List <WordInterpretation>();

            DomainEvent.Publish(new WordCreatedEvent(this));
        }
Exemplo n.º 18
0
        /*
         * This example will hold all domain events until your transaction have been completed.
         * That's great since failing transactions won't result in events for stuff that hasn't been persisted.
         *
         * To keep the example simple we'll use a fake transaction.
         *
         */
        static void Main(string[] args)
        {
            // configure Griffin.Container
            var container = ConfigureGriffinContainer();

            var dbContext = new FakeDbContext();

            // Use a synchronous IoC dispatcher
            var builder    = new EventPipelineBuilder(new ErrorHandler());
            var dispatcher = builder
                             .WaitOnTransactions(dbContext)  //do not release events if a transaction is active
                             .UseGriffinContainer(container) //use Griffin.Container
                             .Build();                       // Build the pipeline dispatcher

            Console.WriteLine("Step 1. A simple publising");
            Console.WriteLine("=============================");
            DomainEvent.Assign(dispatcher);

            // Will be published directly
            DomainEvent.Publish(new UserRegistered("Arne"));


            Console.WriteLine();
            Console.WriteLine("Step 1. Disposed Uow = no events");
            Console.WriteLine("=============================");
            using (var uow = dbContext.CreateUnitOfWork())
            {
                Console.WriteLine("** Nothing should come between this line");
                DomainEvent.Publish(new UserRegistered("Arne"));
                Console.WriteLine("** ...and this  line...");

                //no save = rollback
            }
            Console.WriteLine("* this should come directly after 'And this  line...'");

            Console.WriteLine();
            Console.WriteLine("Step 3. Uow = dispatch after");
            Console.WriteLine("=============================");
            using (var uow = dbContext.CreateUnitOfWork())
            {
                Console.WriteLine("** Nothing should come between this line");
                DomainEvent.Publish(new UserRegistered("Arne"));
                Console.WriteLine("** ...and this  line...");

                uow.SaveChanges();
            }
            Console.WriteLine("** Two domain messages should have come.");

            // and wait
            Console.ReadLine();
        }
Exemplo n.º 19
0
        /*
         * First sample for domain events.
         *
         * As you see below it's increadibly easy to get started with Griffin.Decoupled and Griffin.Container
         *
         */
        static void Main(string[] args)
        {
            // configure Griffin.Container
            var container = ConfigureGriffinContainer();

            // extension method from the "Griffin.Decoupled.Container" nuget package.
            container.DispatchEvents();

            // Publish the event
            DomainEvent.Publish(new UserRegistered("Arne"));

            // and wait
            Console.ReadLine();
        }
Exemplo n.º 20
0
Arquivo: Note.cs Projeto: kimx/Samples
        /// <summary>
        /// Mark item as completed
        /// </summary>
        public void Complete()
        {
            // Might look trivial, but it's in fact invalid logic which may
            // produce other side effects. So throw that exception...
            if (IsCompleted)
            {
                throw new InvalidOperationException("Item has already been marked as completed.");
            }

            IsCompleted = true;
            CompletedAt = DateTime.Now;

            DomainEvent.Publish(new NoteCompleted(Id));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Invoke the command
        /// </summary>
        /// <param name="command">Command</param>
        public void Invoke(CreateUser command)
        {
            var user = _storage.Create(command.UserName);

            user.FullName    = command.FullName;
            user.DisplayName = command.DisplayName;
            _storage.Save(user);

            // Note that the command and not the repository
            // generates the event now.
            //
            // imho it's poor practice to let non business related classes
            // to generate events. But I did it for simplicity in the last example project.
            DomainEvent.Publish(new UserCreated(user.Id));

            Console.WriteLine("All done.");
        }
Exemplo n.º 22
0
Arquivo: Note.cs Projeto: kimx/Samples
        /// <summary>
        /// Updates the text.
        /// </summary>
        /// <param name="newText">The new text.</param>
        /// <exception cref="System.ArgumentNullException">newText</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">newText;Body may max be 500000 bytes.</exception>
        public void Update(string newText)
        {
            if (newText == null)
            {
                throw new ArgumentNullException("newText");
            }
            if (newText.Length > 500000)
            {
                throw new ArgumentOutOfRangeException("newText", newText, "Body may max be 500000 bytes.");
            }

            if (IsCompleted)
            {
                throw new InvalidOperationException("Items may not be changed once completed.");
            }

            var oldText = Body;

            Body      = newText;
            UpdatedAt = DateTime.Now;

            DomainEvent.Publish(new NoteUpdated(Id, oldText, newText));
        }
Exemplo n.º 23
0
        public void TestBusMethod()
        {
            var domainevent = new OrderConfirmedEvent();

            DomainEvent.Publish <OrderConfirmedEvent>(domainevent);
        }
Exemplo n.º 24
0
        public void MyTestMethod()
        {
            var domainevent = new OrderDispatchedEvent();

            DomainEvent.Publish <OrderDispatchedEvent>(domainevent);
        }
Exemplo n.º 25
0
 public void Cancel()
 {
     DomainEvent.Publish(new PlatformCancelledEvent(this));
 }
Exemplo n.º 26
0
 public void ConfirmSubmited() => DomainEvent.Publish(new OrderSubmittedEvent(this)
 {
     ID = Guid.NewGuid(), TimeStamp = DateTime.Now, SubmittedTime = DateTime.Now
 });
Exemplo n.º 27
0
 public void ConfirmPaidFailed() => DomainEvent.Publish(new OrderPaidFailedEvent(this)
 {
     ID = Guid.NewGuid(), TimeStamp = DateTime.Now, FailedTime = DateTime.Now
 });
Exemplo n.º 28
0
 public void ConfirmRefund() => DomainEvent.Publish(new OrderRefundedEvent(this)
 {
     ID = Guid.NewGuid(), TimeStamp = DateTime.Now, RefundTime = DateTime.Now
 });
Exemplo n.º 29
0
 /// <summary>
 /// 下线
 /// </summary>
 public void Offline()
 {
     DomainEvent.Publish <UserOfflineEvent>(new UserOfflineEvent(this));
 }
Exemplo n.º 30
0
 public void ConfirmCancelled() => DomainEvent.Publish(new OrderCancelledEvent(this)
 {
     ID = Guid.NewGuid(), TimeStamp = DateTime.Now, CancelledTime = DateTime.Now
 });