コード例 #1
0
        private static uint KeepListener(
            GLib.Signal.EmissionHook listener,
            string objType, string signalName)
        {
            GLib.GType type = GLib.GType.FromName(objType);
            if (type != GLib.GType.Invalid)
            {
                //FIXME: drop this workaround for bug#386950
                if (signalName.Contains("property"))
                {
                    return(0);
                }

                lock (listenerListSync)
                {
                    ListenerInfo info = new ListenerInfo();
                    info.Id         = (uint)ListenerList.Count + 1;
                    info.SignalName = signalName;
                    info.Type       = type;
                    info.HookId     = GLib.Signal.AddEmissionHook(signalName, type, listener);
                    ListenerList.Add(info.Id, info);
                    return(info.Id);
                }
            }
            else
            {
                throw new NotSupportedException("Invalid object type " + objType);
            }
        }
コード例 #2
0
 public void AddChangeListener(IPreferenceChangeListener listener)
 {
     if (_listenerList == null)
     {
         _listenerList = new ListenerList <IPreferenceChangeListener>();
     }
     _listenerList.Add(listener);
 }
コード例 #3
0
        protected void ProtectedAddListener(object source, IWeakEventListener listener)
        {
            ListenerList list = sourceData[source] as ListenerList;

            if (list != null)
            {
                list.Add(listener);
            }
        }
コード例 #4
0
ファイル: Session.cs プロジェクト: Ricordanza/poderosa
        public override void InitializePlugin(IPoderosaWorld poderosa) {
            _instance = this;
            base.InitializePlugin(poderosa);
            _sessionMap = new TypedHashtable<ISession, SessionHost>();
            _documentMap = new TypedHashtable<IPoderosaDocument, DocumentHost>();
            _docViewRelationHandler = poderosa.PluginManager.CreateExtensionPoint("org.poderosa.core.sessions.docViewRelationHandler", typeof(IDocViewRelationEventHandler), this);
            _activeDocumentChangeListeners = new ListenerList<IActiveDocumentChangeListener>();
            _activeDocumentChangeListeners.Add(new WindowCaptionManager());

            _sessionListeners = new ListenerList<ISessionListener>();
        }
コード例 #5
0
        public override void InitializePlugin(IPoderosaWorld poderosa)
        {
            _instance = this;
            base.InitializePlugin(poderosa);
            _sessionMap                    = new TypedHashtable <ISession, SessionHost>();
            _documentMap                   = new TypedHashtable <IPoderosaDocument, DocumentHost>();
            _docViewRelationHandler        = poderosa.PluginManager.CreateExtensionPoint("org.poderosa.core.sessions.docViewRelationHandler", typeof(IDocViewRelationEventHandler), this);
            _activeDocumentChangeListeners = new ListenerList <IActiveDocumentChangeListener>();
            _activeDocumentChangeListeners.Add(new WindowCaptionManager());

            _sessionListeners = new ListenerList <ISessionListener>();
        }
コード例 #6
0
        private async void GetListeners()
        {
            var listeners = await ListenerAPI.GetAllListeners();

            foreach (var listener in listeners)
            {
                Listeners.Add(new Listener {
                    ListenerName = listener.ListenerName, ListenerGuid = listener.ListenerGuid, ListenerType = listener.Type
                });
                ListenerList.Add(string.Format("{0} : {1}", listener.ListenerName, listener.Type));
            }
        }
