/// <summary>
        /// Connects to the database.
        /// </summary>
        /// <param name="sqlitePlatform">The sqlite platform.</param>
        /// <param name="connectionString">The connection string.</param>
        public async Task ConnectAsync(ISQLitePlatform sqlitePlatform, SQLiteConnectionString connectionString)
        {
            if(IsConnected) {
                throw new InvalidOperationException("Database connection already connected!");
            }

            await LockAsync().ConfigureAwait(false);
            try {
                _connectionString = connectionString;

                Logger.Debug($"Opening connection to database {_connectionString.ConnectionString}...");
                Connection = new SQLiteConnectionWithLock(sqlitePlatform, connectionString);
                AsyncConnection = new SQLiteAsyncConnection(() => Connection);
            } finally {
                Release();
            }
        }
예제 #2
0
        private static SQLiteAsyncConnection CreateDatabaseAsync()
        {
            // Create a new connection

            try
            {
                var platform = new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT();
                var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path,"Storage.SQLite");
                var connectionString = new SQLiteConnectionString(dbPath, true);
                var dbLockedCon = new SQLiteConnectionWithLock(platform ,connectionString);
            
                var db = new SQLiteAsyncConnection(() => dbLockedCon);

                 //Create the tables that do not exist
                Type[] tables = 
                { 
                       typeof(Folders)
                     , typeof(Accounts)
                     , typeof(Emails)
                     , typeof(EmailFrom)
                     , typeof(EmailSender)
                     , typeof(EmailReplyTo)
                     , typeof(Settings)
                };
                var d = db.CreateTablesAsync(tables).Result;
                return db;
            }
            catch(Exception e)
            {
                var mess = e.Message;
                throw;
            }
        }
예제 #3
0
        public Database(ISQLitePlatform platform, string databasePath)
        {
            _connectionParameters = new SQLiteConnectionString(databasePath, false);
            _sqliteConnectionPool = new SQLiteConnectionPool(platform);

            _dbConnection = new SQLiteAsyncConnection(() => _sqliteConnectionPool.GetConnection(_connectionParameters));
        }
		public void SQLiteSimpleCacheRemoveAllTest ()
		{
			SQLiteConnectionString connstring = new SQLiteConnectionString("somepath",false,new Mocks.MockBlobSerializer());
			SQLiteSimpleCache cache = new SQLiteSimpleCache(new Mocks.MockSqlLiteProvider(),connstring,new Mocks.MockByteSerializer());
			cache.RemoveAll (new List<string>{"1","2","3"});
  			Assert.AreEqual (3, MockBase.DeleteStatementsExecuted.Count);
		}
		public void SQLiteSimpleCacheSet_T_Test()
		{
			SQLiteConnectionString connstring = new SQLiteConnectionString("somepath",false,new Mocks.MockBlobSerializer());
			SQLiteSimpleCache cache = new SQLiteSimpleCache(new Mocks.MockSqlLiteProvider(),connstring,new Mocks.MockByteSerializer());
			cache.Set<MockSQLiteData>("1",new MockSQLiteData());
			Assert.AreEqual (1, MockBase.InsertOrReplaceStatementsExecuted.Count);
		}
		public void SQLiteSimpleCacheGet_T_Test ()
		{
			SQLiteConnectionString connstring = new SQLiteConnectionString("somepath",false,new Mocks.MockBlobSerializer());
			SQLiteSimpleCache cache = new SQLiteSimpleCache(new Mocks.MockSqlLiteProvider(),connstring,new Mocks.MockByteSerializer());
			MockSQLiteData myObject = cache.Get<MockSQLiteData>("1");
			//The SQLIteConnection seems to run the command twice 
			//this might be a bug in SQLite that is fixed later thus less then or equal is used.
			Assert.LessOrEqual(1, MockBase.SelectStatementsExecuted.Count);
		}
		public void SQLiteSimpleCacheConstTest ()
		{
			SQLiteConnectionString connstring = new SQLiteConnectionString("somepath",false,new Mocks.MockBlobSerializer());
			SQLiteSimpleCache cache = new SQLiteSimpleCache(new Mocks.MockSqlLiteProvider(),connstring,new Mocks.MockByteSerializer());
			Assert.IsInstanceOf<SQLiteSimpleCache>(cache);
			Assert.AreEqual (1, MockBase.CreateStatementsExecuted.Count);


		}
