예제 #1
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            try
            {
                log.Info("Anagraphic request...calling Health Vault server");
                HVClient clientSample            = new HVClient();
                HealthRecordItemCollection items = clientSample.GetWeightFromHealthVault();

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

                if (authorizedPeople.Count == 0)
                {
                    log.Info("No records were authorized.  Application setup process did not complete.");
                    return(req.CreateResponse(HttpStatusCode.BadRequest, ""));
                }
                PersonInfo personInfo   = authorizedPeople[0];
                JObject    jsonResponse = CreateJsonResponse(personInfo);

                return(req.CreateResponse(HttpStatusCode.OK, jsonResponse));
            }
            catch (global::System.Exception)
            {
//                JObject jsonResponse = CreateUnauthorizedResponse();

                return(req.CreateResponse(HttpStatusCode.Unauthorized, ""));
            }
        }
예제 #2
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");
        }