Exemplo n.º 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            if (this.ViewModel == null)
            {
                return;
            }

            // Settings needed by the Microsoft Graph service client.
            MicrosoftGraphService.SetAuthenticationUiContext(new Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory.PlatformParameters(this));
            MicrosoftGraphService.SetClientId(AppSettings.iOSClientId);
            MicrosoftGraphService.SetRedirectUri(AppSettings.RedirectUri);

            if (Settings.ADAuthenticationEnabled)
            {
                InvokeOnMainThread(() => MicrosoftGraphService.SignInAsync());
            }

            SetUpNavBar();
            this.SetUpTabBar();
            var appDelegate = (MyHealthAppDelegate)UIApplication.SharedApplication.Delegate;

            appDelegate.Tabs = this;
        }
Exemplo n.º 2
0
        internal static async Task <GraphServiceClient> GetGraphServiceClientAsync()
        {
            MicrosoftGraphService graphService = MicrosoftGraphService.Instance;

            if (await graphService.TryLoginAsync())
            {
                return(graphService.GraphProvider);
            }

            return(null);
        }
        public void TestSettingsViewModelCreation()
        {
//{[{
            var identityService       = new IdentityService();
            var microsoftGraphService = new MicrosoftGraphService();
            var userDataService       = new UserDataService(identityService, microsoftGraphService);

            // This test is trivial. Add your own tests for the logic you add to the ViewModel.
            var vm = new SettingsViewModel(identityService, userDataService);
//}]}
        }
Exemplo n.º 4
0
        private async Task LoginAsync()
        {
            // sign into outlook.com account
            if (string.IsNullOrEmpty(MicrosoftGraphService.LoggedInUserEmail))
            {
                await MicrosoftGraphService.SignInAsync();

                var currentUser      = MicrosoftGraphService.LoggedInUser;
                var currentUserEmail = MicrosoftGraphService.LoggedInUserEmail;
            }
        }
Exemplo n.º 5
0
        private async Task AskForADCredentialsAsync()
        {
            MicrosoftGraphService.SetAuthenticationUiContext(new PlatformParameters(PromptBehavior.Always, false));
            MicrosoftGraphService.SetClientId(AppSettings.WUPClientId);
            MicrosoftGraphService.SetRedirectUri(AppSettings.RedirectUri);

            if (Settings.ADAuthenticationEnabled)
            {
                await MicrosoftGraphService.SignInAsync();
            }
        }
Exemplo n.º 6
0
        private static void OnDefaultValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var profileCard = d as ProfileCard;
            MicrosoftGraphService graphService = MicrosoftGraphService.Instance;

            if (!graphService.IsAuthenticated ||
                string.IsNullOrEmpty(profileCard.UserId) ||
                profileCard.UserId.Equals("Invalid UserId"))
            {
                profileCard.InitUserProfile();
            }
        }
Exemplo n.º 7
0
        protected override void ConfigureContainer()
        {
            // register a singleton using Container.RegisterType<IInterface, Type>(new ContainerControlledLifetimeManager());
            base.ConfigureContainer();
            var identityService       = new IdentityService();
            var microsoftGraphService = new MicrosoftGraphService();
            var userDataService       = new UserDataService(identityService, microsoftGraphService);

            Container.RegisterInstance <IResourceLoader>(new ResourceLoaderAdapter(new ResourceLoader()));
            Container.RegisterInstance <IIdentityService>(identityService);
            Container.RegisterInstance <IMicrosoftGraphService>(microsoftGraphService);
            Container.RegisterInstance <IUserDataService>(userDataService);
        }
        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();
//{[{
            var identityService       = new IdentityService();
            var microsoftGraphService = new MicrosoftGraphService();
            var userDataService       = new UserDataService(identityService, microsoftGraphService);

//}]}
            Container.RegisterInstance <IResourceLoader>(new ResourceLoaderAdapter(new ResourceLoader()));
//{[{
            Container.RegisterInstance <IIdentityService>(identityService);
            Container.RegisterInstance <IMicrosoftGraphService>(microsoftGraphService);
            Container.RegisterInstance <IUserDataService>(userDataService);
//}]}
        }
Exemplo n.º 9
0
        public async Task SignInAsync(IPlatformParameters context)
        {
            await MicrosoftGraphService.SignInAsync(context);

            var currentPatient = await GetPatientInfoAsync();

            if (currentPatient != null)
            {
                AppSettings.CurrentPatientId = currentPatient.PatientId;
                // We first get patient's picture from backend
                MicrosoftGraphService.LoggedUserPhoto = currentPatient.Picture;
                // And, then, try to get a newer one from Microsoft Graph
                MicrosoftGraphService.LoggedUserPhoto = await MicrosoftGraphService.GetUserPhotoAsync();
            }

            _messenger.Publish(new LoggedUserInfoChangedMessage(this));
        }