コード例 #7
0
        public void Add(Guid EventID, Del_HandleEvent EventHandler, enPriority HandlePriority)
        {
            //Case:Exist eventId matched ListenerGroup
            if (m_Listeners.TryGetValue(EventID, out var ListenerGroup))
            {
                //Case: Exist priority matched Listener List
                //Act: Just Add Listener
                if (ListenerGroup.TryGetValue(HandlePriority, out var ListenerList))
                {
                    m_PrioritiesDic.Add(EventHandler, HandlePriority);

                    ListenerList.Add(EventHandler);
                }
                //Case: no priority matched Listener List
                //Act: Make a instnace of Listener list first and Add Listener
                else
                {
                    ListenerList = new List <Del_HandleEvent>();

                    m_PrioritiesDic.Add(EventHandler, HandlePriority);

                    ListenerList.Add(EventHandler);

                    ListenerGroup.Add(HandlePriority, ListenerList);
                }
            }
            //Case: no eventId matched ListenerGroup
            else
            {
                //Make an instance of ListenerGroup
                ListenerGroup = new SortedDictionary <enPriority, List <Del_HandleEvent> >();

                //Make an instance of ListenerList
                List <Del_HandleEvent> ListenerList = new List <Del_HandleEvent>();

                //Save to dictionary
                m_PrioritiesDic.Add(EventHandler, HandlePriority);

                //add Handler
                ListenerList.Add(EventHandler);

                //add ListenerList
                ListenerGroup.Add(HandlePriority, ListenerList);

                //add ListenerGroup
                m_Listeners.Add(EventID, ListenerGroup);
            }
        }
コード例 #8
0
        private void AddListener(object source, IWeakEventListener listener, Delegate handler)
        {
            object sourceKey = (source != null) ? source : StaticSource;

            using (Table.WriteLock)
            {
                ListenerList list = (ListenerList)Table[this, sourceKey];

                if (list == null)
                {
                    // no entry in the table - add a new one
                    list = NewListenerList();
                    Table[this, sourceKey] = list;

                    // listen for the desired event
                    StartListening(source);
                }

                // make sure list is ready for writing
                if (ListenerList.PrepareForWriting(ref list))
                {
                    Table[this, source] = list;
                }

                // add a target to the list of listeners
                if (handler != null)
                {
                    list.AddHandler(handler);
                }
                else
                {
                    list.Add(listener);
                }

                // schedule a cleanup pass (heuristic (b) described above)
                ScheduleCleanup();
            }
        }
コード例 #9
0
ファイル: HelloUtil.cs プロジェクト: ABEMBARKA/monoUI
 private static uint KeepListener(
     GLib.Signal.EmissionHook listener,
     string objType, string signalName, string hookData)
 {
     GLib.GType type = GLib.GType.FromName(objType);
     if (type != GLib.GType.Invalid)
     {
         lock (listenerListMutex)
         {
             ListenerInfo info = new ListenerInfo();
             info.Id         = (uint)ListenerList.Count + 1;
             info.SignalName = signalName;
             info.Type       = type;
             info.HookId     = GLib.Signal.AddEmissionHook(signalName, type, listener);
             ListenerList.Add(info.Id, info);
             return(info.Id);
         }
     }
     else
     {
         throw new NotSupportedException("Invalid object type " + objType);
     }
 }
コード例 #10
0
            protected void CopyTo(ListenerList newList)
            {
                IWeakEventListener iwel;

                for (int k = 0, n = Count; k < n; ++k)
                {
                    Listener listener = GetListener(k);
                    if (listener.Target != null)
                    {
                        if (listener.HasHandler)
                        {
                            Delegate handler = listener.Handler;
                            if (handler != null)
                            {
                                newList.AddHandler(handler);
                            }
                        }
                        else if ((iwel = listener.Target as IWeakEventListener) != null)
                        {
                            newList.Add(iwel);
                        }
                    }
                }
            }
コード例 #11
0
 internal void Add(IWeakEventListener listener)
 {
     ListenerList.PrepareForWriting(ref _listeners);
     _listeners.Add(listener);
 }
コード例 #12
0
 //Listener
 public void AddActiveDocumentChangeListener(IActiveDocumentChangeListener listener)
 {
     _activeDocumentChangeListeners.Add(listener);
 }
