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 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;
            }
        }
        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 #4
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();
        }