Ejemplo n.º 1
0
 public void ReleaseEventHandlers()
 {
     render    = new EventRegistrationTokenTable <EventHandler <RenderEventArgs> >();
     command   = new EventRegistrationTokenTable <EventHandler <CommandEventArgs> >();
     testReady = new EventRegistrationTokenTable <EventHandler <TestReadyEventArgs> >();
     testSetup = new EventRegistrationTokenTable <EventHandler <TestSetupEventArgs> >();
 }
 internal void OnQualityChanged()
 {
     //here you raise the event for every subscriber
     EventRegistrationTokenTable <EventHandler <QualityChangedEventArgs> >
     .GetOrCreateEventRegistrationTokenTable(ref m_NumberChangedTokenTable)
     .InvocationList?.Invoke(this, new QualityChangedEventArgs(oldQuality, Quality));
 }
        public void GetOrCreateEventRegistrationTokenTable_NullTable_ReturnsNewTable()
        {
            EventRegistrationTokenTable <Delegate> tokenTable = null;
            EventRegistrationTokenTable <Delegate> result     = EventRegistrationTokenTable <Delegate> .GetOrCreateEventRegistrationTokenTable(ref tokenTable);

            Assert.Null(result.InvocationList);
        }
        public void RemoveEventHandler_RemoveMethodHasTarget_Success()
        {
            bool removeMethodCalled = false;
            Delegate handler = new EventHandler(EventHandlerMethod1);

            var tokenTable = new EventRegistrationTokenTable<Delegate>();
            EventRegistrationToken addToken = tokenTable.AddEventHandler(handler);

            Action<EventRegistrationToken> removeMethod = token =>
            {
                Assert.False(removeMethodCalled);
                removeMethodCalled = true;
                Assert.Equal(addToken, token);
            };
            WindowsRuntimeMarshal.AddEventHandler(eventHandler => addToken, removeMethod, handler);

            // Removing with the same handler but with a different method is a nop.
            WindowsRuntimeMarshal.RemoveEventHandler(token => removeMethodCalled = true, handler);
            Assert.False(removeMethodCalled);

            WindowsRuntimeMarshal.RemoveEventHandler(DifferentRemoveMethod, handler);
            Assert.False(removeMethodCalled);

            // Removing with a different handler but with the same method is a nop.
            WindowsRuntimeMarshal.RemoveEventHandler(removeMethod, new EventHandler(EventHandlerMethod2));
            Assert.False(removeMethodCalled);

            // Removing the same handler and the same method works.
            WindowsRuntimeMarshal.RemoveEventHandler(removeMethod, handler);
            Assert.True(removeMethodCalled);
        }
        public void RemoveEventHandler_RemoveMethodHasNoTarget_Success()
        {
            Delegate handler = new EventHandler(EventHandlerMethod1);

            var tokenTable = new EventRegistrationTokenTable<Delegate>();
            ExpectedRemoveToken = tokenTable.AddEventHandler(handler);

            Action<EventRegistrationToken> removeMethod = RemoveMethod;
            WindowsRuntimeMarshal.AddEventHandler(eventHandler => ExpectedRemoveToken, removeMethod, handler);

            // Removing with the same handler but with a different method is a nop.
            WindowsRuntimeMarshal.RemoveEventHandler(token => RemoveMethodCalled = true, handler);
            Assert.False(RemoveMethodCalled);

            WindowsRuntimeMarshal.RemoveEventHandler(DifferentRemoveMethod, handler);
            Assert.False(RemoveMethodCalled);

            // Removing with a different handler but with the same method is a nop.
            WindowsRuntimeMarshal.RemoveEventHandler(removeMethod, new EventHandler(EventHandlerMethod2));
            Assert.False(RemoveMethodCalled);

            // Removing the same handler and the same method works.
            WindowsRuntimeMarshal.RemoveEventHandler(removeMethod, handler);
            Assert.True(RemoveMethodCalled);
        }
        public void RemoveAllEventHandlers_RemoveMethodHasNoTarget_Success()
        {
            Delegate handler = new EventHandler(EventHandlerMethod1);

            var tokenTable = new EventRegistrationTokenTable<Delegate>();
            EventRegistrationToken token1 = tokenTable.AddEventHandler(handler);
            EventRegistrationToken token2 = tokenTable.AddEventHandler(handler);
            EventRegistrationToken token3 = tokenTable.AddEventHandler(handler);

            Action<EventRegistrationToken> removeMethod = RemoveAllMethod;
            WindowsRuntimeMarshal.AddEventHandler(eventHandler => token1, removeMethod, handler);
            WindowsRuntimeMarshal.AddEventHandler(eventHandler => token2, removeMethod, handler);

            bool removeMethodWithTargetCalled = false;
            WindowsRuntimeMarshal.AddEventHandler(eventHandler => token3, token => removeMethodWithTargetCalled = false, handler);

            // Removing with the same handler but with a different method is a nop.
            WindowsRuntimeMarshal.RemoveAllEventHandlers(token => RemoveMethodCalled = true);
            Assert.Empty(RemoveAllTokens);
            Assert.False(DifferentRemoveAllMethodCalled);
            Assert.False(removeMethodWithTargetCalled);

            WindowsRuntimeMarshal.RemoveAllEventHandlers(DifferentRemoveAllMethod);
            Assert.Empty(RemoveAllTokens);
            Assert.False(DifferentRemoveAllMethodCalled);
            Assert.False(removeMethodWithTargetCalled);

            // Removing the same handler and the same method works.
            WindowsRuntimeMarshal.RemoveAllEventHandlers(removeMethod);
            Assert.Equal(new EventRegistrationToken[] { token1, token2 }, RemoveAllTokens);
            Assert.False(DifferentRemoveAllMethodCalled);
            Assert.False(removeMethodWithTargetCalled);
        }
        public void GetOrCreateEventRegistrationTokenTable_NonNullTable_ReturnsEventTable()
        {
            var tokenTable = new EventRegistrationTokenTable <Delegate>();
            EventRegistrationTokenTable <Delegate> result = EventRegistrationTokenTable <Delegate> .GetOrCreateEventRegistrationTokenTable(ref tokenTable);

            Assert.Same(tokenTable, result);
        }
