/// <summary>
        /// 观察某个事件
        /// </summary>
        /// <param name="observer">观察者</param>
        /// <param name="name">事件名称</param>
        public void addObserver(IObserver observer,string name)
        {
            if(!this.IsHasObservers(observer,name))
            {
                Notification notice = new Notification();
                notice.name = name;
                notice.obj = null;
                notice.observer = observer;

                this.notifications.Add(notice);
            }
        }
        /// <summary>
        /// 观察某个事件
        /// </summary>
        /// <param name="observer">观察者</param>
        /// <param name="name">事件名称</param>
        /// <param name="priority">调用优先级</param>
        public void addObserver(IObserver observer, string name, int priority)
        {
            Notification res = this.notifications.Find(item => item.name == name && item.observer == observer);

            if (res != null && res.priority != priority)
            {
                res.priority = priority;
                return;
            }

            Notification notice = new Notification();
            notice.name = name;
            notice.obj = null;
            notice.observer = observer;
            notice.priority = priority;

            this.notifications.Add(notice);
        }
Пример #3
0
 public void Notice(Notification notification)
 {
     if (notification.name == "NodeUpdate")
     {
         this.BandIngTreeView(null, null);
     }
     else if (notification.name == "PreconditionUpdate")
     {
         this.BandIngTreeView(null, null);
     }
     else if (notification.name == "TreeUpdate")
     {
         this.name = this.treeHandler.Tree.Name;
         this.tabPage.Name = this.treeHandler.Tree.Name;
         if (this.isTemplate)
         {
             this.tabPage.Name = "(T)" + this.treeHandler.Tree.Name;
         }
         if (this.state == PageState.Edit)
         {
             this.tabPage.Text = this.tabPage.Name + "*";
         }
         else
         {
             this.tabPage.Text = this.tabPage.Name;
         }
     }
 }
        public void Notice(Notification notification)
        {
            List<Precondition> obj = (List<Precondition>)notification.obj;
            if (obj != null && obj.Count == 2)
            {
                Precondition org = obj[0];
                Precondition now = obj[1];

                if (org != null && now != null && now != this && org.name == this.name && org.type == this.type)
                {
                    this.name = now.name;
                    this.type = now.type;
                    this.childCount = now.childCount;
                    this.isBase = now.isBase;
                }
            }
        }
Пример #5
0
 public void Notice(Notification notification)
 {
     List<Node> obj = (List<Node>)notification.obj;
     if (obj != null && obj.Count == 2)
     {
         Node org = obj[0];
         Node now = obj[1];
         if (org != null && now != null && now != this && org.name == this.name && org.type == this.type)
         {
             this.name = now.name;
             this.type = now.type;
             this.isVirtual = now.isVirtual;
             this.loopCount = now.loopCount;
             this.finishCondition = now.finishCondition;
         }
     }
 }
        /// <summary>
        /// 触发事件
        /// </summary>
        /// <param name="name">事件名称</param>
        /// <param name="obj">传递参数</param>
        public void postNotification(string name,object obj)
        {
            List<Notification> res = this.notifications.FindAll(itme=>itme.name == name);
            if(res != null && res.Count > 0)
            {
                res.Sort((left, right) =>
                {
                    return left.priority.CompareTo(right.priority);
                });

                foreach (var item in res)
                {
                     if (item.observer != null)
                     {
                         Notification notice = new Notification();
                         notice.name = name;
                         notice.obj = obj;
                         notice.observer = item.observer;
                         notice.priority = item.priority;
                         item.observer.Notice(notice);
                     }
                }
            }
        }