public async Task SelectWithinRadiusAsync()
        {
            try
            {
                Core.Data.Location center = null;
                double             radius = 0;
                string             filter = null;

                object o = executeScript("getCenterPosition", null);
                if (o != null && o.GetType() != typeof(DBNull))
                {
                    string s = o.ToString().Replace("(", "").Replace(")", "");
                    center = Utils.Conversion.StringToLocation(s);
                }
                o = executeScript("getRadius", null);
                if (o != null && o.GetType() != typeof(DBNull))
                {
                    string s = o.ToString();
                    radius = Utils.Conversion.StringToDouble(s) * 1000.0;
                }

                using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase))
                {
                    await Task.Run(new Action(() =>
                    {
                        try
                        {
                            //first get a list of geocache codes
                            List <string> gcList = OKAPIService.GetGeocachesWithinRadius(SiteManager.Instance.ActiveSite, center, radius, filter);
                            using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportingOpencachingGeocaches", "ImportingOpencachingGeocaches", gcList.Count, 0, true))
                            {
                                int gcupdatecount = 1;
                                int max = gcList.Count;
                                while (gcList.Count > 0)
                                {
                                    List <string> lcs = gcList.Take(gcupdatecount).ToList();
                                    gcList.RemoveRange(0, lcs.Count);
                                    List <OKAPIService.Geocache> caches = OKAPIService.GetGeocaches(SiteManager.Instance.ActiveSite, lcs);
                                    Import.AddGeocaches(Core.ApplicationData.Instance.ActiveDatabase, caches);

                                    if (!progress.Update("ImportingOpencachingGeocaches", max, max - gcList.Count))
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Core.ApplicationData.Instance.Logger.AddLog(this, e);
                        }
                    }));
                }
            }
            catch (Exception e)
            {
                Core.ApplicationData.Instance.Logger.AddLog(this, e);
            }
        }
        public async Task SelectWithinBoundsAsync()
        {
            try
            {
                double minLat = 0.0;
                double minLon = 0.0;
                double maxLat = 0.0;
                double maxLon = 0.0;

                object o = executeScript("getBounds", null);
                if (o != null && o.GetType() != typeof(DBNull))
                {
                    string   s     = o.ToString().Replace("(", "").Replace(")", "");
                    string[] parts = s.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    minLat = Utils.Conversion.StringToDouble(parts[0]);
                    minLon = Utils.Conversion.StringToDouble(parts[1]);
                    maxLat = Utils.Conversion.StringToDouble(parts[2]);
                    maxLon = Utils.Conversion.StringToDouble(parts[3]);
                }

                using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase))
                {
                    await Task.Run(new Action(() =>
                    {
                        try
                        {
                            //first get a list of geocache codes
                            List <string> gcList = OKAPIService.GetGeocachesInBBox(SiteManager.Instance.ActiveSite, minLat, minLon, maxLat, maxLon);
                            using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportGeocaches", "ImportGeocaches", gcList.Count, 0, true))
                            {
                                int gcupdatecount = 1;
                                int max = gcList.Count;
                                while (gcList.Count > 0)
                                {
                                    List <string> lcs = gcList.Take(gcupdatecount).ToList();
                                    gcList.RemoveRange(0, lcs.Count);
                                    List <OKAPIService.Geocache> caches = OKAPIService.GetGeocaches(SiteManager.Instance.ActiveSite, lcs);
                                    Import.AddGeocaches(Core.ApplicationData.Instance.ActiveDatabase, caches);

                                    if (!progress.Update("ImportGeocaches", max, max - gcList.Count))
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Core.ApplicationData.Instance.Logger.AddLog(this, e);
                        }
                    }));
                }
            }
            catch (Exception e)
            {
                Core.ApplicationData.Instance.Logger.AddLog(this, e);
            }
        }
Beispiel #3
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (SiteManager.Instance.ActiveSite != null && !string.IsNullOrEmpty(SiteManager.Instance.ActiveSite.Username))
         {
             string username = SiteManager.Instance.ActiveSite.Username;
             string userid   = OKAPIService.GetUserID(SiteManager.Instance.ActiveSite, ref username);
             SiteManager.Instance.ActiveSite.Username = username;
             SiteManager.Instance.ActiveSite.UserID   = userid;
         }
     }
     catch (Exception ex)
     {
         Core.ApplicationData.Instance.Logger.AddLog(this, ex);
     }
 }
