public SqliteSettingsStorage()
        {
            _availableKeys = new Hashtable();
            try
            {
                var sf = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "GSAKWrapper");
                RootSettingsFolder = sf;
                if (!Directory.Exists(sf))
                {
                    Directory.CreateDirectory(sf);
                }

                sf = Path.Combine(sf, "settings.db3");
                if (ApplicationRunning)
                {
                    _dbcon = new Database.DBConSqlite(sf);

                    if (!_dbcon.TableExists("settings"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'settings' (item_name text, item_value text)");
                        _dbcon.ExecuteNonQuery("create index idx_key on settings (item_name)");
                    }
                    else
                    {
                        DbDataReader dr = _dbcon.ExecuteReader("select item_name, item_value from settings");
                        while (dr.Read())
                        {
                            _availableKeys[dr[0] as string] = dr[1] as string;
                        }
                    }

                    object o = _dbcon.ExecuteScalar("PRAGMA integrity_check");
                    if (o as string == "ok")
                    {
                        //what is expected
                    }
                    else
                    {
                        //oeps?
                        _dbcon.Dispose();
                        _dbcon = null;
                    }
                }
            }
            catch//(Exception e)
            {
                _dbcon = null;
            }
        }
Пример #2
0
        public SqliteSettingsStorage()
        {
            _availableKeys = new Hashtable();
            try
            {
                var sf = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "GSAKWrapper");
                RootSettingsFolder = sf;
                if (!Directory.Exists(sf))
                {
                    Directory.CreateDirectory(sf);
                }

                sf = Path.Combine(sf, "settings.db3");
                if (ApplicationRunning)
                {
                    _dbcon = new Database.DBConSqlite(sf);

                    if (!_dbcon.TableExists("settings"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'settings' (item_name text, item_value text)");
                        _dbcon.ExecuteNonQuery("create index idx_key on settings (item_name)");
                    }
                    else
                    {
                        DbDataReader dr = _dbcon.ExecuteReader("select item_name, item_value from settings");
                        while (dr.Read())
                        {
                            _availableKeys[dr[0] as string] = dr[1] as string;
                        }
                    }

                    object o = _dbcon.ExecuteScalar("PRAGMA integrity_check");
                    if (o as string == "ok")
                    {
                        //what is expected
                    }
                    else
                    {
                        //oeps?
                        _dbcon.Dispose();
                        _dbcon = null;
                    }
                }
            }
            catch//(Exception e)
            {
                _dbcon = null;
            }
        }
Пример #3
0
 public void StoreSetting(string name, string value)
 {
     lock (this)
     {
         if (_dbcon != null)
         {
             if (_availableKeys.ContainsKey(name))
             {
                 _dbcon.ExecuteNonQuery(string.Format("update settings set item_value={1} where item_name='{0}'", name, value == null ? "NULL" : string.Format("'{0}'", value.Replace("'", "''"))));
             }
             else
             {
                 _dbcon.ExecuteNonQuery(string.Format("insert into settings (item_name, item_value) values ('{0}', {1})", name, value == null ? "NULL" : string.Format("'{0}'", value.Replace("'", "''"))));
             }
             _availableKeys[name] = value;
         }
     }
 }
Пример #4
0
        public SqliteSettingsStorage()
        {
            _availableKeys = new Hashtable();
            try
            {
                var sf = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "GSAKWrapper");
                RootSettingsFolder = sf;
                if (!Directory.Exists(sf))
                {
                    Directory.CreateDirectory(sf);
                }

                sf = Path.Combine(sf, "settings.db3");
                if (ApplicationRunning)
                {
                    _dbcon = new Database.DBConSqlite(sf);

                    if (!_dbcon.TableExists("settings"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'settings' (item_name text, item_value text)");
                        _dbcon.ExecuteNonQuery("create index idx_key on settings (item_name)");
                    }
                    else
                    {
                        DbDataReader dr = _dbcon.ExecuteReader("select item_name, item_value from settings");
                        while (dr.Read())
                        {
                            _availableKeys[dr[0] as string] = dr[1] as string;
                        }
                    }

                    if (!_dbcon.TableExists("formulasolv"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'formulasolv' (gccode text, formula text)");
                        _dbcon.ExecuteNonQuery("create index idx_form on formulasolv (gccode)");
                    }

                    if (!_dbcon.TableExists("GeocacheCollection"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'GeocacheCollection' (CollectionID integer not null, Name text not null)");
                        _dbcon.ExecuteNonQuery("create index idx_gckey on GeocacheCollection (CollectionID)");
                        _dbcon.ExecuteNonQuery("create index idx_gcname on GeocacheCollection (Name)");
                    }
                    if (!_dbcon.TableExists("GeocacheCollectionItem"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'GeocacheCollectionItem' (CollectionID integer not null, GeocacheCode text not null, Name text not null)");
                        _dbcon.ExecuteNonQuery("create unique index idx_gcikey on GeocacheCollectionItem (CollectionID, GeocacheCode)");

                        _dbcon.ExecuteNonQuery("CREATE TRIGGER Delete_GeocacheCollection Delete ON GeocacheCollection BEGIN delete from GeocacheCollectionItem where CollectionID = old.CollectionID; END");
                    }
                    if (!_dbcon.TableExists("ShapeFileItemV2"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'ShapeFileItemV2' (FileName text, TableName text not null, CoordType text not null, AreaType text not null, NamePrefix text, Encoding text not null, Enabled integer not null)");
                    }
                    if (!_dbcon.TableExists("Scripts"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'Scripts' (Name text not null, ScriptType integer not null, Code text not null)");
                        _dbcon.ExecuteNonQuery("create unique index idx_scname on Scripts (Name)");
                    }

                    object o = _dbcon.ExecuteScalar("PRAGMA integrity_check");
                    if (o as string == "ok")
                    {
                        //what is expected
                    }
                    else
                    {
                        //oeps?
                        _dbcon.Dispose();
                        _dbcon = null;
                    }
                }
            }
            catch//(Exception e)
            {
                _dbcon = null;
            }
        }