Beispiel #1
0
 private void ImageGalleryForm_Shown(object sender, EventArgs e)
 {
     //get from database
     Utils.DBCon dbcon = initDatabase();
     if (dbcon != null)
     {
         DbDataReader dr = dbcon.ExecuteReader("select * from gallery");
         while (dr.Read())
         {
             ImageInfo ai = new ImageInfo();
             ai.Description  = dr["Description"] as string;
             ai.ImageGuid    = dr["ImageGuid"] as string;
             ai.ImgFile      = dr["ImgFile"] as string;
             ai.LogCacheCode = dr["LogCacheCode"] as string;
             ai.LogCode      = dr["LogCode"] as string;
             ai.LogUrl       = dr["LogUrl"] as string;
             ai.LogVisitDate = DateTime.Parse(dr["LogVisitDate"] as string);
             ai.MobileUrl    = dr["MobileUrl"] as string;
             ai.Name         = dr["Name"] as string;
             ai.ThumbFile    = dr["ThumbFile"] as string;
             ai.ThumbUrl     = dr["ThumbUrl"] as string;
             ai.Url          = dr["Url"] as string;
             _imageInfoList.Add(ai);
         }
         dbcon.Dispose();
         dbcon = null;
     }
     ShowImageThumbnails();
 }
Beispiel #2
0
        public void Initialize(Framework.Interfaces.ICore core)
        {
            _core = core;
            _availableWaypoints = new Hashtable();

            try
            {
                _dbcon = new Utils.DBConComSqlite(Path.Combine(core.PluginDataPath, "gcvote.db3"));

                object o = _dbcon.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='votes'");
                if (o == null || o.GetType() == typeof(DBNull))
                {
                    _dbcon.ExecuteNonQuery("create table 'votes' (Waypoint text, VoteMedian float, VoteAvg float, VoteCnt integer, VoteUser double)");
                    _dbcon.ExecuteNonQuery("create unique index idx_votess on votes (Waypoint)");
                }

                DbDataReader dr = _dbcon.ExecuteReader("select Waypoint from votes");
                while (dr.Read())
                {
                    _availableWaypoints.Add(dr[0], true);
                }
            }
            catch
            {
                _dbcon = null;
                _availableWaypoints.Clear();
            }
        }
 private void backupThreadMethod()
 {
     try
     {
         using (Utils.DBCon dbcon = initDatabase())
         {
             int index = 0;
             foreach (Framework.Data.Geocache gc in _core.Geocaches)
             {
                 if (Math.Abs(gc.Lat) > 0.0001 || Math.Abs(gc.Lon) > 0.0001)
                 {
                     if (dbcon.ExecuteNonQuery(string.Format("update coord set lat={0}, lon={1} where code='{2}'", gc.Lat.ToString().Replace(',', '.'), gc.Lon.ToString().Replace(',', '.'), gc.Code.Replace("'", "''"))) == 0)
                     {
                         dbcon.ExecuteNonQuery(string.Format("insert into coord (lat, lon, code) values ({0}, {1}, '{2}')", gc.Lat.ToString().Replace(',', '.'), gc.Lon.ToString().Replace(',', '.'), gc.Code.Replace("'", "''")));
                     }
                     index++;
                     if (index % 1000 == 0)
                     {
                         _context.Send(new SendOrPostCallback(delegate(object state)
                         {
                             toolStripProgressBar1.Value = index;
                         }), null);
                     }
                 }
             }
         }
     }
     catch
     {
     }
     _actionReady.Set();
 }
 private void button1_Click(object sender, EventArgs e)
 {
     this.Cursor = Cursors.WaitCursor;
     try
     {
         using (Utils.DBCon dbcon = initDatabase())
         {
             Framework.Data.Location l = Utils.Conversion.StringToLocation(textBox1.Text);
             if (l != null && listView1.SelectedItems.Count > 0)
             {
                 Framework.Data.Geocache gc = listView1.SelectedItems[0].Tag as Framework.Data.Geocache;
                 if (dbcon.ExecuteNonQuery(string.Format("update coord set lat={0}, lon={1} where code='{2}'", l.SLat, l.SLon, gc.Code.Replace("'", "''"))) == 0)
                 {
                     dbcon.ExecuteNonQuery(string.Format("insert into coord (lat, lon, code) values ({0}, {1}, '{2}')", l.SLat, l.SLon, gc.Code.Replace("'", "''")));
                 }
                 gc.BeginUpdate();
                 gc.Lat = l.Lat;
                 gc.Lon = l.Lon;
                 gc.EndUpdate();
                 listView1.Items.Remove(listView1.SelectedItems[0]);
             }
         }
     }
     catch
     {
     }
     this.Cursor = Cursors.Default;
 }
