/// <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;
            }
        }
 public SQLiteAsyncConnection GetConnection()
 {
     string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
     string path = Path.Combine(documentsPath, AppResources.DatabaseName);
     var platfrom = new SQLitePlatformAndroid();
     var syncConnection = new SQLiteConnectionWithLock(platfrom, new SQLiteConnectionString(path, false));
     return new SQLiteAsyncConnection(() => syncConnection);
 }
示例#4
0
 public SQLiteAsyncConnection ResolveConnection()
 {
     var path = Path.Combine (
         Environment.GetFolderPath (Environment.SpecialFolder.Personal),
         "tasks.db");
     var connection = new SQLiteConnectionWithLock (new SQLite.Net.Platform.XamarinIOS.SQLitePlatformIOS(),
         new SQLiteConnectionString(path, false));
     return new SQLiteAsyncConnection (() => connection);
 }
        public SQLiteConnection GetConnection(string path)
        {
            var fullPath = GetFullDatabasePath (path);

            var platform = new SQLitePlatformIOS ();

            var connectionWithLock = new SQLiteConnectionWithLock (platform, new SQLiteConnectionString (fullPath, true));
            return connectionWithLock;
        }
示例#6
0
 public SqliteContext(ISQLitePlatform platform,DatabaseInitializator init)
 {
     _platform = platform;
     _init = init;
     _dbPath = init.Path;
     var connection = new SQLiteConnectionWithLock(_platform,
         new SQLiteConnectionString(_dbPath, storeDateTimeAsTicks: true));
     _connectionFactory = new Func<SQLiteConnectionWithLock>(() =>connection);
     CreateTables();
 }
        public virtual SQLiteConnection GetConnection(string path)
        {
            var platform = new SQLitePlatformAndroid ();
            SQLiteConnection connectionWithLock;

            string fullPath = GetFullDatabasePath (path);
            connectionWithLock = new SQLiteConnectionWithLock (platform, new SQLiteConnectionString (fullPath, true));

            return connectionWithLock;
        }
        private void InitialiseDatabase()
        {
            var databasePath = GetDatabaseFilePath();

            _sqLiteConnectionWithLock = new SQLiteConnectionWithLock(new SQLitePlatformIOS(),
                                                                     new SQLiteConnectionString(databasePath, storeDateTimeAsTicks: false));
            SqLiteAsyncConnection = new SQLiteAsyncConnection(() => _sqLiteConnectionWithLock);

            CreateTables();
        }
        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;
        }
示例#10
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);
        }
        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;
        }
		public App ()
		{
			var sqliteFilename = "phoenix_imperator_" + Version.Replace(".","_") + ".db3";
			string documentsPath = GetDocumentPath ();
			#if __ANDROID__
			var path = Path.Combine(documentsPath, sqliteFilename);
			#else
			string libraryPath = Path.Combine (documentsPath, "..", "Library"); // Library folder
			var path = Path.Combine(libraryPath, sqliteFilename);
			#endif
			_dbConnection = new SQLiteConnectionWithLock (DatabasePlatform, new SQLiteConnectionString (path, storeDateTimeAsTicks: true));
			Console.WriteLine("SQL Database: " + path);
			Phoenix.Application.Initialize (this, this, this, this);
			MainPage = new RootPage ();
		}
示例#13
0
        public SQLite.Net.Async.SQLiteAsyncConnection ResolveConnection()
        {
            try {
                var path = Path.Combine (
                    Environment.GetFolderPath (Environment.SpecialFolder.Personal),
                    "tasks.db");
                var connection = new SQLiteConnectionWithLock (new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(),
                    new SQLiteConnectionString(path, false)
                );
                return new SQLiteAsyncConnection (() => connection);

            } catch (Exception ex) {
                return null;
            }
        }
        public SQLiteAsyncConnection GetAsyncConnection()
        {
            var dbPath = GetDatabaseFilePath();

            var platForm = new SQLitePlatformIOS();

            var connectionFactory = new Func <SQLiteConnectionWithLock>(
                () => _sqLiteConnectionWithLock ?? (_sqLiteConnectionWithLock = new SQLiteConnectionWithLock(
                                                        platForm,
                                                        new SQLiteConnectionString(dbPath, storeDateTimeAsTicks: true))));

            var asyncConnection = new SQLiteAsyncConnection(connectionFactory);

            return(asyncConnection);
        }
        /// <summary>
        /// Platform (Android) connection.
        /// </summary>
        protected override SQLiteAsyncConnection PlatformConnection()
        {
            var dbPath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                Path.Combine(ApplicationName, "SimpleObjectCache"));

            Directory.CreateDirectory(dbPath);

            var lockedConnection = new SQLiteConnectionWithLock(
                new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(),
                new SQLiteConnectionString(
                    Path.Combine(dbPath, "cache.db3"),
                    true));

            return new SQLiteAsyncConnection(() => lockedConnection);
        }
