Beispiel #1
0
        internal static EventWaiter VerifyWorkspaceFailedEvent(this Workspace workspace, Action <WorkspaceDiagnosticEventArgs> action)
        {
            var wew = new EventWaiter();

            workspace.WorkspaceFailed += wew.Wrap <WorkspaceDiagnosticEventArgs>((sender, args) => action(args));
            return(wew);
        }
Beispiel #2
0
        internal static EventWaiter VerifyWorkspaceChangedEvent(this MSBuildWorkspace workspace, Action <WorkspaceChangeEventArgs> action)
        {
            var wew = new EventWaiter();

            workspace.WorkspaceChanged += wew.Wrap <WorkspaceChangeEventArgs>((sender, args) => action(args));
            return(wew);
        }
Beispiel #3
0
        public ReaderViewBase()
        {
            this.DefaultStyleKey = typeof(ReaderViewBase);

            _gestureRecognizer = new GestureRecognizer();
            _gestureRecognizer.GestureSettings        = GestureSettings.ManipulationTranslateX;
            _gestureRecognizer.ManipulationStarted   += _gestureRecognizer_ManipulationStarted;
            _gestureRecognizer.ManipulationUpdated   += _gestureRecognizer_ManipulationUpdated;
            _gestureRecognizer.ManipulationCompleted += _gestureRecognizer_ManipulationCompleted;

            PointerWheelChangedEventHandler = new PointerEventHandler(_PointerWheelChanged);
            PointerPressedEventHandler      = new PointerEventHandler(_PointerPressed);
            PointerMovedEventHandler        = new PointerEventHandler(_PointerMoved);
            PointerReleasedEventHandler     = new PointerEventHandler(_PointerReleased);
            PointerCanceledEventHandler     = new PointerEventHandler(_PointerCanceled);
            TouchTappedEventHandler         = new TappedEventHandler(_TouchTapped);
            TouchHoldingEventHandler        = new HoldingEventHandler(_TouchHolding);

            this.AddHandler(UIElement.PointerWheelChangedEvent, PointerWheelChangedEventHandler, true);
            this.AddHandler(UIElement.PointerPressedEvent, PointerPressedEventHandler, true);
            this.AddHandler(UIElement.PointerMovedEvent, PointerMovedEventHandler, true);
            this.AddHandler(UIElement.PointerReleasedEvent, PointerReleasedEventHandler, true);
            this.AddHandler(UIElement.PointerCanceledEvent, PointerCanceledEventHandler, true);
            this.AddHandler(UIElement.TappedEvent, TouchTappedEventHandler, true);
            this.AddHandler(UIElement.HoldingEvent, TouchHoldingEventHandler, true);
            this.SizeChanged += ReaderViewBase_SizeChanged;


            IndexWaiter          = new EventWaiter();
            CreateContentDelayer = new EventDelayer();
            CreateContentDelayer.ResetWhenDelayed = true;
            CreateContentDelayer.Arrived         += CreateContentWaiter_Arrived;
        }
        /// <summary> Process the queue. </summary>
        protected override void ProcessQueue()
        {
            // Endless loop unless aborted
            while (ThreadRunState != ThreadRunStates.Abort)
            {
                // Calculate sleep time based on incoming command speed
                //_queueSpeed.SetCount(Queue.Count);
                //_queueSpeed.CalcSleepTime();
                EventWaiter.Wait(1000);

                // Process queue unless stopped
                if (ThreadRunState == ThreadRunStates.Start)
                {
                    // Only actually sleep if there are no commands in the queue
                    //if (Queue.Count == 0) _queueSpeed.Sleep();

                    var dequeueCommand = DequeueCommand();
                    if (dequeueCommand != null)
                    {
                        CmdMessenger.HandleMessage(dequeueCommand);
                    }
                }
                //else
                //{
                //    _queueSpeed.Sleep();
                //}
            }
        }
        public async Task <ReadOnlyCollection <T> > CollectEventArgsAsync <T>(Func <T, bool> predicate, TimeSpan?timeoutoverride = null) where T : AsyncEventArgs
        {
            var timeout = timeoutoverride ?? this.Config.Timeout;

            using var waiter = new EventWaiter <T>(this.Client);
            var res = await waiter.CollectMatches(new CollectRequest <T>(predicate, timeout)).ConfigureAwait(false);

            return(res);
        }
        /// <summary>
        /// Waits for specific event args to be received. Make sure the appropriate <see cref="DiscordIntents"/> are registered, if needed.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="predicate"></param>
        /// <param name="timeoutoverride"></param>
        /// <returns></returns>
        public async Task <InteractivityResult <T> > WaitForEventArgsAsync <T>(Func <T, bool> predicate, TimeSpan?timeoutoverride = null) where T : AsyncEventArgs
        {
            var timeout = timeoutoverride ?? this.Config.Timeout;

            using var waiter = new EventWaiter <T>(this.Client);
            var res = await waiter.WaitForMatch(new MatchRequest <T>(predicate, timeout)).ConfigureAwait(false);

            return(new InteractivityResult <T>(res == null, res));
        }
        public override async Task ConnectAsync() {
            var handshakeWaiter = new EventWaiter();
            Handshaked += handshakeWaiter.Callback;

            await Connect(Address);
            await handshakeWaiter.Wait();

            Handshaked -= handshakeWaiter.Callback;
        }
 protected internal override void Setup(DiscordClient client)
 {
     this.Client = client;
     this.MessageCreatedWaiter     = new EventWaiter <MessageCreateEventArgs>(this.Client);
     this.MessageReactionAddWaiter = new EventWaiter <MessageReactionAddEventArgs>(this.Client);
     this.TypingStartWaiter        = new EventWaiter <TypingStartEventArgs>(this.Client);
     this.Poller            = new Poller(this.Client);
     this.ReactionCollector = new ReactionCollector(this.Client);
     this.Paginator         = new Paginator(this.Client);
 }
