示例#1
0
 public void Dispose()
 {
     CurrentConnectedDatabase = null;
     Core.Settings.Default.PropertyChanged -= Default_PropertyChanged;
     Shapefiles.ShapeFilesManager.Instance.PropertyChanged -= Shapefiles_PropertyChanged;
     Core.ApplicationData.Instance.PropertyChanged         -= Instance_PropertyChanged;
 }
示例#2
0
 public async Task GetAllYourFavoriteGeocachesAsync(Core.Storage.Database db, bool importMissing)
 {
     using (Utils.DataUpdater upd = new Utils.DataUpdater(db))
     {
         await Task.Run(() =>
         {
             try
             {
                 List <string> gcList = null;
                 using (var api = new LiveAPI.GeocachingLiveV6())
                 {
                     var respC = api.Client.GetCacheIdsFavoritedByUser(api.Token);
                     if (respC.Status.StatusCode == 0)
                     {
                         gcList = (from s in respC.CacheCodes select s).ToList();
                         Manager.Instance.AddFavoritedGeocaches(gcList);
                     }
                     else
                     {
                         Core.ApplicationData.Instance.Logger.AddLog(this, new Exception(respC.Status.StatusMessage));
                     }
                 }
                 if (gcList != null && gcList.Count > 0 && importMissing)
                 {
                     List <string> missingList = (from a in gcList where db.GeocacheCollection.GetGeocache(a) == null select a).ToList();
                     LiveAPI.Import.ImportGeocaches(db, gcList);
                 }
             }
             catch (Exception e)
             {
                 Core.ApplicationData.Instance.Logger.AddLog(this, e);
             }
         });
     }
 }
示例#3
0
        public static List <Core.Data.UserWaypoint> ImportUserWaypoints(Core.Storage.Database db, LiveV6.UserWaypoint[] wps, string GeocacheCode)
        {
            List <Core.Data.UserWaypoint> result  = new List <Core.Data.UserWaypoint>();
            List <Core.Data.UserWaypoint> curUwps = Utils.DataAccess.GetUserWaypointsFromGeocache(db, GeocacheCode);

            if (wps != null)
            {
                foreach (var lg in wps)
                {
                    Core.Data.UserWaypoint g = ImportUserWaypoint(db, lg);
                    if (g != null)
                    {
                        result.Add(g);
                        if (curUwps.Contains(g))
                        {
                            curUwps.Remove(g);
                        }
                    }
                }
            }
            foreach (var g in curUwps)
            {
                g.DeleteRecord();
                db.UserWaypointCollection.Remove(g);
            }
            return(result);
        }
示例#4
0
        public static List <Core.Data.GeocacheImage> ImportGeocacheImages(Core.Storage.Database db, LiveV6.ImageData[] wps, string GeocacheCode)
        {
            List <Core.Data.GeocacheImage> result  = new List <Core.Data.GeocacheImage>();
            List <Core.Data.GeocacheImage> curImgs = Utils.DataAccess.GetGeocacheImages(db, GeocacheCode);

            if (wps != null)
            {
                foreach (var lg in wps)
                {
                    Core.Data.GeocacheImage g = ImportGeocacheImage(db, lg, GeocacheCode);
                    if (g != null)
                    {
                        result.Add(g);
                        if (curImgs.Contains(g))
                        {
                            curImgs.Remove(g);
                        }
                    }
                }
            }
            foreach (var g in curImgs)
            {
                g.DeleteRecord();
                db.GeocacheImageCollection.Remove(g);
            }
            return(result);
        }
示例#5
0
        public static Core.Data.LogImage ImportLogImage(Core.Storage.Database db, LiveV6.ImageData img, string LogId)
        {
            Core.Data.LogImage result = null;
            if (img != null)
            {
                result = db.LogImageCollection.GetLogImage(img.Url);

                Core.Data.ILogImageData lgiData;
                if (result == null)
                {
                    lgiData       = new Core.Data.LogImageData();
                    lgiData.ID    = img.Url;
                    lgiData.LogId = LogId;
                    lgiData.Url   = img.Url;
                }
                else
                {
                    lgiData = result;
                }

                lgiData.DataFromDate = DateTime.Now;
                lgiData.Name         = img.Name;

                if (lgiData is Core.Data.LogImageData)
                {
                    if (Utils.DataAccess.AddLogImage(db, lgiData as Core.Data.LogImageData))
                    {
                        result = db.LogImageCollection.GetLogImage(img.Url);
                    }
                }
            }
            return(result);
        }