예제 #8
0
        public ExpenseRepository()
        {
            var platform = DependencyService.Get<ISQLiteDatabase>().GetSQLitePLatform();
            var dbFolder = DependencyService.Get<ISpecialFolder>().DatabaseFolder;
            var dbPath = Path.Combine(dbFolder, DB_NAME);

            var connStg = new SQLiteConnectionString(dbPath, true); 
            Connection = new SQLiteAsyncConnection(() => new SQLiteConnectionWithLock(platform, connStg));
			Init();
        }
예제 #9
0
        public DataService(IDeviceInfo deviceInfo, SQLite.Net.Interop.ISQLitePlatform platform)
        {
            _deviceInfo       = deviceInfo;
            _platform         = platform;
            _path             = Path.Combine(_deviceInfo.DatabasePath, DBNAME);
            _connectionString = new SQLiteConnectionString(_path, true);
            _connectionPool   = new SQLiteConnectionPool(_platform);

            this.CreateTablesIfRequired();
        }
        public SqliteEventStore(ISQLitePlatform sqLitePlatform, string databasePath, GetUtcNow getUtcNow = null)
        {
            Ensure.That(sqLitePlatform, "sqLitePlatform").IsNotNull();
            Ensure.That(databasePath, "databasePath").IsNotNull();

            _getUtcNow = getUtcNow ?? SystemClock.GetUtcNow;
            _connectionPool = new SQLiteConnectionPool(sqLitePlatform);
            var connectionString = new SQLiteConnectionString(databasePath, false);
            _getConnection = () => _connectionPool.GetConnection(connectionString);
        }
        public SQLiteConnection GetConnection()
        {
            var sqliteFilename = "IncidentsSQLite.db3";
            string documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // Documents folder
            var path = Path.Combine (documentsPath, sqliteFilename);

            var platform = new SQLitePlatformAndroid ();
            var sqLiteConnectionString = new SQLiteConnectionString(path, false);

            var conn = new SQLiteConnectionWithLock (platform, sqLiteConnectionString);
            return conn;
        }
예제 #12
0
        //  public SQLiteAsyncConnection GetConnection()
        //   {
        //var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

        //var path = Path.Combine(documentsPath, "MySQLite.db3");

        //Console.WriteLine(path);

        //return new SQLiteAsyncConnection(path);

        //}

        public SQLite.Net.Async.SQLiteAsyncConnection GetConnection()
        {
            var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            var path = Path.Combine(documentsPath, "MySQLite.db3");

            var connectionString   = new SQLite.Net.SQLiteConnectionString(path, false);
            var connectionWithLock = new SQLite.Net.SQLiteConnectionWithLock(new SQLite.Net.Platform.XamarinIOS.SQLitePlatformIOS(), connectionString);
            var connection         = new SQLite.Net.Async.SQLiteAsyncConnection(() => connectionWithLock);

            return(connection);
        }
예제 #13
0
		public SQLite.Net.Async.SQLiteAsyncConnection GetConnection()
		{
			const string sqliteFilename = "Mais.db3";  
			string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
			var path = Path.Combine(documentsPath, sqliteFilename);

			// Cria a conexão
			var plat = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid();
			var param = new SQLite.Net.SQLiteConnectionString(path, false);
			var conn = new SQLite.Net.Async.SQLiteAsyncConnection(() => new SQLiteConnectionWithLock(plat, param));

			return conn;
		}
