Esempio n. 1
0
        private IgnoreService(Framework.Interfaces.ICore core)
        {
            _filterFields = new Hashtable();
            _core = core;

            foreach (string s in Enum.GetNames(typeof(FilterField)))
            {
                _filterFields.Add(s, new Hashtable());
            }

            try
            {
                _databaseFile = System.IO.Path.Combine(core.PluginDataPath, "ignoregc.db3");
                InitDatabase();
                using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFile))
                {
                    DbDataReader dr = dbcon.ExecuteReader("select field, filter from filterfields");
                    while (dr.Read())
                    {
                        Hashtable ht = _filterFields[dr["field"]] as Hashtable;
                        if (ht != null)
                        {
                            ht.Add(dr["filter"], true);
                        }
                    }
                }
            }
            catch
            {
            }
        }
Esempio n. 2
0
 public void GetPolygonOfArea(Framework.Data.AreaInfo area)
 {
     PreLoadAreaInfo();
     if (area.Polygons == null)
     {
         Framework.Data.AreaInfo ainf = (from ai in _cachedAreaInfo where ai.ID == area.ID select ai).FirstOrDefault();
         if (ainf != null)
         {
             try
             {
                 area.Polygons = new List <Framework.Data.Polygon>();
                 using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename))
                 {
                     int actPolyId = -1;
                     Framework.Data.Polygon polg = null;
                     DbDataReader           dr   = dbcon.ExecuteReader(string.Format("select * from poly where areainfoid={0} order by id, position", area.ID));
                     while (dr.Read())
                     {
                         int polyId = (int)dr["id"];
                         if (actPolyId != polyId)
                         {
                             polg = new Framework.Data.Polygon();
                             area.Polygons.Add(polg);
                             actPolyId = polyId;
                         }
                         polg.AddLocation(new Framework.Data.Location((double)dr["lat"], (double)dr["lon"]));
                     }
                 }
             }
             catch
             {
             }
         }
     }
 }
Esempio n. 3
0
        internal bool deleteArea(Framework.Data.AreaType level, string areaName)
        {
            PreLoadAreaInfo();
            bool result = true;

            try
            {
                List <Framework.Data.AreaInfo> ail = GetAreasByName(areaName, level);
                if (ail.Count > 0)
                {
                    foreach (Framework.Data.AreaInfo ai in ail)
                    {
                        using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename))
                        {
                            dbcon.ExecuteNonQuery(string.Format("delete from poly where areainfoid={0}", ai.ID));
                            dbcon.ExecuteNonQuery(string.Format("delete from areainfo where id={0}", ai.ID));
                            _cachedAreaInfo.Remove(ai);
                        }
                    }
                }
            }
            catch
            {
                result = false;
            }
            return(result);
        }
Esempio n. 4
0
        private void CreateDatabase(string filename)
        {
            _dbcon = new Utils.DBConComSqlite(filename);
            cgData cgd = new cgData(_dbcon);

            cgd.Create();
        }
Esempio n. 5
0
        public override bool Initialize(Framework.Interfaces.ICore core)
        {
            AddAction(ACTION_SAVECURRENT);
            AddAction(ACTION_SEP);
            AddAction(ACTION_SPLITSCREEN);

            core.LanguageItems.Add(new Framework.Data.LanguageItem(PresetNameForm.STR_NAME));
            core.LanguageItems.Add(new Framework.Data.LanguageItem(PresetNameForm.STR_OK));
            core.LanguageItems.Add(new Framework.Data.LanguageItem(PresetNameForm.STR_TITLE));

            core.LanguageItems.Add(new Framework.Data.LanguageItem(SettingsPanel.STR_DELETE));
            core.LanguageItems.Add(new Framework.Data.LanguageItem(SettingsPanel.STR_PRESETS));

            if (Properties.Settings.Default.UpgradeNeeded)
            {
                Properties.Settings.Default.Upgrade();
                Properties.Settings.Default.UpgradeNeeded = false;
                Properties.Settings.Default.Save();
            }

            try
            {
                _presetDatabaseFile = System.IO.Path.Combine(new string[] { core.PluginDataPath, "Presets.db3" });
            }
            catch
            {
            }

            try
            {
                if (System.IO.File.Exists(_presetDatabaseFile))
                {
                    using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_presetDatabaseFile))
                    {
                        initDatabase(dbcon);
                        DbDataReader dr = dbcon.ExecuteReader("select name from preset");
                        while (dr.Read())
                        {
                            _presets.Add((string)dr["name"]);
                            AddAction(string.Concat("Presets|", (string)dr["name"]));
                        }
                    }
                }
            }
            catch
            {
            }


            return base.Initialize(core);
        }
Esempio n. 6
0
        private Utils.DBCon initDatabase()
        {
            Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFile);
            object      o     = dbcon.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='scripts'");

            if (o == null || o.GetType() == typeof(DBNull))
            {
                dbcon.ExecuteNonQuery("create table 'scripts' (id text, name text, scripttype text, content text)");
            }
            o = dbcon.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='settings'");
            if (o == null || o.GetType() == typeof(DBNull))
            {
                dbcon.ExecuteNonQuery("create table 'settings' (scriptid text, enable integer, pos integer)");
            }
            return(dbcon);
        }
Esempio n. 7
0
        private void PreLoadAreaInfo()
        {
            if (_cachedAreaInfo == null)
            {
                _cachedAreaInfo = new List <Framework.Data.AreaInfo>();

                try
                {
                    using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename))
                    {
                        if (InitDatabase(dbcon))
                        {
                            DbDataReader dr = dbcon.ExecuteReader("select * from areainfo");
                            while (dr.Read())
                            {
                                Framework.Data.AreaInfo ai = new Framework.Data.AreaInfo();
                                ai.ID       = (int)dr["id"];
                                ai.ParentID = dr["parentid"] == DBNull.Value ? null : dr["parentid"];
                                ai.Level    = (Framework.Data.AreaType)(short)(int) dr["level"];
                                ai.Name     = (string)dr["name"];
                                ai.MinLat   = (double)dr["minlat"];
                                ai.MinLon   = (double)dr["minlon"];
                                ai.MaxLat   = (double)dr["maxlat"];
                                ai.MaxLon   = (double)dr["maxlon"];
                                _cachedAreaInfo.Add(ai);
                            }
                        }

                        object o = dbcon.ExecuteScalar("select Max(id) from areainfo");
                        if (o != null)
                        {
                            _maxAreaInfoId = (int)(long)o;
                        }
                        o = dbcon.ExecuteScalar("select Max(id) from poly");
                        if (o != null)
                        {
                            _maxPolyId = (int)(long)o;
                        }
                    }
                }
                catch
                {
                    //corrupt file
                    _cachedAreaInfo.Clear();
                }
            }
        }
Esempio n. 8
0
 public void Clear()
 {
     try
     {
         foreach (Hashtable ht in _filterFields.Values)
         {
             ht.Clear();
         }
         using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFile))
         {
             dbcon.ExecuteNonQuery("delete from filterfields");
         }
     }
     catch
     {
     }
 }
Esempio n. 9
0
 private Utils.DBCon initDatabase()
 {
     Utils.DBCon dbcon;
     try
     {
         dbcon = new Utils.DBConComSqlite(_databaseFile);
         object o = dbcon.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='gallery'");
         if (o == null || o.GetType() == typeof(DBNull))
         {
             dbcon.ExecuteNonQuery("create table 'gallery' (ImageGuid text, ThumbUrl text, Description text, Name text, MobileUrl text, Url text, LogCacheCode text, LogCode text, LogUrl text, LogVisitDate text, ThumbFile text, ImgFile text)");
         }
     }
     catch
     {
         dbcon = null;
     }
     return(dbcon);
 }
Esempio n. 10
0
        internal bool setParent(Framework.Data.AreaInfo ai, Framework.Data.AreaInfo parent)
        {
            bool result = true;

            try
            {
                using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename))
                {
                    dbcon.ExecuteNonQuery(string.Format("update areainfo set parentid= where id={0}", ai.ID, parent == null ? "NULL" : parent.ID));
                    ai.ParentID = parent == null ? null : parent.ID;
                }
            }
            catch
            {
                result = false;
            }
            return(result);
        }
Esempio n. 11
0
        internal bool deleteArea(Framework.Data.AreaInfo ai)
        {
            bool result = true;

            try
            {
                using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename))
                {
                    dbcon.ExecuteNonQuery(string.Format("delete from poly where areainfoid={0}", ai.ID));
                    dbcon.ExecuteNonQuery(string.Format("delete from areainfo where id={0}", ai.ID));
                    _cachedAreaInfo.Remove(ai);
                }
            }
            catch
            {
                result = false;
            }
            return(result);
        }
Esempio n. 12
0
        public override bool Initialize(Framework.Interfaces.ICore core)
        {
            bool result = base.Initialize(core);
            if (result)
            {
                core.LanguageItems.Add(new Framework.Data.LanguageItem(SettingsPanel.STR_CLEAR));
                core.LanguageItems.Add(new Framework.Data.LanguageItem(SettingsPanel.STR_INFO));

                try
                {
                    _shortcutDatabaseFile = System.IO.Path.Combine(core.PluginDataPath, "Shortcuts.db3" );
                }
                catch
                {
                }

                if (System.IO.File.Exists(_shortcutDatabaseFile))
                {
                    using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_shortcutDatabaseFile))
                    {
                        initDatabase(dbcon);
                        DbDataReader dr = dbcon.ExecuteReader("select * from shortcut");
                        while (dr.Read())
                        {
                            core.ShortcutInfo.Add(new Framework.Data.ShortcutInfo() { PluginType = (string)dr["plugintype"], PluginAction = (string)dr["action"], PluginSubAction = (string)dr["subaction"], ShortcutKeys = (Keys)(int)dr["keys"], ShortcutKeyString = (string)dr["keystring"] });
                        }
                    }
                }
                else
                {
                    core.ShortcutInfo.AddRange(new Framework.Data.ShortcutInfo[]
                            {
                                new Framework.Data.ShortcutInfo(){PluginType="GlobalcachingApplication.Plugins.GCView.GeocacheViewer", PluginAction="View Geocache", PluginSubAction="", ShortcutKeys = Keys.F3, ShortcutKeyString = "F3" },
                                new Framework.Data.ShortcutInfo(){PluginType="GlobalcachingApplication.Plugins.GMap.GMap", PluginAction="Google Map", PluginSubAction="", ShortcutKeys = Keys.Control | Keys.M, ShortcutKeyString = "Ctrl+M" },
                                new Framework.Data.ShortcutInfo(){PluginType="GlobalcachingApplication.Plugins.FilterEx.GeocacheSearch", PluginAction="Search geocache", PluginSubAction="", ShortcutKeys = Keys.Control | Keys.F, ShortcutKeyString = "Ctrl+F" },
                                new Framework.Data.ShortcutInfo(){PluginType="GlobalcachingApplication.Plugins.TxtSearch.GeocacheTextSearch", PluginAction="Search geocache by text", PluginSubAction="", ShortcutKeys = Keys.Control | Keys.T, ShortcutKeyString = "Ctrl+T" },
                            }
                    );
                }
            }
            return result;
        }
Esempio n. 13
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);
            if (result)
            {
                if (action == ACTION_SELECT)
                {
                    Core.Geocaches.BeginUpdate();
                    try
                    {
                        string databaseFile = System.IO.Path.Combine(new string[] { Core.PluginDataPath, "attachements.db3" });
                        if (System.IO.File.Exists(databaseFile))
                        {
                            foreach (Framework.Data.Geocache gc in Core.Geocaches)
                            {
                                gc.Selected = false;
                            }
                            Utils.DBCon dbcon = new Utils.DBConComSqlite(databaseFile);
                            DbDataReader dr = dbcon.ExecuteReader("select distinct code from attachements");
                            while (dr.Read())
                            {
                                string code = dr["code"] as string;
                                Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, code);
                                if (gc != null)
                                {
                                    gc.Selected = true;
                                }
                            }
                        }

                    }
                    catch
                    {
                    }
                    Core.Geocaches.EndUpdate();
                }
            }
            return result;
        }
Esempio n. 14
0
 private Utils.DBCon initDatabase()
 {
     Utils.DBCon result = null;
     try
     {
         string fn = System.IO.Path.Combine(_core.PluginDataPath, "coordsav.db3");
         if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(fn)))
         {
             System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fn));
         }
         result = new Utils.DBConComSqlite(fn);
         object o = result.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='coord'");
         if (o == null || o.GetType() == typeof(DBNull))
         {
             result.ExecuteNonQuery("create table 'coord' (code text, lat real, lon real)");
             result.ExecuteNonQuery("create unique index idx_coord on coord (code)");
         }
     }
     catch
     {
     }
     return(result);
 }
Esempio n. 15
0
 public cgData(Utils.DBConComSqlite db)
 {
     _db = db;
 }
Esempio n. 16
0
        internal bool processTextFile(Framework.Data.AreaType level, string f, Framework.Data.AreaInfo parent)
        {
            PreLoadAreaInfo();
            bool result = false;

            try
            {
                //filename = AreaName
                string areaName = System.IO.Path.GetFileNameWithoutExtension(f);
                char[] num      = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
                int    pos      = 0;
                while (pos < areaName.Length && !num.Contains(areaName[pos]))
                {
                    pos++;
                }
                areaName = areaName.Substring(0, pos);
                string[] lines = System.IO.File.ReadAllLines(f);
                pos = 0;
                if (lines[0].StartsWith("# GsakName="))
                {
                    areaName = lines[0].Substring(lines[0].IndexOf('=') + 1).Trim();
                    pos++;
                }
                string slat = "";
                string slon = "";
                double lat;
                double lon;
                bool   newPoly;
                Framework.Data.AreaInfo        ai;
                List <Framework.Data.AreaInfo> ailist = GetAreasByName(areaName, level);
                bool firstPoint = true;
                if (ailist.Count > 0)
                {
                    ai         = ailist[0];
                    firstPoint = false;
                    newPoly    = false;
                }
                else
                {
                    newPoly = true;
                    ai      = new Framework.Data.AreaInfo();
                    ai.ID   = _maxAreaInfoId + 1;
                    _maxAreaInfoId++;
                    ai.Name     = areaName;
                    ai.Level    = level;
                    ai.Polygons = new List <Framework.Data.Polygon>();
                }
                Framework.Data.Polygon poly = new Framework.Data.Polygon();
                _maxPolyId++;
                using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename))
                {
                    dbcon.BeginTran();
                    while (pos < lines.Length)
                    {
                        string s = lines[pos].Trim();
                        if (!s.StartsWith("#"))
                        {
                            string[] parts = s.Split(new char[] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                            if (parts.Length == 2)
                            {
                                lat = Utils.Conversion.StringToDouble(parts[0]);
                                lon = Utils.Conversion.StringToDouble(parts[1]);
                                if (firstPoint)
                                {
                                    ai.MinLat  = lat;
                                    ai.MaxLat  = lat;
                                    ai.MinLon  = lon;
                                    ai.MaxLon  = lon;
                                    firstPoint = false;
                                }
                                else
                                {
                                    if (lat < ai.MinLat)
                                    {
                                        ai.MinLat = lat;
                                    }
                                    if (lat > ai.MaxLat)
                                    {
                                        ai.MaxLat = lat;
                                    }
                                    if (lon < ai.MinLon)
                                    {
                                        ai.MinLon = lon;
                                    }
                                    if (lon > ai.MaxLon)
                                    {
                                        ai.MaxLon = lon;
                                    }
                                }
                                poly.AddLocation(new Framework.Data.Location(lat, lon));
                                dbcon.ExecuteNonQuery(string.Format("insert into poly (id, areainfoid, position, lat, lon) values ({0}, {1}, {2}, {3}, {4})", _maxPolyId, ai.ID, poly.Count, lat.ToString().Replace(',', '.'), lon.ToString().Replace(',', '.')));
                                if (poly.Count == 1)
                                {
                                    slat = parts[0];
                                    slon = parts[1];
                                    ai.Polygons.Add(poly);
                                }
                                else if (slat == parts[0] && slon == parts[1])
                                {
                                    poly = new Framework.Data.Polygon();
                                    _maxPolyId++;
                                }
                            }
                        }
                        pos++;
                    }
                    if (newPoly)
                    {
                        _cachedAreaInfo.Add(ai);
                        dbcon.ExecuteNonQuery(string.Format("insert into areainfo (id, parentid, level, name, minlat, minlon, maxlat, maxlon) values ({0}, {1}, {2}, '{3}', {4}, {5}, {6}, {7})", ai.ID, parent == null ? "NULL" : parent.ID, (short)ai.Level, ai.Name.Replace("'", "''"), ai.MinLat.ToString().Replace(',', '.'), ai.MinLon.ToString().Replace(',', '.'), ai.MaxLat.ToString().Replace(',', '.'), ai.MaxLon.ToString().Replace(',', '.')));
                    }
                    else
                    {
                        dbcon.ExecuteNonQuery(string.Format("update areainfo set parentid={0}, minlat={1}, minlon={2}, maxlat={3}, maxlon={4} where id={5}", parent == null ? "NULL" : parent.ID, ai.MinLat.ToString().Replace(',', '.'), ai.MinLon.ToString().Replace(',', '.'), ai.MaxLat.ToString().Replace(',', '.'), ai.MaxLon.ToString().Replace(',', '.'), ai.ID));
                    }
                    dbcon.CommitTran();
                    result = true;
                }
            }
            catch
            {
            }
            return(result);
        }