Beispiel #5
0
        public bool InitDatabase(Utils.DBCon dbcon)
        {
            /*
             * database:
             * areainfo -> id, parentid, level, name, minlat, minlon, maxlat, maxlon
             * poly -> id, areainfoid, position, lat, lon
             */
            bool result = false;

            try
            {
                object o = dbcon.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='areainfo'");
                if (o == null || o.GetType() == typeof(DBNull))
                {
                    dbcon.ExecuteNonQuery("create table 'areainfo' (id integer, parentid integer, level integer, name text, minlat real, minlon real, maxlat real, maxlon real)");
                }

                o = dbcon.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='poly'");
                if (o == null || o.GetType() == typeof(DBNull))
                {
                    dbcon.ExecuteNonQuery("create table 'poly' (id integer, areainfoid integer, position integer, lat real, lon real)");
                    dbcon.ExecuteNonQuery("create index idx_poly on poly (areainfoid)");
                }

                result = true;
            }
            catch
            {
            }
            return(result);
        }
Beispiel #6
0
        public void Initialize(Framework.Interfaces.ICore core)
        {
            _core = core;
            _availableWaypoints = new Hashtable();

            try
            {
                _dbcon = new Utils.DBConComSqlite(Path.Combine(core.PluginDataPath,"gcvote.db3"));

                object o = _dbcon.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='votes'");
                if (o == null || o.GetType() == typeof(DBNull))
                {
                    _dbcon.ExecuteNonQuery("create table 'votes' (Waypoint text, VoteMedian float, VoteAvg float, VoteCnt integer, VoteUser double)");
                    _dbcon.ExecuteNonQuery("create unique index idx_votess on votes (Waypoint)");
                }

                DbDataReader dr = _dbcon.ExecuteReader("select Waypoint from votes");
                while (dr.Read())
                {
                    _availableWaypoints.Add(dr[0], true);
                }
            }
            catch
            {
                _dbcon = null;
                _availableWaypoints.Clear();
            }
        }
Beispiel #7
0
 private void deleteScriptData(ScriptInfo si)
 {
     try
     {
         using (Utils.DBCon dbcon = initDatabase())
         {
             dbcon.ExecuteNonQuery(string.Format("delete from scripts where id='{0}'", si.ID));
             dbcon.ExecuteNonQuery(string.Format("delete from settings where scriptid='{0}'", si.ID));
         }
     }
     catch
     {
     }
 }
Beispiel #8
0
 private void saveScriptData(ScriptInfo si)
 {
     try
     {
         using (Utils.DBCon dbcon = initDatabase())
         {
             if (dbcon.ExecuteNonQuery(string.Format("update scripts set name='{1}', content='{2}' where id='{0}'", si.ID, si.Name.Replace("'", "''"), si.Content.Replace("'", "''"))) == 0)
             {
                 dbcon.ExecuteNonQuery(string.Format("insert into scripts (id, name, scripttype, content) values ('{0}', '{1}', '{2}', '{3}')", si.ID, si.Name.Replace("'", "''"), si.ScriptType.ToString(), si.Content.Replace("'", "''")));
             }
         }
     }
     catch
     {
     }
 }
Beispiel #9
0
        public void Initialize(Framework.Interfaces.ICore core)
        {
            if (_bookmarks == null)
            {
                _bookmarks = new Hashtable();

                try
                {
                    _dbcon = new Utils.DBConComSqlite(Path.Combine(core.PluginDataPath, "gccollections.db3"));

                    object o = _dbcon.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='bookmark'");
                    if (o == null || o.GetType() == typeof(DBNull))
                    {
                        _dbcon.ExecuteNonQuery("create table 'bookmark' (ID integer primary key autoincrement, Name text)");

                        _dbcon.ExecuteNonQuery("create table 'codes' (BookmarkID integer, Code text)");
                    }

                    DbDataReader dr = _dbcon.ExecuteReader("select ID, Name from bookmark");
                    while (dr.Read())
                    {
                        BookmarkInfo bmi = new BookmarkInfo();
                        bmi.ID = (int)dr["ID"];
                        bmi.Name = (string)dr["Name"];
                        _bookmarks.Add(bmi.Name.ToLower(), bmi);
                    }

                    dr = _dbcon.ExecuteReader("select BookmarkID, Code from codes");
                    while (dr.Read())
                    {
                        int id = (int)dr["BookmarkID"];
                        BookmarkInfo bmi = (from BookmarkInfo b in _bookmarks.Values where b.ID==id select b).FirstOrDefault();
                        if (bmi != null)
                        {
                            bmi.GeocacheCodes.Add(dr["Code"], true);
                        }
                    }
                }
                catch
                {
                }
            }
        }
