コード例 #1
0
        private INIntent CreateAddMeasureIntent(Measure measure, double breadUnits)
        {
            if (!measure.Level.HasValue)
            {
                throw new InvalidOperationException("Measure must has a level");
            }

            var intent = new AddMeasureIntent
            {
                Level        = new NSNumber(measure.Level / 10.0 ?? 0.0),
                Shortinsulin = new NSNumber(measure.ShortInsulin),
                Breadunits   = new NSNumber(breadUnits)
            };

            var phraseBuilder = new StringBuilder("Add blood sugar");

            phraseBuilder.Append($" {measure.GetLevel()}");

            if (measure.ShortInsulin > 0)
            {
                phraseBuilder.Append($" {measure.ShortInsulin} insulin");
            }

            if (breadUnits > 0)
            {
                phraseBuilder.Append($" {breadUnits} bread units");
            }

            var phrase = phraseBuilder.ToString();

            intent.SuggestedInvocationPhrase = phrase;

            return(intent);
        }
コード例 #2
0
        /// <inheritdoc />
        public override void ResolveShortinsulinForAddMeasure(AddMeasureIntent intent, Action <INIntegerResolutionResult> completion)
        {
            try
            {
                Console.WriteLine(intent.Shortinsulin.Int32Value);

                completion(INIntegerResolutionResult.GetSuccess(intent.Shortinsulin.Int32Value));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #3
0
        /// <inheritdoc />
        public override void ResolveBreadunitsForAddMeasure(AddMeasureIntent intent, Action <INDoubleResolutionResult> completion)
        {
            try
            {
                Console.WriteLine(intent.Breadunits.DoubleValue);

                completion(INDoubleResolutionResult.GetSuccess(intent.Breadunits.DoubleValue));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #4
0
        /// <inheritdoc />
        public override void HandleAddMeasure(AddMeasureIntent intent, Action <AddMeasureIntentResponse> completion)
        {
            try
            {
                if (intent == null)
                {
                    completion(new AddMeasureIntentResponse(AddMeasureIntentResponseCode.Failure, null));

                    return;
                }

                var level        = intent.Level;
                var shortInsulin = intent.Shortinsulin;
                var breadUnits   = intent.Breadunits;

                var hasLevel        = level.DoubleValue > 0;
                var hasShortInsulin = shortInsulin.Int32Value > 0;
                var hasBreadUnits   = breadUnits.DoubleValue > 0;

                var hasSomeValues = hasLevel || hasBreadUnits || hasShortInsulin;

                if (!hasSomeValues)
                {
                    completion(new AddMeasureIntentResponse(AddMeasureIntentResponseCode.Failure, null));

                    return;
                }

                var measureService = new MeasureService(new SharedDatabaseConnectionStringHolder());

                var measure = new Measure
                {
                    Date         = DateTime.UtcNow,
                    Level        = hasLevel ? (int?)(level.DoubleValue * 10) : null,
                    LongInsulin  = 0,
                    ShortInsulin = shortInsulin.Int32Value
                };

                measureService.AddAsync(measure).GetAwaiter().GetResult();
                completion(new AddMeasureIntentResponse(AddMeasureIntentResponseCode.Success, null));
            }
            catch (Exception e)
            {
                var logger = Mvx.IoCProvider
                             .Resolve <IMvxLogProvider>()
                             .GetLogFor <AddMeasureIntentHandler>();

                logger.ErrorException("While handling add measure intent", e);
                completion(new AddMeasureIntentResponse(AddMeasureIntentResponseCode.Failure, null));
            }
        }
コード例 #5
0
ファイル: AppDelegate.cs プロジェクト: l1pton17/Diabetto
        private static void HandleIntent(AddMeasureIntent intent)
        {
            var handler = new AddMeasureIntentHandler();

            handler.HandleAddMeasure(
                intent,
                response =>
            {
                if (response.Code != AddMeasureIntentResponseCode.Success)
                {
                    Console.WriteLine(response.Code);
                }
            });
        }
コード例 #6
0
        /// <inheritdoc />
        public override void ResolveLevelForAddMeasure(AddMeasureIntent intent, Action <INDoubleResolutionResult> completion)
        {
            try
            {
                Console.WriteLine(intent.Level.DoubleValue);

                completion(intent.Level.DoubleValue <= Double.Epsilon
                    ? INDoubleResolutionResult.NeedsValue
                    : INDoubleResolutionResult.GetSuccess(intent.Level.DoubleValue));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #7
0
 public override void ConfirmAddMeasure(AddMeasureIntent intent, Action <AddMeasureIntentResponse> completion)
 {
     completion(new AddMeasureIntentResponse(AddMeasureIntentResponseCode.Success, null));
 }