Esempio n. 17
0
        private void CreateDatabase(string filename)
        {
            _dbcon = new Utils.DBConComSqlite(filename);

            //most code copied from Cachebox (Android)
            int lastDatabaseSchemeVersion = -1;

            if (lastDatabaseSchemeVersion <= 0)
            {
                // First Initialization of the Database
                execSQL("CREATE TABLE [Caches] ([Id] bigint NOT NULL primary key,[GcCode] nvarchar(15) NOT NULL,[GcId] nvarchar (255) NULL,[Latitude] float NULL,[Longitude] float NULL,[Name] nchar (255) NULL,[Size] int NULL,[Difficulty] smallint NULL,[Terrain] smallint NULL,[Archived] bit NULL,[Available] bit NULL,[Found] bit NULL,[Type] smallint NULL,[PlacedBy] nvarchar (255) NULL,[Owner] nvarchar (255) NULL,[DateHidden] datetime NULL,[Hint] ntext NULL,[Description] ntext NULL,[Url] nchar (255) NULL,[NumTravelbugs] smallint NULL,[Rating] smallint NULL,[Vote] smallint NULL,[VotePending] bit NULL,[Notes] ntext NULL,[Solver] ntext NULL,[Favorit] bit NULL,[AttributesPositive] bigint NULL,[AttributesNegative] bigint NULL,[TourName] nchar (255) NULL,[GPXFilename_Id] bigint NULL,[HasUserData] bit NULL,[ListingCheckSum] int NULL DEFAULT 0,[ListingChanged] bit NULL,[ImagesUpdated] bit NULL,[DescriptionImagesUpdated] bit NULL,[CorrectedCoordinates] bit NULL);");
                execSQL("CREATE INDEX [archived_idx] ON [Caches] ([Archived] ASC);");
                execSQL("CREATE INDEX [AttributesNegative_idx] ON [Caches] ([AttributesNegative] ASC);");
                execSQL("CREATE INDEX [AttributesPositive_idx] ON [Caches] ([AttributesPositive] ASC);");
                execSQL("CREATE INDEX [available_idx] ON [Caches] ([Available] ASC);");
                execSQL("CREATE INDEX [Difficulty_idx] ON [Caches] ([Difficulty] ASC);");
                execSQL("CREATE INDEX [Favorit_idx] ON [Caches] ([Favorit] ASC);");
                execSQL("CREATE INDEX [found_idx] ON [Caches] ([Found] ASC);");
                execSQL("CREATE INDEX [GPXFilename_Id_idx] ON [Caches] ([GPXFilename_Id] ASC);");
                execSQL("CREATE INDEX [HasUserData_idx] ON [Caches] ([HasUserData] ASC);");
                execSQL("CREATE INDEX [ListingChanged_idx] ON [Caches] ([ListingChanged] ASC);");
                execSQL("CREATE INDEX [NumTravelbugs_idx] ON [Caches] ([NumTravelbugs] ASC);");
                execSQL("CREATE INDEX [placedby_idx] ON [Caches] ([PlacedBy] ASC);");
                execSQL("CREATE INDEX [Rating_idx] ON [Caches] ([Rating] ASC);");
                execSQL("CREATE INDEX [Size_idx] ON [Caches] ([Size] ASC);");
                execSQL("CREATE INDEX [Terrain_idx] ON [Caches] ([Terrain] ASC);");
                execSQL("CREATE INDEX [Type_idx] ON [Caches] ([Type] ASC);");

                execSQL("CREATE TABLE [CelltowerLocation] ([CellId] nvarchar (20) NOT NULL primary key,[Latitude] float NULL,[Longitude] float NULL);");

                execSQL("CREATE TABLE [GPXFilenames] ([Id] integer not null primary key autoincrement,[GPXFilename] nvarchar (255) NULL,[Imported] datetime NULL, [Name] nvarchar (255) NULL,[CacheCount] int NULL);");

                execSQL("CREATE TABLE [Logs] ([Id] bigint NOT NULL primary key, [CacheId] bigint NULL,[Timestamp] datetime NULL,[Finder] nvarchar (128) NULL,[Type] smallint NULL,[Comment] ntext NULL);");
                execSQL("CREATE INDEX [log_idx] ON [Logs] ([CacheId] ASC);");
                execSQL("CREATE INDEX [timestamp_idx] ON [Logs] ([Timestamp] ASC);");

                execSQL("CREATE TABLE [PocketQueries] ([Id] integer not null primary key autoincrement,[PQName] nvarchar (255) NULL,[CreationTimeOfPQ] datetime NULL);");

                execSQL("CREATE TABLE [Waypoint] ([GcCode] nvarchar(15) NOT NULL primary key,[CacheId] bigint NULL,[Latitude] float NULL,[Longitude] float NULL,[Description] ntext NULL,[Clue] ntext NULL,[Type] smallint NULL,[SyncExclude] bit NULL,[UserWaypoint] bit NULL,[Title] ntext NULL);");
                execSQL("CREATE INDEX [UserWaypoint_idx] ON [Waypoint] ([UserWaypoint] ASC);");

                execSQL("CREATE TABLE [Config] ([Key] nvarchar (30) NOT NULL, [Value] nvarchar (255) NULL);");
                execSQL("CREATE INDEX [Key_idx] ON [Config] ([Key] ASC);");

                execSQL("CREATE TABLE [Replication] ([Id] integer not null primary key autoincrement, [ChangeType] int NOT NULL, [CacheId] bigint NOT NULL, [WpGcCode] nvarchar(15) NOT NULL, [SolverCheckSum] int NULL, [NotesCheckSum] int NULL, [WpCoordCheckSum] int NULL);");
                execSQL("CREATE INDEX [Replication_idx] ON [Replication] ([Id] ASC);");
                execSQL("CREATE INDEX [ReplicationCache_idx] ON [Replication] ([CacheId] ASC);");
            }

            if (lastDatabaseSchemeVersion < 1003)
            {
                execSQL("CREATE TABLE [Locations] ([Id] integer not null primary key autoincrement, [Name] nvarchar (255) NULL, [Latitude] float NULL, [Longitude] float NULL);");
                execSQL("CREATE INDEX [Locatioins_idx] ON [Locations] ([Id] ASC);");

                execSQL("CREATE TABLE [SdfExport] ([Id]  integer not null primary key autoincrement, [Description] nvarchar(255) NULL, [ExportPath] nvarchar(255) NULL, [MaxDistance] float NULL, [LocationID] Bigint NULL, [Filter] ntext NULL, [Update] bit NULL, [ExportImages] bit NULL, [ExportSpoilers] bit NULL, [ExportMaps] bit NULL, [OwnRepository] bit NULL, [ExportMapPacks] bit NULL, [MaxLogs] int NULL);");
                execSQL("CREATE INDEX [SdfExport_idx] ON [SdfExport] ([Id] ASC);");

                execSQL("ALTER TABLE [CACHES] ADD [FirstImported] datetime NULL;");

                execSQL("CREATE TABLE [Category] ([Id]  integer not null primary key autoincrement, [GpxFilename] nvarchar(255) NULL, [Pinned] bit NULL default 0, [CacheCount] int NULL);");
                execSQL("CREATE INDEX [Category_idx] ON [Category] ([Id] ASC);");

                execSQL("ALTER TABLE [GpxFilenames] ADD [CategoryId] bigint NULL;");

                execSQL("ALTER TABLE [Caches] add [state] nvarchar(50) NULL;");
                execSQL("ALTER TABLE [Caches] add [country] nvarchar(50) NULL;");
            }
            if (lastDatabaseSchemeVersion < 1015)
            {
                // GpxFilenames mit Kategorien verknüpfen

                // alte Category Tabelle löschen
                //altered, always is empty
            }
            if (lastDatabaseSchemeVersion < 1016)
            {
                execSQL("ALTER TABLE [CACHES] ADD [ApiStatus] smallint NULL default 0;");
            }
            if (lastDatabaseSchemeVersion < 1017)
            {
                execSQL("CREATE TABLE [Trackable] ([Id] integer not null primary key autoincrement, [Archived] bit NULL, [GcCode] nvarchar(15) NOT NULL, [CacheId] bigint NULL, [CurrentGoal] ntext, [CurrentOwnerName] nvarchar (255) NULL, [DateCreated] datetime NULL, [Description] ntext, [IconUrl] nvarchar (255) NULL, [ImageUrl] nvarchar (255) NULL, [name] nvarchar (255) NULL, [OwnerName] nvarchar (255), [Url] nvarchar (255) NULL);");
                execSQL("CREATE INDEX [cacheid_idx] ON [Trackable] ([CacheId] ASC);");
                execSQL("CREATE TABLE [TbLogs] ([Id] integer not null primary key autoincrement, [TrackableId] integer not NULL, [CacheID] bigint NULL, [GcCode] nvarchar (15) NULL, [LogIsEncoded] bit NULL DEFAULT 0, [LogText] ntext, [LogTypeId] bigint NULL, [LoggedByName] nvarchar (255) NULL, [Visited] datetime NULL);");
                execSQL("CREATE INDEX [trackableid_idx] ON [TbLogs] ([TrackableId] ASC);");
                execSQL("CREATE INDEX [trackablecacheid_idx] ON [TBLOGS] ([CacheId] ASC);");
            }
            if (lastDatabaseSchemeVersion < 1018)
            {
                execSQL("ALTER TABLE [SdfExport] ADD [MapPacks] nvarchar(512) NULL;");
            }
            if (lastDatabaseSchemeVersion < 1019)
            {
                // neue Felder für die erweiterten Attribute einfügen
                execSQL("ALTER TABLE [CACHES] ADD [AttributesPositiveHigh] bigint NULL default 0");
                execSQL("ALTER TABLE [CACHES] ADD [AttributesNegativeHigh] bigint NULL default 0");

                // Die Nummerierung der Attribute stimmte nicht mit der von
                // Groundspeak überein. Bei 16 und 45 wurde jeweils eine
                // Nummber übersprungen
                //altered, always empty
            }
            if (lastDatabaseSchemeVersion < 1020)
            {
                // for long Settings
                execSQL("ALTER TABLE [Config] ADD [LongString] ntext NULL;");
            }
            if (lastDatabaseSchemeVersion < 1021)
            {
                // Image Table
                execSQL("CREATE TABLE [Images] ([Id] integer not null primary key autoincrement, [CacheId] bigint NULL, [GcCode] nvarchar (15) NULL, [Description] ntext, [Name] nvarchar (255) NULL, [ImageUrl] nvarchar (255) NULL, [IsCacheImage] bit NULL);");
                execSQL("CREATE INDEX [images_cacheid_idx] ON [Images] ([CacheId] ASC);");
                execSQL("CREATE INDEX [images_gccode_idx] ON [Images] ([GcCode] ASC);");
                execSQL("CREATE INDEX [images_iscacheimage_idx] ON [Images] ([IsCacheImage] ASC);");
                execSQL("CREATE UNIQUE INDEX [images_imageurl_idx] ON [Images] ([ImageUrl] ASC);");
            }
            if (lastDatabaseSchemeVersion < 1022)
            {
                //execSQL("ALTER TABLE [Caches] ALTER COLUMN [GcCode] nvarchar(15) NOT NULL; ");

                //execSQL("ALTER TABLE [Waypoint] DROP CONSTRAINT Waypoint_PK ");
                //execSQL("ALTER TABLE [Waypoint] ALTER COLUMN [GcCode] nvarchar(15) NOT NULL; ");
                //execSQL("ALTER TABLE [Waypoint] ADD CONSTRAINT  [Waypoint_PK] PRIMARY KEY ([GcCode]); ");

                //execSQL("ALTER TABLE [Replication] ALTER COLUMN [WpGcCode] nvarchar(15) NOT NULL; ");
                //execSQL("ALTER TABLE [Trackable] ALTER COLUMN [GcCode] nvarchar(15) NOT NULL; ");
                //execSQL("ALTER TABLE [TbLogs] ALTER COLUMN [GcCode] nvarchar(15) NOT NULL; ");
                //execSQL("ALTER TABLE [Images] ALTER COLUMN [GcCode] nvarchar(15) NOT NULL; ");
            }
        }
Esempio n. 18
0
 private Hashtable getProcessedPq()
 {
     Hashtable result = new Hashtable();
     if (_databaseFile != null)
     {
         try
         {
             using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFile))
             {
                 initDatabase(dbcon);
                 DbDataReader dr = dbcon.ExecuteReader("select * from processedpq");
                 while (dr.Read())
                 {
                     result.Add(dr["pqname"], DateTime.Parse((string)dr["processdate"]));
                 }
             }
         }
         catch
         {
         }
     }
     return result;
 }
Esempio n. 19
0
 public void AddFilter(FilterField field, string filter)
 {
     try
     {
         Hashtable ht = _filterFields[field.ToString()] as Hashtable;
         if (ht != null)
         {
             if (ht[filter]==null)
             {
                 ht.Add(filter, true);
                 using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFile))
                 {
                     dbcon.ExecuteNonQuery(string.Format("insert into filterfields (field, filter) values ('{0}', '{1}')", field.ToString(), filter.Replace("'", "''")));
                 }
             }
         }
     }
     catch
     {
     }
 }