Beispiel #10
0
        public SqliteSettingsStorage()
        {
            _availableKeys = new Hashtable();
            try
            {
                string sf = Properties.Settings.Default.SettingsFolder;
                if (string.IsNullOrEmpty(sf))
                {
                    sf = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "GAPPSF");
                }
                if (!Directory.Exists(sf))
                {
                    Directory.CreateDirectory(sf);
                }
                Properties.Settings.Default.SettingsFolder = sf;
                Properties.Settings.Default.Save();

                sf = Path.Combine(sf, "settings.db3");
                _dbcon = new Utils.DBConComSqlite(sf);

                if (!_dbcon.TableExists("settings"))
                {
                    _dbcon.ExecuteNonQuery("create table 'settings' (item_name text, item_value text)");
                    _dbcon.ExecuteNonQuery("create index idx_key on settings (item_name)");
                }
                else
                {
                    DbDataReader dr = _dbcon.ExecuteReader("select item_name, item_value from settings");
                    while (dr.Read())
                    {
                        _availableKeys[dr[0] as string] = dr[1] as string;
                    }
                }
            }
            catch
            {
                _dbcon = null;
            }
        }
Beispiel #11
0
 private void saveSettingsData()
 {
     try
     {
         using (Utils.DBCon dbcon = initDatabase())
         {
             foreach (ScriptInfo si in _scripts)
             {
                 if (si.ScriptType == ScriptType.Statistics)
                 {
                     if (dbcon.ExecuteNonQuery(string.Format("update settings set enable={1}, pos={0} where scriptid='{2}'", si.Order, si.Enabled ? 1 : 0, si.ID)) == 0)
                     {
                         dbcon.ExecuteNonQuery(string.Format("insert into settings (scriptid, enable, pos) values ('{2}', {1}, {0})", si.Order, si.Enabled ? 1 : 0, si.ID));
                     }
                 }
             }
         }
     }
     catch
     {
     }
 }
 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);
 }
        private void restoreThreadMethod()
        {
            try
            {
                var gcList = (from Framework.Data.Geocache g in _core.Geocaches where Math.Abs(g.Lat) < 0.0001 && Math.Abs(g.Lon) < 0.0001 select g).ToArray();
                _context.Send(new SendOrPostCallback(delegate(object state)
                {
                    toolStripProgressBar1.Maximum = gcList.Length;
                }), null);

                using (Utils.DBCon dbcon = initDatabase())
                {
                    int index = 0;
                    foreach (Framework.Data.Geocache gc in gcList)
                    {
                        DbDataReader dr = dbcon.ExecuteReader(string.Format("select lat, lon from coord where code='{0}'", gc.Code.Replace("'", "''")));
                        if (dr.Read())
                        {
                            gc.Lat = (double)dr["lat"];
                            gc.Lon = (double)dr["lon"];
                        }
                        index++;
                        if (index % 100 == 0)
                        {
                            _context.Send(new SendOrPostCallback(delegate(object state)
                            {
                                toolStripProgressBar1.Value = index;
                            }), null);
                        }
                    }
                }
            }
            catch
            {
            }
            _actionReady.Set();
        }
Beispiel #14
0
 private void AttachementsForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (e.CloseReason == CloseReason.UserClosing)
     {
         e.Cancel = true;
         Hide();
     }
     else
     {
         if (_dbcon != null)
         {
             _dbcon.Dispose();
             _dbcon = null;
         }
     }
 }