Beispiel #4
0
        public void ImportMyLogsWithCaches(Core.Storage.Database db, SiteInfo activeSite)
        {
            using (Utils.ProgressBlock blockprogress = new Utils.ProgressBlock("ImportingOpencachingLogs", "ImportingOpencachingLogs", 2, 0, true))
            {
                bool cancelled = false;
                try
                {
                    int stepSize = 100;
                    List <OKAPIService.Log> logs = new List <OKAPIService.Log>();

                    using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportingOpencachingLogs", "ImportingOpencachingLogs", 100, 0, true))
                    {
                        List <OKAPIService.Log> pageLogs = OKAPIService.GetLogsOfUserID(activeSite, activeSite.UserID, stepSize, 0);

                        while (pageLogs.Count() > 0)
                        {
                            logs.AddRange(pageLogs);
                            if (!progress.Update("ImportingOpencachingLogs", logs.Count + stepSize, logs.Count))
                            {
                                cancelled = true;
                                break;
                            }
                            else if (pageLogs.Count() < stepSize)
                            {
                                break;
                            }
                            pageLogs = OKAPIService.GetLogsOfUserID(activeSite, activeSite.UserID, stepSize, logs.Count);
                        }
                    }

                    if (!cancelled)
                    {
                        blockprogress.Update("ImportingOpencachingLogs", 2, 1);

                        //we download the geocaches that are not present. But for the ones we have, we need to add the log and mark it as found
                        List <string> gcList = (from a in logs where db.GeocacheCollection.GetGeocache(a.cache_code) != null select a.cache_code).ToList();
                        foreach (string s in gcList)
                        {
                            db.GeocacheCollection.GetGeocache(s).Found = true;
                            var ls = (from a in logs where a.cache_code == s select a).ToList();
                            foreach (var l in ls)
                            {
                                Convert.AddLog(db, l, activeSite.Username, activeSite.UserID);
                            }
                        }

                        gcList = (from a in logs where db.GeocacheCollection.GetGeocache(a.cache_code) == null select a.cache_code).ToList();
                        using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportingOpencachingLogs", "ImportingOpencachingGeocaches", gcList.Count, 0, true))
                        {
                            int gcupdatecount = 1;

                            while (gcList.Count > 0)
                            {
                                List <string> lcs = gcList.Take(gcupdatecount).ToList();
                                gcList.RemoveRange(0, lcs.Count);
                                List <OKAPIService.Geocache> caches = OKAPIService.GetGeocaches(activeSite, lcs);
                                Import.AddGeocaches(db, caches);

                                foreach (var g in caches)
                                {
                                    var ls = (from a in logs where a.cache_code == g.code select a).ToList();
                                    foreach (var l in ls)
                                    {
                                        Convert.AddLog(db, l, activeSite.Username, activeSite.UserID);
                                    }
                                }

                                if (!progress.Update("ImportingOpencachingGeocaches", logs.Count, logs.Count - gcList.Count))
                                {
                                    cancelled = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Core.ApplicationData.Instance.Logger.AddLog(this, e);
                }
            }
        }
Beispiel #5
0
        public static Core.Data.Geocache AddGeocache(Core.Storage.Database db, OKAPIService.Geocache gc)
        {
            Core.Data.Geocache result = null;
            if (gc != null)
            {
                result = db.GeocacheCollection.GetGeocache(gc.code);

                Core.Data.IGeocacheData gcData;
                if (result == null)
                {
                    gcData      = new Core.Data.GeocacheData();
                    gcData.Code = gc.code;
                }
                else
                {
                    gcData = result;
                }

                gcData.Archived  = gc.status == "Archived";
                gcData.Available = gc.status == "Available";

                if (result == null || !result.Locked)
                {
                    gcData.DataFromDate = DateTime.Now;

                    List <int> attris = new List <int>();
                    foreach (string at in gc.attr_acodes)
                    {
                        int code = OKAPIService.MapAttributeACodeToAttributeID(at);
                        if (code > 0)
                        {
                            attris.Add(code);
                        }
                    }
                    gcData.AttributeIds = attris;

                    // 'none', 'nano', 'micro', 'small', 'regular', 'large', 'xlarge', 'other'
                    // we chose to map the containers
                    if (gc.size2 == "none")
                    {
                        gcData.Container = Utils.DataAccess.GetGeocacheContainer(5);
                    }
                    else if (gc.size2 == "micro" || gc.size2 == "nano")
                    {
                        gcData.Container = Utils.DataAccess.GetGeocacheContainer(2);
                    }
                    else if (gc.size2 == "small")
                    {
                        gcData.Container = Utils.DataAccess.GetGeocacheContainer(8);
                    }
                    else if (gc.size2 == "regular")
                    {
                        gcData.Container = Utils.DataAccess.GetGeocacheContainer(3);
                    }
                    else if (gc.size2 == "large" || gc.size2 == "xlarge")
                    {
                        gcData.Container = Utils.DataAccess.GetGeocacheContainer(4);
                    }
                    else
                    {
                        gcData.Container = Utils.DataAccess.GetGeocacheContainer(6);
                    }
                    gcData.Country      = gc.country ?? "";
                    gcData.Difficulty   = gc.difficulty;
                    gcData.EncodedHints = gc.hint2;
                    gcData.Found        = gc.is_found;
                    if (gc.type.ToLower().Contains("traditional"))
                    {
                        gcData.GeocacheType = Utils.DataAccess.GetGeocacheType(96001);
                    }
                    else if (gc.type.ToLower().Contains("multi"))
                    {
                        gcData.GeocacheType = Utils.DataAccess.GetGeocacheType(96002);
                    }
                    else if (gc.type.ToLower().Contains("quiz") || gc.type.ToLower().Contains("puzzle"))
                    {
                        gcData.GeocacheType = Utils.DataAccess.GetGeocacheType(96008);
                    }
                    else if (gc.type.ToLower().Contains("virtual"))
                    {
                        gcData.GeocacheType = Utils.DataAccess.GetGeocacheType(96003);
                    }
                    else if (gc.type.ToLower().Contains("event"))
                    {
                        gcData.GeocacheType = Utils.DataAccess.GetGeocacheType(96004);
                    }
                    else if (gc.type.ToLower().Contains("webcam"))
                    {
                        gcData.GeocacheType = Utils.DataAccess.GetGeocacheType(96006);
                    }
                    else if (gc.type.ToLower().Contains("location") || gc.type.Contains("moving"))
                    {
                        gcData.GeocacheType = Utils.DataAccess.GetGeocacheType(96007);
                    }
                    else
                    {
                        gcData.GeocacheType = Utils.DataAccess.GetGeocacheType(96005);
                    }
                    gcData.Lat                    = Utils.Conversion.StringToDouble(gc.location.Substring(0, gc.location.IndexOf('|')));
                    gcData.Lon                    = Utils.Conversion.StringToDouble(gc.location.Substring(gc.location.IndexOf('|') + 1));
                    gcData.LongDescription        = gc.description;
                    gcData.LongDescriptionInHtml  = true;
                    gcData.Name                   = gc.name;
                    gcData.Owner                  = gc.owner.username;
                    gcData.OwnerId                = gc.owner.uuid;
                    gcData.PlacedBy               = gc.owner.username;
                    gcData.PublishedTime          = DateTime.Parse(gc.date_hidden);
                    gcData.ShortDescription       = "";
                    gcData.ShortDescriptionInHtml = true;
                    gcData.State                  = gc.state ?? "";
                    gcData.Terrain                = gc.terrain;
                    gcData.Url                    = gc.url ?? "";

                    if (gcData is Core.Data.GeocacheData)
                    {
                        if (Utils.DataAccess.AddGeocache(db, gcData as Core.Data.GeocacheData))
                        {
                            result = db.GeocacheCollection.GetGeocache(gcData.Code);
                        }
                        else
                        {
                            result = null;
                        }
                    }
                    if (result != null)
                    {
                        Calculus.SetDistanceAndAngleGeocacheFromLocation(result, Core.ApplicationData.Instance.CenterLocation);
                    }
                }
            }
            return(result);
        }