Esempio n. 20
0
 internal bool deleteArea(Framework.Data.AreaType level, string areaName)
 {
     PreLoadAreaInfo();
     bool result = true;
     try
     {
         List<Framework.Data.AreaInfo> ail = GetAreasByName(areaName, level);
         if (ail.Count > 0)
         {
             foreach (Framework.Data.AreaInfo ai in ail)
             {
                 using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename))
                 {
                     dbcon.ExecuteNonQuery(string.Format("delete from poly where areainfoid={0}", ai.ID));
                     dbcon.ExecuteNonQuery(string.Format("delete from areainfo where id={0}", ai.ID));
                     _cachedAreaInfo.Remove(ai);
                 }
             }
         }
     }
     catch
     {
         result = false;
     }
     return result;
 }
Esempio n. 21
0
 internal bool setParent(Framework.Data.AreaInfo ai, Framework.Data.AreaInfo parent)
 {
     bool result = true;
     try
     {
         using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename))
         {
             dbcon.ExecuteNonQuery(string.Format("update areainfo set parentid= where id={0}", ai.ID, parent == null ? "NULL" : parent.ID));
             ai.ParentID = parent == null ? null : parent.ID;
         }
     }
     catch
     {
         result = false;
     }
     return result;
 }
Esempio n. 22
0
 public override bool ApplySettings(List<System.Windows.Forms.UserControl> configPanels)
 {
     try
     {
         SettingsPanel panel = (from p in configPanels where p.GetType() == typeof(SettingsPanel) select p).FirstOrDefault() as SettingsPanel;
         panel.ApplyShortcuts(Core);
         using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_shortcutDatabaseFile))
         {
             initDatabase(dbcon);
             dbcon.ExecuteNonQuery("delete from shortcut");
             foreach (Framework.Data.ShortcutInfo scuts in Core.ShortcutInfo)
             {
                 dbcon.ExecuteNonQuery(string.Format("insert into shortcut (plugintype, action, subaction, keys, keystring) values ('{0}', '{1}', '{2}', {3}, '{4}')", scuts.PluginType, scuts.PluginAction.Replace("'", "''"), scuts.PluginSubAction.Replace("'", "''"), (int)scuts.ShortcutKeys, scuts.ShortcutKeyString.Replace("'", "''")));
             }
         }
         Core.OnShortcutInfoChanged();
     }
     catch
     {
     }
     return true;
 }
Esempio n. 23
0
 private void openPreset(string presetname)
 {
     try
     {
         int pos = presetname.IndexOf('|');
         if (pos > 0)
         {
             presetname = presetname.Substring(pos + 1);
             if (_presets.Contains(presetname))
             {
                 using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_presetDatabaseFile))
                 {
                     initDatabase(dbcon);
                     List<Framework.Interfaces.IPlugin> pins = Core.GetPlugins();
                     DbDataReader dr = dbcon.ExecuteReader(string.Format("select * from forms where preset='{0}'", presetname));
                     while (dr.Read())
                     {
                         Framework.Interfaces.IPluginUIChildWindow p = (from Framework.Interfaces.IPlugin a in pins where a.GetType().ToString() == (string)dr["plugintype"] select a).FirstOrDefault() as Framework.Interfaces.IPluginUIChildWindow;
                         if (p != null)
                         {
                             if ((int)dr["visible"] == 0)
                             {
                                 if (p.ChildForm != null && p.ChildForm.Visible)
                                 {
                                     p.ChildForm.Hide();
                                 }
                             }
                             else
                             {
                                 if (p.ChildForm == null || !p.ChildForm.Visible)
                                 {
                                     p.Action(p.DefaultAction);
                                 }
                                 if (p.ChildForm != null)
                                 {
                                     p.ChildForm.SetBounds((int)dr["x"], (int)dr["y"], (int)dr["w"], (int)dr["h"]);
                                 }
                             }
                         }
                         else if ((string)dr["plugintype"]=="GlobalcachingApplication.Plugins.Maps.MapsPlugin")
                         {
                             try
                             {
                                 Framework.Interfaces.IPlugin mp = Utils.PluginSupport.PluginByName(Core, "GlobalcachingApplication.Plugins.Maps.MapsPlugin");
                                 if (mp != null)
                                 {
                                     MethodInfo mi = mp.GetType().GetMethod("SetWindowStates");
                                     if (mi != null)
                                     {
                                         mi.Invoke(mp, new object[] { dr["customtag"] as string });
                                     }
                                 }
                             }
                             catch
                             {
                             }
                         }
                     }
                 }
             }
         }
     }
     catch
     {
     }
 }
Esempio n. 24
0
 private Utils.DBCon initDatabase()
 {
     Utils.DBCon dbcon;
     try
     {
         dbcon = new Utils.DBConComSqlite(_databaseFile);
         object o = dbcon.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='gallery'");
         if (o == null || o.GetType() == typeof(DBNull))
         {
             dbcon.ExecuteNonQuery("create table 'gallery' (ImageGuid text, ThumbUrl text, Description text, Name text, MobileUrl text, Url text, LogCacheCode text, LogCode text, LogUrl text, LogVisitDate text, ThumbFile text, ImgFile text)");
         }
     }
     catch
     {
         dbcon = null;
     }
     return dbcon;
 }
Esempio n. 25
0
        private void initDatabase()
        {
            string xmlFileContents;
            Assembly assembly = Assembly.GetExecutingAssembly();
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.LanguageEng.LookupDictionary.xml")))
            {
                xmlFileContents = textStreamReader.ReadToEnd();
            }
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlFileContents);
            XmlElement root = doc.DocumentElement;
            XmlNodeList strngs = root.SelectNodes("string");
            if (strngs != null)
            {
                foreach (XmlNode sn in strngs)
                {
                    if (!string.IsNullOrEmpty(sn.Attributes["value"].InnerText))
                    {
                        _fixedLookupTable[sn.Attributes["name"].InnerText.ToLower()] = sn.Attributes["value"].InnerText;
                    }
                }
            }

            try
            {
                using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_customDictionaryDatabaseFile))
                {
                    object o = dbcon.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='translation'");
                    if (o == null || o.GetType() == typeof(DBNull))
                    {
                        dbcon.ExecuteNonQuery("create table 'translation' (item_name text, item_value text)");
                    }
                    DbDataReader dr = dbcon.ExecuteReader("select * from translation");
                    while (dr.Read())
                    {
                        _customLookupTable[dr["item_name"].ToString().ToLower()] = dr["item_value"].ToString();
                    }
                }
            }
            catch
            {
            }
        }
Esempio n. 26
0
        private void updateProcessedPq(string pqName)
        {
            if (_databaseFile != null)
            {
                try
                {
                    using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFile))
                    {
                        initDatabase(dbcon);

                        //delete older than 8 days
                        DateTime weekAgo = DateTime.Now.AddDays(-8);
                        dbcon.ExecuteNonQuery(string.Format("delete from processedpq where processdate<'{0}'", weekAgo.ToString("s")));

                        if (dbcon.ExecuteNonQuery(string.Format("update processedpq set processdate='{0}' where pqname='{1}'", DateTime.Now.ToString("s"), pqName.Replace("'","''")))==0)
                        {
                            dbcon.ExecuteNonQuery(string.Format("insert into processedpq (pqname, processdate) values ('{1}', '{0}')", DateTime.Now.ToString("s"), pqName.Replace("'", "''")));
                        }
                    }
                }
                catch
                {
                }
            }
        }
Esempio n. 27
0
 private void InitDatabase()
 {
     try
     {
         if (!string.IsNullOrEmpty(_databaseFile))
         {
             Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFile);
             object o = dbcon.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='filterfields'");
             if (o == null || o.GetType() == typeof(DBNull))
             {
                 dbcon.ExecuteNonQuery("create table 'filterfields' (field text, filter text)");
             }
         }
     }
     catch
     {
     }
 }
Esempio n. 28
0
 public void AddCodes(List<string> codes)
 {
     try
     {
         using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFile))
         {
             Hashtable ht = _filterFields[FilterField.GeocacheCode.ToString()] as Hashtable;
             if (ht != null)
             {
                 foreach (string filter in codes)
                 {
                     if (ht[filter.ToUpper()]==null)
                     {
                         ht.Add(filter.ToUpper(), true);
                         dbcon.ExecuteNonQuery(string.Format("insert into filterfields (field, filter) values ('{0}', '{1}')", FilterField.GeocacheCode.ToString(), filter.ToUpper().Replace("'", "''")));
                     }
                 }
             }
         }
     }
     catch
     {
     }
 }
Esempio n. 29
0
 public void GetPolygonOfArea(Framework.Data.AreaInfo area)
 {
     PreLoadAreaInfo();
     if (area.Polygons == null)
     {
         Framework.Data.AreaInfo ainf = (from ai in _cachedAreaInfo where ai.ID == area.ID select ai).FirstOrDefault();
         if (ainf!=null)
         {
             try
             {
                 area.Polygons = new List<Framework.Data.Polygon>();
                 using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename))
                 {
                     int actPolyId = -1;
                     Framework.Data.Polygon polg = null;
                     DbDataReader dr = dbcon.ExecuteReader(string.Format("select * from poly where areainfoid={0} order by id, position", area.ID));
                     while (dr.Read())
                     {
                         int polyId = (int)dr["id"];
                         if (actPolyId != polyId)
                         {
                             polg = new Framework.Data.Polygon();
                             area.Polygons.Add(polg);
                             actPolyId = polyId;
                         }
                         polg.AddLocation(new Framework.Data.Location((double)dr["lat"], (double)dr["lon"]));
                     }
                 }
             }
             catch
             {
             }
         }
     }
 }
Esempio n. 30
0
        private void PreLoadAreaInfo()
        {
            if (_cachedAreaInfo == null)
            {
                _cachedAreaInfo = new List<Framework.Data.AreaInfo>();

                try
                {
                    using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename))
                    {
                        if (InitDatabase(dbcon))
                        {
                            DbDataReader dr = dbcon.ExecuteReader("select * from areainfo");
                            while (dr.Read())
                            {
                                Framework.Data.AreaInfo ai = new Framework.Data.AreaInfo();
                                ai.ID = (int)dr["id"];
                                ai.ParentID = dr["parentid"] == DBNull.Value ? null : dr["parentid"];
                                ai.Level = (Framework.Data.AreaType)(short)(int)dr["level"];
                                ai.Name = (string)dr["name"];
                                ai.MinLat = (double)dr["minlat"];
                                ai.MinLon = (double)dr["minlon"];
                                ai.MaxLat = (double)dr["maxlat"];
                                ai.MaxLon = (double)dr["maxlon"];
                                _cachedAreaInfo.Add(ai);
                            }
                        }

                        object o = dbcon.ExecuteScalar("select Max(id) from areainfo");
                        if (o != null)
                        {
                            _maxAreaInfoId = (int)(long)o;
                        }
                        o = dbcon.ExecuteScalar("select Max(id) from poly");
                        if (o != null)
                        {
                            _maxPolyId = (int)(long)o;
                        }
                    }
                }
                catch
                {
                    //corrupt file
                    _cachedAreaInfo.Clear();
                }
            }
        }
Esempio n. 31
0
 public cgData(Utils.DBConComSqlite db)
 {
     _db = db;
 }
Esempio n. 32
0
 internal bool deleteArea(Framework.Data.AreaInfo ai)
 {
     bool result = true;
     try
     {
         using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename))
         {
             dbcon.ExecuteNonQuery(string.Format("delete from poly where areainfoid={0}", ai.ID));
             dbcon.ExecuteNonQuery(string.Format("delete from areainfo where id={0}", ai.ID));
             _cachedAreaInfo.Remove(ai);
         }
     }
     catch
     {
         result = false;
     }
     return result;
 }