示例#16
0
        public SQLiteAsyncConnection GetConnection()
        {
            const string sqliteFilename = "Conferences.db3";

            var path = Path.Combine(ApplicationData.Current.LocalFolder.Path, sqliteFilename);

            var platform = new SQLitePlatformWinRT();

            var connectionWithLock = new SQLiteConnectionWithLock(
                                          platform,
                                          new SQLiteConnectionString(path, true));

            var connection = new SQLiteAsyncConnection(() => connectionWithLock);

            return connection;
        }
示例#17
0
        public SQLiteAsyncConnection GetConnection()
        {
            const string sqliteFilename = "Conferences.db3";
            var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            var path = Path.Combine(documentsPath, sqliteFilename);

            var platform = new SQLitePlatformAndroid();

            var connectionWithLock = new SQLiteConnectionWithLock(
                                          platform,
                                          new SQLiteConnectionString(path, true));

            var connection = new SQLiteAsyncConnection(() => connectionWithLock);

            return connection;
        }
        public SQLiteAsyncConnection GetAsyncConnection()
        {
            const string sqliteFilename = "XamarinTemplate.db3";
            var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var libraryPath = Path.Combine(documentsPath, "..", "Library");
            var path = Path.Combine(libraryPath, sqliteFilename);

            var platform = new SQLitePlatformIOS();

            var connectionWithLock = new SQLiteConnectionWithLock(
                                          platform,
                                          new SQLiteConnectionString(path, true));

            var connection = new SQLiteAsyncConnection(() => connectionWithLock);

            return connection;
        }
示例#19
0
        public Data()
        {
            // will be created if non-existent
            this.dbFilePath = Path.Combine(
                ApplicationData.Current.LocalFolder.Path,
                "db.sqlite");

            this.dbContext = new SQLiteConnectionWithLock(
                         new SQLitePlatformWinRT(),
                         new SQLiteConnectionString(
                             dbFilePath,
                             storeDateTimeAsTicks: false)
                         );

            this.init();

            this.localFolder = ApplicationData.Current.LocalFolder;

        }
 public static SQLiteAsyncConnection CreateAsyncConnection() {
     var connectionString = new SQLiteConnectionString(DatabaseFilePath, false);
     var connectionWithLock = new SQLiteConnectionWithLock(new SQLitePlatformIOS(), connectionString);
     return new SQLiteAsyncConnection(() => connectionWithLock);
 }
 public void OnApplicationSuspended()
 {
     Connection.Dispose();
     Connection = null;
 }
 public Entry(ISQLitePlatform sqlitePlatform, SQLiteConnectionString connectionString)
 {
     ConnectionString = connectionString;
     Connection = new SQLiteConnectionWithLock(sqlitePlatform, connectionString);
 }
示例#23
0
 public SQLiteService(ISQLitePlatform platform, SQLiteConnectionString connectionString)
 {
     connection = new SQLiteConnectionWithLock(platform, connectionString);
     context = new SQLiteAsyncConnection(() => connection);
     isDisposed = false;
 }
示例#24
0
 public void Drop()
 {
     connectionLock = new SQLiteConnectionWithLock(platform, new SQLiteConnectionString(DbPath, false));
     var connection = new SQLiteAsyncConnection(() => connectionLock);
     connection.DropTableAsync<BackgroundTrackItem>();
 }
示例#25
0
 public Task Remove(BackgroundTrackItem track)
 {
     connectionLock = new SQLiteConnectionWithLock(platform, new SQLiteConnectionString(DbPath, false));
     var connection = new SQLiteAsyncConnection(() => connectionLock);
     return connection.DeleteAsync(track);
 }
示例#26
0
 public Entry(ISQLitePlatform sqlitePlatform, SQLiteConnectionString connectionString)
 {
     ConnectionString = connectionString;
     Connection       = new SQLiteConnectionWithLock(sqlitePlatform, connectionString);
 }
示例#27
0
 public void OnApplicationSuspended()
 {
     Connection.Dispose();
     Connection = null;
 }
示例#28
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; 
                }
            }
        }
示例#29
-1
 public Task AddBunchTracks(dynamic tracks)
 {
     connectionLock = new SQLiteConnectionWithLock(platform, new SQLiteConnectionString(DbPath, false));
     var connection = new SQLiteAsyncConnection(() => connectionLock);
     return connection.InsertAllAsync(tracks);
 }