Exemplo n.º 10
0
        public async Task SignInAsync(IPlatformParameters context)
        {
            if (Settings.SecurityEnabled)
            {
                await MicrosoftGraphService.SignInAsync(context);

                Model.Patient currentPatient = await GetPatientInfo();

                if (currentPatient != null)
                {
                    AppSettings.CurrentPatientId          = currentPatient.PatientId;
                    MicrosoftGraphService.LoggedUserPhoto = currentPatient.Picture;
                }

                PublishChanges();
                LoadUserPhoto();
            }
        }
Exemplo n.º 11
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            RegisterHockeyApp();

            // Settings needed by the Microsoft Graph service client.
            MicrosoftGraphService.SetAuthenticationUiContext(new PlatformParameters(this));
            MicrosoftGraphService.SetClientId(AppSettings.DroidClientId);
            MicrosoftGraphService.SetRedirectUri(AppSettings.RedirectUri);

            if (Settings.ADAuthenticationEnabled)
            {
                Task.Run(() => MicrosoftGraphService.SignInAsync());
            }

            RegisterForPushNotifications();

            _fragmentManager = FragmentManager;
            RegisterFragments(bundle);
            SetContentView(Resource.Layout.MainView);
            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            SetSupportActionBar(toolbar);
            _drawerLayout = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            _drawerLayout.SetDrawerShadow(Resource.Drawable.drawer_shadow_light, (int)GravityFlags.Start);
            _drawerToggle = new MvxActionBarDrawerToggle(this, _drawerLayout,
                                                         Resource.String.drawer_open, Resource.String.drawer_close);
            _drawerToggle.DrawerClosed += (_, e) => InvalidateOptionsMenu();
            _drawerToggle.DrawerOpened += (_, e) => InvalidateOptionsMenu();
            SupportActionBar.SetDisplayShowTitleEnabled(false);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            _drawerToggle.DrawerIndicatorEnabled = true;
            _drawerLayout.SetDrawerListener(_drawerToggle);
            _drawerLayout.Post(() => _drawerToggle.SyncState());
            _bindableProgress = new BindableProgress(this);
            SetUpBindings();

            Akavache.BlobCache.ApplicationName = "MyHealth";

            ViewModel.ShowMenu();
            ViewModel.ShowHome();
        }
Exemplo n.º 12
0
 public void SignOut()
 {
     MicrosoftGraphService.SignOut();
 }
        private async void FetchUserInfoAsync()
        {
            if (string.IsNullOrEmpty(UserId) || UserId.Equals("Invalid UserId"))
            {
                InitUserProfile();
            }
            else
            {
                MicrosoftGraphService graphService = MicrosoftGraphService.Instance;
                if (!(await graphService.TryLoginAsync()))
                {
                    return;
                }

                try
                {
                    var user        = await graphService.GraphProvider.Users[UserId].Request().GetAsync();
                    var profileItem = new ProfileCardItem()
                    {
                        NormalMail        = user.Mail,
                        LargeProfileTitle = user.DisplayName,
                        LargeProfileMail  = user.Mail,
                        DisplayMode       = DisplayMode
                    };

                    if (string.IsNullOrEmpty(user.Mail))
                    {
                        profileItem.UserPhoto = DefaultImage ?? PersonPhoto;
                    }
                    else
                    {
                        try
                        {
                            using (Stream photoStream = await graphService.GraphProvider.Users[UserId].Photo.Content.Request().GetAsync())
                                using (var ras = photoStream.AsRandomAccessStream())
                                {
                                    var bitmapImage = new BitmapImage();
                                    await bitmapImage.SetSourceAsync(ras);

                                    profileItem.UserPhoto = bitmapImage;
                                }
                        }
                        catch
                        {
                            // Swallow error in case of no photo found
                            profileItem.UserPhoto = DefaultImage ?? PersonPhoto;
                        }
                    }

                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        CurrentProfileItem = profileItem;
                    });
                }
                catch (ServiceException ex)
                {
                    // Swallow error in case of no user id found
                    if (!ex.Error.Code.Equals("Request_ResourceNotFound"))
                    {
                        throw;
                    }

                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        UserId = "Invalid UserId";
                    });
                }
            }
        }
Exemplo n.º 14
0
        private async void LoadUserPhoto()
        {
            MicrosoftGraphService.LoggedUserPhoto = await MicrosoftGraphService.GetUserPhotoAsync();

            PublishChanges();
        }