Esempio n. 33
0
        protected override void ExportMethod()
        {
            int max   = _gcList.Count;
            int index = 0;

            Hashtable htAttributes = new Hashtable();

            htAttributes[1]  = "dogs";
            htAttributes[2]  = "fee";
            htAttributes[3]  = "rappelling";
            htAttributes[4]  = "boat";
            htAttributes[5]  = "scuba";
            htAttributes[6]  = "kids";
            htAttributes[7]  = "onehour";
            htAttributes[8]  = "scenic";
            htAttributes[9]  = "hiking";
            htAttributes[10] = "climbing";
            htAttributes[11] = "wading";
            htAttributes[12] = "swimming";
            htAttributes[13] = "available";
            htAttributes[14] = "night";
            htAttributes[15] = "winter";
            htAttributes[16] = "cactus";
            htAttributes[17] = "poisonoak";
            htAttributes[18] = "dangerousanimals";
            htAttributes[19] = "ticks";
            htAttributes[20] = "mine";
            htAttributes[21] = "cliff";
            htAttributes[22] = "hunting";
            htAttributes[23] = "danger";
            htAttributes[24] = "wheelchair";
            htAttributes[25] = "parking";
            htAttributes[26] = "public";
            htAttributes[27] = "water";
            htAttributes[28] = "restrooms";
            htAttributes[29] = "phone";
            htAttributes[30] = "picnic";
            htAttributes[31] = "camping";
            htAttributes[32] = "bicycles";
            htAttributes[33] = "motorcycles";
            htAttributes[34] = "quads";
            htAttributes[35] = "jeeps";
            htAttributes[36] = "snowmobiles";
            htAttributes[37] = "horses";
            htAttributes[38] = "campfires";
            htAttributes[39] = "thorn";
            htAttributes[40] = "stealth";
            htAttributes[41] = "stroller";
            htAttributes[42] = "firstaid";
            htAttributes[43] = "cow";
            htAttributes[44] = "flashlight";
            htAttributes[45] = "landf";
            htAttributes[46] = "rv";
            htAttributes[47] = "field_puzzle";
            htAttributes[48] = "UV";
            htAttributes[49] = "snowshoes";
            htAttributes[50] = "skiis";
            htAttributes[51] = "s-tool";
            htAttributes[52] = "nightcache";
            htAttributes[53] = "parkngrab";
            htAttributes[54] = "AbandonedBuilding";
            htAttributes[55] = "hike_short";
            htAttributes[56] = "hike_med";
            htAttributes[57] = "hike_long";
            htAttributes[58] = "fuel";
            htAttributes[59] = "food";
            htAttributes[60] = "wirelessbeacon";
            htAttributes[61] = "partnership";
            htAttributes[62] = "seasonal";
            htAttributes[63] = "touristOK";
            htAttributes[64] = "treeclimbing";
            htAttributes[65] = "frontyard";
            htAttributes[66] = "teamwork";
            htAttributes[67] = "geotour";


            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_EXPORTINGCB, STR_CREATINGFILE, max, 0, true))
            {
                string cbFile     = System.IO.Path.Combine(_folder, "cgeo.sqlite");
                string cbDataFile = System.IO.Path.Combine(_folder, "data");

                if (System.IO.File.Exists(cbFile))
                {
                    System.IO.File.Delete(cbFile);
                }
                if (System.IO.File.Exists(cbDataFile))
                {
                    System.IO.File.Delete(cbDataFile);
                }
                CreateDatabase(cbFile);

                if (_dbcon != null)
                {
                    _dbcon.ExecuteNonQuery("CREATE TABLE android_metadata (locale TEXT)");
                    _dbcon.ExecuteNonQuery("INSERT INTO android_metadata VALUES('en_US')");
                    //_dbcon.ExecuteNonQuery("CREATE TABLE sqlite_sequence (name, seq)");

                    DbCommand cmd = _dbcon.Command;

                    int detailed        = 1;
                    int reason          = 1;
                    int reliable_latlon = 1;

                    DateTime dt = DateTime.Now.AddSeconds(2);
                    foreach (Framework.Data.Geocache gc in _gcList)
                    {
                        //----------------------------
                        // CACHE
                        //----------------------------
                        cmd.Parameters.Clear();
                        cmd.CommandText = "insert into cg_caches (updated, detailed, detailedupdate, visiteddate, geocode, reason, cacheid, guid, type, name, owner, owner_real, hidden, hint, size, difficulty, terrain, latlon, location, latitude, longitude, reliable_latlon, personal_note, shortdesc, description, favourite_cnt, disabled, archived, members, found, coordsChanged, finalDefined) values (@updated, 1, @detailedupdate, @visiteddate, @geocode, @reason, @cacheid, @guid, @type, @name, @owner, @owner_real, @hidden, @hint, @size, @difficulty, @terrain, @latlon, @location, @latitude, @longitude, @reliable_latlon, @personal_note, @shortdesc, @description, @favourite_cnt, @disabled, @archived, @members, @found, @coordsChanged, @finalDefined)";
                        DbParameter par;
                        par = cmd.CreateParameter();
                        par.ParameterName = "@updated";
                        par.DbType        = DbType.Int64;
                        par.Value         = GetcgeoTime(DateTime.Now);
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@detailed";
                        par.DbType        = DbType.Int32;
                        par.Value         = detailed;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@detailedupdate";
                        par.DbType        = DbType.UInt64;
                        par.Value         = GetcgeoTime(DateTime.Now);
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@visiteddate";
                        par.DbType        = DbType.UInt64;
                        if (gc.FoundDate == null)
                        {
                            par.Value = 0;
                        }
                        else
                        {
                            par.Value = GetcgeoTime((DateTime)gc.FoundDate);
                        }
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@geocode";
                        par.DbType        = DbType.String;
                        par.Value         = gc.Code;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@reason";
                        par.DbType        = DbType.Int32;
                        par.Value         = reason;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@cacheid";
                        par.DbType        = DbType.String;
                        if (gc.ID.StartsWith("GC"))
                        {
                            par.Value = Utils.Conversion.GetCacheIDFromCacheCode(gc.Code).ToString();
                        }
                        else
                        {
                            par.Value = gc.ID;
                        }
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@guid";
                        par.DbType        = DbType.String;
                        par.Value         = DBNull.Value;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@type";
                        par.DbType        = DbType.String;
                        par.Value         = gc.GeocacheType.GPXTag.Split(new char[] { ' ', '-' })[0].ToLower();
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@name";
                        par.DbType        = DbType.String;
                        par.Value         = gc.Name ?? "";
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@owner";
                        par.DbType        = DbType.String;
                        par.Value         = gc.PlacedBy ?? "";
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@owner_real";
                        par.DbType        = DbType.String;
                        par.Value         = gc.Owner ?? "";
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@hidden";
                        par.DbType        = DbType.UInt64;
                        par.Value         = GetcgeoTime(gc.PublishedTime);
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@hint";
                        par.DbType        = DbType.String;
                        par.Value         = gc.EncodedHints ?? "";
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@size";
                        par.DbType        = DbType.String;
                        par.Value         = gc.Container.Name.ToLower();
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@difficulty";
                        par.DbType        = DbType.Single;
                        par.Value         = (float)gc.Difficulty;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@terrain";
                        par.DbType        = DbType.Single;
                        par.Value         = (float)gc.Terrain;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@latlon";
                        par.DbType        = DbType.String;
                        par.Value         = DBNull.Value;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@location";
                        par.DbType        = DbType.String;
                        if (string.IsNullOrEmpty(gc.State))
                        {
                            par.Value = gc.Country ?? "";
                        }
                        else
                        {
                            par.Value = string.Format("{0}, {1}", gc.State, gc.Country ?? "");
                        }
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@latitude";
                        par.DbType        = DbType.Double;
                        par.Value         = gc.ContainsCustomLatLon ? gc.CustomLat : gc.Lat;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@longitude";
                        par.DbType        = DbType.Double;
                        par.Value         = gc.ContainsCustomLatLon ? gc.CustomLon : gc.Lon;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@reliable_latlon";
                        par.DbType        = DbType.Int32;
                        par.Value         = reliable_latlon;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@personal_note";
                        par.DbType        = DbType.String;
                        par.Value         = gc.PersonaleNote ?? "";
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@shortdesc";
                        par.DbType        = DbType.String;
                        if (gc.ShortDescriptionInHtml)
                        {
                            par.Value = gc.ShortDescription ?? "";
                        }
                        else
                        {
                            par.Value = HttpUtility.HtmlEncode(gc.ShortDescription ?? "");
                        }
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@description";
                        par.DbType        = DbType.String;
                        if (gc.LongDescriptionInHtml)
                        {
                            par.Value = gc.LongDescription ?? "";
                        }
                        else
                        {
                            par.Value = HttpUtility.HtmlEncode(gc.LongDescription ?? "");
                        }
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@favourite_cnt";
                        par.DbType        = DbType.Int32;
                        par.Value         = gc.Favorites;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@disabled";
                        par.DbType        = DbType.Int32;
                        par.Value         = gc.Available ? 0 : 1;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@archived";
                        par.DbType        = DbType.Int32;
                        par.Value         = gc.Archived ? 1 : 0;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@members";
                        par.DbType        = DbType.Int32;
                        par.Value         = gc.MemberOnly ? 1 : 0;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@found";
                        par.DbType        = DbType.Int32;
                        par.Value         = gc.Found ? 1 : 0;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@coordsChanged";
                        par.DbType        = DbType.Int32;
                        par.Value         = gc.CustomCoords ? 1 : 0;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@finalDefined";
                        par.DbType        = DbType.Int32;
                        par.Value         = 0;
                        cmd.Parameters.Add(par);

                        int res = cmd.ExecuteNonQuery();
                        cmd.Parameters.Clear();

                        //----------------------------
                        // ATTRIBUTES
                        //----------------------------
                        List <int> attrs = gc.AttributeIds;
                        if (attrs != null && attrs.Count > 0)
                        {
                            cmd.CommandText   = "insert into cg_attributes (geocode, updated, attribute) values (@geocode, @updated, @attribute)";
                            par               = cmd.CreateParameter();
                            par.ParameterName = "@geocode";
                            par.DbType        = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@updated";
                            par.DbType        = DbType.Int64;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@attribute";
                            par.DbType        = DbType.String;
                            cmd.Parameters.Add(par);
                            foreach (int att in attrs)
                            {
                                string atname = htAttributes[Math.Abs(att)] as string;
                                if (!string.IsNullOrEmpty(atname))
                                {
                                    atname = atname.ToLower();
                                    cmd.Parameters["@geocode"].Value   = gc.Code;
                                    cmd.Parameters["@updated"].Value   = GetcgeoTime(DateTime.Now);
                                    cmd.Parameters["@attribute"].Value = att > 0 ? string.Format("{0}_yes", atname) : string.Format("{0}_no", atname);
                                    cmd.ExecuteNonQuery();
                                }
                            }
                            cmd.Parameters.Clear();
                        }

                        //----------------------------
                        // WAYPOINTS
                        //----------------------------
                        List <Framework.Data.Waypoint> wpts = Utils.DataAccess.GetWaypointsFromGeocache(Core.Waypoints, gc.Code);
                        if (wpts != null && wpts.Count > 0)
                        {
                            cmd.CommandText   = "insert into cg_waypoints (geocode, updated, type, prefix, lookup, name, latlon, latitude, longitude, note) values (@geocode, @updated, @type, @prefix, @lookup, @name, @latlon, @latitude, @longitude, @note)";
                            par               = cmd.CreateParameter();
                            par.ParameterName = "@geocode";
                            par.DbType        = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@updated";
                            par.DbType        = DbType.Int64;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@type";
                            par.DbType        = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@prefix";
                            par.DbType        = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@lookup";
                            par.DbType        = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@name";
                            par.DbType        = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@latlon";
                            par.DbType        = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@latitude";
                            par.DbType        = DbType.Double;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@longitude";
                            par.DbType        = DbType.Double;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@note";
                            par.DbType        = DbType.String;
                            cmd.Parameters.Add(par);
                            foreach (Framework.Data.Waypoint wp in wpts)
                            {
                                if (wp.Lat != null && wp.Lon != null)
                                {
                                    cmd.Parameters["@geocode"].Value = gc.Code;
                                    cmd.Parameters["@updated"].Value = GetcgeoTime(DateTime.Now);
                                    switch (wp.WPType.ID)
                                    {
                                    case 217:
                                        cmd.Parameters["@type"].Value = "pkg";
                                        break;

                                    case 220:
                                        cmd.Parameters["@type"].Value = "flag";
                                        break;

                                    case 218:
                                        cmd.Parameters["@type"].Value = "puzzle";
                                        break;

                                    case 452:
                                        cmd.Parameters["@type"].Value = "waypoint";
                                        break;

                                    case 219:
                                        cmd.Parameters["@type"].Value = "stage";
                                        break;

                                    case 221:
                                        cmd.Parameters["@type"].Value = "trailhead";
                                        break;

                                    default:
                                        cmd.Parameters["@type"].Value = "waypoint";
                                        break;
                                    }
                                    cmd.Parameters["@prefix"].Value    = wp.Code.Substring(0, 2);
                                    cmd.Parameters["@lookup"].Value    = "---";
                                    cmd.Parameters["@name"].Value      = wp.Description ?? "";
                                    cmd.Parameters["@latlon"].Value    = Utils.Conversion.GetCoordinatesPresentation((double)wp.Lat, (double)wp.Lon);
                                    cmd.Parameters["@latitude"].Value  = (double)wp.Lat;
                                    cmd.Parameters["@longitude"].Value = (double)wp.Lon;
                                    cmd.Parameters["@note"].Value      = wp.Comment ?? "";

                                    cmd.ExecuteNonQuery();
                                }
                            }
                            cmd.Parameters.Clear();
                        }

                        //----------------------------
                        // LOGS
                        //----------------------------
                        List <Framework.Data.Log> lgs = Utils.DataAccess.GetLogs(Core.Logs, gc.Code);
                        if (lgs != null && lgs.Count > 0)
                        {
                            cmd.CommandText   = "insert into cg_logs (geocode, updated, type, author, log, date, friend) values (@geocode, @updated, @type, @author, @log, @date, 0)";
                            par               = cmd.CreateParameter();
                            par.ParameterName = "@geocode";
                            par.DbType        = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@updated";
                            par.DbType        = DbType.Int64;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@type";
                            par.DbType        = DbType.Int32;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@author";
                            par.DbType        = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@log";
                            par.DbType        = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@date";
                            par.DbType        = DbType.Int64;
                            cmd.Parameters.Add(par);

                            foreach (Framework.Data.Log lg in lgs)
                            {
                                cmd.Parameters["@geocode"].Value = gc.Code;
                                cmd.Parameters["@updated"].Value = GetcgeoTime(DateTime.Now);
                                cmd.Parameters["@type"].Value    = lg.LogType.ID;
                                cmd.Parameters["@author"].Value  = lg.Finder ?? "";
                                cmd.Parameters["@log"].Value     = HttpUtility.HtmlEncode(lg.Text ?? "").Replace("\r", "").Replace("\n", "<br />");
                                cmd.Parameters["@date"].Value    = GetcgeoTime(lg.Date);

                                cmd.ExecuteNonQuery();
                            }
                            cmd.Parameters.Clear();
                        }

                        index++;
                        if (DateTime.Now > dt)
                        {
                            if (!progress.UpdateProgress(STR_EXPORTINGCB, STR_CREATINGFILE, max, index))
                            {
                                break;
                            }
                            dt = DateTime.Now.AddSeconds(2);
                        }
                    }
                    //_dbcon.ExecuteNonQuery(string.Format("insert into sqlite_sequence (name, seq) values ('cg_caches', {0})", index));
                    _dbcon.Dispose();
                    _dbcon = null;

                    //not working. you have to go through recover database on c:geo
                    //System.IO.File.Copy(cbFile, cbDataFile);
                }
            }
        }
Esempio n. 34
0
 internal bool processTextFile(Framework.Data.AreaType level, string f, Framework.Data.AreaInfo parent)
 {
     PreLoadAreaInfo();
     bool result = false;
     try
     {
         //filename = AreaName
         string areaName = System.IO.Path.GetFileNameWithoutExtension(f);
         char[] num = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
         int pos = 0;
         while (pos < areaName.Length && !num.Contains(areaName[pos])) pos++;
         areaName = areaName.Substring(0, pos);
         string[] lines = System.IO.File.ReadAllLines(f);
         pos = 0;
         if (lines[0].StartsWith("# GsakName="))
         {
             areaName = lines[0].Substring(lines[0].IndexOf('=')+1).Trim();
             pos++;
         }
         string slat = "";
         string slon = "";
         double lat;
         double lon;
         bool newPoly;
         Framework.Data.AreaInfo ai;
         List<Framework.Data.AreaInfo> ailist = GetAreasByName(areaName, level);
         bool firstPoint = true;
         if (ailist.Count > 0)
         {
             ai = ailist[0];
             firstPoint = false;
             newPoly = false;
         }
         else
         {
             newPoly = true;
             ai = new Framework.Data.AreaInfo();
             ai.ID = _maxAreaInfoId + 1;
             _maxAreaInfoId++;
             ai.Name = areaName;
             ai.Level = level;
             ai.Polygons = new List<Framework.Data.Polygon>();
         }
         Framework.Data.Polygon poly = new Framework.Data.Polygon();
         _maxPolyId++;
         using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFilename))
         {
             dbcon.BeginTran();
             while (pos < lines.Length)
             {
                 string s = lines[pos].Trim();
                 if (!s.StartsWith("#"))
                 {
                     string[] parts = s.Split(new char[] { ' ', ',', '\t'},  StringSplitOptions.RemoveEmptyEntries);
                     if (parts.Length == 2)
                     {
                         lat = Utils.Conversion.StringToDouble(parts[0]);
                         lon = Utils.Conversion.StringToDouble(parts[1]);
                         if (firstPoint)
                         {
                             ai.MinLat = lat;
                             ai.MaxLat = lat;
                             ai.MinLon = lon;
                             ai.MaxLon = lon;
                             firstPoint = false;
                         }
                         else
                         {
                             if (lat < ai.MinLat) ai.MinLat = lat;
                             if (lat > ai.MaxLat) ai.MaxLat = lat;
                             if (lon < ai.MinLon) ai.MinLon = lon;
                             if (lon > ai.MaxLon) ai.MaxLon = lon;
                         }
                         poly.AddLocation(new Framework.Data.Location(lat, lon));
                         dbcon.ExecuteNonQuery(string.Format("insert into poly (id, areainfoid, position, lat, lon) values ({0}, {1}, {2}, {3}, {4})", _maxPolyId, ai.ID, poly.Count, lat.ToString().Replace(',', '.'), lon.ToString().Replace(',', '.')));
                         if (poly.Count == 1)
                         {
                             slat = parts[0];
                             slon = parts[1];
                             ai.Polygons.Add(poly);
                         }
                         else if (slat == parts[0] && slon == parts[1])
                         {
                             poly = new Framework.Data.Polygon();
                             _maxPolyId++;
                         }
                     }
                 }
                 pos++;
             }
             if (newPoly)
             {
                 _cachedAreaInfo.Add(ai);
                 dbcon.ExecuteNonQuery(string.Format("insert into areainfo (id, parentid, level, name, minlat, minlon, maxlat, maxlon) values ({0}, {1}, {2}, '{3}', {4}, {5}, {6}, {7})", ai.ID, parent == null ? "NULL" : parent.ID, (short)ai.Level, ai.Name.Replace("'", "''"), ai.MinLat.ToString().Replace(',', '.'), ai.MinLon.ToString().Replace(',', '.'), ai.MaxLat.ToString().Replace(',', '.'), ai.MaxLon.ToString().Replace(',', '.')));
             }
             else
             {
                 dbcon.ExecuteNonQuery(string.Format("update areainfo set parentid={0}, minlat={1}, minlon={2}, maxlat={3}, maxlon={4} where id={5}", parent == null ? "NULL" : parent.ID, ai.MinLat.ToString().Replace(',', '.'), ai.MinLon.ToString().Replace(',', '.'), ai.MaxLat.ToString().Replace(',', '.'), ai.MaxLon.ToString().Replace(',', '.'), ai.ID));
             }
             dbcon.CommitTran();
             result = true;
         }
     }
     catch
     {
     }
     return result;
 }
