Exemple #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine(DateTime.Now.TimeOfDay);
            Console.WriteLine("DSS invoked...##");

            var reminderHandler    = new ReminderHandler();
            var motionHandler      = new MotionEventHandler();
            var fallEventHandler   = new FallDetectionHandler();
            var measurementHandler = new MeasurementHandler();

            var url = "amqp://*****:*****@cami-rabbitmq:5672/cami";

            try
            {
                var rmqEvents = new RmqExchange(url, "events", "event.*", (json) => {
                    reminderHandler.Handle(json);
                    motionHandler.Handle(json);
                    fallEventHandler.Handle(json);
                });
                var rmqMeasurements = new RmqExchange(url, "measurements", "measurement.*", (json) => { measurementHandler.Handle(json); });
            }
            catch (Exception ex)
            {
                Console.WriteLine("Something went wrong with the rmq exchange: " + ex);
            }

            Console.WriteLine("RMQ binding done!");


            while (true)
            {
            }

            Console.WriteLine("Exiting DSS...");
        }
        public async Task Does_not_await_completion_of_log_function()
        {
            // setup
            var resetEvent = new ManualResetEvent(false);
            var hasLogged  = false;
            Action <MeasurementDetails> logFunc = async details =>
            {
                // validate
                await Task.Delay(100);

                hasLogged = true;
                resetEvent.Set();
            };
            var expectedResult = Guid.NewGuid().ToString();
            var handler        = new MeasurementHandler(null, new TestHandler(TimeSpan.FromMilliseconds(100), HttpStatusCode.OK, false, expectedResult), logFunc);
            var client         = new HttpClient(handler);

            // execute
            var result = await client.GetStringAsync("http://unit.test");

            // validate that the string was retrieved, but the logger hasn't completed yet
            result.ShouldBeEquivalentTo(expectedResult);
            hasLogged.Should().BeFalse();

            // ensure logging eventually happened
            resetEvent.WaitOne(TimeSpan.FromSeconds(1));
            hasLogged.Should().BeTrue();
        }
        public static readonly string TAG = typeof(MeasurementJob).FullName; //unique TAG

        public override bool OnStartJob(IJobParameters jobParameters)
        {
            Task.Run(async() =>
            {
                TestMeViewModel testMeViewModel = new TestMeViewModel();
                //DependencyService.Get<IBand>().SendVibration();
                await MeasurementHandler.ResendIntervals();                    //resend previous measurements if exist
                await MeasurementHandler.GetStressResult(-1, testMeViewModel); //start new measurement. -1 => real measurement
                String[] stressRes = testMeViewModel.StressResult.Split(" ");
                int tempLen        = stressRes.Length;
                if (stressRes[0] != "Error:" && stressRes[tempLen - 2] != "not") //this is a stress moment
                {
                    CrossLocalNotifications.Current.Show("RelaxApp noticed stress", "Tap into the app for more information");
                    EmailService.Execute(); //send mail to Emergency Contact
                }
            });
            return(true);
        }
Exemple #4
0
        private HttpClient CreateHttpClient(ILoggerFactory loggerFactory, string username, string password)
        {
            // settings take from the Cimpress documentation: https://cimpress-support.atlassian.net/wiki/spaces/CI/pages/168001556/Password-Realm+Grants
            Auth0ClientSettings clientSettings = new Auth0ClientSettings
            {
                Auth0ServerUrl = "https://cimpress.auth0.com/",
                Auth0Audience  = "https://api.cimpress.io/",
                Auth0ClientId  = "ST0wwOc0RavK6P6hhAPZ9Oc2XFD2dGUF",
                Auth0GrantType = "http://auth0.com/oauth/grant-type/password-realm",
                Auth0Realm     = "default",
                Auth0Username  = username,
                Auth0Password  = password
            };
            IAuth0TokenProvider tokenProvider = new PasswordRealmTokenProvider(loggerFactory, clientSettings);
            var measurementHandler            = new MeasurementHandler(loggerFactory.CreateLogger <Program>());
            var handler = new AuthHandler(measurementHandler, loggerFactory.CreateLogger <Program>(), tokenProvider);

            return(new HttpClient(handler));
        }
        public async Task Only_logs_when_completed(Uri uri, HttpStatusCode statusCode, bool throwException, bool isCompleted, bool isFaulted, bool isCanceled)
        {
            // setup
            var resetEvent = new ManualResetEvent(false);
            Action <MeasurementDetails> logFunc = details =>
            {
                // validate
                details.Request.Method.Method.Should().Be("GET");
                details.Request.RequestUri.Should().Be(uri);
                details.SendTask.IsCompleted.Should().Be(isCompleted);
                details.SendTask.IsFaulted.Should().Be(isFaulted);
                details.SendTask.IsCanceled.Should().Be(isCanceled);
                if (!throwException)
                {
                    details.SendTask.Result.StatusCode.Should().Be(statusCode);
                }
                resetEvent.Set();
            };
            var handler = new MeasurementHandler(null, new TestHandler(TimeSpan.FromMilliseconds(100), statusCode, throwException), logFunc);
            var client  = new HttpClient(handler);

            // execute
            try
            {
                await client.GetAsync(uri);
            }
            catch (Exception)
            {
                if (!throwException)
                {
                    throw;
                }
            }

            // wait until the validation has completed (but limit to max 1 second to avoid waiting forever)
            bool awaited = resetEvent.WaitOne(TimeSpan.FromSeconds(1));

            awaited.Should().BeTrue();
        }