Ejemplo n.º 1
0
        internal async void StopServer()
        {
            Running = false;
            await server.Stop();

            StopSignal.Set();
        }
        public RabbitMqConnectionCache(RabbitMqHostSettings settings)
        {
            _signal = new StopSignal();

            _settings = settings;

            _connectionFactory = settings.GetConnectionFactory();
        }
Ejemplo n.º 3
0
        public RabbitMqConnectionCache(RabbitMqHostSettings settings)
        {
            _signal = new StopSignal();

            _settings = settings;

            _connectionFactory = settings.GetConnectionFactory();
        }
Ejemplo n.º 4
0
 internal void Wait()
 {
     StopSignal.WaitOne();
     while (Running)
     {
         StopSignal.WaitOne();
     }
 }
        public IStopSignal RunWhileTrueNewThread(Action action, int intervalInMS)
        {
            StopSignal signal = new StopSignal();

            Thread thread = new Thread(() => WhileTureMethodWrapper.Wrapper(SafeMethodWapper.Wrapper(action), intervalInMS, signal)());

            thread.IsBackground = true;
            thread.Start();
            return(signal);
        }
Ejemplo n.º 6
0
 public async Task Start(StopSignal stopSignal)
 {
     Server.Start();
     await Task.Run(() =>
     {
         while (Server.IsListening)
         {
             HttpListenerContext context   = Server.GetContext();
             HttpListenerRequest request   = context.Request;
             HttpListenerResponse response = context.Response;
             response.StatusCode           = (int)GetCode(stopSignal);
             byte[] responseMessage        = Encoding.UTF8.GetBytes("Test response");
             response.OutputStream.Write(responseMessage, 0, responseMessage.Length);
             response.OutputStream.Close();
             response.Close();
         }
     });
 }
Ejemplo n.º 7
0
        public void IsStopOnSignal()
        {
            StopSignal signal = StopSignal.TooManyRequests;

            using (TestServer testServer = new TestServer())
            {
                TestConfig testConfig = TestConfig;
                testConfig.Url        = new Uri(testServer.Address);
                testConfig.StopSignal = signal;
                Executor.SetConfig(testConfig);
                Executor.Configurate();
                Task.Run(() => testServer.Start(signal));
                Executor.StartTest();
                Task.Delay(5000).Wait();
            }
            int count = Executor.GetResult().Count;

            Assert.True(count < 5 && count > 0);
        }
Ejemplo n.º 8
0
    private void Stop()
    {
        if (WorkerSettings.Multithreaded)
        {
            // Signal the thread to stop
            StopSignal.Set();

            // Wait ten seconds for the thread to finish
            ExitedSignal.WaitOne(10 * 1000);

            // Reset the stop and exited flags so that the thread can be restarted
            StopSignal.Reset();
            ExitedSignal.Reset();
        }
        else
        {
            ThreadTeardown();
        }
    }
Ejemplo n.º 9
0
        public void IsRunningWhileStopSignal()
        {
            StopSignal signal = StopSignal.InternalServerError;

            using (TestServer testServer = new TestServer())
            {
                TestConfig testConfig = TestConfig;
                testConfig.Url        = new Uri(testServer.Address);
                testConfig.StopSignal = signal;
                Executor.SetConfig(testConfig);
                Executor.Configurate();
                Task.Run(() => testServer.Start(StopSignal.Manual));
                Task.Run(Executor.StartTest);
                Task.Delay(5000).Wait();
                Executor.StopExecution();
            }
            int count = Executor.GetResult().Count;

            Assert.True(count > 5);
        }
Ejemplo n.º 10
0
        private HttpStatusCode GetCode(StopSignal stopSignal)
        {
            switch (stopSignal)
            {
            case StopSignal.BadGateway:
                return(HttpStatusCode.BadGateway);

            case StopSignal.BadRequest:
                return(HttpStatusCode.BadRequest);

            case StopSignal.InternalServerError:
                return(HttpStatusCode.InternalServerError);

            case StopSignal.TooManyRequests:
                return(HttpStatusCode.TooManyRequests);

            default:
                return(HttpStatusCode.OK);
            }
        }
Ejemplo n.º 11
0
    private void Run()
    {
        try
        {
            bool receivedStopSignal = false;

            ThreadSetup();

            //Initial wait before starting.
            Thread.Sleep(30);

            while (!receivedStopSignal)
            {
                ThreadUpdate();

                // See if the main thread signaled us to stop
                if (StopSignal.WaitOne(0))
                {
                    receivedStopSignal = true;
                }

                if (!receivedStopSignal)
                {
                    System.Threading.Thread.Sleep(1);
                }
            }

            ThreadTeardown();
        }
        catch (Exception e)
        {
            UnityEngine.Debug.LogError(string.Format("PSMoveWorker: WorkerThread crashed: {0}", e.Message));
            UnityEngine.Debug.LogException(e);
        }
        finally
        {
            ExitedSignal.Set();
        }
    }
Ejemplo n.º 12
0
        private bool IsStopSignal(HttpResponseMessage response)
        {
            StopSignal stopSignal = ConfigParser.GetStopSignal();

            switch (stopSignal)
            {
            case StopSignal.BadGateway:
                if (response.StatusCode == System.Net.HttpStatusCode.BadGateway)
                {
                    return(true);
                }
                break;

            case StopSignal.BadRequest:
                if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
                {
                    return(true);
                }
                break;

            case StopSignal.InternalServerError:
                if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError)
                {
                    return(true);
                }
                break;

            case StopSignal.TooManyRequests:
                if (response.StatusCode == System.Net.HttpStatusCode.TooManyRequests)
                {
                    return(true);
                }
                break;
            }
            return(false);
        }
Ejemplo n.º 13
0
        private void BreakpointExecution(object sender, StopSignal signal)
        {
            Assert.AreEqual(RawPacket.Ack, this.ServerStream.ReadByte());
            Assert.AreEqual(0, this.ServerClient.Available);

            Assert.IsTrue(signal.HasFlag(StopSignal.Breakpoint));
        }
Ejemplo n.º 14
0
 internal void OnBreakExecution(StopSignal signal)
 {
     if (BreakExecution != null)
         BreakExecution(this, signal);
 }
Ejemplo n.º 15
0
 public AbstractWriter SetStopReason(StopSignal stopSignal)
 {
     Result.StopReason = stopSignal.ToString();
     return(this);
 }