Esempio n. 35
0
        private void CreateDatabase(string filename)
        {
            _dbcon = new Utils.DBConComSqlite(filename);

            //most code copied from Cachebox (Android)
            int lastDatabaseSchemeVersion = -1;

            if (lastDatabaseSchemeVersion <= 0)
            {
                // First Initialization of the Database
                execSQL("CREATE TABLE [Caches] ([Id] bigint NOT NULL primary key,[GcCode] nvarchar(15) NOT NULL,[GcId] nvarchar (255) NULL,[Latitude] float NULL,[Longitude] float NULL,[Name] nchar (255) NULL,[Size] int NULL,[Difficulty] smallint NULL,[Terrain] smallint NULL,[Archived] bit NULL,[Available] bit NULL,[Found] bit NULL,[Type] smallint NULL,[PlacedBy] nvarchar (255) NULL,[Owner] nvarchar (255) NULL,[DateHidden] datetime NULL,[Hint] ntext NULL,[Description] ntext NULL,[Url] nchar (255) NULL,[NumTravelbugs] smallint NULL,[Rating] smallint NULL,[Vote] smallint NULL,[VotePending] bit NULL,[Notes] ntext NULL,[Solver] ntext NULL,[Favorit] bit NULL,[AttributesPositive] bigint NULL,[AttributesNegative] bigint NULL,[TourName] nchar (255) NULL,[GPXFilename_Id] bigint NULL,[HasUserData] bit NULL,[ListingCheckSum] int NULL DEFAULT 0,[ListingChanged] bit NULL,[ImagesUpdated] bit NULL,[DescriptionImagesUpdated] bit NULL,[CorrectedCoordinates] bit NULL);");
                execSQL("CREATE INDEX [archived_idx] ON [Caches] ([Archived] ASC);");
                execSQL("CREATE INDEX [AttributesNegative_idx] ON [Caches] ([AttributesNegative] ASC);");
                execSQL("CREATE INDEX [AttributesPositive_idx] ON [Caches] ([AttributesPositive] ASC);");
                execSQL("CREATE INDEX [available_idx] ON [Caches] ([Available] ASC);");
                execSQL("CREATE INDEX [Difficulty_idx] ON [Caches] ([Difficulty] ASC);");
                execSQL("CREATE INDEX [Favorit_idx] ON [Caches] ([Favorit] ASC);");
                execSQL("CREATE INDEX [found_idx] ON [Caches] ([Found] ASC);");
                execSQL("CREATE INDEX [GPXFilename_Id_idx] ON [Caches] ([GPXFilename_Id] ASC);");
                execSQL("CREATE INDEX [HasUserData_idx] ON [Caches] ([HasUserData] ASC);");
                execSQL("CREATE INDEX [ListingChanged_idx] ON [Caches] ([ListingChanged] ASC);");
                execSQL("CREATE INDEX [NumTravelbugs_idx] ON [Caches] ([NumTravelbugs] ASC);");
                execSQL("CREATE INDEX [placedby_idx] ON [Caches] ([PlacedBy] ASC);");
                execSQL("CREATE INDEX [Rating_idx] ON [Caches] ([Rating] ASC);");
                execSQL("CREATE INDEX [Size_idx] ON [Caches] ([Size] ASC);");
                execSQL("CREATE INDEX [Terrain_idx] ON [Caches] ([Terrain] ASC);");
                execSQL("CREATE INDEX [Type_idx] ON [Caches] ([Type] ASC);");

                execSQL("CREATE TABLE [CelltowerLocation] ([CellId] nvarchar (20) NOT NULL primary key,[Latitude] float NULL,[Longitude] float NULL);");

                execSQL("CREATE TABLE [GPXFilenames] ([Id] integer not null primary key autoincrement,[GPXFilename] nvarchar (255) NULL,[Imported] datetime NULL, [Name] nvarchar (255) NULL,[CacheCount] int NULL);");

                execSQL("CREATE TABLE [Logs] ([Id] bigint NOT NULL primary key, [CacheId] bigint NULL,[Timestamp] datetime NULL,[Finder] nvarchar (128) NULL,[Type] smallint NULL,[Comment] ntext NULL);");
                execSQL("CREATE INDEX [log_idx] ON [Logs] ([CacheId] ASC);");
                execSQL("CREATE INDEX [timestamp_idx] ON [Logs] ([Timestamp] ASC);");

                execSQL("CREATE TABLE [PocketQueries] ([Id] integer not null primary key autoincrement,[PQName] nvarchar (255) NULL,[CreationTimeOfPQ] datetime NULL);");

                execSQL("CREATE TABLE [Waypoint] ([GcCode] nvarchar(15) NOT NULL primary key,[CacheId] bigint NULL,[Latitude] float NULL,[Longitude] float NULL,[Description] ntext NULL,[Clue] ntext NULL,[Type] smallint NULL,[SyncExclude] bit NULL,[UserWaypoint] bit NULL,[Title] ntext NULL);");
                execSQL("CREATE INDEX [UserWaypoint_idx] ON [Waypoint] ([UserWaypoint] ASC);");

                execSQL("CREATE TABLE [Config] ([Key] nvarchar (30) NOT NULL, [Value] nvarchar (255) NULL);");
                execSQL("CREATE INDEX [Key_idx] ON [Config] ([Key] ASC);");

                execSQL("CREATE TABLE [Replication] ([Id] integer not null primary key autoincrement, [ChangeType] int NOT NULL, [CacheId] bigint NOT NULL, [WpGcCode] nvarchar(15) NOT NULL, [SolverCheckSum] int NULL, [NotesCheckSum] int NULL, [WpCoordCheckSum] int NULL);");
                execSQL("CREATE INDEX [Replication_idx] ON [Replication] ([Id] ASC);");
                execSQL("CREATE INDEX [ReplicationCache_idx] ON [Replication] ([CacheId] ASC);");
            }

				if (lastDatabaseSchemeVersion < 1003)
				{
					execSQL("CREATE TABLE [Locations] ([Id] integer not null primary key autoincrement, [Name] nvarchar (255) NULL, [Latitude] float NULL, [Longitude] float NULL);");
					execSQL("CREATE INDEX [Locatioins_idx] ON [Locations] ([Id] ASC);");

					execSQL("CREATE TABLE [SdfExport] ([Id]  integer not null primary key autoincrement, [Description] nvarchar(255) NULL, [ExportPath] nvarchar(255) NULL, [MaxDistance] float NULL, [LocationID] Bigint NULL, [Filter] ntext NULL, [Update] bit NULL, [ExportImages] bit NULL, [ExportSpoilers] bit NULL, [ExportMaps] bit NULL, [OwnRepository] bit NULL, [ExportMapPacks] bit NULL, [MaxLogs] int NULL);");
					execSQL("CREATE INDEX [SdfExport_idx] ON [SdfExport] ([Id] ASC);");

					execSQL("ALTER TABLE [CACHES] ADD [FirstImported] datetime NULL;");

					execSQL("CREATE TABLE [Category] ([Id]  integer not null primary key autoincrement, [GpxFilename] nvarchar(255) NULL, [Pinned] bit NULL default 0, [CacheCount] int NULL);");
					execSQL("CREATE INDEX [Category_idx] ON [Category] ([Id] ASC);");

					execSQL("ALTER TABLE [GpxFilenames] ADD [CategoryId] bigint NULL;");

					execSQL("ALTER TABLE [Caches] add [state] nvarchar(50) NULL;");
					execSQL("ALTER TABLE [Caches] add [country] nvarchar(50) NULL;");
				}
				if (lastDatabaseSchemeVersion < 1015)
				{
					// GpxFilenames mit Kategorien verknüpfen

					// alte Category Tabelle löschen
                    //altered, always is empty
				}
				if (lastDatabaseSchemeVersion < 1016)
				{
					execSQL("ALTER TABLE [CACHES] ADD [ApiStatus] smallint NULL default 0;");
				}
				if (lastDatabaseSchemeVersion < 1017)
				{
                    execSQL("CREATE TABLE [Trackable] ([Id] integer not null primary key autoincrement, [Archived] bit NULL, [GcCode] nvarchar(15) NOT NULL, [CacheId] bigint NULL, [CurrentGoal] ntext, [CurrentOwnerName] nvarchar (255) NULL, [DateCreated] datetime NULL, [Description] ntext, [IconUrl] nvarchar (255) NULL, [ImageUrl] nvarchar (255) NULL, [name] nvarchar (255) NULL, [OwnerName] nvarchar (255), [Url] nvarchar (255) NULL);");
					execSQL("CREATE INDEX [cacheid_idx] ON [Trackable] ([CacheId] ASC);");
					execSQL("CREATE TABLE [TbLogs] ([Id] integer not null primary key autoincrement, [TrackableId] integer not NULL, [CacheID] bigint NULL, [GcCode] nvarchar (15) NULL, [LogIsEncoded] bit NULL DEFAULT 0, [LogText] ntext, [LogTypeId] bigint NULL, [LoggedByName] nvarchar (255) NULL, [Visited] datetime NULL);");
					execSQL("CREATE INDEX [trackableid_idx] ON [TbLogs] ([TrackableId] ASC);");
					execSQL("CREATE INDEX [trackablecacheid_idx] ON [TBLOGS] ([CacheId] ASC);");
				}
				if (lastDatabaseSchemeVersion < 1018)
				{
					execSQL("ALTER TABLE [SdfExport] ADD [MapPacks] nvarchar(512) NULL;");

				}
				if (lastDatabaseSchemeVersion < 1019)
				{
					// neue Felder für die erweiterten Attribute einfügen
					execSQL("ALTER TABLE [CACHES] ADD [AttributesPositiveHigh] bigint NULL default 0");
					execSQL("ALTER TABLE [CACHES] ADD [AttributesNegativeHigh] bigint NULL default 0");

					// Die Nummerierung der Attribute stimmte nicht mit der von
					// Groundspeak überein. Bei 16 und 45 wurde jeweils eine
					// Nummber übersprungen
                    //altered, always empty
				}
				if (lastDatabaseSchemeVersion < 1020)
				{
					// for long Settings
					execSQL("ALTER TABLE [Config] ADD [LongString] ntext NULL;");

				}
				if (lastDatabaseSchemeVersion < 1021)
				{
					// Image Table
					execSQL("CREATE TABLE [Images] ([Id] integer not null primary key autoincrement, [CacheId] bigint NULL, [GcCode] nvarchar (15) NULL, [Description] ntext, [Name] nvarchar (255) NULL, [ImageUrl] nvarchar (255) NULL, [IsCacheImage] bit NULL);");
					execSQL("CREATE INDEX [images_cacheid_idx] ON [Images] ([CacheId] ASC);");
					execSQL("CREATE INDEX [images_gccode_idx] ON [Images] ([GcCode] ASC);");
					execSQL("CREATE INDEX [images_iscacheimage_idx] ON [Images] ([IsCacheImage] ASC);");
					execSQL("CREATE UNIQUE INDEX [images_imageurl_idx] ON [Images] ([ImageUrl] ASC);");
				}
				if (lastDatabaseSchemeVersion < 1022)
				{
					//execSQL("ALTER TABLE [Caches] ALTER COLUMN [GcCode] nvarchar(15) NOT NULL; ");

					//execSQL("ALTER TABLE [Waypoint] DROP CONSTRAINT Waypoint_PK ");
					//execSQL("ALTER TABLE [Waypoint] ALTER COLUMN [GcCode] nvarchar(15) NOT NULL; ");
					//execSQL("ALTER TABLE [Waypoint] ADD CONSTRAINT  [Waypoint_PK] PRIMARY KEY ([GcCode]); ");

					//execSQL("ALTER TABLE [Replication] ALTER COLUMN [WpGcCode] nvarchar(15) NOT NULL; ");
					//execSQL("ALTER TABLE [Trackable] ALTER COLUMN [GcCode] nvarchar(15) NOT NULL; ");
					//execSQL("ALTER TABLE [TbLogs] ALTER COLUMN [GcCode] nvarchar(15) NOT NULL; ");
					//execSQL("ALTER TABLE [Images] ALTER COLUMN [GcCode] nvarchar(15) NOT NULL; ");
				}

        }
