public void TestInitialize()
        {
            // Arrange
            Ioc.Container = new DependencyInjectionContainer();

            IServiceLocator serviceLocator = Substitute.For <IServiceLocator>();

            serviceLocator.GetInstance <WebHealthVaultConfiguration>().Returns(new WebHealthVaultConfiguration
            {
                DefaultHealthVaultUrl      = new Uri("http://www.bing.com"),
                DefaultHealthVaultShellUrl = new Uri("http://www.bing.com")
            });

            HealthServiceInstance healthServiceInstance = Substitute.For <HealthServiceInstance>();
            SessionCredential     sessionCredential     = new SessionCredential
            {
                ExpirationUtc = DateTimeOffset.UtcNow.AddHours(4),
                SharedSecret  = SessionSharedSecret,
                Token         = SessionToken
            };

            _userAuthToken = "someToken";

            _webHealthVaultConnection = new WebHealthVaultConnection(serviceLocator)
            {
                UserAuthToken     = _userAuthToken,
                ServiceInstance   = healthServiceInstance,
                SessionCredential = sessionCredential
            };
        }
Ejemplo n.º 2
0
        public async Task <WebConnectionInfo> CreateWebConnectionInfoAsync(string token, string instanceId)
        {
            IServiceInstanceProvider serviceInstanceProvider = _serviceLocator.GetInstance <IServiceInstanceProvider>();
            HealthServiceInstance    serviceInstance         = await serviceInstanceProvider.GetHealthServiceInstanceAsync(instanceId);

            IWebHealthVaultConnection connection = Ioc.Container.Locate <IWebHealthVaultConnection>(
                extraData:
                new
            {
                serviceLocator = _serviceLocator
            });

            WebHealthVaultConnection webHealthVaultConnection = connection as WebHealthVaultConnection;

            webHealthVaultConnection.ServiceInstance = serviceInstance;
            webHealthVaultConnection.UserAuthToken   = token;

            IPersonClient personClient = webHealthVaultConnection.CreatePersonClient();

            var personInfo = await personClient.GetPersonInfoAsync();

            WebConnectionInfo webConnectionInfo = new WebConnectionInfo
            {
                PersonInfo        = personInfo,
                ServiceInstanceId = instanceId,
                SessionCredential = webHealthVaultConnection.SessionCredential,
                UserAuthToken     = token
            };

            return(webConnectionInfo);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Provisions the application.
        /// If application does not exist, it launches the application
        /// creation process.
        /// </summary>
        public void ProvisionApplication()
        {
            // generate a GUID that will be used for the application creation.
            _applicationId = Guid.NewGuid();

            HealthClientApplication client = HealthClientApplication.Create(_applicationId, _masterApplicationId);

            client.StartApplicationCreationProcess();



            // launch dialog box to wait
            MessageBox.Show("After completing application setup in browser, click OK");

            // check if the app is provisioned now
            HealthServiceInstance instance = FindProvisionedServiceInstance();

            if (instance == null)
            {
                MessageBox.Show("The application setup in your browser did not complete.");
                return;
            }

            _serviceInstance         = instance;
            _healthClientApplication = client;

            // the app was provisioned
            _healthClientApplication = HealthClientApplication.Create(
                _applicationId,
                _masterApplicationId,
                _serviceInstance);

            // Get list of authorized people
            ApplicationConnection connection       = HealthClientApplication.ApplicationConnection;
            List <PersonInfo>     authorizedPeople = new List <PersonInfo>(connection.GetAuthorizedPeople());

            if (authorizedPeople.Count == 0)
            {
                MessageBox.Show("No records were authorized.  Application setup process did not complete.");
                return;
            }

            // save person ID, record ID, and service instance ID
            // assumption is the first person is the current person ID and there is only
            // one recordid for the person. For more persons and records, a selection
            // UI would need to be shown
            PersonInfo personInfo = authorizedPeople[0];

            _personId      = personInfo.PersonId;
            _recordId      = personInfo.SelectedRecord.Id;
            _isProvisioned = true;

            SaveUserSettings();

            MessageBox.Show("Application + " + _applicationId + " is now provisioned");
        }
        protected WebHealthVaultConnectionBase(
            IServiceLocator serviceLocator)
            : base(serviceLocator)
        {
            webHealthVaultConfiguration = ServiceLocator.GetInstance <WebHealthVaultConfiguration>();

            ServiceInstance = new HealthServiceInstance
            {
                HealthServiceUrl = UrlUtilities.GetFullPlatformUrl(webHealthVaultConfiguration.DefaultHealthVaultUrl),
                ShellUrl         = webHealthVaultConfiguration.DefaultHealthVaultShellUrl
            };
        }
Ejemplo n.º 5
0
        public async Task NormalRead()
        {
            _subSecretStore.ReadAsync(ServiceInstanceKey).Returns(SampleUtils.GetSampleContent(ServiceInstanceSampleFile));

            LocalObjectStore      localObjectStore = CreateLocalObjectStore();
            HealthServiceInstance serviceInstance  = await localObjectStore.ReadAsync <HealthServiceInstance>(ServiceInstanceKey);

            Assert.AreEqual("test", serviceInstance.Id);
            Assert.AreEqual("Test", serviceInstance.Name);
            Assert.AreEqual("description", serviceInstance.Description);
            Assert.AreEqual(new Uri("http://contoso.com"), serviceInstance.HealthServiceUrl);
            Assert.AreEqual(new Uri("http://contoso.com/shell"), serviceInstance.ShellUrl);
        }
        internal async Task ResetConnectionLeaseTimeOutAsync(WebConnectionInfo webConnectionInfo)
        {
            IServiceInstanceProvider serviceInstanceProvider = Ioc.Get <IServiceInstanceProvider>();
            HealthServiceInstance    serviceInstance         = await serviceInstanceProvider.GetHealthServiceInstanceAsync(webConnectionInfo.ServiceInstanceId);

            WebHealthVaultConfiguration webHealthVaultConfiguration = Ioc.Get <WebHealthVaultConfiguration>();
            var serviceInstanceHealthServiceUrl = serviceInstance.HealthServiceUrl;

            // Set socket to be refreshed in case the end point has been changed based on the healthvault service instance
            if (!webHealthVaultConfiguration.DefaultHealthVaultUrl.Equals(serviceInstanceHealthServiceUrl))
            {
                SetConnectionLeaseTimeOut(serviceInstanceHealthServiceUrl);
            }
        }
Ejemplo n.º 7
0
        public async Task NormalWrite()
        {
            var serviceInstance = new HealthServiceInstance
            {
                Id               = "test",
                Name             = "Test",
                Description      = "description",
                HealthServiceUrl = new Uri("http://contoso.com"),
                ShellUrl         = new Uri("http://contoso.com/shell"),
            };

            LocalObjectStore localObjectStore = CreateLocalObjectStore();
            await localObjectStore.WriteAsync(ServiceInstanceKey, serviceInstance);

            await _subSecretStore.Received().WriteAsync(ServiceInstanceKey, SampleUtils.GetSampleContent(ServiceInstanceSampleFile));
        }
        private void SetupLocalStore()
        {
            var serviceInstance = new HealthServiceInstance
            {
                Id               = "1",
                Name             = "US",
                Description      = "US instance",
                HealthServiceUrl = new Uri("https://platform.healthvault-ppe.com/platform/wildcat.ashx"),
                ShellUrl         = new Uri("https://account.healthvault-ppe.com/")
            };

            var applicationCreationInfo = new ApplicationCreationInfo
            {
                AppInstanceId    = new Guid(ApplicationInstanceId),
                SharedSecret     = ApplicationSharedSecret,
                AppCreationToken = ApplicationCreationToken
            };

            var sessionCredential = new SessionCredential
            {
                Token         = SessionToken,
                SharedSecret  = SessionSharedSecret,
                ExpirationUtc = DateTimeOffset.UtcNow.AddHours(4)
            };

            var personInfo = new PersonInfo
            {
                PersonId = PersonId
            };

            _subLocalObjectStore
            .ReadAsync <HealthServiceInstance>(HealthVaultSodaConnection.ServiceInstanceKey)
            .Returns(serviceInstance);

            _subLocalObjectStore
            .ReadAsync <ApplicationCreationInfo>(HealthVaultSodaConnection.ApplicationCreationInfoKey)
            .Returns(applicationCreationInfo);

            _subLocalObjectStore
            .ReadAsync <SessionCredential>(HealthVaultSodaConnection.SessionCredentialKey)
            .Returns(sessionCredential);

            _subLocalObjectStore
            .ReadAsync <PersonInfo>(HealthVaultSodaConnection.PersonInfoKey)
            .Returns(personInfo);
        }
        private async Task ProvisionForSodaAuthAsync()
        {
            // Set a temporary service instance for the NewApplicationCreationInfo and GetServiceDefinition calls.
            var defaultHealthVaultUrl      = Configuration.DefaultHealthVaultUrl;
            var defaultHealthVaultShellUrl = Configuration.DefaultHealthVaultShellUrl;
            var masterApplicationId        = Configuration.MasterApplicationId;

            ServiceInstance = new HealthServiceInstance(
                "1",
                "Default",
                "Default HealthVault instance",
                UrlUtilities.GetFullPlatformUrl(defaultHealthVaultUrl),
                defaultHealthVaultShellUrl);

            // Note: This apparent circular call is intentional. This method is called from AuthenticateAsync.
            // PlatformClient is calling HealthVaultConnectionBase.ExecuteAsync("NewApplicationCreationInfo"),
            // which avoids calling AuthenticateAsync because "NewApplicationCreationInfo" is an anonymous method.
            IPlatformClient         platformClient             = CreatePlatformClient();
            ApplicationCreationInfo newApplicationCreationInfo = await platformClient.NewApplicationCreationInfoAsync().ConfigureAwait(false);

            string environmentInstanceId = await _shellAuthService.ProvisionApplicationAsync(
                defaultHealthVaultShellUrl,
                masterApplicationId,
                newApplicationCreationInfo.AppCreationToken,
                newApplicationCreationInfo.AppInstanceId.ToString()).ConfigureAwait(false);

            ServiceInfo serviceInfo = await platformClient.GetServiceDefinitionAsync(ServiceInfoSections.Topology).ConfigureAwait(false);

            HealthServiceInstance bouncedHealthServiceInstance;

            if (!serviceInfo.ServiceInstances.TryGetValue(environmentInstanceId, out bouncedHealthServiceInstance))
            {
                // TODO: Come up with better error for  Current HealthServiceException is restrictive.
                throw new HealthServiceException(HealthServiceStatusCode.Failed);
            }

            // We've successfully made it through the flow. Save all the information.
            await _localObjectStore.WriteAsync(ServiceInstanceKey, bouncedHealthServiceInstance).ConfigureAwait(false);

            ServiceInstance = bouncedHealthServiceInstance;

            await _localObjectStore.WriteAsync(ApplicationCreationInfoKey, newApplicationCreationInfo).ConfigureAwait(false);

            ApplicationCreationInfo = newApplicationCreationInfo;
        }
Ejemplo n.º 10
0
        // Enables unit test
        internal async Task <IOfflineHealthVaultConnection> CreateOfflineConnectionInternalAsync(
            string offlinePersonId,
            string instanceId = null,
            SessionCredential sessionCredential = null)
        {
            Guid parsedOfflinePersonId;

            if (!Guid.TryParse(offlinePersonId, out parsedOfflinePersonId))
            {
                throw new ArgumentException("Unable to parse offline person id to Guid", nameof(offlinePersonId));
            }

            IServiceLocator serviceLocator = new ServiceLocator();

            HealthServiceInstance serviceInstance = null;

            if (!string.IsNullOrEmpty(instanceId))
            {
                // Get ServiceInstance
                IServiceInstanceProvider serviceInstanceProvider = serviceLocator.GetInstance <IServiceInstanceProvider>();
                serviceInstance = await serviceInstanceProvider.GetHealthServiceInstanceAsync(instanceId);
            }

            IOfflineHealthVaultConnection offlineHealthVaultConnection = Ioc.Container.Locate <IOfflineHealthVaultConnection>(
                extraData: new { serviceLocator = serviceLocator });

            OfflineHealthVaultConnection connection = offlineHealthVaultConnection as OfflineHealthVaultConnection;

            connection.SessionCredential = sessionCredential;
            connection.OfflinePersonId   = parsedOfflinePersonId;

            // By default, service instance is "US", so do not override in case the instance id is not set
            if (serviceInstance != null)
            {
                connection.ServiceInstance = serviceInstance;
            }

            return(offlineHealthVaultConnection);
        }
Ejemplo n.º 11
0
        // Enables unit test
        internal async Task <IWebHealthVaultConnection> CreateWebConnectionInternalAsync()
        {
            IHealthVaultIdentityProvider healthVaultIdentityProvider = Ioc.Container.Locate <IHealthVaultIdentityProvider>();
            HealthVaultIdentity          identity = healthVaultIdentityProvider.TryGetIdentity();

            IServiceLocator serviceLocator = new ServiceLocator();

            if (identity == null)
            {
                IWebHealthVaultConnection anonymousWebConnection = serviceLocator.GetInstance <IWebHealthVaultConnection>();
                return(anonymousWebConnection);
            }

            var webConnectionInfo = identity.WebConnectionInfo;

            if (webConnectionInfo == null)
            {
                throw new NotSupportedException("WebConnectionInfo is expected for authenticated connections");
            }

            // Get ServiceInstance
            IServiceInstanceProvider serviceInstanceProvider = Ioc.Container.Locate <IServiceInstanceProvider>();
            HealthServiceInstance    serviceInstance         = await serviceInstanceProvider.GetHealthServiceInstanceAsync(webConnectionInfo.ServiceInstanceId);

            // Get AuthInformation
            SessionCredential sessionCredentialToken = webConnectionInfo.SessionCredential;
            string            token = webConnectionInfo.UserAuthToken;

            IWebHealthVaultConnection webConnection = Ioc.Container.Locate <IWebHealthVaultConnection>(extraData: new { serviceLocator = serviceLocator });

            WebHealthVaultConnection connection = webConnection as WebHealthVaultConnection;

            connection.UserAuthToken     = token;
            connection.ServiceInstance   = serviceInstance;
            connection.SessionCredential = sessionCredentialToken;

            return(webConnection);
        }
        /// <summary>
        /// We will mock webhealthvaultconnection and substitute CreatePlatformClient call
        /// on the mock to return a mock platform client. Platform client will substitute
        /// call to platform "getservicedefintion" by returning a dummy serviceinstance with
        /// id set to "US instance".
        /// </summary>
        private async Task <HealthServiceInstance> GetHealthServiceInstanceAsync()
        {
            _webHealthVaultConnection = Substitute.For <IWebHealthVaultConnection>();
            Ioc.Container.Configure(c => { c.ExportInstance(_webHealthVaultConnection).As <IWebHealthVaultConnection>(); });

            IPlatformClient platformClient = Substitute.For <IPlatformClient>();

            _webHealthVaultConnection.CreatePlatformClient().Returns(platformClient);

            ServiceInfo serviceInfo = Substitute.For <ServiceInfo>();

            serviceInfo.ServiceInstances.Add(UsInstanceId, new HealthServiceInstance {
                Id = UsInstanceId
            });

            platformClient
            .GetServiceDefinitionAsync(ServiceInfoSections.Topology)
            .Returns(serviceInfo);

            HealthServiceInstance serviceInstance = await _serviceInstanceProvider.GetHealthServiceInstanceAsync("1");

            return(serviceInstance);
        }