Beispiel #9
0
        IEnumerable <bool> TestFunc(EventWaiter waiter)
        {
            Console.WriteLine("...Process A..."); // ...Process A...

            Elevator elv = theMultishuttle.elevators["L01"];

            yield return(waiter.Wait(elv, "OnElevatorArrived")); // [C]

            Console.WriteLine("...Process B...");                // ...Process B...
        }
 /// <summary> Queue the command wrapped in a command strategy. </summary>
 /// <param name="commandStrategy"> The command strategy. </param>
 public override void QueueCommand(CommandStrategy commandStrategy)
 {
     lock (Queue)
     {
         // Process all generic enqueue strategies
         Queue.Enqueue(commandStrategy);
         foreach (var generalStrategy in GeneralStrategies)
         {
             generalStrategy.OnEnqueue();
         }
     }
     // Give a signal to indicate that a new item has been queued
     EventWaiter.Set();
     if (NewLineReceived != null)
     {
         NewLineReceived(this, new NewLineEvent.NewLineArgs(commandStrategy.Command));
     }
 }
Beispiel #11
0
        public void EventWaiterTest()
        {
            // Delay event invocation
            const int eventDelay = 1000;

            var raiseEventTask = Task.Run(async() => {
                // Wait delay
                await Task.Delay(eventDelay);
                // Raise event
                OnTestEvent(new EventArgs());
            });
            // Get awaiter for event
            var waitEventTask = EventWaiter.WaitAsync <EventArgs>((h) => TestEvent += h, (h) => TestEvent -= h);
            // Wait (await waitEventTask)
            var waitResult = waitEventTask.Wait(eventDelay + 100);

            Assert.True(waitResult);
        }