Esempio n. 36
0
        public override bool ApplySettings(List<System.Windows.Forms.UserControl> configPanels)
        {
            foreach (System.Windows.Forms.UserControl uc in configPanels)
            {
                if (uc is SettingsPanel)
                {
                    SettingsPanel sp = uc as SettingsPanel;
                    List<DictionaryItem> dict = (List<DictionaryItem>)sp.dictionaryEdit1.dataGrid1.ItemsSource;

                    try
                    {
                        bool changed = false;
                        using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_customDictionaryDatabaseFile))
                        {
                            foreach (DictionaryItem di in dict)
                            {
                                string s = _fixedLookupTable[di.Key.ToLower()] as string;
                                string cs = _customLookupTable[di.Key.ToLower()] as string;
                                if (string.IsNullOrEmpty(di.Value) || di.Value==s)
                                {
                                    //remove from custom
                                    if (!string.IsNullOrEmpty(cs))
                                    {
                                        dbcon.ExecuteNonQuery(string.Format("delete from translation where item_name='{0}'", di.Key.ToLower().Replace("'", "''")));
                                        _customLookupTable.Remove(di.Key.ToLower());
                                        changed = true;
                                    }
                                }
                                else if (di.Value!=s && di.Value!=cs)
                                {
                                    _customLookupTable[di.Key.ToLower()] = di.Value;
                                    if (dbcon.ExecuteNonQuery(string.Format("update translation set item_value='{1}' where item_name='{0}'", di.Key.ToLower().Replace("'", "''"), di.Value.Replace("'", "''"))) == 0)
                                    {
                                        dbcon.ExecuteNonQuery(string.Format("insert into translation (item_name, item_value) values ('{0}', '{1}')", di.Key.ToLower().Replace("'", "''"), di.Value.Replace("'", "''")));
                                    }
                                    changed = true;
                                }
                            }
                        }
#if DEBUG
                        if (true)
#else
                        if (changed)
#endif
                        {
                            List<DictionaryItem> sortedDict = (from a in dict orderby a.Key select a).ToList();
                            XmlDocument doc = new XmlDocument();
                            XmlElement root = doc.CreateElement("resources");
                            foreach (DictionaryItem di in sortedDict)
                            {
                                XmlElement lngElement = doc.CreateElement("string");
                                lngElement.SetAttribute("name", di.Key);
                                lngElement.SetAttribute("value", GetTranslation(di.Key) ?? "");
                                root.AppendChild(lngElement);
                            }
                            doc.AppendChild(root);
                            using (TextWriter sw = new StreamWriter(System.IO.Path.Combine(Core.PluginDataPath, "LanguageEng.xml" ), false, Encoding.UTF8)) //Set encoding
                            {
                                doc.Save(sw);
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
            return base.ApplySettings(configPanels);
        }
Esempio n. 37
0
        public async Task ExportToCachebox(List<Core.Data.Geocache> gcList, string targetFolder, int maxLogCount)
        {
            await Task.Run(() =>
            {
                try
                {
                    int max = gcList.Count;
                    int index = 0;
                    DateTime nextUpdate = DateTime.Now.AddSeconds(1);
                    using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ExportCachebox", "CreatingFile", 3, 0, true))
                    {
                        string cbFile = System.IO.Path.Combine(targetFolder, "cachebox.db3");

                        if (System.IO.File.Exists(cbFile))
                        {
                            System.IO.File.Delete(cbFile);
                        }
                        CreateDatabase(cbFile);

                        if (_dbcon != null)
                        {
                            int fixedCatId = 1;
                            string fixedGpxFilename = "12345678.gpx";

                            _dbcon.ExecuteNonQuery("PRAGMA user_version = 1022");

                            _dbcon.ExecuteNonQuery(string.Format("insert into Config (Key, Value) values ('{0}', '{1}')", "DatabaseSchemeVersion", "1022"));
                            _dbcon.ExecuteNonQuery(string.Format("insert into Config (Key, Value) values ('{0}', '{1}')", "DatabaseSchemeVersionWin", "1022"));
                            _dbcon.ExecuteNonQuery(string.Format("insert into Config (Key, Value) values ('{0}', '{1}')", "DatabaseId", DateTime.Now.ToFileTime()));
                            _dbcon.ExecuteNonQuery(string.Format("insert into Config (Key, Value) values ('{0}', '{1}')", "MasterDatabaseId", DateTime.Now.ToFileTime() + 1));

                            _dbcon.ExecuteNonQuery(string.Format("insert into Category (Id, GpxFilename, Pinned) values ({0}, '{1}', {2})", fixedCatId, fixedGpxFilename, 0));
                            _dbcon.ExecuteNonQuery(string.Format("insert into GPXFilenames (Id, GpxFilename, Imported, CategoryId) values ({0}, '{1}', '{2}', {3})", 1, fixedGpxFilename, DateTime.Now.ToString("s"), fixedCatId));


                            //----------------------------
                            // CACHES
                            //----------------------------
                            DbCommand cmd = _dbcon.Command;
                            cmd.CommandText = "insert into Caches (Id, GcCode, GcId, Latitude, Longitude, Name, Size, Difficulty, Terrain, Archived, Available, Found, Type, PlacedBy, Owner, DateHidden, Hint, Description, Url, NumTravelbugs, Rating, Vote, VotePending, Notes, Solver, Favorit, AttributesPositive, AttributesNegative, TourName, GPXFilename_Id, HasUserData, ListingChanged, ImagesUpdated, DescriptionImagesUpdated, CorrectedCoordinates, AttributesPositiveHigh, AttributesNegativeHigh, State, Country) values (@Id, @GcCode, @GcId, @Latitude, @Longitude, @Name, @Size, @Difficulty, @Terrain, @Archived, @Available, @Found, @Type, @PlacedBy, @Owner, @DateHidden, @Hint, @Description, @Url, @NumTravelbugs, @Rating, @Vote, @VotePending, @Notes, @Solver, @Favorit, @AttributesPositive, @AttributesNegative, @TourName, @GPXFilename_Id, @HasUserData, @ListingChanged, @ImagesUpdated, @DescriptionImagesUpdated, @CorrectedCoordinates, @AttributesPositiveHigh, @AttributesNegativeHigh, @State, @Country)";
                            DbParameter par;
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Id";
                            par.DbType = DbType.Int64;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@GcCode";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@GcId";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Latitude";
                            par.DbType = DbType.Single;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Longitude";
                            par.DbType = DbType.Single;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Name";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Size";
                            par.DbType = DbType.Int16;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Difficulty";
                            par.DbType = DbType.Int16;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Terrain";
                            par.DbType = DbType.Int16;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Archived";
                            par.DbType = DbType.Boolean;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Available";
                            par.DbType = DbType.Boolean;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Found";
                            par.DbType = DbType.Boolean;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Type";
                            par.DbType = DbType.Int16;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@PlacedBy";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Owner";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@DateHidden";
                            par.DbType = DbType.DateTime;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Hint";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Description";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Url";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@NumTravelbugs";
                            par.DbType = DbType.Int16;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Rating";
                            par.DbType = DbType.Int16;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Vote";
                            par.DbType = DbType.Int16;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@VotePending";
                            par.DbType = DbType.Boolean;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Notes";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Solver";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Favorit";
                            par.DbType = DbType.Boolean;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@AttributesPositive";
                            par.DbType = DbType.Int64;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@AttributesNegative";
                            par.DbType = DbType.Int64;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@TourName";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@GPXFilename_Id";
                            par.DbType = DbType.Int64;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@HasUserData";
                            par.DbType = DbType.Boolean;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@ListingChanged";
                            par.DbType = DbType.Boolean;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@ImagesUpdated";
                            par.DbType = DbType.Boolean;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@DescriptionImagesUpdated";
                            par.DbType = DbType.Boolean;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@CorrectedCoordinates";
                            par.DbType = DbType.Boolean;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@AttributesPositiveHigh";
                            par.DbType = DbType.Int64;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@AttributesNegativeHigh";
                            par.DbType = DbType.Int64;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@State";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@Country";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);

                            long startCacheId = DateTime.Now.ToFileTime() + 2;
                            long cacheId = startCacheId;
                            using (Utils.ProgressBlock prog = new Utils.ProgressBlock("ExportingGeocaches", gcList.Count, 0))
                            {
                                foreach (Core.Data.Geocache gc in gcList)
                                {
                                    cmd.Parameters["@Id"].Value = cacheId;
                                    cmd.Parameters["@GcCode"].Value = gc.Code;
                                    cmd.Parameters["@GcId"].Value = Utils.Conversion.GetCacheIDFromCacheCode(gc.Code);
                                    if (gc.ContainsCustomLatLon)
                                    {
                                        cmd.Parameters["@Latitude"].Value = (float)gc.CustomLat;
                                        cmd.Parameters["@Longitude"].Value = (float)gc.CustomLon;
                                    }
                                    else
                                    {
                                        cmd.Parameters["@Latitude"].Value = (float)gc.Lat;
                                        cmd.Parameters["@Longitude"].Value = (float)gc.Lon;
                                    }
                                    cmd.Parameters["@Name"].Value = gc.Name ?? "";
                                    switch (gc.Container.ID)
                                    {
                                        case 2:
                                            cmd.Parameters["@Size"].Value = 1;
                                            break;
                                        case 8:
                                            cmd.Parameters["@Size"].Value = 2;
                                            break;
                                        case 4:
                                            cmd.Parameters["@Size"].Value = 3;
                                            break;
                                        case 5:
                                            cmd.Parameters["@Size"].Value = 4;
                                            break;
                                        default:
                                            cmd.Parameters["@Size"].Value = 0;
                                            break;
                                    }
                                    cmd.Parameters["@Difficulty"].Value = (Int16)(gc.Difficulty * 2.0);
                                    cmd.Parameters["@Terrain"].Value = (Int16)(gc.Terrain * 2.0);
                                    cmd.Parameters["@Archived"].Value = gc.Archived;
                                    cmd.Parameters["@Available"].Value = gc.Available;
                                    cmd.Parameters["@Found"].Value = gc.Found;
                                    switch (gc.GeocacheType.ID)
                                    {
                                        case 2:
                                            cmd.Parameters["@Type"].Value = 0;
                                            break;
                                        case 3:
                                            cmd.Parameters["@Type"].Value = 1;
                                            break;
                                        case 4:
                                            cmd.Parameters["@Type"].Value = 8;
                                            break;
                                        case 5:
                                            cmd.Parameters["@Type"].Value = 9;
                                            break;
                                        case 6:
                                            cmd.Parameters["@Type"].Value = 5;
                                            break;
                                        case 8:
                                            cmd.Parameters["@Type"].Value = 2;
                                            break;
                                        case 11:
                                            cmd.Parameters["@Type"].Value = 3;
                                            break;
                                        case 13:
                                            cmd.Parameters["@Type"].Value = 7;
                                            break;
                                        case 137:
                                            cmd.Parameters["@Type"].Value = 4;
                                            break;
                                        case 453:
                                            cmd.Parameters["@Type"].Value = 6;
                                            break;
                                        case 1858:
                                            cmd.Parameters["@Type"].Value = 10;
                                            break;
                                        default:
                                            cmd.Parameters["@Type"].Value = 13;
                                            break;
                                    }
                                    cmd.Parameters["@PlacedBy"].Value = gc.PlacedBy ?? "";
                                    cmd.Parameters["@Owner"].Value = gc.Owner ?? "";
                                    cmd.Parameters["@DateHidden"].Value = gc.PublishedTime;
                                    cmd.Parameters["@Hint"].Value = gc.EncodedHints ?? "";
                                    StringBuilder sb = new StringBuilder();
                                    if (!string.IsNullOrEmpty(gc.ShortDescription))
                                    {
                                        if (gc.ShortDescriptionInHtml)
                                        {
                                            sb.Append(gc.ShortDescription);
                                        }
                                        else
                                        {
                                            sb.Append(HttpUtility.HtmlEncode(gc.ShortDescription).Replace("\r", "").Replace("\n", "<br />"));
                                        }
                                        sb.Append("<br />");
                                    }
                                    if (!string.IsNullOrEmpty(gc.LongDescription))
                                    {
                                        if (gc.LongDescriptionInHtml)
                                        {
                                            sb.Append(gc.LongDescription);
                                        }
                                        else
                                        {
                                            sb.Append(HttpUtility.HtmlEncode(gc.LongDescription).Replace("\r", "").Replace("\n", "<br />"));
                                        }
                                    }
                                    cmd.Parameters["@Description"].Value = sb.ToString();
                                    cmd.Parameters["@Url"].Value = gc.Url ?? "";
                                    cmd.Parameters["@NumTravelbugs"].Value = 0;
                                    cmd.Parameters["@Rating"].Value = 0;
                                    cmd.Parameters["@Vote"].Value = 0;
                                    cmd.Parameters["@VotePending"].Value = false;
                                    sb.Length = 0;
                                    if (gc.ContainsNote)
                                    {
                                        if (!string.IsNullOrEmpty(gc.PersonalNote))
                                        {
                                            sb.Append(gc.PersonalNote);
                                            sb.Append(" - ");
                                        }
                                        if (!string.IsNullOrEmpty(gc.Notes))
                                        {
                                            sb.Append(Utils.Conversion.StripHtmlTags(gc.Notes));
                                        }
                                    }
                                    cmd.Parameters["@Notes"].Value = sb.Length;
                                    cmd.Parameters["@Solver"].Value = "";
                                    cmd.Parameters["@Favorit"].Value = false;

                                    DLong tmpAttributesNegative = new DLong(0, 0);
                                    DLong tmpAttributesPositive = new DLong(0, 0);
                                    List<int> attrs = gc.AttributeIds;
                                    foreach (int ix in attrs)
                                    {
                                        if (ix > 0)
                                        {
                                            tmpAttributesPositive.BitOr(Attributes.GetAttributeDlong(Attributes.getAttributeEnumByGcComId(ix).Attribute));
                                        }
                                        else
                                        {
                                            tmpAttributesNegative.BitOr(Attributes.GetAttributeDlong(Attributes.getAttributeEnumByGcComId(-ix).Attribute));
                                        }
                                    }
                                    long AttributePositiveLow = (long)tmpAttributesPositive.getLow();
                                    long AttributePositiveHigh = (long)tmpAttributesPositive.getHigh();
                                    long AttributesNegativeLow = (long)tmpAttributesNegative.getLow();
                                    long AttributesNegativeHigh = (long)tmpAttributesNegative.getHigh();
                                    cmd.Parameters["@AttributesPositive"].Value = AttributePositiveLow;
                                    cmd.Parameters["@AttributesNegative"].Value = AttributesNegativeLow;
                                    cmd.Parameters["@AttributesPositiveHigh"].Value = AttributePositiveHigh;
                                    cmd.Parameters["@AttributesNegativeHigh"].Value = AttributesNegativeHigh;
                                    cmd.Parameters["@TourName"].Value = "";
                                    cmd.Parameters["@AttributesNegative"].Value = 1;
                                    cmd.Parameters["@HasUserData"].Value = false;
                                    cmd.Parameters["@ListingChanged"].Value = false;
                                    cmd.Parameters["@ImagesUpdated"].Value = false;
                                    cmd.Parameters["@DescriptionImagesUpdated"].Value = false;
                                    cmd.Parameters["@CorrectedCoordinates"].Value = false;
                                    cmd.Parameters["@State"].Value = gc.State ?? "";
                                    cmd.Parameters["@Country"].Value = gc.Country ?? "";

                                    cmd.ExecuteNonQuery();
                                    cacheId++;

                                    index++;
                                    if (DateTime.Now >= nextUpdate)
                                    {
                                        if (!prog.Update("SavingGeocaches", gcList.Count, index))
                                        {
                                            _canceled = true;
                                            break;
                                        }
                                        nextUpdate = DateTime.Now.AddSeconds(1);
                                    }
                                }
                            }
                            if (!_canceled)
                            {
                                progress.Update("CreatingFile", 3, 1);



                                //----------------------------
                                // WAYPOINTS
                                //----------------------------
                                cmd.Parameters.Clear();
                                cmd.CommandText = "insert into Waypoint (GcCode, CacheId, Latitude, Longitude, Description, Clue, Type, SyncExclude, UserWaypoint, Title) values (@GcCode, @CacheId, @Latitude, @Longitude, @Description, @Clue, @Type, @SyncExclude, @UserWaypoint, @Title)";
                                par = cmd.CreateParameter();
                                par.ParameterName = "@GcCode";
                                par.DbType = DbType.String;
                                cmd.Parameters.Add(par);
                                par = cmd.CreateParameter();
                                par.ParameterName = "@CacheId";
                                par.DbType = DbType.Int64;
                                cmd.Parameters.Add(par);
                                par = cmd.CreateParameter();
                                par.ParameterName = "@Latitude";
                                par.DbType = DbType.Single;
                                cmd.Parameters.Add(par);
                                par = cmd.CreateParameter();
                                par.ParameterName = "@Longitude";
                                par.DbType = DbType.Single;
                                cmd.Parameters.Add(par);
                                par = cmd.CreateParameter();
                                par.ParameterName = "@Description";
                                par.DbType = DbType.String;
                                cmd.Parameters.Add(par);
                                par = cmd.CreateParameter();
                                par.ParameterName = "@Clue";
                                par.DbType = DbType.String;
                                cmd.Parameters.Add(par);
                                par = cmd.CreateParameter();
                                par.ParameterName = "@Type";
                                par.DbType = DbType.Int16;
                                cmd.Parameters.Add(par);
                                par = cmd.CreateParameter();
                                par.ParameterName = "@SyncExclude";
                                par.DbType = DbType.Boolean;
                                cmd.Parameters.Add(par);
                                par = cmd.CreateParameter();
                                par.ParameterName = "@UserWaypoint";
                                par.DbType = DbType.Boolean;
                                cmd.Parameters.Add(par);
                                par = cmd.CreateParameter();
                                par.ParameterName = "@Title";
                                par.DbType = DbType.String;
                                cmd.Parameters.Add(par);

                                cacheId = startCacheId;
                                index = 0;
                                using (Utils.ProgressBlock prog = new Utils.ProgressBlock("SavingWaypoints", gcList.Count, 0))
                                {
                                    foreach (Core.Data.Geocache gc in gcList)
                                    {
                                        List<Core.Data.Waypoint> wps = Utils.DataAccess.GetWaypointsFromGeocache(gc.Database, gc.Code);
                                        if (wps != null && wps.Count > 0)
                                        {
                                            foreach (Core.Data.Waypoint wp in wps)
                                            {
                                                if (wp.Lat != null && wp.Lon != null)
                                                {
                                                    cmd.Parameters["@GcCode"].Value = wp.Code;
                                                    cmd.Parameters["@CacheId"].Value = cacheId;
                                                    cmd.Parameters["@Latitude"].Value = (float)(double)wp.Lat;
                                                    cmd.Parameters["@Longitude"].Value = (float)(double)wp.Lon;
                                                    cmd.Parameters["@Description"].Value = wp.Comment ?? "";
                                                    cmd.Parameters["@Clue"].Value = "";
                                                    switch (wp.WPType.ID)
                                                    {
                                                        case 217:
                                                            cmd.Parameters["@Type"].Value = 17;
                                                            break;
                                                        case 220:
                                                            cmd.Parameters["@Type"].Value = 18;
                                                            break;
                                                        case 218:
                                                            cmd.Parameters["@Type"].Value = 15;
                                                            break;
                                                        case 452:
                                                            cmd.Parameters["@Type"].Value = 11;
                                                            break;
                                                        case 219:
                                                            cmd.Parameters["@Type"].Value = 14;
                                                            break;
                                                        case 221:
                                                            cmd.Parameters["@Type"].Value = 16;
                                                            break;
                                                        default:
                                                            cmd.Parameters["@Type"].Value = 13;
                                                            break;
                                                    }
                                                    cmd.Parameters["@SyncExclude"].Value = false;
                                                    cmd.Parameters["@UserWaypoint"].Value = string.IsNullOrEmpty(wp.Url) || !wp.Url.ToLower().StartsWith("http:");
                                                    cmd.Parameters["@Title"].Value = wp.Description ?? "";

                                                    cmd.ExecuteNonQuery();
                                                }
                                            }
                                        }
                                        cacheId++;

                                        index++;
                                        if (DateTime.Now>=nextUpdate)
                                        {
                                            if (!prog.Update("SavingWaypoints", gcList.Count, index))
                                            {
                                                _canceled = true;
                                                break;
                                            }
                                            nextUpdate = DateTime.Now.AddSeconds(1);
                                        }
                                    }
                                }

                                if (!_canceled)
                                {
                                    progress.Update("CreatingFile", 3, index);


                                    //----------------------------
                                    // LOGS
                                    //----------------------------
                                    if (Core.Settings.Default.CacheboxMaxLogCount > 0)
                                    {
                                        cmd.Parameters.Clear();
                                        cmd.CommandText = "insert into Logs (Id, CacheId, Timestamp, Finder, Type, Comment) values (@Id, @CacheId, @Timestamp, @Finder, @Type, @Comment)";
                                        par = cmd.CreateParameter();
                                        par.ParameterName = "@Id";
                                        par.DbType = DbType.Int64;
                                        cmd.Parameters.Add(par);
                                        par = cmd.CreateParameter();
                                        par.ParameterName = "@CacheId";
                                        par.DbType = DbType.Int64;
                                        cmd.Parameters.Add(par);
                                        par = cmd.CreateParameter();
                                        par.ParameterName = "@Timestamp";
                                        par.DbType = DbType.DateTime;
                                        cmd.Parameters.Add(par);
                                        par = cmd.CreateParameter();
                                        par.ParameterName = "@Finder";
                                        par.DbType = DbType.String;
                                        cmd.Parameters.Add(par);
                                        par = cmd.CreateParameter();
                                        par.ParameterName = "@Type";
                                        par.DbType = DbType.Int16;
                                        cmd.Parameters.Add(par);
                                        par = cmd.CreateParameter();
                                        par.ParameterName = "@Comment";
                                        par.DbType = DbType.String;
                                        cmd.Parameters.Add(par);

                                        long logId = 1;
                                        index = 0;
                                        cacheId = startCacheId;
                                        using (Utils.ProgressBlock prog = new Utils.ProgressBlock("SavingLogs", gcList.Count, 0))
                                        {
                                            foreach (Core.Data.Geocache gc in gcList)
                                            {
                                                List<Core.Data.Log> logs = Utils.DataAccess.GetLogs(gc.Database, gc.Code).Take(Core.Settings.Default.CacheboxMaxLogCount).ToList();
                                                if (logs != null && logs.Count > 0)
                                                {
                                                    foreach (Core.Data.Log lg in logs)
                                                    {
                                                        long id = logId;
                                                        if (lg.ID.StartsWith("GL"))
                                                        {
                                                            id = Utils.Conversion.GetCacheIDFromCacheCode(lg.ID);
                                                        }
                                                        else
                                                        {
                                                            long.TryParse(lg.ID, out id);
                                                        }
                                                        cmd.Parameters["@Id"].Value = id;
                                                        cmd.Parameters["@CacheId"].Value = cacheId;
                                                        cmd.Parameters["@Timestamp"].Value = lg.Date;
                                                        cmd.Parameters["@Finder"].Value = lg.Finder ?? "";
                                                        switch (lg.LogType.ID)
                                                        {
                                                            case 2:
                                                                cmd.Parameters["@Type"].Value = 0;
                                                                break;
                                                            case 3:
                                                                cmd.Parameters["@Type"].Value = 1;
                                                                break;
                                                            case 4:
                                                                cmd.Parameters["@Type"].Value = 2;
                                                                break;
                                                            case 24:
                                                                cmd.Parameters["@Type"].Value = 3;
                                                                break;
                                                            case 23:
                                                                cmd.Parameters["@Type"].Value = 4;
                                                                break;
                                                            case 45:
                                                                cmd.Parameters["@Type"].Value = 5;
                                                                break;
                                                            case 22:
                                                                cmd.Parameters["@Type"].Value = 6;
                                                                break;
                                                            case 46:
                                                            case 47:
                                                                cmd.Parameters["@Type"].Value = 7;
                                                                break;
                                                            case 9:
                                                                cmd.Parameters["@Type"].Value = 8;
                                                                break;
                                                            case 10:
                                                                cmd.Parameters["@Type"].Value = 9;
                                                                break;
                                                            case 11:
                                                                cmd.Parameters["@Type"].Value = 10;
                                                                break;
                                                            case 5:
                                                            case 6:
                                                            case 12:
                                                                cmd.Parameters["@Type"].Value = 11;
                                                                break;
                                                            case 18:
                                                                cmd.Parameters["@Type"].Value = 12;
                                                                break;
                                                            case 7:
                                                                cmd.Parameters["@Type"].Value = 13;
                                                                break;
                                                            default:
                                                                cmd.Parameters["@Type"].Value = 2;
                                                                break;
                                                        }
                                                        cmd.Parameters["@Comment"].Value = lg.Text ?? "";

                                                        cmd.ExecuteNonQuery();
                                                    }
                                                }

                                                cacheId++;

                                                index++;
                                                if (DateTime.Now>=nextUpdate)
                                                {
                                                    if (!prog.Update("SavingWaypoints", max, index))
                                                    {
                                                        _canceled = true;
                                                        break;
                                                    }
                                                    nextUpdate = DateTime.Now.AddSeconds(1);
                                                }
                                            }
                                            progress.Update("SavingLogs", max, index);
                                        }
                                    }
                                }
                            }
                            _dbcon.Dispose();
                        }
                    }

                }
                catch (Exception e)
                {
                    Core.ApplicationData.Instance.Logger.AddLog(this, e);
                    try
                    {
                        if (_dbcon!=null)
                        {
                            _dbcon.Dispose();
                            _dbcon = null;
                        }
                    }
                    catch
                    {

                    }
                }
            });
        }
Esempio n. 38
0
 private Utils.DBCon initDatabase()
 {
     Utils.DBCon result = null;
     try
     {
         string fn = System.IO.Path.Combine(_core.PluginDataPath, "coordsav.db3" );
         if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(fn)))
         {
             System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fn));
         }
         result = new Utils.DBConComSqlite(fn);
         object o = result.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='coord'");
         if (o == null || o.GetType() == typeof(DBNull))
         {
             result.ExecuteNonQuery("create table 'coord' (code text, lat real, lon real)");
             result.ExecuteNonQuery("create unique index idx_coord on coord (code)");
         }
     }
     catch
     {
     }
     return result;
 }
