Exemplo n.º 1
0
        public virtual IColleague FindColleague(IColleague colleague)
        {
            int mode = colleague.Mode;
            var coll = Colleagues.ToList <IColleague>().Find(delegate(IColleague cg) { return(cg.Mode == mode); });

            return(coll);
        }
Exemplo n.º 2
0
        public virtual void Introduce(IColleague <T> provider, IColleague <T> consumer)
        {
            IList <IColleague <T> > consumers = new List <IColleague <T> >();

            this.provider  = provider;
            this.consumers = consumers;
        }
Exemplo n.º 3
0
 public void register(IColleague <T> newColleague)
 {
     lock (_lockObj)
     {
         _colleagues.Add(newColleague);
     }
 }
Exemplo n.º 4
0
 public void unregister(IColleague <T> Colleague)
 {
     lock (_lockObj)
     {
         _colleagues.Remove(Colleague);
     }
 }
Exemplo n.º 5
0
 public void Register(IColleague colleague, params string[] topics)
 {
     _colleagues.Add(new ColleagueInfo(
                         colleague,
                         topics.Select(t => t.Trim().ToLower()))
                     );
 }
Exemplo n.º 6
0
 /// <summary>
 /// Registers a Colleague to a specific message
 /// </summary>
 /// <param name="colleague">The colleague to register</param>
 /// <param name="messages">The message to register to</param>
 public void Register(IColleague colleague, IEnumerable <string> messages)
 {
     foreach (string message in messages)
     {
         internalList.AddValue(message, colleague);
     }
 }
Exemplo n.º 7
0
 public void Register(IColleague <T> provider, params IColleague <T>[] consumers)
 {
     this.provider = provider;
     if (consumers != null && consumers.Length > 0)
     {
         this.consumers = new List <IColleague <T> >(consumers);
     }
 }
Exemplo n.º 8
0
        public void RemoveColleague(IColleague colleague)
        {
            if (!Colleagues.Contains(colleague))
            {
                return;
            }

            Colleagues.Remove(colleague);
        }
Exemplo n.º 9
0
 public virtual void Introduce(IColleague <T> provider, params IColleague <T>[] consumers)
 {
     if (consumers.Length > 0)
     {
         IList <IColleague <T> > array = new List <IColleague <T> >(consumers);
         this.consumers = array;
     }
     this.provider = provider;
 }
Exemplo n.º 10
0
        public virtual void Registor(IColleague colleague)
        {
            var coll = FindColleague(colleague);

            if (coll == null)
            {
                Colleagues.Add(colleague);
            }
        }
Exemplo n.º 11
0
 public void Listen(string message, IColleague colleague)
 {
     // If source is self, ignore.
     if (colleague == this)
     {
         return;
     }
     Console.WriteLine($"{colleague.Name} to {Name} : '{message}'");
 }
        public void NotifyAll(string message, IColleague authorColleague)
        {
            Console.WriteLine($"[Mediator] Message from author '{authorColleague.Name}' : {message}");

            foreach (var colleague in colleagues)
            {
                colleague.Receive(message);
            }
        }
Exemplo n.º 13
0
        public virtual void UnRegistor(IColleague colleague)
        {
            var coll = FindColleague(colleague.Mode);

            if (coll != null)
            {
                Colleagues.Remove(colleague);
            }
        }
Exemplo n.º 14
0
 public void HandleRequest(IColleague colleague, string request)
 {
     foreach (var col in _listOfColleagues)
     {
         if (col != colleague)
         {
             col.ReceiveRequest(request);
         }
     }
 }
Exemplo n.º 15
0
 public void broadcastMsg(IColleague <T> from, T msg)
 {
     foreach (IColleague <T> c in _colleagues)
     {
         if (c != from || from == null)
         {
             c.receiveMsg(msg);
         }
     }
 }
Exemplo n.º 16
0
 public void Distribute(IColleague sender, string messageContents)
 {
     foreach (IColleague colleague in _colleagues
              .Where(c => c != sender)
              )
     {
         IMessage message = new Message(sender.Name, messageContents);
         colleague.Receive(message);
     }
 }
Exemplo n.º 17
0
        public MediatorWeight(decimal weightOption, decimal weightCredit, decimal weightLoan)
        {
            this._weightOption = weightOption;
            this._weightCredit = weightCredit;
            this._weightLoan   = weightLoan;

            this.Option = new OptionColleague();
            this.Credit = new CreditColleague();
            this.Loan   = new LoanColleague();
        }
Exemplo n.º 18
0
 void IMediator <T> .DistributeMessage(IColleague <T> sender, T message)
 {
     foreach (IColleague <T> c in colleagueList)
     {
         if (c != sender)    //don't need to send message to sender
         {
             c.ReceiveMessage(message);
         }
     }
 }
