//REGRESA LOS CONTACTOS REGISTRADOS void RegresaContactos() { //INICIALIZAMOS NUESTRO DATASTORE InicializarDropboxDatastore(Account.LinkedAccount); //RECUPERAMOS LA TABLA DE NUESTRO DATASTORE DBTable table = DropboxDatastore.GetTable("Contactos"); //INICIALIZAMOS LA LISTA DE CONTACTOS Lista_Contactos = new List <Contacto> (); //RECUPERAMOS TODOS LOS CONTACTOS DE NUESTRA TABLA var results = table.Query(); //SI HAY CONTACTOS LLENAMOS NUESTRA LISTA Y LA ASIGNAMOS A NUESTRO ADAPTER if (results.Count() > 0) { foreach (DBRecord row in results.AsList()) { Lista_Contactos.Add(new Contacto(row.GetString("Id"), row.GetString("Nombre"), row.GetString("Telefono"))); } lvadapter.refresh(Lista_Contactos); } //SINCRONIZAMOS LOS DATOS DropboxDatastore.Sync(); //CERRAMOS LA CONEXION A NUESTRO DATASTORE DropboxDatastore.Close(); }
public void Sync() { if (DropboxDatastore == null) { return; } var changes = DropboxDatastore.Sync(); if (changes != null && changes.Count > 0) { var messageType = typeof(DrbxReceivedMessage <>); var messenger = Mvx.Resolve <IMvxMessenger>(); foreach (var change in changes) { var map = MvxDBMapping.Get(change.Key); if (map == null) { continue; } Type[] typeArgs = { map.Type }; var makeme = messageType.MakeGenericType(typeArgs); foreach (var record in change.Value) { var m = Activator.CreateInstance(makeme, this, record.ToMvxDBRecord()) as MvxMessage; messenger.Publish(m, makeme); } } } }
void StartApp(DBAccount account = null) { InitializeDropbox(account); Log("StartApp", "Syncing monkies..."); DropboxDatastore.Sync(); Monkeys = GetMonkeys(); DrawMonkeys(Monkeys); }
public void Delete() { if (DropboxDatastore != null && DropboxDatastore.IsOpen) { DropboxDatastore.Close(); DropboxDatastore.Manager.DeleteDatastore("default"); } }
//REGISTRA CONTACTO void RegistraContacto(String Nombre, String Telefono) { //INICIALIZAMOS NUESTRO DATASTORE InicializarDropboxDatastore(Account.LinkedAccount); //RECUPERAMOS LA TABLA DE NUESTRO DATASTORE PARA REGISTRAR EN ELLA EL NUEVO CONTACTO DBTable table = DropboxDatastore.GetTable("Contactos"); int New_id = 1; //RECUPERAMOS TODO LOS CONTACTOS DE LA TABLA var results = table.Query(); //RECUPERAMOS EL ULTIMO ID DEL CONTACTO REGISTRADO Y LO AUMENTAMOS PARA REGISTRA OTRO NUEVO Y NO SE //DUPLIQUEN if (results.Count() > 0) { DBRecord UltimoRegistro = results.AsList() [results.Count() - 1]; New_id = int.Parse(UltimoRegistro.GetString("Id")) + 1; } //CREAMOS UN OBJECTO DE TIPO CONTACTO Contacto cto = new Contacto(New_id.ToString(), Nombre, Telefono); //REGISTRAMOS EL OBJECTO CONTACTO PASANDO LA PROPIEDAD DE "Campos" QUE ES DE TIPO DBFields table.Insert(cto.Campos()); //VERIFICAMOS QUE NUESTRA DATASTORE ESTE ABIERTA PARA PODER REALIZAR EL ALTA DEL CONACTO if (!EstatusDataStore()) { //REINICIAMOS LA CONEXION CON DROPBOX ReiniciarConexion(); } else { // SI NO HAY NINGUN PROBLEMA DE CONEXION PROCEDEMOS A REALIZAR LA SINCRONIZACION CON NUESTRO DATASTORE // Y DAR DE ALTA NUESTRO CONTACTO DropboxDatastore.Sync(); Toast.MakeText(this, "Contacto Registrado", ToastLength.Long).Show(); txtNombre.Text = ""; txtTelefono.Text = ""; //CERRAMOS LA CONEXION A NUESTRO DATASTORE DropboxDatastore.Close(); } }
void HandleStoreChange(object sender, DBDatastore.SyncStatusEventArgs e) { if (e.P0.SyncStatus.HasIncoming) { if (!Account.HasLinkedAccount) { Log("InitializeDropbox", "Account no longer linked, so abandoning."); DropboxDatastore.DatastoreChanged -= HandleStoreChange; } Console.WriteLine("Datastore needs to be re-synced."); DropboxDatastore.Sync(); Monkeys = GetMonkeys(); DrawMonkeys(Monkeys); } }
void UpdateDropbox() { Log("Updating Dropbox"); var table = DropboxDatastore.GetTable("monkeys"); // Update records in local cache. if (Records.Count == 0) { for (var i = 0; i < MainLayout.ChildCount; i++) { var view = (MonkeyView)MainLayout.GetChildAt(i); var monkey = view.Monkey; monkey.Z = i; var record = table.GetOrInsert(monkey.Name, monkey.ToFields()); Records[monkey.Name] = record; } } else { for (var i = 0; i < MainLayout.ChildCount; i++) { var view = (MonkeyView)MainLayout.GetChildAt(i); var monkey = view.Monkey; monkey.Z = i; DBRecord record; var hasValue = Records.TryGetValue(monkey.Name, out record); if (hasValue) { record.SetAll(monkey.ToFields()); } else { table.GetOrInsert(monkey.Name, monkey.ToFields()); } } } if (!VerifyStore()) { RestartAuthFlow(); } else { DropboxDatastore.Sync(); } }
//REGISTRA CONTACTO void BuscaContacto(string id) { InicializarDropboxDatastore(Account.LinkedAccount); //RECUPERAMOS LA TABLA DE NUESTRO DATASTORE PARA REGISTRAR EN ELLA EL NUEVO CONTACTO DBTable table = DropboxDatastore.GetTable("Contactos"); //RECUPERA CONTACTO CREANDO UN FILTRO var fieldsFiltro = new DBFields(); fieldsFiltro.Set("Id", id); //APLICAMOS EL FILTRO AL QUERY var results = table.Query(fieldsFiltro); //VERIFICAMOS EL RESULTADO Y SI TIENE RECUPERAMOS EL CONTACTO if (results.Count() > 0) { temp_contacto = results.AsList() [0]; txtNombre.Text = temp_contacto.GetString("Nombre"); txtTelefono.Text = temp_contacto.GetString("Telefono"); } else { Toast.MakeText(this, "No se encontro el contacto", ToastLength.Long).Show(); } //SINCRONIZAMOS LOS DATOS DropboxDatastore.Sync(); //CERRAMOS LA CONEXION A NUESTRO DATASTORE DropboxDatastore.Close(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Create your application here SetContentView(Resource.Layout.editar_contacto); btnActualizar = FindViewById <Button> (Resource.Id.btnActualizar); btnBorrar = FindViewById <Button> (Resource.Id.btnBorrar); txtNombre = FindViewById <EditText> (Resource.Id.txtNombre); txtTelefono = FindViewById <EditText> (Resource.Id.txtTelefono); //ACTUALIZA LOS DATOS DEL CONTACTO btnActualizar.Click += delegate { //VERIFICAMOS QUE LA VARAIBLE NO SEA NULL if (temp_contacto != null) { //INICIALIZAMOS EL DATASTORE InicializarDropboxDatastore(Account.LinkedAccount); //ASIGNAMOS LOS NUEVOS VALORES temp_contacto.Set("Nombre", txtNombre.Text); temp_contacto.Set("Telefono", txtTelefono.Text); //SINCRONIZAMOS PARA CONFIRMAR LOS CAMBIOS DropboxDatastore.Sync(); Toast.MakeText(this, "Se actualizo el contacto", ToastLength.Long).Show(); //CERRAMOS EL DATASTORE DropboxDatastore.Close(); } else { Toast.MakeText(this, "No hay objecto para actualizar", ToastLength.Long).Show(); } }; //BORRA EL CONTACTO btnBorrar.Click += delegate { //VERIFICAMOS QUE LA VARAIBLE NO SEA NULL if (temp_contacto != null) { //INICIALIZAMOS EL DATASTORE InicializarDropboxDatastore(Account.LinkedAccount); //INVOCAMOS EL METODO DELETE temp_contacto.DeleteRecord(); //SINCRONIZAMOS PARA CONFIRMAR LOS CAMBIOS DropboxDatastore.Sync(); Toast.MakeText(this, "Contacto Borrado", ToastLength.Long).Show(); txtNombre.Text = ""; txtTelefono.Text = ""; //CERRAMOS EL DATASTORE DropboxDatastore.Close(); } else { Toast.MakeText(this, "No hay objecto para eliminar", ToastLength.Long).Show(); } }; id = Intent.GetStringExtra("id") ?? "0"; IniciaConexionCuentaDropBox(); }
IEnumerable <Monkey> GetMonkeys() { if (!VerifyStore()) { RestartAuthFlow(); return(null); } Log("GetMonkeys", "Getting monkies..."); var table = DropboxDatastore.GetTable("monkeys"); var values = new List <Monkey>(6); var queryResults = table.Query(); var results = queryResults.ToEnumerable <DBRecord>().Where(r => !r.IsDeleted).ToList(); // If we have more records than we should, // just start fresh. if (results.Count > 6) { foreach (var record in results) { record.DeleteRecord(); } } if (results.Count == 0) { // Generate random monkeys. values.AddRange(Monkey.GetAllMonkeys()); Records = new Dictionary <string, DBRecord>(); } else { Records = results.ToDictionary(x => x.GetString("Name"), x => x); // Process existing monkeys. foreach (var row in results) { // Remove any MonkeyBox app data that's still in the old format. var currentRow = row; if (row.FieldNames().All(r => currentRow.GetFieldType(r).ToString() == "STRING")) { row.DeleteRecord(); continue; } values.Add(new Monkey { Name = row.GetString("Name"), Scale = Convert.ToSingle(row.GetDouble("Scale")), Rotation = Convert.ToSingle(row.GetDouble("Rotation")), X = Convert.ToSingle(row.GetDouble("X")), Y = Convert.ToSingle(row.GetDouble("Y")), Z = Convert.ToInt32(row.GetLong("Z")) }); } // Create new MonkeyBox app data if we just removed old data. if (values.Count == 0) { // Generate random monkeys. values.AddRange(Monkey.GetAllMonkeys()); foreach (var val in values) { var record = table.GetOrInsert(val.Name, val.ToFields()); Records[val.Name] = record; } DropboxDatastore.Sync(); } } return(values); }
public IMvxDBTable <T> GetTable <T>(string tableName) where T : IMvxDBEntity { return(new MvxDBTable <T>(DropboxDatastore.GetTable(tableName), this)); }