示例#6
0
 public async Task ImportGeocacheDistanceAsync(Core.Storage.Database db)
 {
     using (Utils.DataUpdater upd = new Utils.DataUpdater(db))
     {
         await Task.Run(new Action(() => ImportGeocacheDistance(db)));
     }
 }
示例#7
0
 public async Task UpdateGeocachesAsync(Core.Storage.Database db)
 {
     using (Utils.DataUpdater upd = new Utils.DataUpdater(db))
     {
         await Task.Run(new Action(() => UpdateGeocaches(db)));
     }
 }
示例#8
0
 private void updateGeocachesFromGlobalcachingEU(Core.Storage.Database db, string country, List <string> missingGcList)
 {
     using (System.Net.WebClient wc = new System.Net.WebClient())
     {
         string doc = wc.DownloadString(string.Format("http://www.globalcaching.eu/Service/GeocacheCodes.aspx?country={0}&token={1}", country, System.Web.HttpUtility.UrlEncode(Core.Settings.Default.LiveAPIToken ?? "")));
         if (doc != null)
         {
             string[]           lines = doc.Replace("\r", "").Split(new char[] { '\n' });
             Core.Data.Geocache gc;
             char[]             sep = new char[] { ',' };
             string[]           parts;
             foreach (string s in lines)
             {
                 parts = s.Split(sep);
                 if (parts.Length > 2)
                 {
                     gc = db.GeocacheCollection.GetGeocache(parts[0]);
                     if (gc != null)
                     {
                         gc.Archived  = parts[1] != "0";
                         gc.Available = parts[2] != "0";
                     }
                     else if (parts[1] == "0") //add only none archived
                     {
                         missingGcList.Add(parts[0]);
                     }
                 }
             }
         }
     }
 }
示例#9
0
 public async Task ImportMyLogsWithCachesAsync(Core.Storage.Database db, SiteInfo activeSite)
 {
     using (Utils.DataUpdater upd = new Utils.DataUpdater(db))
     {
         await Task.Run(new Action(() => ImportMyLogsWithCaches(db, activeSite)));
     }
 }
示例#10
0
 public async Task ImportFavoritesAsync(Core.Storage.Database db)
 {
     using (Utils.DataUpdater upd = new Utils.DataUpdater(db))
     {
         await Task.Run(new Action(() => ImportFavorites(db)));
     }
 }
示例#11
0
 public async Task ImportMunzeesFromDfxAtAsync(Core.Storage.Database db, string url)
 {
     using (Utils.DataUpdater upd = new Utils.DataUpdater(db))
     {
         await Task.Run(new Action(() => ImportMunzeesFromDfxAt(db, url)));
     }
 }
示例#12
0
        public async Task <bool> ExportAsync(string filename, Core.Storage.Database db, List <Core.Data.Geocache> gcList)
        {
            bool result = false;
            await Task.Run(() => { result = Export(filename, db, gcList); });

            return(result);
        }
示例#13
0
 private void getCopiedSelectionGeocacheInbackgroundMethod()
 {
     try
     {
         LiveAPI.Import.ImportGeocaches(_copySelectionDb, _importGeocaches);
         foreach (string s in _importGeocaches)
         {
             var gc = _copySelectionDb.GeocacheCollection.GetGeocache(s);
             if (gc != null)
             {
                 gc.Selected = true;
             }
         }
     }
     catch (Exception e)
     {
         Core.ApplicationData.Instance.Logger.AddLog(this, e);
     }
     _context.Post(new SendOrPostCallback(delegate(object state)
     {
         _dataUpdater.Dispose();
         _dataUpdater = null;
         _importGeocaches.Clear();
         _getGeocacheThread = null;
         _copySelectionDb   = null;
     }), null);
 }
 public async Task BackupDatabase(object database)
 {
     Core.Storage.Database db = database as Core.Storage.Database;
     if (db != null)
     {
         await db.BackupAsync();
     }
 }