Exemplo n.º 19
0
 public void DistributeMessage(IColleague <T> sender, T message)
 {
     foreach (var colleague in this.ColleagueList)
     {
         if (colleague != sender)
         {
             colleague.ReceiveMessage(message);
         }
     }
 }
Exemplo n.º 20
0
 public void SendMessage(string message, IColleague colleague)
 {
     foreach (var x in ColleagueList)
     {
         if (x != colleague)
         {
             Console.WriteLine("\n" + colleague.Name + " has sent: " + message + " to " + x.Name + "\n");
             x.Receive(this, message);
         }
     }
 }
Exemplo n.º 21
0
        public void Send(object message, IColleague colleague)
        {
            if (colleague == _uploadFileViewModel)
            {
                _selectInputVariablesViewModel.Receive(message);
                _selectOutputVariablesViewModel.Receive(message);
            }

            OnPropertyChanged(nameof(SelectInputVariablesViewModel));
            OnPropertyChanged(nameof(SelectOutputVariablesViewModel));
        }
Exemplo n.º 22
0
 public void Send(string message, IColleague colleague)
 {
     if (colleague == FirstColleague)
     {
         ConcreteColleague2.Notify(message);
     }
     else
     {
         ConcreteColleague1.Notify(message);
     }
 }
Exemplo n.º 23
0
        public void RegisterColleague(IColleague colleague)
        {
            if (Colleagues.Contains(colleague))
            {
                return;
            }

            colleague.SetMediator(this);

            Colleagues.Add(colleague);
        }
 public void DistributeMessage(IColleague <T> sender, T message)
 {
     foreach (var c in this._colleagueList)
     {
         // not to send itself
         if (c != sender)
         {
             c.ReceiveMessage(message);
         }
     }
 }
Exemplo n.º 25
0
 public void Send(string msg, IColleague coll)
 {
     if (coll == Jack)
     {
         Jhon.Notify(msg);
     }
     else if (coll == Jhon)
     {
         Jack.Notify(msg);
     }
 }
Exemplo n.º 26
0
 public void ExecuteCommand(string command, IColleague receiver, params object[] args)
 {
     switch (command)
     {
     case "Listen":
     {
         (receiver as PlayerServiceProxyColleague).Listen(receiver.BondedColleague as Player, args[0] as LogicFacade);
         break;
     }
     }
 }
Exemplo n.º 27
0
 public void DistributeMessage(IColleague <T> sender, T message)
 {
     foreach (IColleague <T> colleague in colleagueList)
     {
         //Excpet for sender, Distribute the message to all the Registered collagues
         if (colleague != sender)
         {
             colleague.RecieveMessage(message);
         }
     }
 }
Exemplo n.º 28
0
 public void Register(IColleague colleague)
 {
     if (!registered.Contains(colleague))
     {
         registered.Add(colleague);
         colleague.Mediator = this;
         if (colleague.BondedColleague != null)
         {
             colleague.BondedColleague.Mediator = this;
         }
     }
 }
Exemplo n.º 29
0
        public void NotifyAll(string message, IColleague sender)
        {
            foreach (IColleague colleague in colleagues)
            {
                if (colleague == sender)
                {
                    continue;
                }

                colleague.Receive($"{message} from {sender}");
            }
        }
Exemplo n.º 30
0
        public void SendMessage(IColleague sender, string type, string content)
        {
            foreach (IColleague colleague in Colleagues)
            {
                if (colleague == sender)
                {
                    continue;
                }

                colleague.ReceiveMessage(type, content);
            }
        }
Exemplo n.º 31
0
        /// <summary>
        /// Registers a Colleague to a specific message
        /// </summary>
        /// <param name="colleague">The colleague to register</param>
        /// <param name="messages">The message to register to</param>
        public void Register(IColleague colleague, IEnumerable<string> messages)
        {
            foreach (string message in messages)
            {
                if (!_internalList.ContainsKey(message))
                {
                    _internalList[message] = new List<IColleague>(1);
                }
                else
                {
                    if (_internalList[message] == null)
                        _internalList[message] = new List<IColleague>(1);
                }

                _internalList[message].Add(colleague);
            }
        }
Exemplo n.º 32
0
 /// <summary>
 /// 中介者可以动态地与某个同事建立联系  
 /// </summary>
 /// <param name="name"></param>
 /// <param name="colleague"></param>
 public void AddColleague(String name, IColleague colleague)
 {
     //在中介者这里帮助具体同事建立起于中介者的联系
     colleague.SetMediator(this);
     this.Colleagues.Add(name, colleague);
 }
Exemplo n.º 33
0
 /// <summary>
 /// Registers a Colleague to a specific message
 /// </summary>
 /// <param name="colleague">The colleague to register</param>
 /// <param name="messages">The message to register to</param>
 public void Register(IColleague colleague, IEnumerable<string> messages)
 {
     foreach (string message in messages)
         internalList.AddValue(message, colleague);
 }