Beispiel #15
0
        private void getImagesThreadMethod()
        {
            try
            {
                using (Utils.ProgressBlock blockprogress = new Utils.ProgressBlock(OwnerPlugin as Utils.BasePlugin.Plugin, STR_IMPORTINGMYF, STR_IMPORTINGMYF, 1, 0))
                {
                    try
                    {
                        Utils.DBCon dbcon = initDatabase();

                        var logs = new List <Utils.API.LiveV6.GeocacheLog>();

                        using (System.Net.WebClient wc = new System.Net.WebClient())
                            using (var api = new Utils.API.GeocachingLiveV6(Core))
                            {
                                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(OwnerPlugin as Utils.BasePlugin.Plugin, STR_IMPORTINGMYF, STR_IMPORTINGLOGS, 100, 0, true))
                                {
                                    var req = new Utils.API.LiveV6.GetUsersGeocacheLogsRequest();
                                    req.AccessToken     = api.Token;
                                    req.ExcludeArchived = false;
                                    req.MaxPerPage      = 50;
                                    req.StartIndex      = 0;
                                    req.LogTypes        = (from a in Core.LogTypes select(long) a.ID).ToArray();
                                    var resp = api.Client.GetUsersGeocacheLogs(req);
                                    while (resp.Status.StatusCode == 0)
                                    {
                                        logs.AddRange(resp.Logs);
                                        foreach (var log in resp.Logs)
                                        {
                                            if (log.Images != null && !log.IsArchived)
                                            {
                                                foreach (var li in log.Images)
                                                {
                                                    string    imgGuid = li.ImageGuid.ToString("N");
                                                    ImageInfo ii      = (from a in _imageInfoList where a.ImageGuid == imgGuid select a).FirstOrDefault();
                                                    if (ii == null)
                                                    {
                                                        ii              = new ImageInfo();
                                                        ii.Description  = li.Description;
                                                        ii.ImageGuid    = imgGuid;
                                                        ii.MobileUrl    = li.MobileUrl ?? "";
                                                        ii.Name         = li.Name ?? "";
                                                        ii.ThumbUrl     = li.ThumbUrl;
                                                        ii.Url          = li.Url;
                                                        ii.LogCacheCode = log.CacheCode;
                                                        ii.LogCode      = log.Code;
                                                        ii.LogUrl       = log.Url;
                                                        ii.LogVisitDate = log.VisitDate;

                                                        ii.ThumbFile = Path.Combine(_thumbFolder, Path.GetFileName(li.ThumbUrl));
                                                        ii.ImgFile   = Path.Combine(_imgFolder, Path.GetFileName(li.Url));

                                                        _imageInfoList.Add(ii);

                                                        dbcon.ExecuteNonQuery(string.Format("insert into gallery (ImageGuid, ThumbUrl, Description, Name, MobileUrl, Url, LogCacheCode, LogCode, LogUrl, LogVisitDate, ThumbFile, ImgFile) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')", ii.ImageGuid.Replace("'", "''"), ii.ThumbUrl.Replace("'", "''"), ii.Description.Replace("'", "''"), ii.Name.Replace("'", "''"), ii.MobileUrl.Replace("'", "''"), ii.Url.Replace("'", "''"), ii.LogCacheCode.Replace("'", "''"), ii.LogCode.Replace("'", "''"), ii.LogUrl.Replace("'", "''"), ii.LogVisitDate.ToString("s").Replace("'", "''"), ii.ThumbFile.Replace("'", "''"), ii.ImgFile.Replace("'", "''")));
                                                    }
                                                    //check if local file(s) exist(s)
                                                    //not fail on img download!
                                                    try
                                                    {
                                                        if (!File.Exists(ii.ThumbFile))
                                                        {
                                                            wc.DownloadFile(li.ThumbUrl, ii.ThumbFile);
                                                        }
                                                        if (!File.Exists(ii.ImgFile))
                                                        {
                                                            wc.DownloadFile(li.Url, ii.ImgFile);
                                                        }
                                                    }
                                                    catch
                                                    {
                                                    }
                                                }
                                            }
                                        }

                                        if (resp.Logs.Count() >= req.MaxPerPage)
                                        {
                                            req.StartIndex = logs.Count;
                                            if (!progress.UpdateProgress(STR_IMPORTINGMYF, STR_IMPORTINGLOGS, logs.Count + req.MaxPerPage, logs.Count))
                                            {
                                                break;
                                            }
                                            Thread.Sleep(1500);
                                            resp = api.Client.GetUsersGeocacheLogs(req);
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    if (resp.Status.StatusCode != 0)
                                    {
                                        _errormessage = resp.Status.StatusMessage;
                                    }
                                }
                            }
                        if (dbcon != null)
                        {
                            dbcon.Dispose();
                            dbcon = null;
                        }
                    }
                    catch (Exception e)
                    {
                        _errormessage = e.Message;
                    }
                }
            }
            catch
            {
            }
            _actionReady.Set();
        }
Beispiel #16
0
        private void StatisticsGeneratorForm_Shown(object sender, EventArgs e)
        {
            _scriptFile = new TemporaryFile(true);

            _templatesNode          = new TreeNode("Templates");
            _templatesNode.Checked  = true;
            _extensionsNode         = new TreeNode("Extensions");
            _extensionsNode.Checked = true;
            _skinsNode         = new TreeNode("Skins");
            _skinsNode.Checked = true;
            _statsNode         = new TreeNode("Statistics");
            _statsNode.Checked = true;

            treeView1.Nodes.Add(_templatesNode);
            treeView1.Nodes.Add(_extensionsNode);
            treeView1.Nodes.Add(_skinsNode);
            treeView1.Nodes.Add(_statsNode);

            Assembly assembly = Assembly.GetExecutingAssembly();

            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.DefaultTemplate.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "templ_1";
                si.Name       = "Default Template";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Template;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.DefaultExtension.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "ext_1";
                si.Name       = "Default Extension";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Extension;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.DefaultSkin.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "skin_1";
                si.Name       = "Default Skin";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Skin;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.GoogleChartAPI.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "ext_2";
                si.Name       = "Google Chart API";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Extension;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.foundCaches.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "FoundCaches";
                si.Name       = "Found caches";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.DaysCached.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "DaysCached";
                si.Name       = "Days cached";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.History.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "History";
                si.Name       = "History";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.DTMatrix.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "DTMatrix";
                si.Name       = "DT Matrix";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.DiffTerr.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "DiffTerr";
                si.Name       = "Difficulty and terrain";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.Milestones.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "Milestones";
                si.Name       = "Milestones";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.CacheSizeAndType.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "CacheST";
                si.Name       = "Cache size and type";
                si.ReadOnly   = true;
                si.Order      = 2;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.LocationsTable.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "LocationsTable";
                si.Name       = "Locations table";
                si.ReadOnly   = true;
                si.Order      = 3;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.LogLengthTable.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "LogLengthTable";
                si.Name       = "Log length table";
                si.ReadOnly   = true;
                si.Order      = 3;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = false;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.myGeoToolsBadges.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "myGeoToolsBadges";
                si.Name       = "myGeoTools Badges";
                si.ReadOnly   = true;
                si.Order      = 10;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = false;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.WorldMap66.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "WorldMap66";
                si.Name       = "World map";
                si.ReadOnly   = true;
                si.Order      = 4;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.EuropeMap66.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "EuropeMap66";
                si.Name       = "Europe map";
                si.ReadOnly   = true;
                si.Order      = 5;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.TotalFoundsPerMonthGraph.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "TotalFoundsPerMonthGraph";
                si.Name       = "Total founds per month graph";
                si.ReadOnly   = true;
                si.Order      = 50;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.DiffTerrPie.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "DiffTerrPie";
                si.Name       = "Difficulty and terrain pie";
                si.ReadOnly   = true;
                si.Order      = 51;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.CacheTypeRatioGraph.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "CacheTypeRatioGraph";
                si.Name       = "Cache type ratio graph";
                si.ReadOnly   = true;
                si.Order      = 52;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.CacheTravelDistanceGraph.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "CacheTravelDistanceGraph";
                si.Name       = "Cache travel distance graph";
                si.ReadOnly   = true;
                si.Order      = 53;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }

            try
            {
                using (Utils.DBCon dbcon = initDatabase())
                {
                    DbDataReader dr = dbcon.ExecuteReader("select * from scripts");
                    while (dr.Read())
                    {
                        ScriptInfo si = new ScriptInfo();
                        si.Content    = dr["content"] as string;
                        si.ID         = dr["id"] as string;
                        si.Name       = dr["name"] as string;
                        si.ReadOnly   = false;
                        si.ScriptType = (ScriptType)Enum.Parse(typeof(ScriptType), dr["scripttype"] as string);
                        _scripts.Add(si);
                    }
                    dr = dbcon.ExecuteReader("select * from settings");
                    while (dr.Read())
                    {
                        ScriptInfo si = (from s in _scripts where s.ID == (string)dr["scriptid"] select s).FirstOrDefault();
                        if (si != null)
                        {
                            si.Order   = (int)dr["pos"];
                            si.Enabled = (int)dr["enable"] != 0;
                        }
                    }
                }
            }
            catch
            {
            }

            addNodes(ScriptType.Template, _templatesNode);
            addNodes(ScriptType.Extension, _extensionsNode);
            addNodes(ScriptType.Skin, _skinsNode);
            addNodes(ScriptType.Statistics, _statsNode);

            treeView1.ExpandAll();

            GenerateScript();
        }