Beispiel #12
0
        public ReaderView()
        {
            this.DefaultStyleKey = typeof(ReaderView);

            _GestureRecognizer = new GestureRecognizer();
            _GestureRecognizer.GestureSettings        = GestureSettings.ManipulationTranslateX;
            _GestureRecognizer.ManipulationStarted   += _GestureRecognizer_ManipulationStarted;
            _GestureRecognizer.ManipulationUpdated   += _GestureRecognizer_ManipulationUpdated;
            _GestureRecognizer.ManipulationCompleted += _GestureRecognizer_ManipulationCompleted;

            PointerWheelChangedEventHandler = new PointerEventHandler(_PointerWheelChanged);
            PointerPressedEventHandler      = new PointerEventHandler(_PointerPressed);
            PointerMovedEventHandler        = new PointerEventHandler(_PointerMoved);
            PointerReleasedEventHandler     = new PointerEventHandler(_PointerReleased);
            PointerCanceledEventHandler     = new PointerEventHandler(_PointerCanceled);

            this.AddHandler(UIElement.PointerWheelChangedEvent, PointerWheelChangedEventHandler, true);
            this.AddHandler(UIElement.PointerPressedEvent, PointerPressedEventHandler, true);
            this.AddHandler(UIElement.PointerMovedEvent, PointerMovedEventHandler, true);
            this.AddHandler(UIElement.PointerReleasedEvent, PointerReleasedEventHandler, true);
            this.AddHandler(UIElement.PointerCanceledEvent, PointerCanceledEventHandler, true);
            this.SizeChanged += ReaderView_SizeChanged;


            IndexWaiter          = new EventWaiter();
            CreateContentDelayer = new EventDelayer();
            CreateContentDelayer.ResetWhenDelayed = true;
            CreateContentDelayer.Arrived         += CreateContentWaiter_Arrived;

            this.Unloaded += (s, a) =>
            {
                this.RemoveHandler(UIElement.PointerWheelChangedEvent, PointerWheelChangedEventHandler);
                this.RemoveHandler(UIElement.PointerPressedEvent, PointerPressedEventHandler);
                this.RemoveHandler(UIElement.PointerMovedEvent, PointerMovedEventHandler);
                this.RemoveHandler(UIElement.PointerReleasedEvent, PointerReleasedEventHandler);
                this.RemoveHandler(UIElement.PointerCanceledEvent, PointerCanceledEventHandler);
            };
        }
Beispiel #13
0
        public async Task TestDocumentEvents()
        {
            using (var workspace = CreateWorkspace())
            {
                var doc1Text          = "public class C { }";
                var document          = new TestHostDocument(doc1Text);
                var project1          = new TestHostProject(workspace, document, name: "project1");
                var longEventTimeout  = TimeSpan.FromMinutes(5);
                var shortEventTimeout = TimeSpan.FromSeconds(5);

                workspace.AddTestProject(project1);

                // Creating two waiters that will allow us to know for certain if the events have fired.
                using (var closeWaiter = new EventWaiter())
                    using (var openWaiter = new EventWaiter())
                    {
                        // Wrapping event handlers so they can notify us on being called.
                        var documentOpenedEventHandler = openWaiter.Wrap <DocumentEventArgs>(
                            (sender, args) => Assert.True(args.Document.Id == document.Id,
                                                          "The document given to the 'DocumentOpened' event handler did not have the same id as the one created for the test."));

                        var documentClosedEventHandler = closeWaiter.Wrap <DocumentEventArgs>(
                            (sender, args) => Assert.True(args.Document.Id == document.Id,
                                                          "The document given to the 'DocumentClosed' event handler did not have the same id as the one created for the test."));

                        workspace.DocumentOpened += documentOpenedEventHandler;
                        workspace.DocumentClosed += documentClosedEventHandler;

                        workspace.OpenDocument(document.Id);
                        workspace.CloseDocument(document.Id);

                        // Wait for all workspace tasks to finish.  After this is finished executing, all handlers should have been notified.
                        await WaitForWorkspaceOperationsToComplete(workspace);

                        // Wait to receive signal that events have fired.
                        Assert.True(openWaiter.WaitForEventToFire(longEventTimeout),
                                    string.Format("event 'DocumentOpened' was not fired within {0} minutes.",
                                                  longEventTimeout.Minutes));

                        Assert.True(closeWaiter.WaitForEventToFire(longEventTimeout),
                                    string.Format("event 'DocumentClosed' was not fired within {0} minutes.",
                                                  longEventTimeout.Minutes));

                        workspace.DocumentOpened -= documentOpenedEventHandler;
                        workspace.DocumentClosed -= documentClosedEventHandler;

                        workspace.OpenDocument(document.Id);
                        workspace.CloseDocument(document.Id);

                        // Wait for all workspace tasks to finish.  After this is finished executing, all handlers should have been notified.
                        await WaitForWorkspaceOperationsToComplete(workspace);

                        // Verifying that an event has not been called is difficult to prove.
                        // All events should have already been called so we wait 5 seconds and then assume the event handler was removed correctly.
                        Assert.False(openWaiter.WaitForEventToFire(shortEventTimeout),
                                     string.Format("event handler 'DocumentOpened' was called within {0} seconds though it was removed from the list.",
                                                   shortEventTimeout.Seconds));

                        Assert.False(closeWaiter.WaitForEventToFire(shortEventTimeout),
                                     string.Format("event handler 'DocumentClosed' was called within {0} seconds though it was removed from the list.",
                                                   shortEventTimeout.Seconds));
                    }
            }
        }