Ejemplo n.º 8
0
        public string RaiseManualEvent(int number)
        {
            WinRTDelegate d = EventRegistrationTokenTable <WinRTDelegate>
                              .GetOrCreateEventRegistrationTokenTable(ref m_manualEvent).InvocationList;

            return((d == null) ? "No callbacks registered" : d(number));
        }
Ejemplo n.º 9
0
        void IAo3TrackHelper.Reset()
        {
            EventRegistrationTokenTable <EventHandler <object> > .GetOrCreateEventRegistrationTokenTable(ref _JumpToLastLocationEvent).InvocationList = null;

            EventRegistrationTokenTable <EventHandler <object> > .GetOrCreateEventRegistrationTokenTable(ref _AlterFontSizeEvent).InvocationList = null;

            EventRegistrationTokenTable <EventHandler <object> > .GetOrCreateEventRegistrationTokenTable(ref _RequestSpeechText).InvocationList = null;
        }
Ejemplo n.º 10
0
        public void log(string text)
        {
            Debug.WriteLine(text);

            EventHandler <string> temp = EventRegistrationTokenTable <EventHandler <string> > .GetOrCreateEventRegistrationTokenTable(ref onLog).InvocationList;

            temp?.Invoke(null, text);
        }
 public CoreWindowKeyProvider(CoreWindow window)
 {
     this.window         = window;
     this.upHandlers     = new Dictionary <EventRegistrationToken, TypedEventHandler <CoreWindow, KeyEventArgs> >();
     this.upTokenTable   = new EventRegistrationTokenTable <TypedEventHandler <CoreWindow, KeyEventArgs> >();
     this.downHandlers   = new Dictionary <EventRegistrationToken, TypedEventHandler <CoreWindow, KeyEventArgs> >();
     this.downTokenTable = new EventRegistrationTokenTable <TypedEventHandler <CoreWindow, KeyEventArgs> >();
 }
        public void InvocationList_SetNull_GetReturnsNull()
        {
            var tokenTable = new EventRegistrationTokenTable <Delegate>();

            tokenTable.AddEventHandler(new EventHandler(EventHandlerMethod1));

            tokenTable.InvocationList = null;
            Assert.Null(tokenTable.InvocationList);
        }
