public NotificationsPage(BandDeviceInfo info, BandClient bandClient, BandTile tile) : base(info, bandClient) { InitializeComponent(); ViewModel = new NotificationsViewModel(info, bandClient, tile); }
public SensorsPage(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { InitializeComponent(); ViewModel = new SensorsViewModel(BandInfo, BandClient); }
public async Task Connect(BandDeviceInfo selectedBandToConnectWith = null) { var pairedBands = await GetPairedBandsAsync(); try { if (selectedBandToConnectWith != null) { BandClient = await BandClientManager.Instance.ConnectAsync(selectedBandToConnectWith); BandClientName = selectedBandToConnectWith.Name; } else if (pairedBands != null && pairedBands.Any()) { BandClient = await BandClientManager.Instance.ConnectAsync(pairedBands.First()); BandClientName = pairedBands.First().Name; } // do work after successful connect } catch (Exception ex) { // handle a Band connection exception throw new CouldntConnectToBandException(); } }
public async Task <String> ConnectToBand(BandDeviceInfo b) { band = b; bandClient = await bandClientManager.ConnectAsync(band); return(String.Format("connected to {0} !", band.Name)); }
public SensorsViewModel(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { sensorManager = bandClient.SensorManager; Sensors = new ObservableCollection <BaseViewModel>(); Init(); }
public ClientPage(BandDeviceInfo info) { InitializeComponent(); clientViewModel = new ClientViewModel(info); ViewModel = clientViewModel; }
public PersonalizationPage(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { InitializeComponent(); personalizationViewModel = new PersonalizationViewModel(info, bandClient); ViewModel = personalizationViewModel; }
public VibrationsViewModel(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { notifiactionManager = bandClient.NotificationManager; VibrateCommand = new Command(async() => { await notifiactionManager.VibrateAsync((VibrationType)vibrationIndex); }); }
public VibrationsViewModel(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { notifiactionManager = bandClient.NotificationManager; VibrateCommand = new Command(async () => { await notifiactionManager.VibrateAsync((VibrationType)vibrationIndex); }); }
public AddTilePage(BandDeviceInfo info, BandClient bandClient, BandTile tile) : base(info, bandClient) { InitializeComponent(); addTileViewModel = new AddTileViewModel(info, bandClient, tile); Init(); ViewModel = addTileViewModel; }
public VibrationsPage(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { InitializeComponent(); ViewModel = new VibrationsViewModel(info, bandClient); foreach (var type in VibrationsViewModel.GetVibrationTypes()) { vibrationTypesPicker.Items.Add(type); } }
private static async void getBands() { var bands = await bandService.getBands(); band = bands.FirstOrDefault(); if (band == null) { Console.WriteLine("failed"); return; } Console.WriteLine(band.Name); }
private async void getBands() { var bands = await bandService.getBands(); band = bands.FirstOrDefault(); if (band == null) { this.CurrentStatus = "No bands found"; return; } this.ConnectButtonText = "Connect to Band: " + band.Name; }
private async void ConnectToBand() { this.CurrentStatus = "Connecting..."; try { int index = MainPageNew.bandSelectedIndex; band = BandList[index]; this.BandId = await AzureDbservice.getBandIdForUserId(App.User.UserId, App.GroupId, band.Name); var result = await bandService.ConnectToBand(band, App.User); if (result) { this.CurrentStatus = "Connected to band : " + band.Name; this.ConnectButtonEnabled = false; bandService.PropertyChanged += BandService_PropertyChanged; bandService.UpdateFluidLoss(); // Band Readings await bandService.StartReadingSkinTemp(); await bandService.StartReadingHeartRate(); await bandService.StartReadingGSR(); await bandService.StartReadingUV(); await bandService.StartReadingAmbientLight(); await bandService.StartReadingPedometer(); await bandService.StartReadingCalories(); //await bandService.StartReadingFluidLoss(); InserToDB(); return; } else { throw new Exception("cannot connect"); } } catch (Exception e) { this.CurrentStatus = "Failed to connect : " + band.Name; } }
public AddTileViewModel(BandDeviceInfo info, BandClient bandClient, BandTile tile) : this(info, bandClient) { TileId = tile.Id.ToString("D"); TileName = tile.Name; TileIcon = tile.Icon; TileBadge = tile.SmallIcon; DisableScreenTimeout = tile.IsScreenTimeoutDisabled; if (tile.Theme != BandTheme.Empty) { UseCustomTheme = true; TileTheme = tile.Theme; } else { TileTheme = App.DefaultTheme; } }
public TilesPage(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { InitializeComponent(); var addTile = new ToolbarItem { Text = "Add", Icon = OnPlatform( iOS: (FileImageSource)FileImageSource.FromFile("Icons/Add.png"), Android: (FileImageSource)FileImageSource.FromFile("Add.png"), Windows: (FileImageSource)FileImageSource.FromFile("Assets/Icons/Add.png")) }; addTile.Clicked += AddTileButtonClicked; ToolbarItems.Add(addTile); ViewModel = new TilesViewModel(info, bandClient); }
public AddTileViewModel(BandDeviceInfo info, BandClient bandClient, BandTile tile) : this(info, bandClient) { TileId = tile.Id.ToString("D"); TileName = tile.Name; TileIcon = tile.Icon; AllowBadging = tile.SmallIcon != null; TileBadge = tile.SmallIcon; if (tile.Theme != default(BandTheme)) { UseCustomTheme = true; TileTheme = tile.Theme; } else { TileTheme = App.DefaultTheme; } }
public NotificationsViewModel(BandDeviceInfo info, BandClient bandClient, BandTile tile) : base(info, bandClient) { notifiactionManager = bandClient.NotificationManager; this.tile = tile; SendMessageCommand = new Command(async() => { await notifiactionManager.SendMessageAsync(tile.Id, Title, Body, DateTime.Now); }); SendMessageWithDialogCommand = new Command(async() => { await notifiactionManager.SendMessageAsync(tile.Id, Title, Body, DateTime.Now, true); }); ShowDialogCommand = new Command(async() => { await notifiactionManager.ShowDialogAsync(tile.Id, Title, Body); }); }
public NotificationsViewModel(BandDeviceInfo info, BandClient bandClient, BandTile tile) : base(info, bandClient) { notifiactionManager = bandClient.NotificationManager; this.tile = tile; SendMessageCommand = new Command(async () => { await notifiactionManager.SendMessageAsync(tile.Id, Title, Body, DateTime.Now); }); SendMessageWithDialogCommand = new Command(async () => { await notifiactionManager.SendMessageAsync(tile.Id, Title, Body, DateTime.Now, true); }); ShowDialogCommand = new Command(async () => { await notifiactionManager.ShowDialogAsync(tile.Id, Title, Body); }); }
public async Task <bool> ConnectToBand(BandDeviceInfo b, User user) { band = b; try { this.user = user; bandClient = await bandClientManager.ConnectAsync(band); } catch (Exception ex) { String.Format("Exception: " + ex); return(false); } if (bandClient != null) { return(true); } return(false); }
public PersonalizationViewModel(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { personalizationManager = bandClient.PersonalizationManager; GetBandThemeCommand = new Command(async () => { BandTheme = await personalizationManager.GetThemeAsync(); }); DefaultBandThemeCommand = new Command(() => { BandTheme = App.DefaultTheme; }); SetBandThemeCommand = new Command(async () => { await personalizationManager.SetThemeAsync(BandTheme); }); GetMeTileImageCommand = new Command(async () => { MeTileImage = await personalizationManager.GetMeTileImageAsync(); }); DefaultMeTileImageCommand = new Command(async () => { MeTileImage = await App.LoadImageResourceAsync("Resources/metile.png"); }); SelectMeTileImageCommand = new Command(async () => { var photo = await CrossMedia.Current.PickPhotoAsync(); if (photo != null) { MeTileImage = await BandImage.FromStreamAsync(photo.GetStream()); } }, () => CrossMedia.Current.IsPickPhotoSupported); SetMeTileImageCommand = new Command(async () => { await personalizationManager.SetMeTileImageAsync(MeTileImage); }); Init(); }
public PersonalizationViewModel(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { personalizationManager = bandClient.PersonalizationManager; GetBandThemeCommand = new Command(async() => { BandTheme = await personalizationManager.GetThemeAsync(); }); DefaultBandThemeCommand = new Command(() => { BandTheme = App.DefaultTheme; }); SetBandThemeCommand = new Command(async() => { await personalizationManager.SetThemeAsync(BandTheme); }); GetMeTileImageCommand = new Command(async() => { MeTileImage = await personalizationManager.GetMeTileImageAsync(); }); DefaultMeTileImageCommand = new Command(async() => { MeTileImage = await App.LoadImageResourceAsync("Resources/metile.png"); }); SelectMeTileImageCommand = new Command(async() => { var photo = await CrossMedia.Current.PickPhotoAsync(); if (photo != null) { MeTileImage = await BandImage.FromStreamAsync(photo.GetStream()); } }, () => CrossMedia.Current.IsPickPhotoSupported); SetMeTileImageCommand = new Command(async() => { await personalizationManager.SetMeTileImageAsync(MeTileImage); }); Init(); }
public BaseClientViewModel(BandDeviceInfo info, BandClient bandClient) { BandClient = bandClient; BandInfo = info; }
protected static void ConnectClient(CancellationToken cancellationToken = default(CancellationToken)) { if (!SensusServiceHelper.Get().EnableBluetooth(true, "Sensus uses Bluetooth to collect data from your Microsoft Band, which is being used in one of your studies.")) { throw new MicrosoftBandClientConnectException("Bluetooth not enabled."); } lock (BAND_CLIENT_LOCKER) { if (!BAND_CLIENT_CONNECTING) { BAND_CLIENT_CONNECTING = true; BAND_CLIENT_CONNECT_WAIT.Reset(); Task.Run(async() => { try { if (BandClient?.IsConnected ?? false) { return; } int connectAttempt = 0; while (++connectAttempt <= BAND_CLIENT_CONNECT_ATTEMPTS && (BandClient == null || !BandClient.IsConnected) && !cancellationToken.IsCancellationRequested) { try { SensusServiceHelper.Get().Logger.Log("Connect attempt " + connectAttempt + " of " + BAND_CLIENT_CONNECT_ATTEMPTS + ".", LoggingLevel.Normal, typeof(MicrosoftBandProbeBase)); BandClientManager bandManager = BandClientManager.Instance; BandDeviceInfo band = (await bandManager.GetPairedBandsAsync()).FirstOrDefault(); if (band == null) { SensusServiceHelper.Get().Logger.Log("No paired Bands.", LoggingLevel.Normal, typeof(MicrosoftBandProbeBase)); Thread.Sleep(BAND_CLIENT_CONNECT_TIMEOUT_MS); } else { Task <BandClient> connectTask = bandManager.ConnectAsync(band); if (await Task.WhenAny(connectTask, Task.Delay(BAND_CLIENT_CONNECT_TIMEOUT_MS)) == connectTask) { BandClient = await connectTask; if (BandClient.IsConnected) { SensusServiceHelper.Get().Logger.Log("Connected.", LoggingLevel.Normal, typeof(MicrosoftBandProbeBase)); } else { SensusServiceHelper.Get().Logger.Log("Could not connect.", LoggingLevel.Normal, typeof(MicrosoftBandProbeBase)); } } else { SensusServiceHelper.Get().Logger.Log("Timed out.", LoggingLevel.Normal, typeof(MicrosoftBandProbeBase)); } } } catch (Exception ex) { SensusServiceHelper.Get().Logger.Log("Exception while connecting to Band: " + ex.Message, LoggingLevel.Normal, typeof(MicrosoftBandProbeBase)); } } } catch (Exception ex) { SensusServiceHelper.Get().Logger.Log("Failed to reuse/establish connected Band client: " + ex.Message, LoggingLevel.Normal, typeof(MicrosoftBandProbeBase)); } finally { BAND_CLIENT_CONNECT_WAIT.Set(); BAND_CLIENT_CONNECTING = false; } }); } } BAND_CLIENT_CONNECT_WAIT.WaitOne(); if (BandClient == null || !BandClient.IsConnected) { throw new MicrosoftBandClientConnectException("Failed to connect to Band."); } }
public ClientViewModel(BandDeviceInfo info) : base(info, null) { }
public BaseClientContentPage(BandDeviceInfo info, BandClient bandClient) { BandInfo = info; BandClient = bandClient; }
public TilesViewModel(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { tileManager = bandClient.TileManager; Tiles = new ObservableCollection<TileViewModel>(); }
public AddTileViewModel(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { tileManager = bandClient.TileManager; tileTheme = App.DefaultTheme; tileId = Guid.NewGuid(); tileName = "New Tile"; GenerateTileIdCommand = new Command(() => { TileId = Guid.NewGuid().ToString("D"); }); DefaultTileIconCommand = new Command(async() => { TileIcon = await App.LoadImageResourceAsync("Resources/tile.png"); }); SelectTileIconCommand = new Command(async() => { var photo = await CrossMedia.Current.PickPhotoAsync(); if (photo != null) { TileIcon = await BandImage.FromStreamAsync(photo.GetStream()); } }, () => CrossMedia.Current.IsPickPhotoSupported); DefaultTileBadgeCommand = new Command(async() => { TileBadge = await App.LoadImageResourceAsync("Resources/badge.png"); }); SelectTileBadgeCommand = new Command(async() => { var photo = await CrossMedia.Current.PickPhotoAsync(); if (photo != null) { TileBadge = await BandImage.FromStreamAsync(photo.GetStream()); } }, () => CrossMedia.Current.IsPickPhotoSupported); DefaultThemeCommand = new Command(() => { TileTheme = App.DefaultTheme; }); AddTileCommand = new Command(async() => { var tile = new BandTile(tileId) { Icon = TileIcon, Name = TileName }; if (AllowBadging) { tile.SmallIcon = TileBadge; } if (UseCustomTheme) { tile.Theme = TileTheme; } await tileManager.AddTileAsync(tile); }); RemoveTileCommand = new Command(async() => { await tileManager.RemoveTileAsync(tileId); }); }
public TilesViewModel(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { tileManager = bandClient.TileManager; Tiles = new ObservableCollection <TileViewModel>(); }
public AddTileViewModel(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { tileManager = bandClient.TileManager; tileTheme = App.DefaultTheme; tileId = Guid.NewGuid(); tileName = "New Tile"; GenerateTileIdCommand = new Command(() => { TileId = Guid.NewGuid().ToString("D"); }); DefaultTileIconCommand = new Command(async () => { TileIcon = await App.LoadImageResourceAsync("Resources/tile.png"); }); SelectTileIconCommand = new Command(async () => { var photo = await CrossMedia.Current.PickPhotoAsync(); if (photo != null) { TileIcon = await BandImage.FromStreamAsync(photo.GetStream()); } }, () => CrossMedia.Current.IsPickPhotoSupported); DefaultTileBadgeCommand = new Command(async () => { TileBadge = await App.LoadImageResourceAsync("Resources/badge.png"); }); SelectTileBadgeCommand = new Command(async () => { var photo = await CrossMedia.Current.PickPhotoAsync(); if (photo != null) { TileBadge = await BandImage.FromStreamAsync(photo.GetStream()); } }, () => CrossMedia.Current.IsPickPhotoSupported); DefaultThemeCommand = new Command(() => { TileTheme = App.DefaultTheme; }); AddTileCommand = new Command(async () => { var tile = new BandTile(tileId) { Icon = TileIcon, Name = TileName, SmallIcon = TileBadge, IsScreenTimeoutDisabled = DisableScreenTimeout }; if (UseCustomTheme) { tile.Theme = TileTheme; } tile.PageImages.AddRange(new[] { await App.LoadImageResourceAsync("Resources/star.png") }); var layouts = CreatePageLayouts(); tile.PageLayouts.AddRange(layouts); await tileManager.AddTileAsync(tile); var datas = CreatePageDatas(); await tileManager.SetTilePageDataAsync(tile.Id, datas); }); RemoveTileCommand = new Command(async () => { await tileManager.RemoveTileAsync(tileId); }); }
protected static void ConnectClient(MicrosoftBandProbeBase configureProbeIfConnected = null) { if (!SensusServiceHelper.Get().EnableBluetooth(true, "Sensus uses Bluetooth to collect data from your Microsoft Band, which is being used in one of your studies.")) { return; } if (configureProbeIfConnected != null) { lock (CONFIGURE_PROBES_IF_CONNECTED) { CONFIGURE_PROBES_IF_CONNECTED.Add(configureProbeIfConnected); } } lock (BAND_CLIENT_LOCKER) { if (!BAND_CLIENT_CONNECTING) { BAND_CLIENT_CONNECTING = true; BAND_CLIENT_CONNECT_WAIT.Reset(); Task.Run(async() => { try { // if we already have a connection, configure any waiting probes if (BandClient?.IsConnected ?? false) { lock (CONFIGURE_PROBES_IF_CONNECTED) { foreach (MicrosoftBandProbeBase probe in CONFIGURE_PROBES_IF_CONNECTED) { try { probe.Configure(BandClient); } catch (Exception ex) { SensusServiceHelper.Get().Logger.Log("Failed to configure probe on existing connection: " + ex.Message, LoggingLevel.Normal, probe.GetType()); } } CONFIGURE_PROBES_IF_CONNECTED.Clear(); } } // otherwise, attempt to connect else { int connectAttempt = 0; while (++connectAttempt <= BAND_CLIENT_CONNECT_ATTEMPTS && (BandClient == null || !BandClient.IsConnected)) { SensusServiceHelper.Get().Logger.Log("Connect attempt " + connectAttempt + " of " + BAND_CLIENT_CONNECT_ATTEMPTS + ".", LoggingLevel.Normal, typeof(MicrosoftBandProbeBase)); BandClientManager bandManager = BandClientManager.Instance; BandDeviceInfo band = (await bandManager.GetPairedBandsAsync()).FirstOrDefault(); if (band == null) { SensusServiceHelper.Get().Logger.Log("No paired Bands.", LoggingLevel.Normal, typeof(MicrosoftBandProbeBase)); Thread.Sleep(BAND_CLIENT_CONNECT_TIMEOUT_MS); } else { Task <BandClient> connectTask = bandManager.ConnectAsync(band); if (await Task.WhenAny(connectTask, Task.Delay(BAND_CLIENT_CONNECT_TIMEOUT_MS)) == connectTask) { BandClient = await connectTask; } else { SensusServiceHelper.Get().Logger.Log("Timed out.", LoggingLevel.Normal, typeof(MicrosoftBandProbeBase)); } } } // if we connected successfully, use the new client to (re)configure all probes that should be running. if (BandClient?.IsConnected ?? false) { lock (CONFIGURE_PROBES_IF_CONNECTED) { foreach (MicrosoftBandProbeBase probe in BandProbesThatShouldBeRunning) { try { probe.Configure(BandClient); } catch (Exception ex) { SensusServiceHelper.Get().Logger.Log("Failed to start readings for Band probe: " + ex.Message, LoggingLevel.Normal, probe.GetType()); } } CONFIGURE_PROBES_IF_CONNECTED.Clear(); } } } } catch (Exception ex) { SensusServiceHelper.Get().Logger.Log("Failed to connect to Band: " + ex.Message, LoggingLevel.Normal, typeof(MicrosoftBandProbeBase)); } finally { BAND_CLIENT_CONNECT_WAIT.Set(); BAND_CLIENT_CONNECTING = false; } }); } } BAND_CLIENT_CONNECT_WAIT.WaitOne(); if (BandClient == null || !BandClient.IsConnected) { throw new MicrosoftBandClientConnectException("Failed to connect to Band."); } }