Exemple #1
0
        public GlucoseService(IEventAggregator eventAggregator, IUserRepository userRepository, IUserSettingsRepository userSettingsRepository,
                              ISensorRepository sensorRepository, IGlucoseMeasureRepository GlucoseMeasureRepository, AppSettings settings)
        {
            this.eventAggregator          = eventAggregator;
            this.userRepository           = userRepository;
            this.userSettingsRepository   = userSettingsRepository;
            this.sensorRepository         = sensorRepository;
            this.glucoseMeasureRepository = GlucoseMeasureRepository;
            this.appSettings = settings;

            // subscription to the init measureServiceEvent
            // This event is possibly raised by the background service after its full initialization
            this.eventAggregator.GetEvent <InitMeasureServiceEvent>().Subscribe(async(value) =>
            {
                // intialize the measure service. We know he's awaken so we can get the dependancy
                this.measureService = Xamarin.Forms.DependencyService.Get <IMeasure>(DependencyFetchTarget.GlobalInstance);

                // then we awake the device
                await WakeUpMeasureServiceAsync();
            });

            // subscription to the LastMeasureReceivedEvent
            // This event could be raised by the Hidden page for the purpose of simulated data
            this.eventAggregator.GetEvent <LastMeasureReceivedEvent>().Subscribe((value) =>
            {
                SpreadLastMeasure(value);
                ProcessAveragesValues();
            }
                                                                                 );
        }
        public HiddenPageViewModel(IEventAggregator eventAggregator, INavigationService navigationService, IUserRepository userRepository,
                                   IGlucoseMeasureRepository glucoseMeasureRepository, AppSettings settings) : base(navigationService)
        {
            this.eventAggregator          = eventAggregator;
            this.userRepository           = userRepository;
            this.glucoseMeasureRepository = glucoseMeasureRepository;
            this.settings = settings;
            this.LoadHistoricalDataInTheZoneCommand    = new DelegateCommand(async() => await LoadHistoricalDataAsync(this.settings.CSV_IN_ZONE_FILENAME));
            this.LoadHistoricalDataNotInTheZoneCommand = new DelegateCommand(async() => await LoadHistoricalDataAsync(this.settings.CSV_NOT_IN_ZONE_FILENAME));
            this.SimulateMeasureValueCommand           = new DelegateCommand(async() => await SimulateMeasureValueAsync());
            this.LastMeasures = new List <HiddenHistoricalMeasure>();

            GetLastSixtyMinutesMeasures();
        }