Esempio n. 39
0
 public void RemoveFilter(FilterField field, string filter)
 {
     try
     {
         Hashtable ht = _filterFields[field.ToString()] as Hashtable;
         if (ht != null)
         {
             if (ht[filter]!=null)
             {
                 ht.Remove(filter);
                 using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_databaseFile))
                 {
                     dbcon.ExecuteNonQuery(string.Format("delete from filterfields where field = '{0}' and filter = '{1}'", field.ToString(), filter.Replace("'", "''")));
                 }
             }
         }
     }
     catch
     {
     }
 }
Esempio n. 40
0
        private void newPreset()
        {
            //check if saved preset
            string presetname = null;
            using (PresetNameForm dlg = new PresetNameForm(_presets))
            {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    presetname = dlg.PresetName;
                }
            }
            if (!string.IsNullOrEmpty(presetname))
            {
                try
                {
                    using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_presetDatabaseFile))
                    {
                        initDatabase(dbcon);
                        if (!_presets.Contains(presetname))
                        {
                            //we need to add the action
                            AddAction(string.Concat("Presets|",presetname));
                            Framework.Interfaces.IPluginUIMainWindow main = (from Framework.Interfaces.IPluginUIMainWindow a in Core.GetPlugin(Framework.PluginType.UIMainWindow) select a).FirstOrDefault();
                            main.AddAction(this, "Presets", presetname);

                            _presets.Add(presetname);

                        }
                        dbcon.ExecuteNonQuery(string.Format("delete from forms where preset='{0}'", presetname));
                        dbcon.ExecuteNonQuery(string.Format("delete from preset where name='{0}'", presetname));

                        dbcon.ExecuteNonQuery(string.Format("insert into preset (name) values ('{0}')", presetname));
                        List<Framework.Interfaces.IPlugin> pins = Core.GetPlugins();
                        foreach (Framework.Interfaces.IPlugin pin in pins)
                        {
                            Framework.Interfaces.IPluginUIChildWindow p = pin as Framework.Interfaces.IPluginUIChildWindow;
                            if (p != null)
                            {
                                if (p.ChildForm != null && p.ChildForm.Visible)
                                {
                                    dbcon.ExecuteNonQuery(string.Format("insert into forms (preset, plugintype, x, y, w, h, visible) values ('{0}', '{1}', {2}, {3}, {4}, {5}, 1)", presetname, p.GetType().ToString(), p.ChildForm.Left, p.ChildForm.Top, p.ChildForm.Width, p.ChildForm.Height));
                                }
                                else
                                {
                                    dbcon.ExecuteNonQuery(string.Format("insert into forms (preset, plugintype, x, y, w, h, visible) values ('{0}', '{1}', 0, 0, 100, 100, 0)", presetname, p.GetType().ToString()));
                                }
                            }
                            else if (pin.GetType().ToString() == "GlobalcachingApplication.Plugins.Maps.MapsPlugin")
                            {
                                //special onw
                                try
                                {
                                    MethodInfo mi = pin.GetType().GetMethod("GetWindowStateText");
                                    if (mi != null)
                                    {
                                        string s = mi.Invoke(pin, null) as string;
                                        if (s != null)
                                        {
                                            dbcon.ExecuteNonQuery(string.Format("insert into forms (preset, plugintype, x, y, w, h, visible, customtag) values ('{0}', '{1}', 0, 0, 100, 100, 0, '{2}')", presetname, pin.GetType().ToString(), s.Replace("'", "''")));
                                        }
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }
                catch
                {
                }
            }
        }
Esempio n. 41
0
 private void CreateDatabase(string filename)
 {
     _dbcon = new Utils.DBConComSqlite(filename);
     cgData cgd = new cgData(_dbcon);
     cgd.Create();
 }
Esempio n. 42
0
        public override bool ApplySettings(List<System.Windows.Forms.UserControl> configPanels)
        {
            try
            {
                SettingsPanel panel = (from p in configPanels where p.GetType() == typeof(SettingsPanel) select p).FirstOrDefault() as SettingsPanel;
                List<string> presets = panel.PresetNames;
                if (presets.Count != _presets.Count)
                {
                    using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_presetDatabaseFile))
                    {
                        initDatabase(dbcon);
                        List<string> tobeRemoved = new List<string>();
                        foreach (string p in _presets)
                        {
                            if (!presets.Contains(p))
                            {
                                dbcon.ExecuteNonQuery(string.Format("delete from forms where preset='{0}'", p.Replace("'","''")));
                                dbcon.ExecuteNonQuery(string.Format("delete from preset where name='{0}'", p.Replace("'", "''")));

                                RemoveAction(string.Concat("Presets|", p));
                                tobeRemoved.Add(p);
                            }
                        }
                        foreach (string p in tobeRemoved)
                        {
                            _presets.Remove(p);
                        }
                    }
                }
            }
            catch
            {
            }
            return true;
        }
