//public void updateRecordSummaryTable() //{ // var query = "select count(*) from {0}"; // var allBlobs = GetAllBobs(); // var clientRecords = (from record in allBlobs // select new PPDataSet().fromJson(record)); // var allRecords = ( // from record in clientRecords // let val = record.FieldValues // .FirstOrDefault(f => f.Name == Constants.FIELD_PPX_DATEOFVISIT) // where val != null // let visitDate = string.IsNullOrWhiteSpace(val.Value) ? DateTime.MinValue : Convert.ToDateTime(val.Value) // select new RecordSummary() // { // Id = record.Id.Value, // EntityId = record.EntityId.Value, // KindName = record.FormName, // //Constants.PPX_KIND_DISPLAYNAMES[record.FormName], // VisitDate = visitDate // }).ToList(); // var db = new LocalDB3().DB; // allRecords.ForEach(t => db.InsertOrReplace(t)); // var allSaved = db.Table<RecordSummary>().ToList(); //} public void updateRecordSummaryTable() { var allBlobs = GetAllBobs(); var clientRecords = (from record in allBlobs select DbSaveableEntity.fromJson <GeneralEntityDataset>(record) //select new GeneralEntityDataset().fromJson(record) ).ToList(); var allRecords = ( from record in clientRecords let val = record.FieldValues .FirstOrDefault(f => f.Name == ContextManager.FIELD_VISITDATE) where val != null let visitDate = string.IsNullOrWhiteSpace(val.Value) ? DateTime.MinValue : Convert.ToDateTime(val.Value) select new RecordSummary() { Id = record.Id.Value, EntityId = record.EntityId.Value, KindName = record.FormName, VisitDate = visitDate }).ToList(); var db = new LocalDB3().DB; allRecords.ForEach(t => db.InsertOrReplace(t)); var allSaved = db.Table <RecordSummary>().ToList(); }
internal List <AppUser> LoadCredentials() { var allCreds = new TableStore(KindName).GetAllBlobs(); if (allCreds == null) { return(new List <AppUser>()); } return((from credString in allCreds select DbSaveableEntity.fromJson <AppUser>(credString)).ToList()); }
private void MenuSmmaries_Click(object sender, RoutedEventArgs e) { var addRecordsFromTablet = false; if (addRecordsFromTablet) { //we have records that couldn't be synced from the tablet var toSave = new List <CloudEntity>(); var txt = File.ReadAllText("Assets\\unsyncd.txt"); var outEntities = txt.DecompressFromBase64String(); var now = DateTime.Now.AddDays(-8); var asBinary = now.ToBinary(); var processors = new Dictionary <string, List <CloudEntity> >(); foreach (var outEntity in outEntities) { var ppdataset = DbSaveableEntity.fromJson <GeneralEntityDataset>(new KindItem(outEntity.DataBlob)); var saveable = new DbSaveableEntity(ppdataset) { kindName = new KindName(ppdataset.FormName) }; if (!processors.ContainsKey(ppdataset.FormName)) { processors[ppdataset.FormName] = new List <CloudEntity>(); } var cloudEntity = new CloudEntity() { Id = saveable.Id.Value, EntityId = saveable.EntityId.Value, EditDay = now.toYMDInt(), EditDate = asBinary, DataBlob = saveable .getJson() .Encrypt() .Value, FormName = ppdataset.FormName, KindMetaData = saveable.Entity.KindMetaData ?? string.Empty }; processors[ppdataset.FormName].Add(cloudEntity); } foreach (var item in processors) { new KindDataProcessor() .addToProcessingQueue(item.Key, item.Value); } //we save them to local AppInstance.Instance.CloudDbInstance.RefreshLocalEntities(setProgressValue); } MessageBox.Show("Menu item clicked "); }
public override int Update(List <T> clients) { foreach (var client in clients) { var ge = new GeneralEntityDataset() { EntityId = client.EntityId, FormName = _kindName, Id = client.Id, FieldValues = client.ToValuesList(), KindMetaData = client.KindMetaData }; var saveable = new DbSaveableEntity(ge); saveable.Save(); } return(0); }
protected void ShowMyView() { SetContentView(myView); addDefaultNavBehaviours(); bindDateDialogEventsForView(myView); setDefaultValuesForView(myView); loadClientFromIntent(); if (isInEditMode()) { //means we have data to edit var jsonRecord = this.Intent.GetStringExtra(Constants.BUNDLE_DATATOEDIT); var saveableEntity = DbSaveableEntity .fromJson <GeneralEntityDataset>(new KindItem(jsonRecord)); //var saveableEntity = JsonConvert // .DeserializeObject<GeneralEntityDataset>(jsonRecord); if (saveableEntity != null) { var viewFields = GetFieldsForView(myView); var indexedData = saveableEntity.FieldValues; var fvp = getNameValuePairs(viewFields, indexedData); setViewData(fvp); } else { //we abort and show the home page } } else if (IsFirstPage && CurrentClient != null) { //if requires selection of client, we show the client selection dialog //loadClientFromIntent(); //load client information if it has any indexed fields var viewFields = GetFieldsForView(myView); var indexedData = CurrentClient.ToValuesList(); var fvp = getNameValuePairs(viewFields, indexedData); //remove date of visit field fvp.RemoveAll(t => t.Field.name == Constants.FIELD_PPX_DATEOFVISIT || t.Field.name == Constants.FIELD_VMMC_DATEOFVISIT ); setViewData(fvp); } }
public static string deidentifyBlob(this string dataBlob, string formName) { var toReturn = string.Empty; //we deserialise the blob to its base form var deserialised = DbSaveableEntity.fromJson <GeneralEntityDataset>( new KindItem(dataBlob) ); var fieldValues = deserialised.FieldValues; //we get the field dictionary for this entity //we read each field, and deidentify if needed based on field attributes //and copy to out object //copy out object to the out entity return(dataBlob); }
private async void SaveUserOptions_Click(object sender, EventArgs e) { var userAuthenticator = new UserAuthenticator(); var userCreds = userAuthenticator.LoadCredentials(); var tNames = FindViewById <EditText>(Resource.Id.tUserNames); var tusername = FindViewById <EditText>(Resource.Id.tUserName); var tpasscode = FindViewById <EditText>(Resource.Id.tUserPassCode); var tpasscodAgain = FindViewById <EditText>(Resource.Id.tUserPassCodeAgain); if (string.IsNullOrWhiteSpace(tNames.Text) || string.IsNullOrWhiteSpace(tusername.Text) || string.IsNullOrWhiteSpace(tpasscode.Text) || (tpasscode.Text != tpasscodAgain.Text)) { showDialog("Alert", "UserName and Passcode are both required, and Passcodes should match"); return; } var uname = tusername.Text.ToLowerInvariant(); var passcode = Convert.ToInt32(tpasscode.Text); var hash = userAuthenticator.computeHash(uname, passcode); var matchingCred = (from cred in userCreds where cred.UserId == uname select cred).FirstOrDefault(); AppUser user = null; if (matchingCred == null) { //means we're ading a new user Toast.MakeText(this, "Creating new user", ToastLength.Long); var id = AppInstance.Instance.LocalEntityStoreInstance.InstanceLocalDb.newId(); user = new AppUser() { Id = new KindKey(id), EntityId = new KindKey(id), UserId = uname, Names = tNames.Text.ToUpperInvariant(), KnownBolg = hash, KindMetaData = (new KindMetaData() { chksum = 1, devid = AppInstance.Instance.Configuration.Serial, facidx = 0 } ).getJson() }; } else { //confirm with the user Toast.MakeText(this, "User found. Updating record", ToastLength.Long); user = matchingCred; user.KnownBolg = hash; user.Names = tNames.Text.ToUpperInvariant(); if (user.EntityId == null) { user.EntityId = user.Id; } if (string.IsNullOrWhiteSpace(user.KindMetaData)) { user.KindMetaData = (new KindMetaData() { chksum = 1, devid = AppInstance.Instance.Configuration.Serial, facidx = 0 } ).getJson(); } else { var metadata = new KindMetaData().fromJson(new KindItem(user.KindMetaData)); metadata.chksum += 1; user.KindMetaData = metadata.getJson(); } } //we save to the database Toast.MakeText(this, "Saving to database", ToastLength.Long); var saveableEntity = new DbSaveableEntity(user) { kindName = UserAuthenticator.KindName }; saveableEntity.Save(); Toast.MakeText(this, "Changes saved", ToastLength.Long); //we reset the form tNames.Text = ""; tusername.Text = ""; tpasscode.Text = ""; tpasscodAgain.Text = ""; //save to cloud var dbentity = new DbSaveableEntity(user.asGeneralEntity(UserAuthenticator.KindName)) { kindName = UserAuthenticator.KindName }; AppInstance.Instance.CloudDbInstance.AddToOutQueue(dbentity); await AppInstance.Instance.CloudDbInstance.EnsureServerSync(new WaitDialogHelper(this, sendToast)); }
private async Task <int> doFinalise() { //we get the data var data = getFormData(); if (data.Count == 0) { return(0); } //if (isInEditMode()) //{ // //means we have data to edit // var jsonRecord = this.Intent.GetStringExtra(Constants.BUNDLE_DATATOEDIT); // var oldRec = DbSaveableEntity // .fromJson<GeneralEntityDataset>(new KindItem(jsonRecord)); // if (!string.IsNullOrWhiteSpace(oldRec.KindMetaData)) // { // var oldMetaData = new KindMetaData().fromJson(new KindItem(oldRec.KindMetaData)); // metaData.chksum = oldMetaData.chksum + 1; // } //} var dateEdited = DateTime.Now; var saveable = getEntityDataset(data, dateEdited); //we start the saving business //:) // //1. Save to module specific lookup tables, if on registration page if (IsRegistrationEndPage()) { saveClientSummary(saveable.FieldValues, saveable.EntityId); } //2. Save the whole record to the local blob db var saveableEntity = new DbSaveableEntity(saveable) { kindName = _kindName }; saveableEntity.Save(); //3. Extract record header and save to Record Summary new LocalDB3().DB.InsertOrReplace(new RecordSummary() { Id = saveable.Id.Value, EntityId = saveable.EntityId.Value, VisitDate = dateEdited, KindName = saveable.FormName }); //4. Save to OutDb, which is used for web uploading //fire and forget AppInstance.Instance.CloudDbInstance.AddToOutQueue(saveableEntity); AppInstance.Instance.TemporalViewData.Clear(); //5. Initiate Server Sync. Ideally, this should be non-blocking //we show the splash screen and await results of the operation //todo: show dialog when beginning server sync and await excution var syncRes = await AppInstance.Instance. CloudDbInstance.EnsureServerSync(new WaitDialogHelper(this, sendToast)); return(syncRes); }