public async Task BeginDropDatabase(Action sucessCallback, Action <Exception> failureCallback) { await Task.Run(() => { try { FileInfo fileInfo = new FileInfo(this.DatabaseFileName); ISQLiteConnection con = this.Connection as ISQLiteConnection; if (null != con) { con.Dispose(); GC.Collect(); } fileInfo.Delete(); this.Connection = null; sucessCallback(); } catch (Exception ex) { Telemetry.TrackException(ex); failureCallback(ex); } }); }
public CustomListAdapter(Activity context) //We need a context to inflate our row view from : base() { this.context = context; //For demo purposes we hard code some data here //sqlite save var myanimallist = new List <Animal>(); ISQLiteConnection conn = null; ISQLiteConnection connactiond = null; ISQLiteConnectionFactory factory = new MvxDroidSQLiteConnectionFactory(); ISQLiteConnectionFactory factoryd = new MvxDroidSQLiteConnectionFactory(); var sqlitedir = new Java.IO.File(global::Android.OS.Environment.GetExternalStoragePublicDirectory(global::Android.OS.Environment.DirectoryPictures), "Boruto"); string filenameaction = sqlitedir.Path + "/mysqliteaction.db"; connactiond = factoryd.Create(filenameaction); connactiond.CreateTable <MyCheckbox>(); connactiond.CreateCommand("DELETE FROM MyCheckbox").ExecuteNonQuery(); connactiond.Dispose(); connactiond.Commit(); connactiond.Close(); if (File.Exists(filenameaction)) { File.Delete(filenameaction); } string filename = sqlitedir.Path + "/mysqliteimage.db"; //Toast.MakeText(Application.Context, filename, ToastLength.Long).Show(); conn = factory.Create(filename); conn.CreateTable <Myimage>(); var countidx = 0; foreach (var e in conn.Table <Myimage>().Where(e => e.Date == "30-12-2016")) { var mystrarray = e.Imagepath.Split('/'); var myeleidx = mystrarray.Length - 1; var newanialele = new Animal() { Name = mystrarray[myeleidx], Description = e.Imagepath, Image = e.Imagepath, Mycheckbox = countidx }; myanimallist.Add(newanialele); countidx++; } //Toast.MakeText(this, mycount.ToString(), ToastLength.Short).Show(); conn.Close(); this.items = myanimallist; //sqlite save end }
public void CloseConnection() { if (_connection != null) { lock (_connectionLock) { if (_connection != null) { _connection.Dispose(); _connection = null; } } } }
async public Task BeginRestore(string myBackupDirectory, bool relocateOnRestore, Action sucessCallback, Action <Exception> failureCallback) { await Task.Run(() => { try { // Validate input parameters if (string.IsNullOrEmpty(this.DatabaseFileName) || string.IsNullOrWhiteSpace(this.DatabaseFileName)) { throw new NullReferenceException("Target database file is empty."); } // Cloase down our DB connectoin so that the files can be overwritten ISQLiteConnection con = this.Connection as ISQLiteConnection; if (null != con) { con.Dispose(); GC.Collect(); } // Copy all of the files across DirectoryInfo sourceDirinfo = new DirectoryInfo(myBackupDirectory); // Get all of the files in the source directory FileInfo[] sourceFileInfoList = sourceDirinfo.GetFiles(); FileInfo destFileInfo = new FileInfo(this.DatabaseFileName); // Get the destination directory foreach (FileInfo dbFileInfo in sourceFileInfoList) { string destFileName = Path.Combine(destFileInfo.DirectoryName, dbFileInfo.Name); dbFileInfo.CopyTo(destFileName, true); } sucessCallback(); } catch (Exception ex) { Telemetry.TrackException(ex); failureCallback(ex); } }); }
internal void ResetConnection() { _sqlConnection.Dispose(); _sqlConnection = new SQLiteConnection(DatabasePath); }