Ejemplo n.º 13
0
        public void Fire(object sender, T argument)
        {
            EventHandler <T> temp = EventRegistrationTokenTable <EventHandler <T> > .GetOrCreateEventRegistrationTokenTable(ref m_EventTokenTable).InvocationList;

            if (temp != null)
            {
                temp(sender, argument);
            }
        }
Ejemplo n.º 14
0
        internal void OnStatusChanged(string code)
        {
            var temp =
                EventRegistrationTokenTable <EventHandler <string> >
                .GetOrCreateEventRegistrationTokenTable(ref _mStatusChangedTokenTable)
                .InvocationList;

            temp?.Invoke(this, code);
        }
Ejemplo n.º 15
0
        void IAo3TrackHelper.OnRequestSpeechText()
        {
            var handlers =
                EventRegistrationTokenTable <EventHandler <object> >
                .GetOrCreateEventRegistrationTokenTable(ref _RequestSpeechText)
                .InvocationList;

            handlers?.Invoke(this, true);
        }
Ejemplo n.º 16
0
        void IAo3TrackHelper.OnAlterFontSize(int fontSize)
        {
            var handlers =
                EventRegistrationTokenTable <EventHandler <object> >
                .GetOrCreateEventRegistrationTokenTable(ref _AlterFontSizeEvent)
                .InvocationList;

            handlers?.Invoke(this, fontSize);
        }
Ejemplo n.º 17
0
        void IAo3TrackHelper.OnJumpToLastLocation(bool pagejump)
        {
            var handlers =
                EventRegistrationTokenTable <EventHandler <object> >
                .GetOrCreateEventRegistrationTokenTable(ref _JumpToLastLocationEvent)
                .InvocationList;

            handlers?.Invoke(this, pagejump);
        }
Ejemplo n.º 18
0
        // void CollectionChanged.remove(EventRegistrationToken token)
        internal void remove_CollectionChanged(EventRegistrationToken token)
        {
            INotifyCollectionChanged _this = Unsafe.As <INotifyCollectionChanged>(this);
            EventRegistrationTokenTable <NotifyCollectionChangedEventHandler> table = s_weakTable.GetOrCreateValue(_this);

            if (table.RemoveEventHandler(token, out NotifyCollectionChangedEventHandler? handler))
            {
                _this.CollectionChanged -= handler;
            }
        }
Ejemplo n.º 19
0
        // void PropertyChanged.remove(EventRegistrationToken token)
        private void remove_CanExecuteChanged(EventRegistrationToken token)
        {
            ICommand _this = Unsafe.As <ICommand>(this);
            EventRegistrationTokenTable <EventHandler> table = s_weakTable.GetOrCreateValue(_this);

            if (table.RemoveEventHandler(token, out EventHandler handler))
            {
                _this.CanExecuteChanged -= handler;
            }
        }
        public void AddEventHandler_Null_ReturnsZeroToken()
        {
            var tokenTable = new EventRegistrationTokenTable <Delegate>();
            EventRegistrationToken token = tokenTable.AddEventHandler(null);

            Assert.Equal(0, token.GetHashCode());

            // Removing this token should be a nop.
            tokenTable.RemoveEventHandler(token);
        }
Ejemplo n.º 21
0
        // void PropertyChanged.remove(EventRegistrationToken token)
        internal void remove_PropertyChanged(EventRegistrationToken token)
        {
            INotifyPropertyChanged _this = Unsafe.As <INotifyPropertyChanged>(this);
            EventRegistrationTokenTable <PropertyChangedEventHandler> table = s_weakTable.GetOrCreateValue(_this);

            if (table.RemoveEventHandler(token, out PropertyChangedEventHandler handler))
            {
                _this.PropertyChanged -= handler;
            }
        }
        public void AddEventHandler_SingleInvocationList_AddsSingleDelegateToInvocationList()
        {
            EventHandler handler    = new EventHandler(EventHandlerMethod1);
            var          tokenTable = new EventRegistrationTokenTable <Delegate>();

            EventRegistrationToken token = tokenTable.AddEventHandler(handler);

            Assert.NotEqual(0, token.GetHashCode());
            Assert.Equal(new Delegate[] { handler }, tokenTable.InvocationList.GetInvocationList());
        }
        public void InvocationList_SetDelegate_GetReturnsExpected()
        {
            Delegate invocationList = new EventHandler(EventHandlerMethod1);
            var      tokenTable     = new EventRegistrationTokenTable <Delegate>()
            {
                InvocationList = invocationList
            };

            Assert.Equal(new Delegate[] { invocationList }, tokenTable.InvocationList.GetInvocationList());
        }
