Example #1
0
        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);
        }
Example #2
0
        /// <summary>
        /// Remove an event handler previously added with RegisterDevToolsProtocolEventReceived
        /// </summary>
        /// <param name="token"></param>
        public void UnregisterDevToolsProtocolEventReceived(long token)
        {
            EventRegistrationToken registrationToken = new EventRegistrationToken()
            {
                value = token
            };

            _reciever.remove_DevToolsProtocolEventReceived(registrationToken);
        }
 public void Equals_Object_ReturnsExpected(EventRegistrationToken token, object other, bool expected)
 {
     Assert.Equal(expected, token.Equals(other));
     if (other is EventRegistrationToken otherToken)
     {
         Assert.Equal(expected, token == otherToken);
         Assert.Equal(!expected, token != otherToken);
         Assert.Equal(expected, token.GetHashCode().Equals(other.GetHashCode()));
     }
 }
        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);
        }
Example #5
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;
            }
        }
Example #6
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;
            }
        }
        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());
        }
Example #8
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;
            }
        }
Example #9
0
        /// <summary>
        /// Unregisters a NewVersionAvailable event.
        /// </summary>
        /// <param name="token"></param>
        public void UnregisterNewVersionAvailable(long token)
        {
            _newVersionAvailableCallbacks.Remove(token);

            EventRegistrationToken registrationToken = new EventRegistrationToken()
            {
                value = token
            };

            _environment.remove_NewVersionAvailable(registrationToken);
        }
Example #10
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);
        }
        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);
        }
Example #12
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);
        }
        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());
        }
        public void RemoveEventHandler_NullHandler_Nop()
        {
            bool removeMethodCalled = false;
            Delegate handler = new EventHandler(EventHandlerMethod1);

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

            Action<EventRegistrationToken> removeMethod = token => removeMethodCalled = true;
            WindowsRuntimeMarshal.AddEventHandler(eventHandler => addToken, removeMethod, handler);

            WindowsRuntimeMarshal.RemoveEventHandler<Delegate>(removeMethod, null);
            Assert.False(removeMethodCalled);
        }
        public void AddEventHandler_MultipleTimes_AddsEachDelegateToInvocationList()
        {
            EventHandler handler    = new EventHandler(EventHandlerMethod1);
            var          tokenTable = new EventRegistrationTokenTable <Delegate>();

            EventRegistrationToken token1 = tokenTable.AddEventHandler(handler);

            Assert.NotEqual(0, token1.GetHashCode());

            EventRegistrationToken token2 = tokenTable.AddEventHandler(handler);

            Assert.NotEqual(token1.GetHashCode(), token2.GetHashCode());

            Assert.Equal(new Delegate[] { handler, handler }, tokenTable.InvocationList.GetInvocationList());
        }
Example #16
0
        async private void button_Click(object sender, RoutedEventArgs e)
        {
            CloseClient();

            SimpleVideoClient rtpClient = new SimpleVideoClient();

            progressRing.Visibility = Visibility.Visible;
            progressRing.IsActive   = true;

            var rtpUri = uriTextBox.Text;

            started = rtpClient.Started += new EventHandler <SimpleVideoClientStartedEventArgs>(this, OnStarted);
            stoped  = rtpClient.Stopped += new EventHandler <SimpleVideoClientStoppedEventArgs>(this, OnStopped);
            Uri urr = new Uri(rtpUri);
            await rtpClient.ConnectAsync(urr);
        }
        public static IEnumerable <object[]> Equals_TestData()
        {
            var tokenTable = new EventRegistrationTokenTable <Delegate>();
            EventRegistrationToken token      = tokenTable.AddEventHandler(new EventHandler(EventHandlerMethod1));
            EventRegistrationToken emptyToken = tokenTable.AddEventHandler(null);

            yield return(new object[] { token, token, true });

            yield return(new object[] { token, emptyToken, false });

            yield return(new object[] { emptyToken, emptyToken, true });

            yield return(new object[] { emptyToken, new EventRegistrationToken(), true });

            yield return(new object[] { token, new object(), false });

            yield return(new object[] { token, null, false });
        }
        private static WFD.IAsyncCausalityTracerStatics LoadFactory()
        {
            if (!Environment.IsWinRTSupported)
            {
                return(null);
            }

            //COM Class Id
            string ClassId = "Windows.Foundation.Diagnostics.AsyncCausalityTracer";

            //COM Interface GUID  {50850B26-267E-451B-A890-AB6A370245EE}
            Guid guid = new Guid(0x50850B26, 0x267E, 0x451B, 0xA8, 0x90, 0XAB, 0x6A, 0x37, 0x02, 0x45, 0xEE);

            Object factory = null;

            WFD.IAsyncCausalityTracerStatics validFactory = null;

            try
            {
                int hresult = Microsoft.Win32.UnsafeNativeMethods.RoGetActivationFactory(ClassId, ref guid, out factory);

                if (hresult < 0 || factory == null)
                {
                    return(null);                                //This prevents having an exception thrown in case IAsyncCausalityTracerStatics isn't registered.
                }
                validFactory = (WFD.IAsyncCausalityTracerStatics)factory;

                EventRegistrationToken token = validFactory.add_TracingStatusChanged(new EventHandler <WFD.TracingStatusChangedEventArgs>(TracingStatusChangedHandler));
                Contract.Assert(token != null, "EventRegistrationToken is null");
            }
            catch (Exception)
            {
                // Although catching generic Exception is not recommended, this file is one exception
                // since we don't want to propagate any kind of exception to the user since all we are
                // doing here depends on internal state.
                return(null);
            }

            return(validFactory);
        }
