private async void MenuServerSync_Click(object sender, RoutedEventArgs e) { //we test the connection var isConnected = await CloudDb.checkConnection(); if (!isConnected) { MessageBox.Show("No internet connection detected"); return; } var dialog = MessageBox.Show("Do you want to start data download from the server", "Please confirm action", MessageBoxButton.OKCancel); if (dialog != MessageBoxResult.OK) { return; } //we get list of files to download var syncOldData = this.menuServerSyncOldData == sender; var res = await AppInstance.Instance.CloudDbInstance .EnsureServerSync(setProgressValue, syncOldData); //for each file, we download AppInstance.Instance.CloudDbInstance.RefreshLocalEntities(setProgressValue); //we decrypt //we deidentify //and save to the main datastore MessageBox.Show("Menu item clicked "); }
public void InitialiseAppResources(AssetManager assetManager, Activity context) { AppDomain.CurrentDomain.UnhandledException += uncaughtExceptionHandler; //ContextManager = null; ModuleContext = null; _assetManager = assetManager; _mainContext = context; TemporalViewData = new Dictionary <int, List <FieldValuePair> >(); ApiAssets = new Dictionary <string, string>(); //we read the api key file var inputStream = assetManager.Open(Constants.API_KEYFILE); var jsonObject = System.Json.JsonValue.Load(inputStream); foreach (var assetName in Constants.ASSET_LIST) { ApiAssets[assetName] = jsonObject.decryptAndGetApiSetting(assetName); } //we need to have this class initialised LocalEntityStoreInstance = new LocalEntityStore(); LocalEntityStoreInstance.buildTables(false); CloudDbInstance = new CloudDb(_assetManager); //Android.OS.Build.Serial var configuration = new LocalDB3().DB.Table <DeviceConfiguration>().FirstOrDefault(); Configuration = configuration; }
public void InitialiseAppResources(AssetManager assetManager, Activity context) { //ContextManager = null; ModuleContext = null; _assetManager = assetManager; _mainContext = context; TemporalViewData = new Dictionary <int, List <FieldValuePair> >(); ApiAssets = new Dictionary <string, string>(); //we read the api key file var bytes = SyncManager.Properties.Resources.api_keys; var inputStream = new MemoryStream(bytes).toText(); //var keys = new Dictionary<string, string>(); var jObject = Newtonsoft.Json.JsonConvert.DeserializeObject(inputStream) as Newtonsoft.Json.Linq.JContainer; var tokens = jObject.ToList <JToken>(); foreach (var token in tokens) { var name = token.First(); var assetName = name.Path; var assetValue = name.Value <string>(); if (Constants.ASSET_LIST.Contains(assetName.ToLowerInvariant())) { ApiAssets[assetName] = assetValue; } } var saveDictionaryToDb = false; if (saveDictionaryToDb) { updateFieldDictionary(); } CloudDbInstance = new CloudDb() { ApiAssets = ApiAssets, }; //var allKindNames = new List<string>(); //foreach (var ctxt in currentContexts) // foreach (var kind in ctxt.KindDisplayNames.Keys) // allKindNames.Add(kind); //this creates a table used to store a decrypted set of similar data var dropAndRecreate = false; var allTables = CloudDb.getAllKindNames(); foreach (var table in allTables) { new CloudLocalStore(table.toKind()).build(); new CloudLocalStore(CloudDb.getLocalTableName(table).toKind()) .build(dropAndRecreate); new FieldValueStore(CloudDb.getTableFieldValueName(table)) .build(dropAndRecreate); } }
public Button updateUnsyncedRecsStats() { var unsyncdRecs = new CloudDb(Assets).GetRecordsToSync(); var buttonServerSync = FindViewById <Button>(Resource.Id.buttonDatastoreSync); buttonServerSync.Text = string.Format("Upload ({0} available)", unsyncdRecs.Count); return(buttonServerSync); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); showDefaultHome(); var buttonSendReport = FindViewById <Button>(Resource.Id.buttonSendReport); buttonSendReport.Click += (sender, e) => { var textRecordSummaries = FindViewById <TextView>(Resource.Id.textRecordSummaries); if (textRecordSummaries == null) { return; } if (string.IsNullOrWhiteSpace(textRecordSummaries.Text) || textRecordSummaries.Text == Resources.GetString(Resource.String.sys_not_updated)) { sendToast("No data to send. Run a report first", ToastLength.Long); return; } new EmailSender() { appContext = this, receipients = new List <string>() { "*****@*****.**" }, messageSubject = "Summary Report", message = textRecordSummaries.Text }.Send(); }; //we get the number of unsync'd records var unsyncdRecs = new CloudDb(Assets).GetRecordsToSync(); var buttonServerSync = FindViewById <Button>(Resource.Id.buttonDatastoreSync); buttonServerSync.Text = string.Format("Save to Server. {0} unsaved", unsyncdRecs.Count); buttonServerSync.Click += async(sender, e) => { Toast.MakeText(this, "Performing action requested", Android.Widget.ToastLength.Short).Show(); await AppInstance.Instance.CloudDbInstance.EnsureServerSync( new WaitDialogHelper(this, sendToast)); Toast.MakeText(this, "Completed performing action requested", Android.Widget.ToastLength.Short).Show(); }; }
public void InitialiseAppResources(AssetManager assetManager, Activity context) { //ContextManager = null; ModuleContext = null; _assetManager = assetManager; _mainContext = context; TemporalViewData = new Dictionary <int, List <FieldValuePair> >(); ApiAssets = new Dictionary <string, string>(); //we read the api key file var bytes = Properties.Resources.api_keys; var inputStream = new MemoryStream(bytes).toText(); //var keys = new Dictionary<string, string>(); var jObject = Newtonsoft.Json.JsonConvert.DeserializeObject(inputStream) as Newtonsoft.Json.Linq.JContainer; var tokens = jObject.ToList <JToken>(); foreach (var token in tokens) { var name = token.First(); var assetName = name.Path; var assetValue = name.Value <string>(); if (Constants.ASSET_LIST.Contains(assetName.ToLowerInvariant())) { ApiAssets[assetName] = assetValue; } } //initialise the data dictionary, if not yet var currentContexts = new List <BaseContextManager>(); var allContexts = new List <BaseContextManager>() { new LspContextManager(null, null), new VmmcContextManager(null, null), new PpxContextManager(null, null) }; foreach (var projContext in allContexts) { if (projContext.FieldItems != null) { currentContexts.Add(projContext); } } var saveDictionaryToDb = false; if (saveDictionaryToDb) { var fieldDictionaryStore = new FieldDictionaryStore(); foreach (var currCtxt in currentContexts) { fieldDictionaryStore.getFields(currCtxt.Name, currCtxt.FieldItems); } fieldDictionaryStore.saveToDb(); } CloudDbInstance = new CloudDb() { ApiAssets = ApiAssets }; var allTables = CloudDb.getAllKindNames(); foreach (var table in allTables) { new CloudLocalStore(table.toKind()).build(); //this creates a table used to store a decrypted set of similar data var dropAndRecreate = false; new CloudLocalStore(CloudDb.getLocalTableName(table).toKind()) .build(dropAndRecreate); new FieldValueStore(CloudDb.getTableFieldValueName(table)) .build(dropAndRecreate); } }