コード例 #13
0
            public ListenerList GetListenerList(string propertyName)
            {
                ListenerList list;

                if (!String.IsNullOrEmpty(propertyName))
                {
                    // source has changed a particular property.  Notify targets
                    // who are listening either for this property or for all properties.
                    PropertyRecord pr = (PropertyRecord)_dict[propertyName];
                    ListenerList <PropertyChangedEventArgs> listeners = (pr == null) ? null : pr.List;
                    PropertyRecord genericRecord = (PropertyRecord)_dict[String.Empty];
                    ListenerList <PropertyChangedEventArgs> genericListeners = (genericRecord == null) ? null : genericRecord.List;

                    if (genericListeners == null)
                    {
                        if (listeners != null)
                        {
                            list = listeners;           // only specific listeners
                        }
                        else
                        {
                            list = ListenerList.Empty;  // no listeners at all
                        }
                    }
                    else
                    {
                        if (listeners != null)
                        {
                            // there are both specific and generic listeners -
                            // combine the two lists.
                            list = new ListenerList <PropertyChangedEventArgs>(listeners.Count + genericListeners.Count);
                            for (int i = 0, n = listeners.Count; i < n; ++i)
                            {
                                list.Add(listeners[i]);
                            }
                            for (int i = 0, n = genericListeners.Count; i < n; ++i)
                            {
                                list.Add(genericListeners[i]);
                            }
                        }
                        else
                        {
                            list = genericListeners;    // only generic listeners
                        }
                    }
                }
                else
                {
                    // source has changed all properties.  Notify all targets.
                    // Use previously calculated combined list, if available.
                    PropertyRecord pr = (PropertyRecord)_dict[AllListenersKey];
                    ListenerList <PropertyChangedEventArgs> pcList = (pr == null) ? null : pr.List;

                    if (pcList == null)
                    {
                        // make one pass to compute the size of the combined list.
                        // This avoids expensive reallocations.
                        int size = 0;
                        foreach (DictionaryEntry de in _dict)
                        {
                            Debug.Assert((String)de.Key != AllListenersKey, "special key should not appear");
                            size += ((PropertyRecord)de.Value).List.Count;
                        }

                        // create the combined list
                        pcList = new ListenerList <PropertyChangedEventArgs>(size);

                        // fill in the combined list
                        foreach (DictionaryEntry de in _dict)
                        {
                            ListenerList listeners = ((PropertyRecord)de.Value).List;
                            for (int i = 0, n = listeners.Count; i < n; ++i)
                            {
                                pcList.Add(listeners.GetListener(i));
                            }
                        }

                        // save the result for future use (see below)
                        _proposedAllListenersList = pcList;
                    }

                    list = pcList;
                }

                return(list);
            }
コード例 #14
0
ファイル: WeakEventManager.cs プロジェクト: JianwenSun/cc
            protected void CopyTo(ListenerList newList)
            {
                IWeakEventListener iwel;

                for (int k=0, n=Count; k<n; ++k)
                {
                    Listener listener = GetListener(k);
                    if (listener.Target != null)
                    {
                        if (listener.HasHandler)
                        {
                            Delegate handler = listener.Handler;
                            if (handler != null)
                            {
                                newList.AddHandler(handler);
                            }
                        }
                        else if ((iwel = listener.Target as IWeakEventListener) != null)
                        {
                            newList.Add(iwel);
                        }
                    }
                }
            }