예제 #14
0
		public SQLiteAsyncConnection GetConnection()
		{
			var sqliteFilename = "Mais.db3";
			string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); // Documents folder
			string libraryPath = Path.Combine(documentsPath, "..", "Library"); // Library folder
			var path = Path.Combine(libraryPath, sqliteFilename);
			// Create the connection
			var plat = new SQLite.Net.Platform.XamarinIOS.SQLitePlatformIOS();
			var param = new SQLite.Net.SQLiteConnectionString(path, false);
			var conn = new SQLite.Net.Async.SQLiteAsyncConnection(() => new SQLiteConnectionWithLock(plat, param));
			// Return the database connection
			return conn;

		}
예제 #15
0
        public SQLiteAsyncConnection GetAsyncConnection()
        {
            var sqliteFilename = "IncidentsSQLite.db3";
            string documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // Documents folder
            string libraryPath = Path.Combine (documentsPath, "..", "Library"); // Library folder
            var path = Path.Combine (libraryPath, sqliteFilename);

            var platform = new SQLitePlatformIOS ();
            var sqLiteConnectionString = new SQLiteConnectionString(path, false);

            var conn = new SQLiteConnectionWithLock (platform, sqLiteConnectionString);
            var connAsync = new SQLiteAsyncConnection (() => conn);
            return connAsync;
        }
예제 #16
0
 private void SetConnection()
 {
     try
     {
         var path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, _databaseName);
         var platform = new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT();
         var param = new SQLiteConnectionString(path, false);
         _connectionToDatabaseAsync = new SQLiteAsyncConnection(() => new SQLiteConnectionWithLock(platform, param));
         _connectionToDatabase = new SQLiteConnection(platform, path);
     }
     catch
     {
         _connectionToDatabaseAsync = null;
     }
 }
예제 #17
0
        public SQLiteConnectionWithLock GetConnection(SQLiteConnectionString connectionString)
        {
            lock (_entriesLock)
            {
                Entry entry;
                var   key = connectionString.ConnectionString;

                if (!_entries.TryGetValue(key, out entry))
                {
                    entry         = new Entry(_sqlitePlatform, connectionString);
                    _entries[key] = entry;
                }

                return(entry.Connection);
            }
        }
        public SQLiteConnectionWithLock GetConnection(SQLiteConnectionString connectionString)
        {
            lock (_entriesLock)
            {
                Entry entry;
                var key = connectionString.ConnectionString;

                if (!_entries.TryGetValue(key, out entry))
                {
                    entry = new Entry(_sqlitePlatform, connectionString);
                    _entries[key] = entry;
                }

                return entry.Connection;
            }
        }
예제 #19
0
 public SQLiteService(ISQLitePlatform platform, SQLiteConnectionString connectionString)
 {
     connection = new SQLiteConnectionWithLock(platform, connectionString);
     context = new SQLiteAsyncConnection(() => connection);
     isDisposed = false;
 }
 public SQLiteConnectionWithLock(ISQLitePlatform sqlitePlatform, SQLiteConnectionString connectionString)
     : base(sqlitePlatform, connectionString.DatabasePath, connectionString.StoreDateTimeAsTicks, connectionString.Serializer, null, null, connectionString.Resolver) { }
