Пример #1
0
 /// <summary>
 /// listen or cancel listening to transceiver
 /// </summary>
 /// <param name="transceiver"></param>
 /// <param name="bListen"></param>
 private void Listen(IClientMailTransceiver transceiver, bool bListen)
 {
     if (bListen)
     {
         transceiver.ResetedEvent           += this.OnDispatcherReseted;
         transceiver.IncomingLetterEvent    += this.OnIncomingLetter;
         transceiver.TransmissionErrorEvent += this.OnTransmissionError;
     }
     else
     {
         transceiver.ResetedEvent           -= this.OnDispatcherReseted;
         transceiver.IncomingLetterEvent    -= this.OnIncomingLetter;
         transceiver.TransmissionErrorEvent -= this.OnTransmissionError;
     }
 }
Пример #2
0
        internal IClientMailTransceiver Connect(IClientMailTransceiver dispatcher)
        {
            if (this.transceiver != null)
            {
                // dispose the old dispatcher
                this.transceiver.Dispose();
                // unregiseter event listenings on old dispatcher
                this.Listen(this.transceiver, false);
            }
            this.transceiver = dispatcher;
            // register event listenings on new dispatcher
            this.Listen(this.transceiver, true);

            return(dispatcher);
        }
Пример #3
0
 /// <summary>
 /// destroy this postoffice, the registered mailboxes and the transceiver
 /// </summary>
 public void Dispose()
 {
     rwlsDictName2MailBox.EnterWriteLock();
     foreach (var mailBox in dictName2MailBox.Values)
     {
         mailBox.Destroy();
     }
     dictName2MailBox.Clear();
     rwlsDictName2MailBox.ExitWriteLock();
     if (this.transceiver != null)
     {
         this.Listen(this.transceiver, false);
         this.transceiver.Dispose();
         this.transceiver = null;
     }
 }