private void SubscribeEvent()
        {
            //订阅数据实体的增删改事件,以更新呈现

            #region MainMenuAddedEvent

            SubscriptionToken menuEntityAddedEventToken =
                _eventAggregator.GetEvent <MenuStripItemAddedEvent>().Subscribe((e) =>
            {
                _controller.Add(e.Entity,
                                (node) =>
                {
                    if (String.IsNullOrEmpty(e.Entity.ParentId) && node.Codon.DataBoundType == typeof(MenuEntityFolder))
                    {
                        return(true);
                    }
                    else
                    {
                        if (node.Codon.DataBoundType == typeof(MenuEntity))
                        {
                            MenuEntity entity = (MenuEntity)node.DataBoundItem;
                            return(e.Entity.ParentId == entity.Id);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                });
            });

            #endregion

            #region MainMenuRemovedEvent

            SubscriptionToken menuEntityRemovedEvent =
                _eventAggregator.GetEvent <MenuStripItemRemovedEvent>().Subscribe((e) => { _controller.Remove(e.Entity); });

            #endregion

            #region MainMenuUpdatedEvent

            SubscriptionToken menuEntityUpdatedEvent =
                _eventAggregator.GetEvent <MenuStripItemUpdatedEvent>().Subscribe((e) => { _controller.Update(e.Entity); });

            #endregion

            #region MainMenuMoveBeforeEvent

            SubscriptionToken menuEntityMoveBeforeEvent =
                _eventAggregator.GetEvent <MenuStripItemMoveBeforeEvent>().Subscribe((e) =>
            {
                _controller.MoveBefore(
                    (source) =>
                {
                    if (source.Codon.DataBoundType == typeof(MenuEntity))
                    {
                        MenuEntity menuEntity = (MenuEntity)source.DataBoundItem;
                        return(menuEntity.Id == e.Id);
                    }
                    else
                    {
                        return(false);
                    }
                },
                    (target) =>
                {
                    if (target.Codon.DataBoundType == typeof(MenuEntity))
                    {
                        MenuEntity menuEntity = (MenuEntity)target.DataBoundItem;
                        return(menuEntity.Id == e.BeforeId);
                    }
                    else
                    {
                        return(false);
                    }
                }
                    );
                //_navigationTreeController.Select((node) =>
                //{
                //    if (node.Codon.DataBoundType == typeof(MenuEntity))
                //    {
                //        MenuEntity menuEntity = (MenuEntity)node.DataBoundItem;
                //        return menuEntity.Id == e.Id;
                //    }
                //    else
                //        return false;
                //});
            });

            #endregion

            #region MainMenuMoveAfterEvent

            SubscriptionToken menuEntityMoveAfterEvent =
                _eventAggregator.GetEvent <MenuStripItemMoveAfterEvent>().Subscribe((e) =>
            {
                _controller.MoveAfter(
                    (source) =>
                {
                    if (source.Codon.DataBoundType == typeof(MenuEntity))
                    {
                        MenuEntity menuEntity = (MenuEntity)source.DataBoundItem;
                        return(menuEntity.Id == e.Id);
                    }
                    else
                    {
                        return(false);
                    }
                },
                    (target) =>
                {
                    if (target.Codon.DataBoundType == typeof(MenuEntity))
                    {
                        MenuEntity menuEntity = (MenuEntity)target.DataBoundItem;
                        return(menuEntity.Id == e.AfterId);
                    }
                    else
                    {
                        return(false);
                    }
                }
                    );
                //_navigationTreeController.Select((node) =>
                //{
                //    if (node.Codon.DataBoundType == typeof(MenuEntity))
                //    {
                //        MenuEntity menuEntity = (MenuEntity)node.DataBoundItem;
                //        return menuEntity.Id == e.Id;
                //    }
                //    else
                //        return false;
                //});
            });

            #endregion

            #region * Unsubscribe *

            this.Disposed += (sender, e) =>
            {
                _eventAggregator.GetEvent <MenuStripItemAddedEvent>().Unsubscribe(menuEntityAddedEventToken);
                _eventAggregator.GetEvent <MenuStripItemRemovedEvent>().Unsubscribe(menuEntityRemovedEvent);
                _eventAggregator.GetEvent <MenuStripItemUpdatedEvent>().Unsubscribe(menuEntityUpdatedEvent);
                _eventAggregator.GetEvent <MenuStripItemMoveBeforeEvent>().Unsubscribe(menuEntityMoveBeforeEvent);
                _eventAggregator.GetEvent <MenuStripItemMoveAfterEvent>().Unsubscribe(menuEntityMoveAfterEvent);
            };

            #endregion
        }
Пример #2
0
        private void SubscribeEvent()
        {
            //订阅数据实体的增删改事件,以更新呈现

            #region Page

            #region ToolStripPageAddedEvent

            SubscriptionToken toolStripPageAddedEventToken =
                _eventAggregator.GetEvent <ToolStripPageAddedEvent>().Subscribe((e) =>
            {
                _controller.Add(e.Entity,
                                (node) =>
                {
                    if (node.Codon.DataBoundType == typeof(ToolStripItemFolder))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });
            });

            #endregion

            #region ToolStripPageUpdatedEvent

            SubscriptionToken toolStripPageUpdatedEventToken =
                _eventAggregator.GetEvent <ToolStripPageUpdatedEvent>().Subscribe((e) => { _controller.Update(e.Entity); });

            #endregion

            #region ToolStripPageRemovedEvent

            SubscriptionToken toolStripPageRemovedEventToken =
                _eventAggregator.GetEvent <ToolStripPageRemovedEvent>().Subscribe((e) => { _controller.Remove(e.Entity); });

            #endregion

            #region ToolStripPageMoveBeforeEvent

            SubscriptionToken toolStripPageMoveBeforeEventToken =
                _eventAggregator.GetEvent <ToolStripPageMoveBeforeEvent>().Subscribe((e) =>
            {
                _controller.MoveBefore(
                    (source) =>
                {
                    if (source.Codon.DataBoundType == typeof(ToolStripPageEntity))
                    {
                        ToolStripPageEntity toolStripPageEntity = (ToolStripPageEntity)source.DataBoundItem;
                        return(toolStripPageEntity.Id == e.Id);
                    }
                    else
                    {
                        return(false);
                    }
                },
                    (target) =>
                {
                    if (target.Codon.DataBoundType == typeof(ToolStripPageEntity))
                    {
                        ToolStripPageEntity toolStripPageEntity = (ToolStripPageEntity)target.DataBoundItem;
                        return(toolStripPageEntity.Id == e.BeforeId);
                    }
                    else
                    {
                        return(false);
                    }
                }
                    );
            });

            #endregion

            #region ToolStripPageMoveAfterEvent

            SubscriptionToken toolStripPageMoveAfterEventToken =
                _eventAggregator.GetEvent <ToolStripPageMoveAfterEvent>().Subscribe((e) =>
            {
                _controller.MoveAfter(
                    (source) =>
                {
                    if (source.Codon.DataBoundType == typeof(ToolStripPageEntity))
                    {
                        ToolStripPageEntity toolStripPageEntity = (ToolStripPageEntity)source.DataBoundItem;
                        return(toolStripPageEntity.Id == e.Id);
                    }
                    else
                    {
                        return(false);
                    }
                },
                    (target) =>
                {
                    if (target.Codon.DataBoundType == typeof(ToolStripPageEntity))
                    {
                        ToolStripPageEntity toolStripPageEntity = (ToolStripPageEntity)target.DataBoundItem;
                        return(toolStripPageEntity.Id == e.AfterId);
                    }
                    else
                    {
                        return(false);
                    }
                }
                    );
            });

            #endregion

            #endregion

            #region Group

            #region ToolStripGroupAddedEvent

            SubscriptionToken toolStripGroupAddedEventToken =
                _eventAggregator.GetEvent <ToolStripGroupAddedEvent>().Subscribe((e) =>
            {
                _controller.Add(e.Entity,
                                (node) =>
                {
                    if (node.Codon.DataBoundType == typeof(ToolStripPageEntity))
                    {
                        ToolStripPageEntity entity = (ToolStripPageEntity)node.DataBoundItem;
                        return(e.Entity.PageId == entity.Id);
                    }
                    else
                    {
                        return(false);
                    }
                });
            });

            #endregion

            #region ToolStripGroupUpdatedEvent

            SubscriptionToken toolStripGroupUpdatedEventToken =
                _eventAggregator.GetEvent <ToolStripGroupUpdatedEvent>().Subscribe((e) => { _controller.Update(e.Entity); });

            #endregion

            #region ToolStripGroupRemovedEvent

            SubscriptionToken toolStripGroupRemovedEventToken =
                _eventAggregator.GetEvent <ToolStripGroupRemovedEvent>().Subscribe((e) => { _controller.Remove(e.Entity); });

            #endregion

            #region ToolStripGroupMoveBeforeEvent

            SubscriptionToken toolStripGroupMoveBeforeEventToken =
                _eventAggregator.GetEvent <ToolStripGroupMoveBeforeEvent>().Subscribe((e) =>
            {
                _controller.MoveBefore(
                    (source) =>
                {
                    if (source.Codon.DataBoundType == typeof(ToolStripGroupEntity))
                    {
                        ToolStripGroupEntity toolStripGroupEntity = (ToolStripGroupEntity)source.DataBoundItem;
                        return(toolStripGroupEntity.Id == e.Id);
                    }
                    else
                    {
                        return(false);
                    }
                },
                    (target) =>
                {
                    if (target.Codon.DataBoundType == typeof(ToolStripGroupEntity))
                    {
                        ToolStripGroupEntity toolStripGroupEntity = (ToolStripGroupEntity)target.DataBoundItem;
                        return(toolStripGroupEntity.Id == e.BeforeId);
                    }
                    else
                    {
                        return(false);
                    }
                }
                    );
            });

            #endregion

            #region ToolStripGroupMoveAfterEvent

            SubscriptionToken toolStripGroupMoveAfterEventToken =
                _eventAggregator.GetEvent <ToolStripGroupMoveAfterEvent>().Subscribe((e) =>
            {
                _controller.MoveAfter(
                    (source) =>
                {
                    if (source.Codon.DataBoundType == typeof(ToolStripGroupEntity))
                    {
                        ToolStripGroupEntity toolStripGroupEntity = (ToolStripGroupEntity)source.DataBoundItem;
                        return(toolStripGroupEntity.Id == e.Id);
                    }
                    else
                    {
                        return(false);
                    }
                },
                    (target) =>
                {
                    if (target.Codon.DataBoundType == typeof(ToolStripGroupEntity))
                    {
                        ToolStripGroupEntity toolStripGroupEntity = (ToolStripGroupEntity)target.DataBoundItem;
                        return(toolStripGroupEntity.Id == e.AfterId);
                    }
                    else
                    {
                        return(false);
                    }
                }
                    );
            });

            #endregion

            #endregion

            #region Items

            #region ToolStripItemAddedEvent

            SubscriptionToken toolStripItemAddedEventToken =
                _eventAggregator.GetEvent <ToolStripItemAddedEvent>().Subscribe((e) =>
            {
                _controller.Add(e.Entity,
                                (node) =>
                {
                    if (node.Codon.DataBoundType == typeof(ToolStripGroupEntity))
                    {
                        ToolStripGroupEntity entity = (ToolStripGroupEntity)node.DataBoundItem;
                        return(e.Entity.GroupId == entity.Id);
                    }
                    else
                    {
                        return(false);
                    }
                });
            });

            #endregion

            #region ToolStripItemRemovedEvent

            SubscriptionToken toolStripItemRemovedEventToken =
                _eventAggregator.GetEvent <ToolStripItemRemovedEvent>().Subscribe((e) => { _controller.Remove(e.Entity); });

            #endregion

            #region ToolStripItemUpdatedEvent

            SubscriptionToken toolStripItemUpdatedEventToken =
                _eventAggregator.GetEvent <ToolStripItemUpdatedEvent>().Subscribe((e) => { _controller.Update(e.Entity); });

            #endregion

            #region ToolStripItemMoveBeforeEvent

            SubscriptionToken toolStripItemMoveBeforeEventToken =
                _eventAggregator.GetEvent <ToolStripItemMoveBeforeEvent>().Subscribe((e) =>
            {
                _controller.MoveBefore(
                    (source) =>
                {
                    if (source.Codon.DataBoundType == typeof(ToolStripItemAbstract))
                    {
                        ToolStripItemAbstract toolStripEntity = (ToolStripItemAbstract)source.DataBoundItem;
                        return(toolStripEntity.Id == e.Id);
                    }
                    else
                    {
                        return(false);
                    }
                },
                    (target) =>
                {
                    if (target.Codon.DataBoundType == typeof(ToolStripItemAbstract))
                    {
                        ToolStripItemAbstract toolStripEntity = (ToolStripItemAbstract)target.DataBoundItem;
                        return(toolStripEntity.Id == e.BeforeId);
                    }
                    else
                    {
                        return(false);
                    }
                }
                    );
                //_navigationTreeController.Select((node) =>
                //{
                //    if (node.Codon.DataBoundType == typeof(ToolStripItemAbstract))
                //    {
                //        ToolStripItemAbstract menuEntity = (ToolStripItemAbstract)node.DataBoundItem;
                //        return menuEntity.Id == e.Id;
                //    }
                //    else
                //        return false;
                //});
            });

            #endregion

            #region ToolStripItemMoveAfterEvent

            SubscriptionToken toolStripItemMoveAfterEventToken =
                _eventAggregator.GetEvent <ToolStripItemMoveAfterEvent>().Subscribe((e) =>
            {
                _controller.MoveAfter(
                    (source) =>
                {
                    if (source.Codon.DataBoundType == typeof(ToolStripItemAbstract))
                    {
                        ToolStripItemAbstract toolStripEntity = (ToolStripItemAbstract)source.DataBoundItem;
                        return(toolStripEntity.Id == e.Id);
                    }
                    else
                    {
                        return(false);
                    }
                },
                    (target) =>
                {
                    if (target.Codon.DataBoundType == typeof(ToolStripItemAbstract))
                    {
                        ToolStripItemAbstract toolStripEntity = (ToolStripItemAbstract)target.DataBoundItem;
                        return(toolStripEntity.Id == e.AfterId);
                    }
                    else
                    {
                        return(false);
                    }
                }
                    );
                //_navigationTreeController.Select((node) =>
                //{
                //    if (node.Codon.DataBoundType == typeof(ToolStripItemAbstract))
                //    {
                //        ToolStripItemAbstract menuEntity = (ToolStripItemAbstract)node.DataBoundItem;
                //        return menuEntity.Id == e.Id;
                //    }
                //    else
                //        return false;
                //});
            });

            #endregion

            #endregion

            #region * Unsubscribe *

            this.Disposed += (sender, e) =>
            {
                _eventAggregator.GetEvent <ToolStripPageAddedEvent>().Unsubscribe(toolStripPageAddedEventToken);
                _eventAggregator.GetEvent <ToolStripPageUpdatedEvent>().Unsubscribe(toolStripPageUpdatedEventToken);
                _eventAggregator.GetEvent <ToolStripPageRemovedEvent>().Unsubscribe(toolStripPageRemovedEventToken);
                _eventAggregator.GetEvent <ToolStripPageMoveBeforeEvent>().Unsubscribe(toolStripPageMoveBeforeEventToken);
                _eventAggregator.GetEvent <ToolStripPageMoveAfterEvent>().Unsubscribe(toolStripPageMoveAfterEventToken);

                _eventAggregator.GetEvent <ToolStripGroupAddedEvent>().Unsubscribe(toolStripGroupAddedEventToken);
                _eventAggregator.GetEvent <ToolStripGroupUpdatedEvent>().Unsubscribe(toolStripGroupUpdatedEventToken);
                _eventAggregator.GetEvent <ToolStripGroupRemovedEvent>().Unsubscribe(toolStripGroupRemovedEventToken);
                _eventAggregator.GetEvent <ToolStripGroupMoveBeforeEvent>().Unsubscribe(toolStripGroupMoveBeforeEventToken);
                _eventAggregator.GetEvent <ToolStripGroupMoveAfterEvent>().Unsubscribe(toolStripGroupMoveAfterEventToken);

                _eventAggregator.GetEvent <ToolStripItemAddedEvent>().Unsubscribe(toolStripItemAddedEventToken);
                _eventAggregator.GetEvent <ToolStripItemRemovedEvent>().Unsubscribe(toolStripItemRemovedEventToken);
                _eventAggregator.GetEvent <ToolStripItemUpdatedEvent>().Unsubscribe(toolStripItemUpdatedEventToken);
                _eventAggregator.GetEvent <ToolStripItemMoveBeforeEvent>().Unsubscribe(toolStripItemMoveBeforeEventToken);
                _eventAggregator.GetEvent <ToolStripItemMoveAfterEvent>().Unsubscribe(toolStripItemMoveAfterEventToken);
            };

            #endregion
        }