예제 #21
0
 /// <summary>
 /// Creates an instance of this class
 /// </summary>
 /// <param name="connectionString">The MapBox tiles file</param>
 /// <param name="schema">The tile schema (should be of <see cref="GlobalMercator"/></param>
 /// <param name="type">The type of the MapBox tiles file</param>
 public MbTilesTileSource(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
     : this(new MbTilesProvider(connectionString, schema, type))
 {
 }
예제 #22
0
        /// <summary>
        /// Connects the library database connections.
        /// </summary>
        /// <param name="dbPath">The database path.</param>
        /// <param name="dbName">Name of the database.</param>
        public async Task ConnectAsync(string dbPath, string dbName)
        {
            if(Connection.IsConnected) {
                Logger.Warn("Database connection already initialized!");
                return;
            }

            if(null == SQLitePlatform) {
                throw new InvalidOperationException("Invalid SQLite platform!");
            }

            // connect to the database
            SQLiteConnectionString connectionString = new SQLiteConnectionString(Path.Combine(dbPath, dbName), true);
            Logger.Info($"Connecting to database at {connectionString.ConnectionString}...");
            await Connection.ConnectAsync(SQLitePlatform, connectionString).ConfigureAwait(false);
        }
 public SQLiteConnectionWithLock(ISQLitePlatform sqlitePlatform, SQLiteConnectionString connectionString)
     : base(sqlitePlatform, connectionString.DatabasePath, connectionString.StoreDateTimeAsTicks)
 {
 }
 public static SQLiteAsyncConnection CreateAsyncConnection() {
     var connectionString = new SQLiteConnectionString(DatabaseFilePath, false);
     var connectionWithLock = new SQLiteConnectionWithLock(new SQLitePlatformIOS(), connectionString);
     return new SQLiteAsyncConnection(() => connectionWithLock);
 }
예제 #25
0
 internal MbTilesProvider(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
 {
     _cache = new MbTilesCache(connectionString, schema, type);
 }
예제 #26
0
        public static void Main()
        {
            Task.Run(() =>
            {
                SplashScreen splashScreen = new SplashScreen("SplashScreen.png");
                splashScreen.Show(true);
            });

            // Logger initialization
            string pathtolog = null;
            try
            {
                pathtolog = Path.Combine(FileService.GetPathToApplicationDataFolder(), "log.db");
                SQLiteConnectionString connstr = new SQLiteConnectionString(pathtolog,false);
                SQLiteConnectionWithLock SQLiteLogConnection = new SQLiteConnectionWithLock(new SQLitePlatformWin32(), connstr);
                
                LoggerSettings LoggerSettings = new LoggerSettings();
                LoggerSettings.DeleteMessagesOnStart = true;

                Logger.LoggerSettings = LoggerSettings;
                //SQLiteLoggerAdapter.Initialization(LoggerSettings,SQLiteLogConnection);
                 
                App.StaticLogger = new Logger(new SQLiteLoggerAdapter(LoggerSettings,new SQLiteAsyncConnection(()=>SQLiteLogConnection)));

            } catch(Exception ex)
            {
                MessageBox.Show("Cannot create a log"+Environment.NewLine+"path: "+pathtolog+Environment.NewLine+ex.Message);
                return;
            }


            App.StaticLogger.Write<Program>(LogMsgType.Trace,"This is developer copy = "+FileService.IsDevelopmentCopy);
            App.StaticLogger.Write<Program>(LogMsgType.Trace,"App folder : "+FileService.GetPathToApplicationFolder());
            App.StaticLogger.Write<Program>(LogMsgType.Trace,"App data folder : "+FileService.GetPathToApplicationDataFolder());
            
            //if (!FileService.IsDevelopmentCopy)
            //{
                  string path =  FileService.GetPathToApplicationDataFolder();
                  AppDomain.CurrentDomain.SetData("DataDirectory",path);
            //}


            if (!Debugger.IsAttached)
            {
                //App.SplashScreen = new SplashScreen("Images/TxFlag_256.png");
                //App.SplashScreen.Show(false, true);
            }

            // Make sure the settings are properly saved in the end
            //AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;

            App.StaticLogger.Write<Program>(LogMsgType.Trace,"Loading a localization file");
            Tx.UseFileSystemWatcher = false;
            Tx.LoadFromXmlFile(Path.Combine(FileService.GetPathToApplicationFolder(), "Dictionary.txd"));

            App.StaticLogger.Write<Program>(LogMsgType.Trace,"Set culture");
            string appCulture = "";
            if (!string.IsNullOrWhiteSpace(appCulture))
            {
                Tx.SetCulture(appCulture);
            }


            //EFDbContext.DataBase.Migrate();

            App.AppWnd_ViewModel = new AppWnd_ViewModel();
            App.NavigationService = new NavigationService(App.AppWnd_ViewModel);


            try
            {
                App app = new App();
                app.InitializeComponent();
                app.Run();
                
            } catch(Exception ex)
            {
                if (ex.GetType() != typeof(ObjectNotInitializedYetException))
                {
                    App.StaticLogger.WriteExeption<Program>(ex, "General exception");
                    MessageBox.Show(
                        "General exception " + Environment.NewLine + 
                        ex.Message + Environment.NewLine +
                        "Exception type  :" + ex.GetType() + Environment.NewLine +
                        "Stack trace :" + Environment.NewLine +
                        ex.StackTrace
                    
                        );
                    //SQLiteLoggerAdapter.Close();
                    throw; 
                }
            }
        }
예제 #27
0
		public SQLiteConnection GetConnection(){
			var connectionString = new SQLiteConnectionString (DbPath, true);
			if (_connectionPool == null)
				_connectionPool = GetConnectionPool ();
			return _connectionPool.GetConnection (connectionString);
		}
 public SQLiteConnectionWithLock(ISQLitePlatform sqlitePlatform, SQLiteConnectionString connectionString)
     : base(sqlitePlatform, connectionString.DatabasePath, connectionString.StoreDateTimeAsTicks)
 {
 }
		public async void SQLiteSimpleCacheSetAllAsync_T_Test()
		{
			SQLiteConnectionString connstring = new SQLiteConnectionString("somepath",false,new Mocks.MockBlobSerializer());
			SQLiteSimpleCache cache = new SQLiteSimpleCache(new Mocks.MockSqlLiteProvider(),connstring,new Mocks.MockByteSerializer());
			await cache.SetAllAsync<MockSQLiteData>(new Dictionary<string,MockSQLiteData>()
				{
					{"0",new MockSQLiteData()},
					{"1",new MockSQLiteData()}
				});
			Assert.AreEqual (2, MockBase.InsertOrReplaceStatementsExecuted.Count);
		}
		public async void SQLiteSimpleCacheReplace_T_AsyncTest()
		{
			SQLiteConnectionString connstring = new SQLiteConnectionString("somepath",false,new Mocks.MockBlobSerializer());
			SQLiteSimpleCache cache = new SQLiteSimpleCache(new Mocks.MockSqlLiteProvider(),connstring,new Mocks.MockByteSerializer());
			await cache.ReplaceAsync<MockSQLiteData>("1",new MockSQLiteData());
			Assert.AreEqual (1, MockBase.DeleteStatementsExecuted.Count);
			Assert.AreEqual (1, MockBase.InsertStatementsExecuted.Count);
		}
 public Entry(ISQLitePlatform sqlitePlatform, SQLiteConnectionString connectionString)
 {
     ConnectionString = connectionString;
     Connection = new SQLiteConnectionWithLock(sqlitePlatform, connectionString);
 }
예제 #32
0
 public SQLiteConnectionWithLock([NotNull] ISQLitePlatform sqlitePlatform, [NotNull] SQLiteConnectionString connectionString)
     : base(sqlitePlatform, connectionString.DatabasePath, connectionString.StoreDateTimeAsTicks, connectionString.Serializer, null, null, connectionString.Resolver)
 {
 }
		public void SQLiteSimpleCacheFlushAll_T_Test()
		{
			SQLiteConnectionString connstring = new SQLiteConnectionString("somepath",false,new Mocks.MockBlobSerializer());
			SQLiteSimpleCache cache = new SQLiteSimpleCache(new Mocks.MockSqlLiteProvider(),connstring,new Mocks.MockByteSerializer());
			cache.FlushAll();
			Assert.AreEqual (1, MockBase.DeleteStatementsExecuted.Count);
		}
예제 #34
0
 public Entry(ISQLitePlatform sqlitePlatform, SQLiteConnectionString connectionString)
 {
     ConnectionString = connectionString;
     Connection       = new SQLiteConnectionWithLock(sqlitePlatform, connectionString);
 }
        /// <summary>
        /// Closes the connection.
        /// </summary>
        public async Task CloseAsync()
        {
            if(!IsConnected) {
                return;
            }

            await LockAsync().ConfigureAwait(false);
            try {
                Logger.Debug($"Closing connection to database {_connectionString.ConnectionString}...");

                AsyncConnection = null;

                Connection.Close();
                Connection = null;

                _connectionString = null;
            } finally {
                Release();
            }
        }