コード例 #15
0
            public ListenerList GetListenerList(string propertyName)
            {
                ListenerList list;

                if (!String.IsNullOrEmpty(propertyName))
                {
                    // source has changed a particular property.  Notify targets
                    // who are listening either for this property or for all properties.
                    PropertyRecord pr = (PropertyRecord)_dict[propertyName];
                    ListenerList<PropertyChangedEventArgs> listeners = (pr == null) ? null : pr.List;
                    PropertyRecord genericRecord = (PropertyRecord)_dict[String.Empty];
                    ListenerList<PropertyChangedEventArgs> genericListeners = (genericRecord == null) ? null : genericRecord.List;

                    if (genericListeners == null)
                    {
                        if (listeners != null)
                        {
                            list = listeners;           // only specific listeners
                        }
                        else
                        {
                            list = ListenerList.Empty;  // no listeners at all
                        }
                    }
                    else
                    {
                        if (listeners != null)
                        {
                            // there are both specific and generic listeners -
                            // combine the two lists.
                            list = new ListenerList<PropertyChangedEventArgs>(listeners.Count + genericListeners.Count);
                            for (int i=0, n=listeners.Count; i<n; ++i)
                                list.Add(listeners[i]);
                            for (int i=0, n=genericListeners.Count; i<n; ++i)
                                list.Add(genericListeners[i]);
                        }
                        else
                        {
                            list = genericListeners;    // only generic listeners
                        }
                    }
                }
                else
                {
                    // source has changed all properties.  Notify all targets.
                    // Use previously calculated combined list, if available.
                    PropertyRecord pr = (PropertyRecord)_dict[AllListenersKey];
                    ListenerList<PropertyChangedEventArgs> pcList = (pr == null) ? null : pr.List;

                    if (pcList == null)
                    {
                        // make one pass to compute the size of the combined list.
                        // This avoids expensive reallocations.
                        int size = 0;
                        foreach (DictionaryEntry de in _dict)
                        {
                            Debug.Assert((String)de.Key != AllListenersKey, "special key should not appear");
                            size += ((PropertyRecord)de.Value).List.Count;
                        }

                        // create the combined list
                        pcList = new ListenerList<PropertyChangedEventArgs>(size);

                        // fill in the combined list
                        foreach (DictionaryEntry de in _dict)
                        {
                            ListenerList listeners = ((PropertyRecord)de.Value).List;
                            for (int i=0, n=listeners.Count;  i<n;  ++i)
                            {
                                pcList.Add(listeners.GetListener(i));
                            }
                        }

                        // save the result for future use (see below)
                        _proposedAllListenersList = pcList;
                    }

                    list = pcList;
                }

                return list;
            }
コード例 #16
0
ファイル: CommandManager.cs プロジェクト: yueker/poderosa
 public void AddKeyBindChangeListener(IKeyBindChangeListener listener)
 {
     _keyBindChangeListener.Add(listener);
 }
コード例 #17
0
        // event handler for PropertyChanged event
        private void OnPropertyChanged(object sender, PropertyChangedEventArgs args)
        {
            ListenerList list;
            string       propertyName = args.PropertyName;

            // get the list of listeners
            using (ReadLock)
            {
                // look up the list of listeners
                HybridDictionary dict = (HybridDictionary)this[sender];

                if (dict == null)
                {
                    // this can happen when the last listener stops listening, but the
                    // source raises the event on another thread after the dictionary
                    // has been removed (bug 1235351)
                    list = ListenerList.Empty;
                }
                else if (!String.IsNullOrEmpty(propertyName))
                {
                    // source has changed a particular property.  Notify targets
                    // who are listening either for this property or for all properties.
                    ListenerList <PropertyChangedEventArgs> listeners        = (ListenerList <PropertyChangedEventArgs>)dict[propertyName];
                    ListenerList <PropertyChangedEventArgs> genericListeners = (ListenerList <PropertyChangedEventArgs>)dict[String.Empty];

                    if (genericListeners == null)
                    {
                        if (listeners != null)
                        {
                            list = listeners;           // only specific listeners
                        }
                        else
                        {
                            list = ListenerList.Empty;  // no listeners at all
                        }
                    }
                    else
                    {
                        if (listeners != null)
                        {
                            // there are both specific and generic listeners -
                            // combine the two lists.
                            list = new ListenerList <PropertyChangedEventArgs>(listeners.Count + genericListeners.Count);
                            for (int i = 0, n = listeners.Count; i < n; ++i)
                            {
                                list.Add(listeners.GetListener(i));
                            }
                            for (int i = 0, n = genericListeners.Count; i < n; ++i)
                            {
                                list.Add(genericListeners.GetListener(i));
                            }
                        }
                        else
                        {
                            list = genericListeners;    // only generic listeners
                        }
                    }
                }
                else
                {
                    // source has changed all properties.  Notify all targets.
                    // Use previously calculated combined list, if available.
                    list = (ListenerList)dict[AllListenersKey];

                    if (list == null)
                    {
                        // make one pass to compute the size of the combined list.
                        // This avoids expensive reallocations.
                        int size = 0;
                        foreach (DictionaryEntry de in dict)
                        {
                            Debug.Assert((String)de.Key != AllListenersKey, "special key should not appear");
                            size += ((ListenerList)de.Value).Count;
                        }

                        // create the combined list
                        list = new ListenerList <PropertyChangedEventArgs>(size);

                        // fill in the combined list
                        foreach (DictionaryEntry de in dict)
                        {
                            ListenerList listeners = ((ListenerList)de.Value);
                            for (int i = 0, n = listeners.Count; i < n; ++i)
                            {
                                list.Add(listeners.GetListener(i));
                            }
                        }

                        // save the result for future use (see below)
                        _proposedAllListenersList = list;
                    }
                }

                // mark the list "in use", even outside the read lock,
                // so that any writers will know not to modify it (they'll
                // modify a clone intead).
                list.BeginUse();
            }

            // deliver the event, being sure to undo the effect of BeginUse().
            try
            {
                DeliverEventToList(sender, args, list);
            }
            finally
            {
                list.EndUse();
            }

            // if we calculated an AllListeners list, we should now try to store
            // it in the dictionary so it can be used in the future.  This must be
            // done under a WriteLock - which is why we didn't do it immediately.
            if (_proposedAllListenersList == list)
            {
                using (WriteLock)
                {
                    // test again, in case another thread changed _proposedAllListersList.
                    if (_proposedAllListenersList == list)
                    {
                        HybridDictionary dict = (HybridDictionary)this[sender];
                        if (dict != null)
                        {
                            dict[AllListenersKey] = list;
                        }

                        _proposedAllListenersList = null;
                    }

                    // Another thread could have changed _proposedAllListersList
                    // since we set it (earlier in this method), either
                    // because it calculated a new one while handling a PropertyChanged(""),
                    // or because it added/removed/purged a listener.
                    // In that case, we will simply abandon our proposed list and we'll
                    // have to compute it again the next time.  But that only happens
                    // if there's thread contention.  It's not worth doing something
                    // more complicated just for that case.
                }
            }
        }