示例#15
0
        public override async Task ExecuteAsync(object parameter)
        {
            Core.ApplicationData.Instance.BeginActiviy();
            Core.Storage.Database db = Core.ApplicationData.Instance.ActiveDatabase;
            if (db != null)
            {
                using (Utils.DataUpdater upd = new Utils.DataUpdater(db))
                {
                    await Task.Run(() =>
                    {
                        Utils.ProgressBlock prog = null;
                        DateTime nextUpdate      = DateTime.Now.AddSeconds(1);
                        if (_showProgress)
                        {
                            prog = new Utils.ProgressBlock("PerfomingAction", "PerfomingAction", db.GeocacheCollection.Count, 0, true);
                        }
                        try
                        {
                            int index = 0;
                            foreach (Core.Data.Geocache gc in db.GeocacheCollection)
                            {
                                _geocacheAction(gc);

                                if (prog != null)
                                {
                                    index++;
                                    if (DateTime.Now >= nextUpdate)
                                    {
                                        if (!prog.Update("PerfomingAction", db.GeocacheCollection.Count, index))
                                        {
                                            break;
                                        }
                                        nextUpdate = DateTime.Now.AddSeconds(1);
                                    }
                                }
                            }
                            if (prog != null)
                            {
                                prog.Dispose();
                                prog = null;
                            }
                        }
                        catch (Exception e)
                        {
                            Core.ApplicationData.Instance.Logger.AddLog(this, e);
                            if (prog != null)
                            {
                                prog.Dispose();
                                prog = null;
                            }
                        }
                    });
                }
            }
            ;
            Core.ApplicationData.Instance.EndActiviy();
        }
示例#16
0
 async public Task CopyGeocachesAsync(Core.Storage.Database db, List <string> gcList)
 {
     await Task.Run(() =>
     {
         _sourceDatabaseFilename = db.FileName;
         _gcCodes = new List <string>();
         _gcCodes.AddRange(gcList);
     });
 }
示例#17
0
 public static async Task ImportGeocacheImagesAsync(Core.Storage.Database db, List <Core.Data.Geocache> gcList)
 {
     using (Utils.DataUpdater upd = new Utils.DataUpdater(db))
     {
         await Task.Run(() =>
         {
             ImportGeocacheImages(db, gcList);
         });
     }
 }
示例#18
0
 public async Task ImportNotesAsync(Core.Storage.Database db, bool importMissing)
 {
     using (Utils.DataUpdater upd = new Utils.DataUpdater(db))
     {
         await Task.Run(() =>
         {
             ImportNotes(db, importMissing);
         });
     }
 }
示例#19
0
 public static void ImportGeocaches(Core.Storage.Database db, List <string> gcCodes)
 {
     try
     {
         using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportingGeocaches", "ImportingGeocaches", gcCodes.Count, 0, true))
         {
             int totalcount = gcCodes.Count;
             using (var client = new GeocachingLiveV6())
             {
                 int index = 0;
                 while (gcCodes.Count > 0)
                 {
                     LiveV6.SearchForGeocachesRequest req = new LiveV6.SearchForGeocachesRequest();
                     req.IsLite               = Core.Settings.Default.LiveAPIMemberTypeId == 1;
                     req.AccessToken          = client.Token;
                     req.CacheCode            = new LiveV6.CacheCodeFilter();
                     req.CacheCode.CacheCodes = (from a in gcCodes select a).Take(Core.Settings.Default.LiveAPIImportGeocachesBatchSize).ToArray();
                     req.MaxPerPage           = Core.Settings.Default.LiveAPIImportGeocachesBatchSize;
                     req.GeocacheLogCount     = 5;
                     index += req.CacheCode.CacheCodes.Length;
                     gcCodes.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                     var resp = client.Client.SearchForGeocaches(req);
                     if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                     {
                         List <Core.Data.Geocache> upList = ImportGeocaches(db, resp.Geocaches);
                         if (Core.Settings.Default.LiveAPIDeselectAfterUpdate)
                         {
                             foreach (var g in upList)
                             {
                                 g.Selected = false;
                             }
                         }
                     }
                     else
                     {
                         Core.ApplicationData.Instance.Logger.AddLog(new Import(), new Exception(resp.Status.StatusMessage));
                         break;
                     }
                     if (!progress.Update("ImportingGeocaches", totalcount, index))
                     {
                         break;
                     }
                     if (gcCodes.Count > 0)
                     {
                         System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelaySearchForGeocaches);
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Core.ApplicationData.Instance.Logger.AddLog(new Import(), e);
     }
 }
示例#20
0
 void Instance_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "ActiveGeocache")
     {
         UpdateView(true);
     }
     else if (e.PropertyName == "ActiveDatabase")
     {
         CurrentConnectedDatabase = Core.ApplicationData.Instance.ActiveDatabase;
     }
 }
 public void RemoveDatabase(object database)
 {
     Core.Storage.Database db = database as Core.Storage.Database;
     if (db != null)
     {
         if (Core.ApplicationData.Instance.ActiveDatabase == db)
         {
             Core.ApplicationData.Instance.ActiveDatabase = null;
         }
         Core.ApplicationData.Instance.Databases.Remove(db);
     }
 }
示例#22
0
 public async Task ExportToGarminPOIAsync(Core.Storage.Database db, List <Core.Data.Geocache> gcList)
 {
     await Task.Run(() =>
     {
         try
         {
             ExportToGarminPOI(db, gcList);
         }
         catch (Exception e)
         {
             Core.ApplicationData.Instance.Logger.AddLog(this, e);
         }
     });
 }
示例#23
0
        public async Task ImportFile(Core.Storage.Database db)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName   = "";                                 // Default file name
            dlg.DefaultExt = ".gde";                             // Default file extension
            dlg.Filter     = "GAPP Data Exchange (*.gde)|*.gde"; // Filter files by extension

            // Show open file dialog box
            Nullable <bool> result = dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                await ImportFile(db, dlg.FileName);
            }
        }
