public static HealthRecordItemCollection GetHVItemsOffline(Guid personId, Guid recordGuid, DateTime? lastSync) { // Do the offline connection OfflineWebApplicationConnection offlineConn = new OfflineWebApplicationConnection(personId); offlineConn.RequestTimeoutSeconds = 180; //extending time to prevent time outs for accounts with large number of items offlineConn.Authenticate(); HealthRecordAccessor accessor = new HealthRecordAccessor(offlineConn, recordGuid); HealthRecordSearcher searcher = accessor.CreateSearcher(); HealthRecordFilter filter = new HealthRecordFilter(Exercise.TypeId, AerobicSession.TypeId); if (lastSync.HasValue) filter.UpdatedDateMin = (DateTime)lastSync; searcher.Filters.Add(filter); HealthRecordItemCollection items = null; try { items = searcher.GetMatchingItems()[0]; } catch (Exception err) { WlkMiTracer.Instance.Log("HVSync.cs:GetHVItemsOffline", WlkMiEvent.AppSync, WlkMiCat.Error, string.Format("Error for user {0} : {1} ", recordGuid.ToString(), err.ToString())); } return items; }
/// <summary> /// Creates Offline Web Application Connection /// </summary> /// <param name="personId">Person Id who granted permission to perform operation</param> /// <returns>Returns authentication connection</returns> public static OfflineWebApplicationConnection CreateConnection(Guid personId) { OfflineWebApplicationConnection offlineConn = new OfflineWebApplicationConnection(ApplicationID, WebApplicationConfiguration.HealthServiceUrl, personId); offlineConn.Authenticate(); return offlineConn; }
public static void CreateApplication() { // Create an offline connection, we use an empty Guid as personId // There is a bug to create a constructor without requiring a guid //// Use this only if you master application wants to do this in Offline mode OfflineWebApplicationConnection offlineConnection = new OfflineWebApplicationConnection(Guid.Empty); offlineConnection.Authenticate(); // Setting up the application we want to create ApplicationInfo appInfo = new ApplicationInfo(); appInfo.Name = "Android application"; appInfo.AuthorizationReason = "Android aplication"; appInfo.Description = "Just an android application"; // get a base64 encoded logo appInfo.LargeLogo = new ApplicationBinaryConfiguration( "C:\\blah.png", "image/gif"); // base64 encoded public key for this application appInfo.PublicKeys.Add( GetPublicKeyFromPfxOrP12("C:\\JourneyCompass.cer")); // You need to have PrivacyStatement + TermsOfUse or ActionUrl appInfo.PrivacyStatement = new ApplicationBinaryConfiguration( "C:\\privacy.txt", "text/plain"); appInfo.TermsOfUse = new ApplicationBinaryConfiguration ("C:\\terms.txt", "text/plain"); //actionUrl //appInfo.ActionUrl = new Uri("http://localhost/redirect.aspx"); // Create and add the rules individually List<AuthorizationSetDefinition> rules = new List<AuthorizationSetDefinition>(); rules.Add((AuthorizationSetDefinition)(new TypeIdSetDefinition(Height.TypeId))); rules.Add((AuthorizationSetDefinition)(new TypeIdSetDefinition(new Guid("a5033c9d-08cf-4204-9bd3-cb412ce39fc0")))); AuthorizationRule rule1 = new AuthorizationRule( HealthRecordItemPermissions.All, rules, null); // Here we are setting up the child as an offline application appInfo.OfflineBaseAuthorizations.Add(rule1); // Add more rules, if needed // Lets make the child app! Provisioner.AddApplication(offlineConnection, appInfo); }
public ActionResult GetAuthorizedAccounts() { var ret = new { status = "ok" }; var appId = HealthApplicationConfiguration.Current.ApplicationId; var offline = new OfflineWebApplicationConnection(appId, WebApplicationConfiguration.HealthServiceUrl.ToString(), Guid.Empty); offline.Authenticate(); var coll = PatientConnection.GetValidatedConnections(offline); var res = from t in coll select new { personId = t.PersonId, recordId = t.RecordId }; return Json(new { status = ret.status, results = res } , JsonRequestBehavior.AllowGet); }
/// <summary> /// Fetch the <see cref="HealthRecordItem" /> instances that are specified /// in the ChangedItems collection. /// </summary> /// <remarks> /// After the operation has completed, see <see cref="HealthRecordItemChangedItem.Item" /> /// to use the fetched <see cref="HealthRecordItem" /> /// /// Items that have been removed from a record or are otherwise inaccessible will /// have a <see cref="HealthRecordItemChangedItem.Item" /> value of null. /// </remarks> /// /// <param name="applicationId">The application id to use.</param> /// <param name="healthServiceUrl">The health service URL to use.</param> /// /// <exception cref="ArgumentNullException"> /// The <paramref name="healthServiceUrl"/> parameter is <b>null</b>. /// </exception> public void GetItems(Guid applicationId, string healthServiceUrl) { Validator.ThrowIfArgumentNull(healthServiceUrl, "healthServiceUrl", "HealthServiceUrlNull"); if (ChangedItems.Count == 0) { return; } OfflineWebApplicationConnection offlineConn = new OfflineWebApplicationConnection( applicationId, healthServiceUrl, _personId); offlineConn.Authenticate(); HealthRecordAccessor accessor = new HealthRecordAccessor(offlineConn, _recordId); HealthRecordSearcher searcher = accessor.CreateSearcher(); HealthRecordFilter filter = new HealthRecordFilter(); searcher.Filters.Add(filter); Dictionary<Guid, HealthRecordItemChangedItem> changedLookup = new Dictionary<Guid, HealthRecordItemChangedItem>(ChangedItems.Count); foreach (HealthRecordItemChangedItem item in ChangedItems) { filter.ItemIds.Add(item.Id); changedLookup.Add(item.Id, item); } HealthRecordItemCollection things = searcher.GetMatchingItems()[0]; // Take the resultant items and put them back in the ChangedItems collection foreach (HealthRecordItem fetchedItem in things) { HealthRecordItemChangedItem item = changedLookup[fetchedItem.Key.Id]; item.Item = fetchedItem; } }
public static void SyncWlkMiWithHealthVault( DateTime? lastUpdatedDate) { WlkMiTracer.Instance.Log("HVSync.cs", WlkMiEvent.AppSync, WlkMiCat.Info, "Getting updated records from HealthVault"); // Do the offline connection OfflineWebApplicationConnection offlineConn = new OfflineWebApplicationConnection(); offlineConn.Authenticate(); IList<Guid> updatedUserIds = offlineConn.GetUpdatedRecordsForApplication(lastUpdatedDate); WlkMiTracer.Instance.Log("HVSync.cs", WlkMiEvent.AppSync, WlkMiCat.Info, string.Format("Got {0} updated records from HealthVault", updatedUserIds.Count)); foreach (Guid recordid in updatedUserIds) { ProfileModel syncUser = ProfileModel.Fetch(recordid); if (syncUser == null) { WlkMiTracer.Instance.Log("HVSync.cs", WlkMiEvent.AppSync, WlkMiCat.Error, string.Format("No WlkMi user found for recordif {0} ", recordid)); continue; } // Decide to update this guy? if (syncUser.UserCtx.hv_last_sync_time > DateTime.Now.AddSeconds( -Constants.UserSyncIntervalInSeconds)) { WlkMiTracer.Instance.Log("HVSync.cs", WlkMiEvent.AppSync, WlkMiCat.Info, string.Format("Skipping sync for user {0} ", syncUser.UserCtx.user_id)); } else { HVSync.OfflineSyncUser(syncUser); } } }