Beispiel #14
0
        public void TestDocumentEvents()
        {
            using (var workspace = CreateWorkspace())
            {
                var doc1Text = "public class C { }";
                var document = new TestHostDocument(doc1Text);
                var project1 = new TestHostProject(workspace, document, name: "project1");
                var longEventTimeout = TimeSpan.FromMinutes(5);
                var shortEventTimeout = TimeSpan.FromSeconds(5);

                workspace.AddTestProject(project1);

                // Creating two waiters that will allow us to know for certain if the events have fired.
                using (var closeWaiter = new EventWaiter())
                using (var openWaiter = new EventWaiter())
                {
                    // Wrapping event handlers so they can notify us on being called.
                    var documentOpenedEventHandler = openWaiter.Wrap<DocumentEventArgs>(
                        (sender, args) => Assert.True(args.Document.Id == document.Id,
                        "The document given to the 'DocumentOpened' event handler did not have the same id as the one created for the test."));

                    var documentClosedEventHandler = closeWaiter.Wrap<DocumentEventArgs>(
                        (sender, args) => Assert.True(args.Document.Id == document.Id,
                        "The document given to the 'DocumentClosed' event handler did not have the same id as the one created for the test."));

                    workspace.DocumentOpened += documentOpenedEventHandler;
                    workspace.DocumentClosed += documentClosedEventHandler;

                    workspace.OpenDocument(document.Id);
                    workspace.CloseDocument(document.Id);

                    // Wait for all workspace tasks to finish.  After this is finished executing, all handlers should have been notified.
                    WaitForWorkspaceOperationsToComplete(workspace);

                    // Wait to recieve signal that events have fired.
                    Assert.True(openWaiter.WaitForEventToFire(longEventTimeout),
                                            string.Format("event 'DocumentOpened' was not fired within {0} minutes.",
                                            longEventTimeout.Minutes));

                    Assert.True(closeWaiter.WaitForEventToFire(longEventTimeout),
                                            string.Format("event 'DocumentClosed' was not fired within {0} minutes.",
                                            longEventTimeout.Minutes));

                    workspace.DocumentOpened -= documentOpenedEventHandler;
                    workspace.DocumentClosed -= documentClosedEventHandler;

                    workspace.OpenDocument(document.Id);
                    workspace.CloseDocument(document.Id);

                    // Wait for all workspace tasks to finish.  After this is finished executing, all handlers should have been notified.
                    WaitForWorkspaceOperationsToComplete(workspace);

                    // Verifiying that an event has not been called is difficult to prove.  
                    // All events should have already been called so we wait 5 seconds and then assume the event handler was removed correctly. 
                    Assert.False(openWaiter.WaitForEventToFire(shortEventTimeout),
                                            string.Format("event handler 'DocumentOpened' was called within {0} seconds though it was removed from the list.",
                                            shortEventTimeout.Seconds));

                    Assert.False(closeWaiter.WaitForEventToFire(shortEventTimeout),
                                            string.Format("event handler 'DocumentClosed' was called within {0} seconds though it was removed from the list.",
                                            shortEventTimeout.Seconds));
                }
            }
        }
 internal static EventWaiter VerifyWorkspaceFailedEvent(this MSBuildWorkspace workspace, Action<WorkspaceDiagnosticEventArgs> action)
 {
     var wew = new EventWaiter();
     workspace.WorkspaceFailed += wew.Wrap<WorkspaceDiagnosticEventArgs>((sender, args) => action(args));
     return wew;
 }
 internal static EventWaiter VerifyWorkspaceChangedEvent(this Workspace workspace, Action<WorkspaceChangeEventArgs> action)
 {
     var wew = new EventWaiter();
     workspace.WorkspaceChanged += wew.Wrap<WorkspaceChangeEventArgs>((sender, args) => action(args));
     return wew;
 }