示例#24
0
        public static List <Core.Data.Geocache> ImportGeocaches(Core.Storage.Database db, LiveV6.Geocache[] gcList)
        {
            List <Core.Data.Geocache> result = new List <Core.Data.Geocache>();

            if (gcList != null)
            {
                foreach (var gc in gcList)
                {
                    Core.Data.Geocache g = ImportGeocache(db, gc);
                    if (g != null)
                    {
                        result.Add(g);
                    }
                }
            }
            return(result);
        }
示例#25
0
        public static List <Core.Data.Log> ImportLogs(Core.Storage.Database db, LiveV6.GeocacheLog[] lgs)
        {
            List <Core.Data.Log> result = new List <Core.Data.Log>();

            if (lgs != null)
            {
                foreach (var lg in lgs)
                {
                    Core.Data.Log g = ImportLog(db, lg);
                    if (g != null)
                    {
                        result.Add(g);
                    }
                }
            }
            return(result);
        }
示例#26
0
        public static List <Core.Data.LogImage> ImportLogImages(Core.Storage.Database db, LiveV6.ImageData[] imgs, string LogId)
        {
            List <Core.Data.LogImage> result = new List <Core.Data.LogImage>();

            if (imgs != null)
            {
                foreach (var lg in imgs)
                {
                    Core.Data.LogImage g = ImportLogImage(db, lg, LogId);
                    if (g != null)
                    {
                        result.Add(g);
                    }
                }
            }
            return(result);
        }
示例#27
0
        public static List <Core.Data.Waypoint> ImportWaypoints(Core.Storage.Database db, LiveV6.AdditionalWaypoint[] wps)
        {
            List <Core.Data.Waypoint> result = new List <Core.Data.Waypoint>();

            if (wps != null)
            {
                foreach (var lg in wps)
                {
                    Core.Data.Waypoint g = ImportWaypoint(db, lg);
                    if (g != null)
                    {
                        result.Add(g);
                    }
                }
            }
            return(result);
        }
示例#28
0
        private bool Export(string filename, Core.Storage.Database db, List <Core.Data.Geocache> gcList)
        {
            bool result = false;

            try
            {
                using (FileCollection fileCollection = new FileCollection(filename))
                {
                    result = Save(fileCollection, db, gcList);
                }
            }
            catch (Exception e)
            {
                Core.ApplicationData.Instance.Logger.AddLog(this, e);
            }
            return(result);
        }