Example #19
0
        private static WFD.IAsyncCausalityTracerStatics LoadFactory()
        {
            //COM Class Id
            string ClassId = "Windows.Foundation.Diagnostics.AsyncCausalityTracer";

            //COM Interface GUID  {50850B26-267E-451B-A890-AB6A370245EE}
            Guid guid = new Guid(0x50850B26, 0x267E, 0x451B, 0xA8, 0x90, 0XAB, 0x6A, 0x37, 0x02, 0x45, 0xEE);

            Object factory = null;

            try
            {
                factory = Microsoft.Win32.UnsafeNativeMethods.RoGetActivationFactory(ClassId, ref guid);
            }
            catch (COMException)
            {
                //IAsyncCausalityTracerStatics interface not present in this OS
                return(null);
            }
            catch (EntryPointNotFoundException)
            {
                //RoGetActivationFactory method not present in combase.dll
                return(null);
            }
            catch (DllNotFoundException)
            {
                //combase.dll not found
                return(null);
            }

            WFD.IAsyncCausalityTracerStatics validFactory = (WFD.IAsyncCausalityTracerStatics)factory;

            EventRegistrationToken token = validFactory.add_TracingStatusChanged(new EventHandler <WFD.TracingStatusChangedEventArgs>(TracingStatusChangedHandler));

            Contract.Assert(token != null, "EventRegistrationToken is null");

            return(validFactory);
        }
Example #20
0
        static AsyncCausalityTracer()
        {
            if (!Environment.IsWinRTSupported)
            {
                return;
            }
            string activatableClassId = "Windows.Foundation.Diagnostics.AsyncCausalityTracer";
            Guid   guid = new Guid(1350896422, 9854, 17691, 168, 144, 171, 106, 55, 2, 69, 238);
            object obj  = null;

            try
            {
                int num = Microsoft.Win32.UnsafeNativeMethods.RoGetActivationFactory(activatableClassId, ref guid, out obj);
                if (num >= 0 && obj != null)
                {
                    AsyncCausalityTracer.s_TracerFactory = (IAsyncCausalityTracerStatics)obj;
                    EventRegistrationToken eventRegistrationToken = AsyncCausalityTracer.s_TracerFactory.add_TracingStatusChanged(new EventHandler <TracingStatusChangedEventArgs>(AsyncCausalityTracer.TracingStatusChangedHandler));
                }
            }
            catch (Exception ex)
            {
                AsyncCausalityTracer.LogAndDisable(ex);
            }
        }
Example #21
0
 /// <summary>
 /// Removes a handler from the observed event.
 /// </summary>
 /// <param name="token">
 /// The token to remove.
 /// </param>
 public void Remove(EventRegistrationToken token)
 {
     InnerRemove(null, () => token);
 }
 public HRESULT remove_MapChanged(EventRegistrationToken token)
 {
     return(((delegate * unmanaged <IObservableMap <K, V> *, EventRegistrationToken, int>)(lpVtbl[7]))((IObservableMap <K, V> *)Unsafe.AsPointer(ref this), token));
 }
 private static void RemoveMethod(EventRegistrationToken token)
 {
     Assert.False(RemoveMethodCalled);
     RemoveMethodCalled = true;
     Assert.Equal(ExpectedRemoveToken, token);
 }
Example #24
0
 /// <summary>Removes the event handler that is associated with the specified token from the table and the invocation list. </summary><param name="token">The token that was returned when the event handler was added. </param>
 public void RemoveEventHandler(EventRegistrationToken token)
 {
     throw new NotImplementedException();
 }
 public void RemoveEventHandler(EventRegistrationToken token);
 private static void DifferentRemoveAllMethod(EventRegistrationToken token) => DifferentRemoveAllMethodCalled = true;
 private static void RemoveAllMethod(EventRegistrationToken token) => RemoveAllTokens.Add(token);