コード例 #1
1
        /// <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
ファイル: Database.cs プロジェクト: KeesPolling/Popmail
        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 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);
 }
コード例 #5
0
        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();
 }
コード例 #7
0
        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;
        }
コード例 #8
0
        private void InitialiseDatabase()
        {
            var databasePath = GetDatabaseFilePath();

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

            CreateTables();
        }
コード例 #9
0
        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);
        }
コード例 #11
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;
        }
コード例 #12
0
		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;
            }
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        /// <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
ファイル: 39.cs プロジェクト: RobGibbens/CodeStock
        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
ファイル: 33.cs プロジェクト: RobGibbens/CodeStock
        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;
        }
コード例 #18
0
        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
ファイル: Data.cs プロジェクト: TsvetanMilanov/RoomMeasurer
        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;

        }
コード例 #20
0
 public static SQLiteAsyncConnection CreateAsyncConnection() {
     var connectionString = new SQLiteConnectionString(DatabaseFilePath, false);
     var connectionWithLock = new SQLiteConnectionWithLock(new SQLitePlatformIOS(), connectionString);
     return new SQLiteAsyncConnection(() => connectionWithLock);
 }
コード例 #21
0
 public void OnApplicationSuspended()
 {
     Connection.Dispose();
     Connection = null;
 }
コード例 #22
0
 public Entry(ISQLitePlatform sqlitePlatform, SQLiteConnectionString connectionString)
 {
     ConnectionString = connectionString;
     Connection = new SQLiteConnectionWithLock(sqlitePlatform, connectionString);
 }
コード例 #23
0
ファイル: SQLiteService.cs プロジェクト: SamirHafez/Fresh
 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
ファイル: Program.cs プロジェクト: vlkam/OpenLearningPlayer
        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);
 }