public static DBRecord Update(this DBRecord record, TodoItem t) { record.Set("Title", t.Name); record.Set("Description", t.Notes); record.Set("IsDone", t.Done); return(record); }
public DBRecord Decompress(ARZFile arzFile) { // record variables have this format: // 0x00 int16 specifies data type: // 0x0000 = int - data will be an int32 // 0x0001 = float - data will be a Single // 0x0002 = string - data will be an int32 that is index into string table // 0x0003 = bool - data will be an int32 // 0x02 int16 specifies number of values (usually 1, but sometimes more (for arrays) // 0x04 int32 key string ID (the id into the string table for this variable name // 0x08 data value byte[] data = DecompressBytes(arzFile); // Lets dump the file to disk //System.IO.FileStream dump = new System.IO.FileStream("recdump.dat", System.IO.FileMode.Create, System.IO.FileAccess.Write); //try //{ // dump.Write(data, 0, data.Length); //} //finally //{ // dump.Close(); //} int numDWords = data.Length / 4; int numVariables = numDWords / 3; if (data.Length % 4 != 0) { throw new ApplicationException(string.Format("Error while parsing arz record {0}, data Length = {1} which is not a multiple of 4", ID, (int)data.Length)); } DBRecord record = new DBRecord(ID, RecordType); // Create a memory stream to read the binary data MemoryStream inStream = new MemoryStream(data, false); BinaryReader inReader = new BinaryReader(inStream); try { int i = 0; while (i < numDWords) { int pos = (int)inReader.BaseStream.Position; short dataType = inReader.ReadInt16(); short valCount = inReader.ReadInt16(); int variableID = inReader.ReadInt32(); string variableName = arzFile.Getstring(variableID); if (variableName == null) { throw new ApplicationException(string.Format("Error while parsing arz record {0}, variable is NULL", ID)); } if (dataType < 0 || dataType > 3) { throw new ApplicationException(string.Format("Error while parsing arz record {0}, variable {2}, bad dataType {3}", ID, variableName, dataType)); } Variable v = new Variable(variableName, (VariableDataType)dataType, valCount); if (valCount < 1) { throw new ApplicationException(string.Format("Error while parsing arz record {0}, variable {1}, bad valCount {2}", ID, variableName, valCount)); } i += 2 + valCount; // increment our dword count for (int j = 0; j < valCount; ++j) { switch (v.DataType) { case VariableDataType.Integer: case VariableDataType.Boolean: { int val = inReader.ReadInt32(); v[j] = val; break; } case VariableDataType.Float: { float val = inReader.ReadSingle(); v[j] = val; break; } case VariableDataType.StringVar: { int id = inReader.ReadInt32(); string val = arzFile.Getstring(id); if (val == null) { val = ""; } else { val = val.Trim(); } v[j] = val; break; } default: { int val = inReader.ReadInt32(); v[j] = val; break; } } } record.Set(v); } } finally { inReader.Close(); } return(record); }
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(); }