コード例 #18
0
        public void Run(string[] args)
        {
            if (args.Length == 0)
            {
                Help();
                return;
            }

            var e = args.GetEnumerator();

            while (e.MoveNext())
            {
                var a = ((string)e.Current).ToLowerInvariant();
                if (a == "-help" || a == "-h" || a == "-?")
                {
                    Help();
                    return;
                }
                else if (a == "-output" || a == "-out")
                {
                    if (e.MoveNext())
                    {
                        ViewFactory.Builder.SetPath((string)e.Current);
                        View = ViewFactory.CreateView();
                    }
                    else
                    {
                        throw new Exception(BAD_COMMAND_LINE_SYNTAX);
                    }
                }
                else if (a == "-target")
                {
                    if (e.MoveNext())
                    {
                        target = new ConnectionTarget();
                        if (!target.Parse((string)e.Current))
                        {
                            throw new Exception(BAD_TARGET);
                        }
                    }
                    else
                    {
                        throw new Exception(BAD_COMMAND_LINE_SYNTAX);
                    }
                }
                else if (a == "-address" || a == "-addr")
                {
                    if (e.MoveNext())
                    {
                        if (target == null)
                        {
                            throw new Exception(NO_TARGET);
                        }
                        target.Address = (string)e.Current;
                    }
                    else
                    {
                        throw new Exception(BAD_COMMAND_LINE_SYNTAX);
                    }
                }
                else if (a == "-port")
                {
                    if (e.MoveNext())
                    {
                        nonSecurePort = int.Parse((string)e.Current);
                    }
                    else
                    {
                        throw new Exception(BAD_COMMAND_LINE_SYNTAX);
                    }
                    if (nonSecurePort <= 0 || 65536 <= nonSecurePort)
                    {
                        throw new Exception(BAD_NPORT);
                    }
                }
                else if (a == "-secureport" || a == "-secport")
                {
                    if (e.MoveNext())
                    {
                        securePort = int.Parse((string)e.Current);
                    }
                    else
                    {
                        throw new Exception(BAD_COMMAND_LINE_SYNTAX);
                    }
                    if (securePort <= 0 || 65536 <= securePort)
                    {
                        throw new Exception(BAD_SPORT);
                    }
                }
                else if (a == "-certpath")
                {
                    if (e.MoveNext())
                    {
                        certificatePath = (string)e.Current;
                    }
                    else
                    {
                        throw new Exception(BAD_COMMAND_LINE_SYNTAX);
                    }
                }
                else if (a == "-certpassword" || a == "-certpasswd" || a == "-certpass")
                {
                    if (e.MoveNext())
                    {
                        certificatePassword = (string)e.Current;
                    }
                    else
                    {
                        throw new Exception(BAD_COMMAND_LINE_SYNTAX);
                    }
                }
                else if (a == "-shutdown")
                {
                    commandRequest = "shutdown";
                }
                else if (a == "-commandtarget" || a == "-cmdtarget")
                {
                    if (e.MoveNext())
                    {
                        commandTarget = (string)e.Current;
                    }
                    else
                    {
                        throw new Exception(BAD_COMMAND_LINE_SYNTAX);
                    }
                    var ss = commandTarget.Split(new char[] { ':' });
                    if (ss.Length == 2)
                    {
                        commandTarget = ss[0];
                        commandPort   = int.Parse(ss[1]);
                    }
                    else if (ss.Length != 1)
                    {
                        throw new Exception(BAD_COMMAND_LINE_SYNTAX);
                    }
                }
                else if (a == "-commandport" || a == "-cmdport")
                {
                    if (e.MoveNext())
                    {
                        commandPort = int.Parse((string)e.Current);
                    }
                    else
                    {
                        throw new Exception(BAD_COMMAND_LINE_SYNTAX);
                    }
                }
#if DEBUG
                else if (a == "-debug")
                {
                    System.Diagnostics.Debugger.Launch();
                }
#endif
                else
                {
                    throw new Exception(BAD_COMMAND_LINE_SYNTAX);
                }
            }

            if (target != null)
            {
                if (nonSecurePort == 0 && target.Type == ConnectionType.Raw)
                {
                    nonSecurePort = HttpConstants.HTTP_PORT;
                }
                if (nonSecurePort > 0)
                {
                    var nonSecureListener = new NonSecureListener()
                    {
                        Destination = target,
                        Port        = nonSecurePort
                    };
                    ListenerList.Add(nonSecureListener);
                }

                if ((certificatePath != null && certificatePassword == null) || (certificatePath == null && certificatePassword != null))
                {
                    throw new Exception(CERTIFICATE_PATH_AND_PASSWORD);
                }
                if (securePort == 0 && (target.Type == ConnectionType.Encrypted || certificatePath != null))
                {
                    securePort = HttpConstants.HTTPS_PORT;
                }
                if (securePort > 0)
                {
                    if (certificatePath == null || certificatePassword == null)
                    {
                        throw new Exception(CERTIFICATE_PATH_AND_PASSWORD);
                    }
                    var secureListener = new SecureListener()
                    {
                        Destination               = target,
                        Port                      = securePort,
                        ServerCertificatePath     = certificatePath,
                        ServerCertificatePassword = certificatePassword
                    };
                    ListenerList.Add(secureListener);
                }
            }

            if (ListenerList.Count > 0)
            {
                if (commandRequest != null)
                {
                    throw new Exception(EXCLUSIVE_REQUESTS);
                }

                var commandListener = new CommandListener()
                {
                    Port       = commandPort,
                    OnShutdown = ShutDown
                };
                ListenerList.Add(commandListener);

                foreach (var listener in ListenerList)
                {
                    listener.Start();
                }

                TerminateEvent.WaitOne();

                foreach (var listener in ListenerList)
                {
                    listener.Stop();
                }

                foreach (var listener in ListenerList)
                {
                    listener.Wait();
                }
            }
            else if (commandRequest != null)
            {
                var commandClient = new CommandClient()
                {
                    Hostname = commandTarget,
                    Port     = commandPort
                };
                commandClient.Send(commandRequest);
            }
            else
            {
                throw new Exception(BAD_COMMAND_LINE_SYNTAX);
            }
        }
