Esempio n. 1
0
        public void TestMessageLoop()
        {
            /* GIVEN */
            var autoResetEvent = new AutoResetEvent(false);
            var messageLoop    = new MessageLoop();

            /* WHEN */
            var cancelThread = new Thread(() =>
            {
                while (!messageLoop.IsRunning)
                {
                    /*
                     * We need to wait until it actually started.
                     * However this will stop if the autoResetEvent is not fulfilled in time.
                     */
                }

                autoResetEvent.Set();
                messageLoop.Stop();
            });

            cancelThread.Start();
            messageLoop.Start();

            /* THEN */
            Assert.IsTrue(autoResetEvent.WaitOne(waitTimeInMilliseconds));
        }
Esempio n. 2
0
            public async Task ProcessMessages([Frozen] IMessageService messageService, [Frozen] BaseRequest message,
                                              MessageLoop sut)
            {
                await sut.Start();

                messageService.Received(1).Process(message, Arg.Any <Stream>(), Arg.Any <Stream>());
            }
Esempio n. 3
0
            public async Task UseIMessageSerializer([Frozen] IMessageSerializer messageSerializer, MessageLoop sut)
            {
                await sut.Start();

                messageSerializer
                .Received(1)
                .DeserializeWithLengthPrefix <BaseRequest>(Arg.Any <Stream>(), PrefixStyle.Base128);
            }
Esempio n. 4
0
            public async Task CreatesAnonymousPipes([Frozen] IStreamFactory streamFactory, InputData input, MessageLoop sut)
            {
                await sut.Start();

                streamFactory.Received(1).CreateAnonymousPipeClientStream(PipeDirection.In, input.PipeInName);
                streamFactory.Received(1).CreateAnonymousPipeClientStream(PipeDirection.Out, input.PipeOutName);
                streamFactory.Received(1).CreateAnonymousPipeClientStream(PipeDirection.Out, input.PipeEventName);
            }
Esempio n. 5
0
 public void Start(Node[] initialNodes)
 {
     MessageLoop.Start();
     foreach (var item in initialNodes)
     {
         SendFindNode(item);
     }
     RaiseStateChanged(DhtState.Ready);
 }
Esempio n. 6
0
        public WebSocket(IntPtr handle) : base(handle)
        {
            HandleMessage += OnReceiveMessage;

            // Create and start the general message loop
            messageLoop = new MessageLoop(this);
            messageLoop.Start();

            // Create and start the receive message loop
            receiveLoop = new MessageLoop(this);
            receiveLoop.Start();
        }
        public bool Tap()
        {
            new Thread(() =>
            {
                // This hook is called in the context of the thread that installed it. As the
                // call is made by sending a message to the thread that installed the hook,
                // the thread that installed the hook must have a message loop. To ensure a
                // message loop is present for the hook to work even if the hook is installed
                // in the thread context of a console application having no message loop, hook
                // installation will be done in a separate thread with a separate message loop.
                // See https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms644986(v%3Dvs.85)#remarks

                Install();

                _messageLoop.Start();
            }).Start();

            return(IsInstalled);
        }
Esempio n. 8
0
        private void OnInitialize(object sender, InitializeEventArgs args)
        {
            // Open the file system on the file_thread_. Since this is the first
            // operation we perform there, and because we do everything on the
            // file_thread_ synchronously, this ensures that the FileSystem is open
            // before any FileIO operations execute.
            messageLoop = new MessageLoop(this);
            var startTask = messageLoop.Start();

            runloop = new MessageLoop(this);
            runloop.Start();

            // Set the MessageLoop that the filesystem will run asynchronously with
            // This is not necassary though as the async will run regardless if a
            // MessageLoop is set or not.
            fileSystem.MessageLoop = messageLoop;

            OpenFileSystem();
        }
Esempio n. 9
0
        public async Task Start()
        {
            bodyMessageLoop = new MessageLoop(instance);
            bodyMessageLoop.Start();

            var openresult = await urlLoader.OpenAsync(urlRequest, bodyMessageLoop);

            if (openresult != PPError.Ok)
            {
                ReportResultAndDie(url, "URLLoader.Open() failed", false);
                return;
            }
            // Here you would process the headers. A real program would want to at least
            // check the HTTP code and potentially cancel the request.
            // var response = loader.ResponseInfo;
            var response = urlLoader.ResponseInfo;

            instance.LogToConsole(PPLogLevel.Warning, response.ToString());

            // Try to figure out how many bytes of data are going to be downloaded in
            // order to allocate memory for the response body in advance (this will
            // reduce heap traffic and also the amount of memory allocated).
            // It is not a problem if this fails, it just means that the
            // urlResponseBody.Append call in URLLoaderHandler:AppendDataBytes()
            // will allocate the memory later on.
            long bytesReceived          = 0;
            long totalBytesToBeReceived = 0;

            if (urlLoader.GetDownloadProgress(out bytesReceived, out totalBytesToBeReceived))
            {
                if (totalBytesToBeReceived > 0)
                {
                    urlResponseBody = new StringBuilder((int)totalBytesToBeReceived);
                }
            }

            // We will not use the download progress anymore, so just disable it.
            urlRequest.SetRecordDownloadProgress(false);
            // Start streaming.
            await ReadBody();
        }
Esempio n. 10
0
        /// <summary>
        /// Starts this Window. (shows and begins event handling)
        /// </summary>
        public void Start()
        {
            if(Started)
            {
                throw new Exception("Window already started!");
            }

            //specify the creation parameters
            CreateParams paras = new CreateParams();
            paras.Caption = "";
            paras.ClassStyle = 0x0003;//CS_HREDRAW | CS_VREDRAW
            paras.Style = DEFAULT_WINDOW_STYLE;
            Rectangle dimension = GetWindowDimensions();
            paras.X = dimension.X;
            paras.Y = dimension.Y;
            paras.Width = dimension.Width;
            paras.Height = dimension.Height;

            //start message loop
            MessageLoopObj = new MessageLoop();
            MessageLoopObj.Start<object>(() => CreateHandle(paras));

            Started = true;

            //if pending fullscreen, actually perform action
            if(Fullscreen)
                Fullscreen = true;

            ShowWindow(Handle, 1);//WINDOW_SHOW_NORMAL

            //if pending maximize, actually perform action
            if(Maximized)
                Maximized = true;
        }
Esempio n. 11
0
            public async Task SubscribeToMediaPlayerEventsUsingIEventService([Frozen] IEventService eventService, MessageLoop sut)
            {
                await sut.Start();

                eventService.Received(1).Subscribe(Arg.Any <Stream>());
            }