示例#29
0
        public static Core.Data.Log AddLog(Core.Storage.Database db, OKAPIService.Log lg, string finder, string finderId)
        {
            Core.Data.Log result = null;
            if (lg != null)
            {
                result = db.LogCollection.GetLog(lg.uuid);

                Core.Data.ILogData lgData;
                if (result == null)
                {
                    lgData    = new Core.Data.LogData();
                    lgData.ID = lg.uuid;
                }
                else
                {
                    lgData = result;
                }

                lgData.DataFromDate = DateTime.Now;
                lgData.Date         = DateTime.Parse(lg.date);
                lgData.Encoded      = false;
                if (lg.user == null)
                {
                    lgData.Finder   = finder;
                    lgData.FinderId = finderId;
                }
                else
                {
                    lgData.Finder   = lg.user.username;
                    lgData.FinderId = lg.user.uuid;
                }
                lgData.GeocacheCode = lg.cache_code;
                lgData.Text         = lg.comment;
                lgData.LogType      = Utils.DataAccess.GetLogType(lg.type);

                if (lgData is Core.Data.LogData)
                {
                    if (Utils.DataAccess.AddLog(db, lgData as Core.Data.LogData))
                    {
                        result = db.LogCollection.GetLog(lgData.ID);
                    }
                }
            }
            return(result);
        }
示例#30
0
 public void ImportFavorites(Core.Storage.Database db)
 {
     try
     {
         using (Utils.ProgressBlock progress = new Utils.ProgressBlock("GetFavoritesFromGlobalcaching", "DownloadingData", 1, 0))
         {
             using (System.Net.WebClient wc = new System.Net.WebClient())
             {
                 string doc = wc.DownloadString(string.Format("http://www.globalcaching.eu/Service/CacheFavorites.aspx?token={0}", System.Web.HttpUtility.UrlEncode(Core.Settings.Default.LiveAPIToken ?? "")));
                 if (doc != null)
                 {
                     string[] lines = doc.Replace("\r", "").Split(new char[] { '\n' });
                     progress.Update("SavingGeocaches", lines.Length, 0);
                     Core.Data.Geocache gc;
                     char[]             sep = new char[] { ',' };
                     string[]           parts;
                     DateTime           nextUpdate = DateTime.Now.AddSeconds(1);
                     int index = 0;
                     foreach (string s in lines)
                     {
                         parts = s.Split(sep);
                         if (parts.Length > 0)
                         {
                             gc = db.GeocacheCollection.GetGeocache(parts[0]);
                             if (gc != null)
                             {
                                 gc.Favorites = int.Parse(parts[1]);
                             }
                         }
                         index++;
                         if (DateTime.Now >= nextUpdate)
                         {
                             progress.Update("SavingGeocaches", lines.Length, index);
                             nextUpdate = DateTime.Now.AddSeconds(1);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Core.ApplicationData.Instance.Logger.AddLog(this, e);
     }
 }
示例#31
0
        public async Task RestoreDatabase(object database)
        {
            Core.Storage.Database db = database as Core.Storage.Database;
            if (db != null)
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.InitialDirectory = System.IO.Path.GetDirectoryName(db.FileName);
                dlg.FileName = ""; // Default file name
                dlg.Filter = string.Format("GAPP SF backup ({0}.gsf.bak)|{0}.bak*", System.IO.Path.GetFileName(db.FileName)); // Filter files by extension 

                // Show open file dialog box
                Nullable<bool> result = dlg.ShowDialog();

                // Process open file dialog box results 
                if (result == true)
                {
                    int pos = dlg.FileName.ToLower().LastIndexOf(".bak");
                    string orgFn = dlg.FileName.Substring(0, pos);

                    //if database is open at the moment, close it.
                    db = (from a in Core.ApplicationData.Instance.Databases where string.Compare(a.FileName, orgFn, true) == 0 select a).FirstOrDefault();
                    if (db != null)
                    {
                        if (Core.ApplicationData.Instance.ActiveDatabase == db)
                        {
                            Core.ApplicationData.Instance.ActiveDatabase = null;
                        }
                        Core.ApplicationData.Instance.Databases.Remove(db);
                    }

                    //now, delete index file
                    string indexFile = string.Concat(orgFn, ".gsx");
                    if (System.IO.File.Exists(indexFile))
                    {
                        System.IO.File.Delete(indexFile);
                    }

                    if (System.IO.File.Exists(orgFn))
                    {
                        System.IO.File.Delete(orgFn);
                    }
                    System.IO.File.Move(dlg.FileName, orgFn);

                    //load database
                    bool success;
                    db = new Core.Storage.Database(orgFn);
                    using (Utils.DataUpdater upd = new Utils.DataUpdater(db, true))
                    {
                        success = await db.InitializeAsync();
                    }
                    if (success)
                    {
                        Core.ApplicationData.Instance.Databases.Add(db);
                        Core.ApplicationData.Instance.ActiveDatabase = db;
                    }
                    else
                    {
                        db.Dispose();
                    }
                }
            }
        }