Exemple #3
0
        public HomePageViewModel(IEventAggregator ea, INavigationService navigationService, IUserRepository userRepository,
                                 IGlucoseMeasureRepository glucoseMeasureRepository, AppSettings settings) : base(navigationService)
        {
            eventAggregator               = ea;
            this.userRepository           = userRepository;
            this.glucoseMeasureRepository = glucoseMeasureRepository;
            this.settings = settings;



            this.NavigateToDriveCommand = new DelegateCommand(async() =>
            {
                await this.NavigationService.NavigateAsync("/RootPage/PrismNavigationPage/MainTabbedPage?selectedTab=DrivePage");
            });

            this.NavigateToAlertsCommand = new DelegateCommand(async() =>
            {
                await this.NavigationService.NavigateAsync("/RootPage/PrismNavigationPage/MainTabbedPage?selectedTab=AlertsPage");
            });

            this.NavigateToReportsCommand = new DelegateCommand(async() =>
            {
                await this.NavigationService.NavigateAsync("/RootPage/PrismNavigationPage/MainTabbedPage?selectedTab=ReportsPage");
            });

            this.NavigateToBluetoothCommand = new DelegateCommand(async() =>
            {
                await this.NavigationService.NavigateAsync("/RootPage/PrismNavigationPage/MainTabbedPage?selectedTab=BluetoothPage");
            });

            this.AlertsCommand = new DelegateCommand(async() =>
            {
                await this.NavigationService.NavigateAsync("/RootPage/PrismNavigationPage/MainTabbedPage?selectedTab=AlertsPage");
            });

            if (!Utils.IsValidTDE(settings.TDE))
            {
                var closer = DependencyService.Get <ICloseApplication>();
                closer?.closeApplication();
            }

            IsAlert        = this.userRepository.GetCurrentUser().IsAlert;
            IsWidgetEnable = this.userRepository.GetCurrentUser().IsWidgetEnable;
        }
        /// <summary>
        /// The reports page viewmodel constructor
        /// </summary>
        /// <param name="ea"></param>
        /// <param name="glucoseMeasureRepository"></param>
        /// <param name="navigationService"></param>
        public ReportsPageViewModel(IEventAggregator eventAggregator, IGlucoseMeasureRepository glucoseMeasureRepository, IUserRepository userRepository,
                                    INavigationService navigationService, IUserSettingsRepository userSettingsRepository, AppSettings settings)
            : base(navigationService)
        {
            //Repositories init
            this.eventAggregator          = eventAggregator;
            this.glucoseMeasureRepository = glucoseMeasureRepository;
            this.userRepository           = userRepository;
            this.settings = settings;
            this.userSettingsRepository = userSettingsRepository;
            this.ChartVertAxeMaxValue   = this.settings.CHART_VERT_AXE_MAX;
            this.ChartVertAxeMinValue   = this.settings.CHART_VERT_AXE_MIN;

            this.uniqueUserId  = userRepository.GetCurrentUser().Id;
            this.ChartDataList = new ObservableCollection <ChartData>();

            this.MinimumGlucoseTreshold = this.userSettingsRepository.GetCurrentUserSettings().MinimumGlucoseTreshold;
            this.MaximumGlucoseTreshold = this.userSettingsRepository.GetCurrentUserSettings().MaximumGlucoseTreshold;

            //Initialize
            ChartSortValue      = ChartSortEnum.SortByDay;
            this.ChartDataList  = GetChartData();
            MajorStepUnitType   = TimeInterval.Hour;
            this.MajorStepValue = majorStepValueDay;

            this.SortByDayCommand = new DelegateCommand(() =>
            {
                ChartSortValue          = ChartSortEnum.SortByDay;
                this.ChartDataList      = GetChartData();
                MajorStepUnitType       = TimeInterval.Hour;
                this.MajorStepValue     = majorStepValueDay;
                this.DateLabelFormatter = null;
            });

            this.SortByWeekCommand = new DelegateCommand(() =>
            {
                ChartSortValue          = ChartSortEnum.SortByWeek;
                this.ChartDataList      = GetChartDataByWeek();
                MajorStepUnitType       = TimeInterval.Day;
                this.MajorStepValue     = majorStepValueWeek;
                this.DateLabelFormatter = new DateLabelWeekFormatter();
            });

            this.SortByHalfMonthCommand = new DelegateCommand(() =>
            {
                ChartSortValue          = ChartSortEnum.SortByHalfMonth;
                this.ChartDataList      = GetChartDataByHalfMonth();
                MajorStepUnitType       = TimeInterval.Day;
                this.MajorStepValue     = majorStepValueHalfMonth;
                this.DateLabelFormatter = null;
            });

            this.SortByMonthCommand = new DelegateCommand(() =>
            {
                ChartSortValue          = ChartSortEnum.SortByMonth;
                this.ChartDataList      = GetChartDataByMonth();
                MajorStepUnitType       = TimeInterval.Day;
                this.MajorStepValue     = majorStepValueMonth;
                this.DateLabelFormatter = null;
            });

            this.ExportCommand = new DelegateCommand(() =>
            {
                try
                {
                    List <GlucoseMeasure> input     = glucoseMeasureRepository.GetAllMeasuresByUser(uniqueUserId);
                    List <CsvGlucoseMeasure> output = CSVHelper.ConvertGlucoseToCsvGlucoseFormat(input);
                    //string s = CSVHelper.GetCSV(output);

                    var pathFile    = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads);
                    string filename = Path.Combine(pathFile.ToString(), "H&D_Datas.csv");

                    GenerateDocument(filename, output);
                }
                catch (Exception ex)
                {
                }
            });

            LoadAveragesData();

            this.eventAggregator.GetEvent <NotificationMeasureEvent>().Subscribe((notification) => {
                LoadAveragesData();
                this.ChartDataList = GetChartData();
            });
        }
        /// <summary>
        /// Initializes a new instance of the class <see cref="BluetoothPageViewModel"/>
        /// </summary>
        /// <param name="eventAggregator"></param>
        /// <param name="navigationService"></param>
        /// <param name="userRepository"></param>
        /// <param name="userSettingsRepository"></param>
        /// <param name="sensorRepository"></param>
        /// <param name="bleService"></param>
        public BluetoothPageViewModel(IEventAggregator eventAggregator, INavigationService navigationService, IUserRepository userRepository,
                                      IUserSettingsRepository userSettingsRepository, ISensorRepository sensorRepository, IGlucoseMeasureRepository glucoseMeasureRepository, BluetoothScanService bleService, AppSettings settings) : base(navigationService)
        {
            this.eventAggregator = eventAggregator;
            this.settings        = settings;

            InitializeDeviceItemTemplate();

            this.BleService               = bleService;
            this.UserRepository           = userRepository;
            this.UserSettingsRepository   = userSettingsRepository;
            this.GlucoseMeasureRepository = glucoseMeasureRepository;
            this.CurrentUser              = this.UserRepository.GetCurrentUser();
            this.CurrentUserSettings      = this.UserSettingsRepository.GetCurrentUserSettings();
            this.DeviceIsBoundedToUser    = this.CurrentUser.DeviceIsBounded;
            this.availableDevices         = new ObservableCollection <Models.Device>();

            this.CalibrationSourceValue  = this.CurrentUserSettings.CalibrationSourcedValue;
            this.CalibrationRevisedValue = this.CurrentUserSettings.CalibrationRevisedValue;
            this.IsBluetoothActive       = this.BleService.Ble.IsOn;

            //Visual var initialization
            this.IsFocused = false;

            // The measure background service
            this.MeasureService = DependencyService.Get <IMeasure>(DependencyFetchTarget.GlobalInstance);

            // if current user has an affected device, we set the position to the 3rd tab
            if (DeviceIsBoundedToUser)
            {
                this.CarouselPosition = this.settings.BLUETOOTH_INDEX_PAGE_DEVICE;
            }
            else
            {
                this.CarouselPosition = this.settings.BLUETOOTH_INDEX_PAGE_DEFAULT;
            }

            // Unregister device command
            this.UnregisterDeviceCommand = new DelegateCommand(() => UnregisterDevice(true));

            // Register scan device command
            this.ScanDeviceCommand = new DelegateCommand(() => ScanForDevices());

            // Register the save calibration command
            this.UnfocusCalibrationCommand = new DelegateCommand(() =>
            {
                this.IsFocused = false;
                //Reset value
                if (CalibrationRevisedValue == 0f)
                {
                    CalibrationRevisedValue = AjustedValueTmp;
                }
                SaveCalibrationValues(true);
                App.Current.MainPage.DisplayAlert("", Utils.GetTranslation("BluetoothPage_CalibrationSaved"), Utils.GetTranslation("OK"));

                this.CalibrationSourceValue = CalibrationRevisedValue;

                Analytics.TrackEvent(AnalyticsEvent.BluetoothCalibrationChanged);
            });

            //
            this.FocusAdjustedValueCommand = new DelegateCommand(() =>
            {
                this.IsFocused  = true;
                AjustedValueTmp = CalibrationRevisedValue;
                this.CalibrationRevisedValue = 0f;
            });

            // Register to events
            this.eventAggregator.GetEvent <BluetoothStateChangeEvent>().Subscribe((value) => {
                switch (value)
                {
                case Plugin.BLE.Abstractions.Contracts.BluetoothState.TurningOn:
                    this.IsBluetoothActive = true;
                    break;

                case Plugin.BLE.Abstractions.Contracts.BluetoothState.TurningOff:
                    this.IsBluetoothActive = false;
                    break;
                }
            });

            this.eventAggregator.GetEvent <NotificationMeasureEvent>().Subscribe(value => {
                this.CalibrationSourceValue  = value.NewMeasure;
                this.CalibrationRevisedValue = value.NewMeasure;
            });
        }