コード例 #19
0
        // event handler for PropertyChanged event
        private void OnPropertyChanged(object sender, PropertyChangedEventArgs args)
        {
            ListenerList list;
            string propertyName = args.PropertyName;

            // get the list of listeners
            using (ReadLock)
            {
                // look up the list of listeners
                HybridDictionary dict = (HybridDictionary)this[sender];

                if (dict == null)
                {
                    // this can happen when the last listener stops listening, but the
                    // source raises the event on another thread after the dictionary
                    // has been removed (bug 1235351)
                    list = ListenerList.Empty;
                }
                else if (!String.IsNullOrEmpty(propertyName))
                {
                    // source has changed a particular property.  Notify targets
                    // who are listening either for this property or for all properties.
                    ListenerList<PropertyChangedEventArgs> listeners = (ListenerList<PropertyChangedEventArgs>)dict[propertyName];
                    ListenerList<PropertyChangedEventArgs> genericListeners = (ListenerList<PropertyChangedEventArgs>)dict[String.Empty];

                    if (genericListeners == null)
                    {
                        if (listeners != null)
                        {
                            list = listeners;           // only specific listeners
                        }
                        else
                        {
                            list = ListenerList.Empty;  // no listeners at all
                        }
                    }
                    else
                    {
                        if (listeners != null)
                        {
                            // there are both specific and generic listeners -
                            // combine the two lists.
                            list = new ListenerList<PropertyChangedEventArgs>(listeners.Count + genericListeners.Count);
                            for (int i=0, n=listeners.Count; i<n; ++i)
                                list.Add(listeners.GetListener(i));
                            for (int i=0, n=genericListeners.Count; i<n; ++i)
                                list.Add(genericListeners.GetListener(i));
                        }
                        else
                        {
                            list = genericListeners;    // only generic listeners
                        }
                    }
                }
                else
                {
                    // source has changed all properties.  Notify all targets.
                    // Use previously calculated combined list, if available.
                    list = (ListenerList)dict[AllListenersKey];

                    if (list == null)
                    {
                        // make one pass to compute the size of the combined list.
                        // This avoids expensive reallocations.
                        int size = 0;
                        foreach (DictionaryEntry de in dict)
                        {
                            Debug.Assert((String)de.Key != AllListenersKey, "special key should not appear");
                            size += ((ListenerList)de.Value).Count;
                        }

                        // create the combined list
                        list = new ListenerList<PropertyChangedEventArgs>(size);

                        // fill in the combined list
                        foreach (DictionaryEntry de in dict)
                        {
                            ListenerList listeners = ((ListenerList)de.Value);
                            for (int i=0, n=listeners.Count;  i<n;  ++i)
                            {
                                list.Add(listeners.GetListener(i));
                            }
                        }

                        // save the result for future use (see below)
                        _proposedAllListenersList = list;
                    }
                }

                // mark the list "in use", even outside the read lock,
                // so that any writers will know not to modify it (they'll
                // modify a clone intead).
                list.BeginUse();
            }

            // deliver the event, being sure to undo the effect of BeginUse().
            try
            {
                DeliverEventToList(sender, args, list);
            }
            finally
            {
                list.EndUse();
            }

            // if we calculated an AllListeners list, we should now try to store
            // it in the dictionary so it can be used in the future.  This must be
            // done under a WriteLock - which is why we didn't do it immediately.
            if (_proposedAllListenersList == list)
            {
                using (WriteLock)
                {
                    // test again, in case another thread changed _proposedAllListersList.
                    if (_proposedAllListenersList == list)
                    {
                        HybridDictionary dict = (HybridDictionary)this[sender];
                        if (dict != null)
                        {
                            dict[AllListenersKey] = list;
                        }

                        _proposedAllListenersList = null;
                    }

                    // Another thread could have changed _proposedAllListersList
                    // since we set it (earlier in this method), either
                    // because it calculated a new one while handling a PropertyChanged(""),
                    // or because it added/removed/purged a listener.
                    // In that case, we will simply abandon our proposed list and we'll
                    // have to compute it again the next time.  But that only happens
                    // if there's thread contention.  It's not worth doing something
                    // more complicated just for that case.
                }
            }
        }
コード例 #20
0
 public void AddListener(ITerminalSettingsChangeListener l)
 {
     _listeners.Add(l);
 }
コード例 #21
0
 public void AddSessionListener(ISessionListener listener)
 {
     _sessionListeners.Add(listener);
 }