Ejemplo n.º 24
0
        // EventRegistrationToken PropertyChanged.add(PropertyChangedEventHandler value)
        internal EventRegistrationToken add_PropertyChanged(PropertyChangedEventHandler value)
        {
            INotifyPropertyChanged _this = Unsafe.As <INotifyPropertyChanged>(this);
            EventRegistrationTokenTable <PropertyChangedEventHandler> table = s_weakTable.GetOrCreateValue(_this);

            EventRegistrationToken token = table.AddEventHandler(value);

            _this.PropertyChanged += value;

            return(token);
        }
Ejemplo n.º 25
0
 private void Grid_Holding(object sender, HoldingRoutedEventArgs e)
 {
     if (e.PointerDeviceType == PointerDeviceType.Touch && e.HoldingState == Windows.UI.Input.HoldingState.Started)
     {
         //LongPressed?.Invoke(this, e);
         //MenuTriggered?.Invoke(this, e.GetPosition(this), true);
         EventRegistrationTokenTable <EventHandler <LongPressEventArgs> >
         .GetOrCreateEventRegistrationTokenTable(ref m_LongPressedTokenTable)
         .InvocationList?.Invoke(this, new LongPressEventArgs(e.GetPosition(this), true));
     }
 }
Ejemplo n.º 26
0
        internal void OnStringChanged(string s)
        {
            EventHandler <StringChangedEventArgs> temp =
                EventRegistrationTokenTable <EventHandler <StringChangedEventArgs> >
                .GetOrCreateEventRegistrationTokenTable(ref m_StringChangedTokenTable)
                .InvocationList;

            if (temp != null)
            {
                temp(this, new StringChangedEventArgs(s));
            }
        }
Ejemplo n.º 27
0
        // EventRegistrationToken PropertyChanged.add(EventHandler<object> value)
        private EventRegistrationToken add_CanExecuteChanged(EventHandler <object> value)
        {
            ICommand _this = Unsafe.As <ICommand>(this);
            EventRegistrationTokenTable <EventHandler> table = s_weakTable.GetOrCreateValue(_this);

            EventHandler           handler = ICommandAdapterHelpers.CreateWrapperHandler(value);
            EventRegistrationToken token   = table.AddEventHandler(handler);

            _this.CanExecuteChanged += handler;

            return(token);
        }
Ejemplo n.º 28
0
            private void RaiseConfigurationChanged()
            {
                var temp =
                    EventRegistrationTokenTable <ConfigurationChangedEventHandler>
                    .GetOrCreateEventRegistrationTokenTable(ref _configurationChangedTokenTable)
                    .InvocationList;

                if (temp != null)
                {
                    temp(this);
                }
            }
        public void RemoveEventHandler_Token_RemovesFromTable()
        {
            EventHandler           handler    = new EventHandler(EventHandlerMethod1);
            var                    tokenTable = new EventRegistrationTokenTable <Delegate>();
            EventRegistrationToken token      = tokenTable.AddEventHandler(handler);

            tokenTable.RemoveEventHandler(token);
            Assert.Null(tokenTable.InvocationList);

            // Calls to RemoveEventHandler after removal are nops.
            tokenTable.RemoveEventHandler(token);
        }
        public void AddEventHandler_MultipleInvocationList_AddsAllDelegateToInvocationLists()
        {
            EventHandler handler1        = new EventHandler(EventHandlerMethod1);
            EventHandler handler2        = new EventHandler(EventHandlerMethod2);
            EventHandler combinedHandler = (EventHandler)Delegate.Combine(handler1, handler2);

            var tokenTable = new EventRegistrationTokenTable <Delegate>();

            EventRegistrationToken token = tokenTable.AddEventHandler(combinedHandler);

            Assert.NotEqual(0, token.GetHashCode());
            Assert.Equal(new Delegate[] { handler1, handler2 }, tokenTable.InvocationList.GetInvocationList());
        }