Beispiel #17
0
 private Utils.DBCon initDatabase()
 {
     if (_dbcon == null)
     {
         try
         {
             _dbcon = new Utils.DBConComSqlite(_databaseFile);
             object o = _dbcon.ExecuteScalar("SELECT name FROM sqlite_master WHERE type='table' AND name='attachements'");
             if (o == null || o.GetType() == typeof(DBNull))
             {
                 _dbcon.ExecuteNonQuery("create table 'attachements' (code text, filepath text, comment text)");
                 _dbcon.ExecuteNonQuery("create unique index idx_attachements on attachements (code)");
             }
         }
         catch
         {
             _dbcon = null;
         }
     }
     return _dbcon;
 }
        public SqliteSettingsStorage()
        {
            _availableKeys = new Hashtable();
            _ignoredGeocacheCodes = new Hashtable();
            _ignoredGeocacheNames = new Hashtable();
            _ignoredGeocacheOwners = new Hashtable();
            try
            {
                string sf = Properties.Settings.Default.SettingsFolder;
                if (string.IsNullOrEmpty(sf))
                {
                    sf = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "GAPPSF");
                }
                if (!Directory.Exists(sf))
                {
                    Directory.CreateDirectory(sf);
                }
                Properties.Settings.Default.SettingsFolder = sf;
                Properties.Settings.Default.Save();

                sf = Path.Combine(sf, "settings.db3");
                //if (!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
                {
                    _dbcon = new Utils.DBConComSqlite(sf);

                    if (!_dbcon.TableExists("settings"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'settings' (item_name text, item_value text)");
                        _dbcon.ExecuteNonQuery("create index idx_key on settings (item_name)");
                    }
                    else
                    {
                        DbDataReader dr = _dbcon.ExecuteReader("select item_name, item_value from settings");
                        while (dr.Read())
                        {
                            _availableKeys[dr[0] as string] = dr[1] as string;
                        }
                    }
                    if (!_dbcon.TableExists("ignoregc"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'ignoregc' (item_name text, item_value text)");
                    }
                    else
                    {
                        DbDataReader dr = _dbcon.ExecuteReader("select item_name, item_value from ignoregc");
                        while (dr.Read())
                        {
                            string item = dr[0] as string;
                            if (item == "code")
                            {
                                _ignoredGeocacheCodes[dr[1] as string] = true;
                            }
                            else if (item == "name")
                            {
                                _ignoredGeocacheNames[dr[1] as string] = true;
                            }
                            else if (item == "owner")
                            {
                                _ignoredGeocacheOwners[dr[1] as string] = true;
                            }
                        }
                    }
                    if (!_dbcon.TableExists("gccombm"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'gccombm' (bm_id text, bm_name text, bmguid text)");
                        _dbcon.ExecuteNonQuery("create index idx_bmid on gccombm (bm_id)");
                    }
                    if (!_dbcon.TableExists("gccomgc"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'gccomgc' (bm_id text, gccode text)");
                        _dbcon.ExecuteNonQuery("create index idx_bmgcid on gccomgc (bm_id)");
                    }
                    if (!_dbcon.TableExists("attachm"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'attachm' (gccode text, filename text, comments text)");
                        _dbcon.ExecuteNonQuery("create index idx_att on attachm (gccode)");
                    }
                    if (!_dbcon.TableExists("formulasolv"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'formulasolv' (gccode text, formula text)");
                        _dbcon.ExecuteNonQuery("create index idx_form on formulasolv (gccode)");
                    }
                    if (!_dbcon.TableExists("gcnotes"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'gcnotes' (gccode text, notes text)");
                        _dbcon.ExecuteNonQuery("create index idx_note on gcnotes (gccode)");
                    }
                    if (!_dbcon.TableExists("gccollection"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'gccollection' (col_id integer primary key autoincrement, name text)");
                        //_dbcon.ExecuteNonQuery("create index idx_col on gccollection (name)");
                    }
                    if (!_dbcon.TableExists("gcincol"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'gcincol' (col_id integer, gccode text)");
                        _dbcon.ExecuteNonQuery("create index idx_gccol on gcincol (col_id)");
                    }
                    if (!_dbcon.TableExists("gcdist"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'gcdist' (gccode text, dist float)");
                        _dbcon.ExecuteNonQuery("create index idx_dist on gcdist (gccode)");
                    }
                    if (!_dbcon.TableExists("gcvotes"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'gcvotes' (gccode text, VoteMedian float, VoteAvg float, VoteCnt integer, VoteUser float)");
                        _dbcon.ExecuteNonQuery("create unique index idx_gcvotes on gcvotes (gccode)");
                    }

                    if (!_dbcon.TableExists("trkgroups"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'trkgroups' (id integer, name text)");
                    }
                    if (!_dbcon.TableExists("trkimages"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'trkimages' (url text, imagedata blob)");
                    }
                    if (!_dbcon.TableExists("trktrackables"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'trktrackables' (groupid integer, AllowedToBeCollected integer, Archived integer, BugTypeID integer, Code text, CurrentGeocacheCode text, CurrentGoal text, DateCreated text, Description text, IconUrl text, Id integer, InCollection integer, Name text, TBTypeName text, Url text, WptTypeID integer, Owner text, HopCount integer, DiscoverCount integer, InCacheCount integer, DistanceKm real, Lat real, Lon real)");
                        _dbcon.ExecuteNonQuery("create index idx_trackablesgroup on trktrackables (groupid)");
                        _dbcon.ExecuteNonQuery("create index idx_trackablescode on trktrackables (code)");
                    }
                    if (!_dbcon.TableExists("trktravels"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'trktravels' (pos integer, TrackableCode text, GeocacheCode text, lat real, lon real, DateLogged text)");
                        _dbcon.ExecuteNonQuery("create index idx_travels on trktravels (TrackableCode)");
                    }
                    if (!_dbcon.TableExists("trklogs"))
                    {
                        _dbcon.ExecuteNonQuery("create table 'trklogs' (TrackableCode text, ID integer, LogCode text, GeocacheCode text, IsArchived integer, LoggedBy text, LogGuid text, LogIsEncoded integer, LogText text, WptLogTypeId integer, Url text, UTCCreateDate text, VisitDate text)");
                        _dbcon.ExecuteNonQuery("create index idx_logstb on trklogs (TrackableCode)");
                        _dbcon.ExecuteNonQuery("create index idx_logsid on trklogs (ID)");
                    }


                    object o = _dbcon.ExecuteScalar("PRAGMA integrity_check");
                    if (o as string == "ok")
                    {
                        //what is expected
                    }
                    else
                    {
                        //oeps?
                        _dbcon.Dispose();
                        _dbcon = null;
                    }
                }
            }
            catch//(Exception e)
            {
                //Core.ApplicationData.Instance.Logger.AddLog(this, e);
                _dbcon = null;
            }
        }
Beispiel #19
0
        private void TrackableGroupsForm_Shown(object sender, EventArgs e)
        {
            PluginSettings.Instance.DatabaseFileName = System.IO.Path.Combine(Core.PluginDataPath, "TrkGroup.db3" );

            try
            {
                _dbcon = new Utils.DBConComSqlite(PluginSettings.Instance.DatabaseFileName);
                initDatabase(_dbcon);
                DbDataReader dr = _dbcon.ExecuteReader("select * from groups");
                while (dr.Read())
                {
                    TrackableGroup tg = new TrackableGroup();
                    tg.ID = (int)dr["id"];
                    tg.Name = (string)dr["name"];
                    _trackableGroups.Add(tg);
                }
                initImageList();
                comboBoxGroup.Items.AddRange(_trackableGroups.ToArray());
            }
            catch
            {
                _dbcon = null;
            }

            comboBoxGroup_SelectedValueChanged(this, EventArgs.Empty);
            SelectedLanguageChanged(this, EventArgs.Empty);
        }
Beispiel #20
0
 public void Dispose()
 {
     if (_dbcon!=null)
     {
         _dbcon.Dispose();
         _dbcon = null;
     }
 }
Beispiel #21
0
        public bool PrepareRestoreBackup(string id)
        {
            bool result = false;
            lock (this)
            {
                bool restoreConnection = _dbcon != null;
                try
                {
                    if (restoreConnection)
                    {
                        //copy settings.db3 to settings.db3.bak
                        if (_dbcon != null)
                        {
                            _dbcon.Dispose();
                            _dbcon = null;
                        }
                        File.Copy(Path.Combine(Properties.Settings.Default.SettingsFolder, "settings.db3"), Path.Combine(Properties.Settings.Default.SettingsFolder, "settings.db3.bak"), true);
                    }
                    File.Copy(Path.Combine(Properties.Settings.Default.SettingsFolder, id), Path.Combine(Properties.Settings.Default.SettingsFolder, "settings.db3"), true);

                    if (restoreConnection)
                    {
                        //connect to previous settings file, so the backup is not overwritten.
                        //application needs to restart
                        //after restart the backup is used
                        string sf = Path.Combine(Properties.Settings.Default.SettingsFolder, "settings.db3.bak");
                        _dbcon = new Utils.DBConComSqlite(sf);
                    }

                    result = true;
                }
                catch (Exception e)
                {
                    Core.ApplicationData.Instance.Logger.AddLog(this, e);

                    if (restoreConnection)
                    {
                        string sf = Path.Combine(Properties.Settings.Default.SettingsFolder, "settings.db3");
                        if (_dbcon != null)
                        {
                            _dbcon.Dispose();
                            _dbcon = null;
                        }
                        _dbcon = new Utils.DBConComSqlite(sf);
                    }
                }
            }
            return result;
        }
Beispiel #22
0
        public SqliteSettingsStorage()
        {
            _availableKeys = new Hashtable();
            _ignoredGeocacheCodes = new Hashtable();
            _ignoredGeocacheNames = new Hashtable();
            _ignoredGeocacheOwners = new Hashtable();
            try
            {
                string sf = Properties.Settings.Default.SettingsFolder;
                if (string.IsNullOrEmpty(sf))
                {
                    sf = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "GAPPSF");
                }
                if (!Directory.Exists(sf))
                {
                    Directory.CreateDirectory(sf);
                }
                Properties.Settings.Default.SettingsFolder = sf;
                Properties.Settings.Default.Save();

                sf = Path.Combine(sf, "settings.db3");

                _dbcon = new Utils.DBConComSqlite(sf);

                if (!_dbcon.TableExists("settings"))
                {
                    _dbcon.ExecuteNonQuery("create table 'settings' (item_name text, item_value text)");
                    _dbcon.ExecuteNonQuery("create index idx_key on settings (item_name)");
                }
                else
                {
                    DbDataReader dr = _dbcon.ExecuteReader("select item_name, item_value from settings");
                    while (dr.Read())
                    {
                        _availableKeys[dr[0] as string] = dr[1] as string;
                    }
                }
                if (!_dbcon.TableExists("ignoregc"))
                {
                    _dbcon.ExecuteNonQuery("create table 'ignoregc' (item_name text, item_value text)");
                }
                else
                {
                    DbDataReader dr = _dbcon.ExecuteReader("select item_name, item_value from ignoregc");
                    while (dr.Read())
                    {
                        string item = dr[0] as string;
                        if (item == "code")
                        {
                            _ignoredGeocacheCodes[dr[1] as string] = true;
                        }
                        else if (item == "name")
                        {
                            _ignoredGeocacheNames[dr[1] as string] = true;
                        }
                        else if (item == "owner")
                        {
                            _ignoredGeocacheOwners[dr[1] as string] = true;
                        }
                    }
                }
                if (!_dbcon.TableExists("gccombm"))
                {
                    _dbcon.ExecuteNonQuery("create table 'gccombm' (bm_id text, bm_name text, bmguid text)");
                    _dbcon.ExecuteNonQuery("create index idx_bmid on gccombm (bm_id)");
                }
                if (!_dbcon.TableExists("gccomgc"))
                {
                    _dbcon.ExecuteNonQuery("create table 'gccomgc' (bm_id text, gccode text)");
                    _dbcon.ExecuteNonQuery("create index idx_bmgcid on gccomgc (bm_id)");
                }
                if (!_dbcon.TableExists("attachm"))
                {
                    _dbcon.ExecuteNonQuery("create table 'attachm' (gccode text, filename text, comments text)");
                    _dbcon.ExecuteNonQuery("create index idx_att on attachm (gccode)");
                }
                if (!_dbcon.TableExists("formulasolv"))
                {
                    _dbcon.ExecuteNonQuery("create table 'formulasolv' (gccode text, formula text)");
                    _dbcon.ExecuteNonQuery("create index idx_form on formulasolv (gccode)");
                }
                if (!_dbcon.TableExists("gcnotes"))
                {
                    _dbcon.ExecuteNonQuery("create table 'gcnotes' (gccode text, notes text)");
                    _dbcon.ExecuteNonQuery("create index idx_note on gcnotes (gccode)");
                }
                if (!_dbcon.TableExists("gccollection"))
                {
                    _dbcon.ExecuteNonQuery("create table 'gccollection' (col_id integer primary key autoincrement, name text)");
                    //_dbcon.ExecuteNonQuery("create index idx_col on gccollection (name)");
                }
                if (!_dbcon.TableExists("gcincol"))
                {
                    _dbcon.ExecuteNonQuery("create table 'gcincol' (col_id integer, gccode text)");
                    _dbcon.ExecuteNonQuery("create index idx_gccol on gcincol (col_id)");
                }
                if (!_dbcon.TableExists("gcdist"))
                {
                    _dbcon.ExecuteNonQuery("create table 'gcdist' (gccode text, dist float)");
                    _dbcon.ExecuteNonQuery("create index idx_dist on gcdist (gccode)");
                }
                if (!_dbcon.TableExists("gcvotes"))
                {
                    _dbcon.ExecuteNonQuery("create table 'gcvotes' (gccode text, VoteMedian float, VoteAvg float, VoteCnt integer, VoteUser float)");
                    _dbcon.ExecuteNonQuery("create unique index idx_gcvotes on gcvotes (gccode)");
                }

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