Esempio n. 43
0
        protected override void ExportMethod()
        {
            int max = _gcList.Count;
            int index = 0;

            Hashtable htAttributes = new Hashtable();
            htAttributes[1] = "dogs";
            htAttributes[2] = "fee";
            htAttributes[3] = "rappelling";
            htAttributes[4] = "boat";
            htAttributes[5] = "scuba";
            htAttributes[6] = "kids";
            htAttributes[7] = "onehour";
            htAttributes[8] = "scenic";
            htAttributes[9] = "hiking";
            htAttributes[10] = "climbing";
            htAttributes[11] = "wading";
            htAttributes[12] = "swimming";
            htAttributes[13] = "available";
            htAttributes[14] = "night";
            htAttributes[15] = "winter";
            htAttributes[16] = "cactus";
            htAttributes[17] = "poisonoak";
            htAttributes[18] = "dangerousanimals";
            htAttributes[19] = "ticks";
            htAttributes[20] = "mine";
            htAttributes[21] = "cliff";
            htAttributes[22] = "hunting";
            htAttributes[23] = "danger";
            htAttributes[24] = "wheelchair";
            htAttributes[25] = "parking";
            htAttributes[26] = "public";
            htAttributes[27] = "water";
            htAttributes[28] = "restrooms";
            htAttributes[29] = "phone";
            htAttributes[30] = "picnic";
            htAttributes[31] = "camping";
            htAttributes[32] = "bicycles";
            htAttributes[33] = "motorcycles";
            htAttributes[34] = "quads";
            htAttributes[35] = "jeeps";
            htAttributes[36] = "snowmobiles";
            htAttributes[37] = "horses";
            htAttributes[38] = "campfires";
            htAttributes[39] = "thorn";
            htAttributes[40] = "stealth";
            htAttributes[41] = "stroller";
            htAttributes[42] = "firstaid";
            htAttributes[43] = "cow";
            htAttributes[44] = "flashlight";
            htAttributes[45] = "landf";
            htAttributes[46] = "rv";
            htAttributes[47] = "field_puzzle";
            htAttributes[48] = "UV";
            htAttributes[49] = "snowshoes";
            htAttributes[50] = "skiis";
            htAttributes[51] = "s-tool";
            htAttributes[52] = "nightcache";
            htAttributes[53] = "parkngrab";
            htAttributes[54] = "AbandonedBuilding";
            htAttributes[55] = "hike_short";
            htAttributes[56] = "hike_med";
            htAttributes[57] = "hike_long";
            htAttributes[58] = "fuel";
            htAttributes[59] = "food";
            htAttributes[60] = "wirelessbeacon";
            htAttributes[61] = "partnership";
            htAttributes[62] = "seasonal";
            htAttributes[63] = "touristOK";
            htAttributes[64] = "treeclimbing";
            htAttributes[65] = "frontyard";
            htAttributes[66] = "teamwork";
            htAttributes[67] = "geotour";


            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_EXPORTINGCB, STR_CREATINGFILE, max, 0, true))
            {
                string cbFile = System.IO.Path.Combine(_folder, "cgeo.sqlite");
                string cbDataFile = System.IO.Path.Combine(_folder, "data");

                if (System.IO.File.Exists(cbFile))
                {
                    System.IO.File.Delete(cbFile);
                }
                if (System.IO.File.Exists(cbDataFile))
                {
                    System.IO.File.Delete(cbDataFile);
                }
                CreateDatabase(cbFile);

                if (_dbcon != null)
                {
                    _dbcon.ExecuteNonQuery("CREATE TABLE android_metadata (locale TEXT)");
                    _dbcon.ExecuteNonQuery("INSERT INTO android_metadata VALUES('en_US')");
                    //_dbcon.ExecuteNonQuery("CREATE TABLE sqlite_sequence (name, seq)");

                    DbCommand cmd = _dbcon.Command;

                    int detailed = 1;
                    int reason = 1;
                    int reliable_latlon = 1;

                    DateTime dt = DateTime.Now.AddSeconds(2);
                    foreach (Framework.Data.Geocache gc in _gcList)
                    {
                        //----------------------------
                        // CACHE
                        //----------------------------
                        cmd.Parameters.Clear();
                        cmd.CommandText = "insert into cg_caches (updated, detailed, detailedupdate, visiteddate, geocode, reason, cacheid, guid, type, name, owner, owner_real, hidden, hint, size, difficulty, terrain, latlon, location, latitude, longitude, reliable_latlon, personal_note, shortdesc, description, favourite_cnt, disabled, archived, members, found, coordsChanged, finalDefined) values (@updated, 1, @detailedupdate, @visiteddate, @geocode, @reason, @cacheid, @guid, @type, @name, @owner, @owner_real, @hidden, @hint, @size, @difficulty, @terrain, @latlon, @location, @latitude, @longitude, @reliable_latlon, @personal_note, @shortdesc, @description, @favourite_cnt, @disabled, @archived, @members, @found, @coordsChanged, @finalDefined)";
                        DbParameter par;
                        par = cmd.CreateParameter();
                        par.ParameterName = "@updated";
                        par.DbType = DbType.Int64;
                        par.Value = GetcgeoTime(DateTime.Now);
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@detailed";
                        par.DbType = DbType.Int32;
                        par.Value = detailed;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@detailedupdate";
                        par.DbType = DbType.UInt64;
                        par.Value = GetcgeoTime(DateTime.Now);
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@visiteddate";
                        par.DbType = DbType.UInt64;
                        if (gc.FoundDate == null)
                        {
                            par.Value = 0;
                        }
                        else
                        {
                            par.Value = GetcgeoTime((DateTime)gc.FoundDate);
                        }
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@geocode";
                        par.DbType = DbType.String;
                        par.Value = gc.Code;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@reason";
                        par.DbType = DbType.Int32;
                        par.Value = reason;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@cacheid";
                        par.DbType = DbType.String;
                        if (gc.ID.StartsWith("GC"))
                        {
                            par.Value = Utils.Conversion.GetCacheIDFromCacheCode(gc.Code).ToString();
                        }
                        else
                        {
                            par.Value = gc.ID;
                        }
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@guid";
                        par.DbType = DbType.String;
                        par.Value = DBNull.Value;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@type";
                        par.DbType = DbType.String;
                        par.Value = gc.GeocacheType.GPXTag.Split(new char[] { ' ', '-' })[0].ToLower();
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@name";
                        par.DbType = DbType.String;
                        par.Value = gc.Name??"";
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@owner";
                        par.DbType = DbType.String;
                        par.Value = gc.PlacedBy ?? "";
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@owner_real";
                        par.DbType = DbType.String;
                        par.Value = gc.Owner ?? "";
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@hidden";
                        par.DbType = DbType.UInt64;
                        par.Value = GetcgeoTime(gc.PublishedTime);
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@hint";
                        par.DbType = DbType.String;
                        par.Value = gc.EncodedHints ?? "";
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@size";
                        par.DbType = DbType.String;
                        par.Value = gc.Container.Name.ToLower();
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@difficulty";
                        par.DbType = DbType.Single;
                        par.Value = (float)gc.Difficulty;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@terrain";
                        par.DbType = DbType.Single;
                        par.Value = (float)gc.Terrain;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@latlon";
                        par.DbType = DbType.String;
                        par.Value = DBNull.Value;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@location";
                        par.DbType = DbType.String;
                        if (string.IsNullOrEmpty(gc.State))
                        {
                            par.Value = gc.Country ?? "";
                        }
                        else
                        {
                            par.Value = string.Format("{0}, {1}", gc.State, gc.Country ?? "");
                        }
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@latitude";
                        par.DbType = DbType.Double;
                        par.Value = gc.ContainsCustomLatLon ? gc.CustomLat : gc.Lat;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@longitude";
                        par.DbType = DbType.Double;
                        par.Value = gc.ContainsCustomLatLon ? gc.CustomLon : gc.Lon;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@reliable_latlon";
                        par.DbType = DbType.Int32;
                        par.Value = reliable_latlon;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@personal_note";
                        par.DbType = DbType.String;
                        par.Value = gc.PersonaleNote??"";
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@shortdesc";
                        par.DbType = DbType.String;
                        if (gc.ShortDescriptionInHtml)
                        {
                            par.Value = gc.ShortDescription ?? "";
                        }
                        else
                        {
                            par.Value = HttpUtility.HtmlEncode(gc.ShortDescription ?? "");
                        }
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@description";
                        par.DbType = DbType.String;
                        if (gc.LongDescriptionInHtml)
                        {
                            par.Value = gc.LongDescription ?? "";
                        }
                        else
                        {
                            par.Value = HttpUtility.HtmlEncode(gc.LongDescription ?? "");
                        }
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@favourite_cnt";
                        par.DbType = DbType.Int32;
                        par.Value = gc.Favorites;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@disabled";
                        par.DbType = DbType.Int32;
                        par.Value = gc.Available ? 0 : 1;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@archived";
                        par.DbType = DbType.Int32;
                        par.Value = gc.Archived ? 1 : 0;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@members";
                        par.DbType = DbType.Int32;
                        par.Value = gc.MemberOnly ? 1 : 0;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@found";
                        par.DbType = DbType.Int32;
                        par.Value = gc.Found ? 1 : 0;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@coordsChanged";
                        par.DbType = DbType.Int32;
                        par.Value = gc.CustomCoords ? 1 : 0;
                        cmd.Parameters.Add(par);
                        par = cmd.CreateParameter();
                        par.ParameterName = "@finalDefined";
                        par.DbType = DbType.Int32;
                        par.Value = 0;
                        cmd.Parameters.Add(par);

                        int res = cmd.ExecuteNonQuery();
                        cmd.Parameters.Clear();

                        //----------------------------
                        // ATTRIBUTES
                        //----------------------------
                        List<int> attrs = gc.AttributeIds;
                        if (attrs != null && attrs.Count > 0)
                        {
                            cmd.CommandText = "insert into cg_attributes (geocode, updated, attribute) values (@geocode, @updated, @attribute)";
                            par = cmd.CreateParameter();
                            par.ParameterName = "@geocode";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@updated";
                            par.DbType = DbType.Int64;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@attribute";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            foreach (int att in attrs)
                            {
                                string atname = htAttributes[Math.Abs(att)] as string;
                                if (!string.IsNullOrEmpty(atname))
                                {
                                    atname = atname.ToLower();
                                    cmd.Parameters["@geocode"].Value = gc.Code;
                                    cmd.Parameters["@updated"].Value = GetcgeoTime(DateTime.Now);
                                    cmd.Parameters["@attribute"].Value = att > 0 ? string.Format("{0}_yes", atname) : string.Format("{0}_no", atname);
                                    cmd.ExecuteNonQuery();
                                }
                            }
                            cmd.Parameters.Clear();
                        }

                        //----------------------------
                        // WAYPOINTS
                        //----------------------------
                        List<Framework.Data.Waypoint> wpts = Utils.DataAccess.GetWaypointsFromGeocache(Core.Waypoints, gc.Code);
                        if (wpts != null && wpts.Count > 0)
                        {
                            cmd.CommandText = "insert into cg_waypoints (geocode, updated, type, prefix, lookup, name, latlon, latitude, longitude, note) values (@geocode, @updated, @type, @prefix, @lookup, @name, @latlon, @latitude, @longitude, @note)";
                            par = cmd.CreateParameter();
                            par.ParameterName = "@geocode";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@updated";
                            par.DbType = DbType.Int64;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@type";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@prefix";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@lookup";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@name";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@latlon";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@latitude";
                            par.DbType = DbType.Double;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@longitude";
                            par.DbType = DbType.Double;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@note";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            foreach (Framework.Data.Waypoint wp in wpts)
                            {
                                if (wp.Lat != null && wp.Lon != null)
                                {
                                    cmd.Parameters["@geocode"].Value = gc.Code;
                                    cmd.Parameters["@updated"].Value = GetcgeoTime(DateTime.Now);
                                    switch (wp.WPType.ID)
                                    {
                                        case 217:
                                            cmd.Parameters["@type"].Value = "pkg";
                                            break;
                                        case 220:
                                            cmd.Parameters["@type"].Value = "flag";
                                            break;
                                        case 218:
                                            cmd.Parameters["@type"].Value = "puzzle";
                                            break;
                                        case 452:
                                            cmd.Parameters["@type"].Value = "waypoint";
                                            break;
                                        case 219:
                                            cmd.Parameters["@type"].Value = "stage";
                                            break;
                                        case 221:
                                            cmd.Parameters["@type"].Value = "trailhead";
                                            break;
                                        default:
                                            cmd.Parameters["@type"].Value = "waypoint";
                                            break;
                                    }
                                    cmd.Parameters["@prefix"].Value = wp.Code.Substring(0,2);
                                    cmd.Parameters["@lookup"].Value = "---";
                                    cmd.Parameters["@name"].Value = wp.Description ?? "";
                                    cmd.Parameters["@latlon"].Value = Utils.Conversion.GetCoordinatesPresentation((double)wp.Lat,(double)wp.Lon);
                                    cmd.Parameters["@latitude"].Value = (double)wp.Lat;
                                    cmd.Parameters["@longitude"].Value = (double)wp.Lon;
                                    cmd.Parameters["@note"].Value = wp.Comment??"";

                                    cmd.ExecuteNonQuery();
                                }
                            }
                            cmd.Parameters.Clear();
                        }
                        
                        //----------------------------
                        // LOGS
                        //----------------------------
                        List<Framework.Data.Log> lgs = Utils.DataAccess.GetLogs(Core.Logs, gc.Code);
                        if (lgs != null && lgs.Count > 0)
                        {
                            cmd.CommandText = "insert into cg_logs (geocode, updated, type, author, log, date, friend) values (@geocode, @updated, @type, @author, @log, @date, 0)";
                            par = cmd.CreateParameter();
                            par.ParameterName = "@geocode";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@updated";
                            par.DbType = DbType.Int64;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@type";
                            par.DbType = DbType.Int32;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@author";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@log";
                            par.DbType = DbType.String;
                            cmd.Parameters.Add(par);
                            par = cmd.CreateParameter();
                            par.ParameterName = "@date";
                            par.DbType = DbType.Int64;
                            cmd.Parameters.Add(par);

                            foreach (Framework.Data.Log lg in lgs)
                            {
                                cmd.Parameters["@geocode"].Value = gc.Code;
                                cmd.Parameters["@updated"].Value = GetcgeoTime(DateTime.Now);
                                cmd.Parameters["@type"].Value = lg.LogType.ID;
                                cmd.Parameters["@author"].Value = lg.Finder??"";
                                cmd.Parameters["@log"].Value = HttpUtility.HtmlEncode(lg.Text ?? "").Replace("\r", "").Replace("\n", "<br />");
                                cmd.Parameters["@date"].Value = GetcgeoTime(lg.Date);

                                cmd.ExecuteNonQuery();
                            }
                            cmd.Parameters.Clear();
                        }

                        index++;
                        if (DateTime.Now > dt)
                        {
                            if (!progress.UpdateProgress(STR_EXPORTINGCB, STR_CREATINGFILE, max, index))
                            {
                                break;
                            }
                            dt = DateTime.Now.AddSeconds(2);
                        }
                    }
                    //_dbcon.ExecuteNonQuery(string.Format("insert into sqlite_sequence (name, seq) values ('cg_caches', {0})", index));
                    _dbcon.Dispose();
                    _dbcon = null;

                    //not working. you have to go through recover database on c:geo
                    //System.IO.File.Copy(cbFile, cbDataFile);
                }
            }
        }