Exemple #1
0
        public List <Core.Data.AreaInfo> GetEnvelopAreasOfLocation(Core.Data.Location loc, List <Core.Data.AreaInfo> inAreas)
        {
            List <Core.Data.AreaInfo> result = null;

            if (loc.Lat >= _shpYMin && loc.Lat <= _shpYMax && loc.Lon >= _shpXMin && loc.Lon <= _shpXMax)
            {
                //all areas with point in envelope
                var ais = from r in _areaInfos
                          join b in inAreas on r equals b
                          where loc.Lat >= r.MinLat && loc.Lat <= r.MaxLat && loc.Lon >= r.MinLon && loc.Lon <= r.MaxLon
                          select r;
                foreach (var ai in ais)
                {
                    if (IsLocationInEnvelopArea(loc, ai))
                    {
                        if (result == null)
                        {
                            result = new List <Core.Data.AreaInfo>();
                        }
                        result.Add(ai);
                    }
                }
            }
            return(result);
        }
Exemple #2
0
        private bool IsLocationInEnvelopArea(Core.Data.Location loc, Core.Data.AreaInfo area)
        {
            bool result = false;

            //point in envelope of area
            if (loc.Lat >= area.MinLat && loc.Lat <= area.MaxLat && loc.Lon >= area.MinLon && loc.Lon <= area.MaxLon)
            {
                bool releasePoly = area.Polygons == null;
                if (area.Polygons == null)
                {
                    GetPolygonOfArea(area);
                }
                if (area.Polygons != null)
                {
                    foreach (var r in area.Polygons)
                    {
                        //point in envelope of polygon
                        if (loc.Lat >= r.MinLat && loc.Lat <= r.MaxLat && loc.Lon >= r.MinLon && loc.Lon <= r.MaxLon)
                        {
                            result = true;
                            break;
                        }
                    }
                }
                if (releasePoly)
                {
                    area.Polygons = null;
                }
            }
            return(result);
        }
Exemple #3
0
 public static Core.Data.Location GetLocationOfAddress(string address)
 {
     Core.Data.Location result = null;
     try
     {
         string         s  = null;
         HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", HttpUtility.UrlEncode(address)));
         wr.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
         wr.Method    = WebRequestMethods.Http.Get;
         using (HttpWebResponse webResponse = (HttpWebResponse)wr.GetResponse())
         {
             using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
             {
                 s = reader.ReadToEnd();
                 webResponse.Close();
             }
         }
         if (s != null && s.Length > 0)
         {
             XmlDocument xdoc = new XmlDocument();
             xdoc.LoadXml(s);
             XmlNode n = xdoc.SelectSingleNode("GeocodeResponse/result/geometry/location");
             result = new Core.Data.Location(Conversion.StringToDouble(n.SelectSingleNode("lat").InnerText), Conversion.StringToDouble(n.SelectSingleNode("lng").InnerText));
         }
     }
     catch
     {
         result = null;
     }
     return(result);
 }
        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 void updateLocation(double lat, double lon)
 {
     Dispatcher.BeginInvoke((Action)(() =>
     {
         Core.Data.Location l = new Core.Data.Location(lat, lon);
         CoordText = l.ToString();
     }));
 }
Exemple #6
0
 private Core.Data.Location getLocation()
 {
     Core.Data.Location result = Utils.Conversion.StringToLocation(Core.Settings.Default.GeocacheFilterLocation);
     if (result == null)
     {
         //address?
         result = Utils.Geocoder.GetLocationOfAddress(Core.Settings.Default.GeocacheFilterLocation);
     }
     return(result);
 }
Exemple #7
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     Core.Data.Location l = getLocation();
     if (l == null)
     {
         Core.Settings.Default.GeocacheFilterLocation = "";
     }
     else
     {
         Core.Settings.Default.GeocacheFilterLocation = l.ToString();
     }
 }
Exemple #8
0
        public override object Execute(object[] args, ExecutionContext ctx)
        {
            ArgumentChecker checker = new ArgumentChecker(this.GetType().Name);

            checker.CheckForNumberOfArguments(ref args, 1, 1);
            Core.Data.Location ll = Utils.Conversion.StringToLocation(args[0].ToString());
            if (ll != null)
            {
                return(ll.Lon.ToString("G", CultureInfo.InvariantCulture));
            }
            return("");
        }
Exemple #9
0
        public static List <string> GetGeocachesWithinRadius(SiteInfo si, Core.Data.Location loc, double radiusKm, string filter)
        {
            List <string> result;

            if (!string.IsNullOrEmpty(filter))
            {
                filter = string.Concat("&", filter);
            }
            string url = string.Format("{0}services/caches/search/nearest?center={1}|{2}&radius={3}{4}&limit=500&consumer_key={5}", si.OKAPIBaseUrl, loc.Lat.ToString().Replace(',', '.'), loc.Lon.ToString().Replace(',', '.'), radiusKm.ToString().Replace(',', '.'), filter, HttpUtility.UrlEncode(si.ConsumerKey));

            result = GetGeocachesByUrl(url);
            return(result);
        }
Exemple #10
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     Core.Data.Location l = getLocation();
     if (l == null)
     {
         l = Core.ApplicationData.Instance.CenterLocation;
     }
     Dialogs.GetLocationWindow dlg = new Dialogs.GetLocationWindow(l);
     if (dlg.ShowDialog() == true)
     {
         Core.Settings.Default.GeocacheFilterLocation = dlg.Location.ToString();
     }
 }
        public List <Core.Data.AreaInfo> GetEnvelopAreasOfLocation(Core.Data.Location loc, List <Core.Data.AreaInfo> inAreas)
        {
            List <Core.Data.AreaInfo> result = new List <Core.Data.AreaInfo>();

            foreach (var sf in _shapeFiles)
            {
                List <Core.Data.AreaInfo> areas = sf.GetEnvelopAreasOfLocation(loc, inAreas);
                if (areas != null)
                {
                    result.AddRange(areas);
                }
            }
            return(result);
        }
Exemple #12
0
        public override object Execute(object[] args, ExecutionContext ctx)
        {
            string          res     = "";
            ArgumentChecker checker = new ArgumentChecker(this.GetType().Name);

            checker.CheckForNumberOfArguments(ref args, 2, null);
            Core.Data.Location ll1 = Utils.Conversion.StringToLocation(args[0].ToString());
            Core.Data.Location ll2 = Utils.Conversion.StringToLocation(args[1].ToString());
            if ((ll1 != null) && (ll2 != null))
            {
                GeodeticMeasurement gm = Utils.Calculus.CalculateDistance(ll1.Lat, ll1.Lon, ll2.Lat, ll2.Lon);
                res = gm.Azimuth.Degrees.ToString("0");
            }
            return(res);
        }
Exemple #13
0
 private void Button_Click_4(object sender, RoutedEventArgs e)
 {
     Core.Data.Location ll = null;
     if (tbSolutions.SelectionLength > 0)
     {
         ll = Utils.Conversion.StringToLocation(tbSolutions.SelectedText);
     }
     if (ll != null)
     {
         Utils.DataAccess.SetCenterLocation(ll.Lat, ll.Lon);
     }
     else
     {
         Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, StrRes.GetString(StrRes.NO_PROPER_COORDINATES_SELECTED));
     }
 }
Exemple #14
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     Core.Data.Location l = null;
     if (Core.ApplicationData.Instance.ActiveGeocache != null)
     {
         l = new Core.Data.Location(Core.ApplicationData.Instance.ActiveGeocache.Lat, Core.ApplicationData.Instance.ActiveGeocache.Lon);
     }
     if (l == null)
     {
         l = Core.ApplicationData.Instance.CenterLocation;
     }
     Dialogs.GetLocationWindow dlg = new Dialogs.GetLocationWindow(l);
     if (dlg.ShowDialog() == true)
     {
         GeocacheCoordinate = dlg.Location.ToString();
     }
 }
        public GetLocationWindow(Core.Data.Location location)
        {
            _scriptObj = new ObjectForScriptingCallback(this);

            Location = location;
            if (Location == null)
            {
                CoordText = "";
            }
            else
            {
                CoordText = Location.ToString();
            }
            DataContext = this;

            InitializeComponent();
            webBrowser.ObjectForScripting = _scriptObj;
        }
Exemple #16
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     Core.Data.Location l = null;
     if (Core.ApplicationData.Instance.ActiveGeocache != null)
     {
         if (Core.ApplicationData.Instance.ActiveGeocache.ContainsCustomLatLon)
         {
             l = new Core.Data.Location((double)Core.ApplicationData.Instance.ActiveGeocache.CustomLat, (double)Core.ApplicationData.Instance.ActiveGeocache.CustomLon);
         }
     }
     if (l == null)
     {
         l = Core.ApplicationData.Instance.CenterLocation;
     }
     Dialogs.GetLocationWindow dlg = new Dialogs.GetLocationWindow(l);
     if (dlg.ShowDialog() == true)
     {
         WaypointLocation = dlg.Location.ToString();
     }
 }
Exemple #17
0
        public override object Execute(object[] args, ExecutionContext ctx)
        {
            string          ret     = "";
            ArgumentChecker checker = new ArgumentChecker(this.GetType().Name);

            checker.CheckForNumberOfArguments(ref args, 3, null);
            Core.Data.Location ll       = Utils.Conversion.StringToLocation(args[0].ToString());
            double             distance = Utils.Conversion.StringToDouble(args[1].ToString());
            double             angle    = Utils.Conversion.StringToDouble(args[2].ToString());

            if (ll != null)
            {
                GeodeticCalculator gc = new GeodeticCalculator();
                GlobalCoordinates  p  = gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84,
                                                                            new GlobalCoordinates(new Angle(ll.Lat), new Angle(ll.Lon)),
                                                                            new Angle(angle), distance);
                ret = Utils.Conversion.GetCoordinatesPresentation(p.Latitude.Degrees, p.Longitude.Degrees);
            }

            return(ret);
        }
Exemple #18
0
 public static string GetCityName(Core.Data.Location ll)
 {
     return(GetCityName(ll.Lat, ll.Lon));
 }
        public async Task SelectWithinRadiusAsync()
        {
            try
            {
                Core.Data.Location center = null;
                double             radius = 0;
                var sc = selectionContext.GeocacheSelectionContext;

                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
                        {
                            List <Core.Data.Geocache> gcList;
                            if (sc == GAPPSF.UIControls.SelectionContext.Context.NewSelection)
                            {
                                gcList = Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection;
                            }
                            else if (sc == GAPPSF.UIControls.SelectionContext.Context.WithinSelection)
                            {
                                gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where a.Selected select a).ToList();
                            }
                            else
                            {
                                gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where !a.Selected select a).ToList();
                            }
                            DateTime nextUpdate = DateTime.Now.AddSeconds(1);
                            using (Utils.ProgressBlock prog = new Utils.ProgressBlock("Searching", "Searching", gcList.Count, 0, true))
                            {
                                int index = 0;
                                foreach (var gc in gcList)
                                {
                                    gc.Selected = Utils.Calculus.CalculateDistance(gc, center).EllipsoidalDistance <= radius;

                                    index++;
                                    if (DateTime.Now >= nextUpdate)
                                    {
                                        if (!prog.Update("Searching", gcList.Count, index))
                                        {
                                            break;
                                        }
                                        nextUpdate = DateTime.Now.AddSeconds(1);
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Core.ApplicationData.Instance.Logger.AddLog(this, e);
                        }
                    }));
                }
            }
            catch (Exception e)
            {
                Core.ApplicationData.Instance.Logger.AddLog(this, e);
            }
        }
Exemple #20
0
        public override object Execute(object[] args, ExecutionContext ctx)
        {
            string          ret     = StrRes.GetString(StrRes.STR_NO_CROSSING);
            ArgumentChecker checker = new ArgumentChecker(this.GetType().Name);

            checker.CheckForNumberOfArguments(ref args, 4, null);

            Core.Data.Location ll0 = Utils.Conversion.StringToLocation(args[0].ToString());
            Core.Data.Location ll1 = Utils.Conversion.StringToLocation(args[1].ToString());
            Core.Data.Location ll2 = Utils.Conversion.StringToLocation(args[2].ToString());
            Core.Data.Location ll3 = Utils.Conversion.StringToLocation(args[3].ToString());

            // x -> Lon , y -> Lat
            decimal y0 = (decimal)ll0.Lat;
            decimal y1 = (decimal)ll1.Lat;
            decimal y2 = (decimal)ll2.Lat;
            decimal y3 = (decimal)ll3.Lat;

            decimal x0 = (decimal)ll0.Lon;
            decimal x1 = (decimal)ll1.Lon;
            decimal x2 = (decimal)ll2.Lon;
            decimal x3 = (decimal)ll3.Lon;

            decimal?m0 = null;  // Gerade 1 senkrecht -> alle x-Werte der Geraden sind gleich
            decimal?m1 = null;  // Gerade 2 senkrecht -> alle x-Werte der Geraden sind gleich
            decimal?n0 = null;
            decimal?n1 = null;

            if (x1 != x0)
            {
                m0 = (y1 - y0) / (x1 - x0);
            }

            if (x3 != x2)
            {
                m1 = (y3 - y2) / (x3 - x2);
            }

            if (m0 != m1)
            {
                decimal?lon = null;
                decimal?lat = null;
                if (m0 == null)
                {
                    n1  = y2 - x2 * m1;
                    lon = x0;
                    lat = m1 * x0 + n1;
                }
                else if (m1 == null)
                {
                    n0  = y0 - x0 * m0;
                    lon = x2;
                    lat = m0 * x2 + n0;
                }
                else
                {
                    n0 = y0 - x0 * m0;
                    n1 = y2 - x2 * m1;

                    lon = (n1 - n0) / (m0 - m1); // x
                    lat = lon * m0 + n0;         // y
                }
                ret = Utils.Conversion.GetCoordinatesPresentation((double)lat, (double)lon);
            }
            return(ret);
        }
 public override bool PrepareRun()
 {
     if (Values.Count > 1)
     {
         try
         {
             _loc = Utils.Conversion.StringToLocation(Values[0]);
             _value = Utils.Conversion.StringToDouble(Values[1]);
         }
         catch
         {
         }
     }
     return base.PrepareRun();
 }
Exemple #22
0
        public async Task UpdateGeocache(string param)
        {
            if (Core.ApplicationData.Instance.ActiveDatabase != null)
            {
                List <Core.Data.Geocache> gcList = null;
                if (Core.Settings.Default.GCEditorEditActiveOnly)
                {
                    if (Core.ApplicationData.Instance.ActiveGeocache != null)
                    {
                        gcList = new List <Core.Data.Geocache>();
                        gcList.Add(Core.ApplicationData.Instance.ActiveGeocache);
                    }
                }
                else
                {
                    gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where a.Selected select a).ToList();
                }
                if (gcList != null)
                {
                    using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase))
                    {
                        GeocacheData.GeocacheType = geocacheTypeCombo.SelectedItem;
                        double?dist = null;
                        if (!string.IsNullOrEmpty(gcDistance.Text))
                        {
                            dist = Utils.Conversion.StringToDouble(gcDistance.Text);
                        }
                        await Task.Run(() =>
                        {
                            try
                            {
                                DateTime nextUpdate = DateTime.Now.AddSeconds(1);
                                int index           = 0;
                                using (Utils.ProgressBlock prog = new Utils.ProgressBlock("SavingGeocaches", "SavingGeocaches", gcList.Count, 0))
                                {
                                    foreach (var gc in gcList)
                                    {
                                        if (param == "Name")
                                        {
                                            gc.Name = GeocacheData.Name;
                                        }
                                        else if (param == "PublishedTime")
                                        {
                                            gc.PublishedTime = GeocacheData.PublishedTime;
                                        }
                                        else if (param == "Coordinate")
                                        {
                                            Core.Data.Location l = Utils.Conversion.StringToLocation(GeocacheCoordinate);
                                            if (l != null)
                                            {
                                                gc.Lat = l.Lat;
                                                gc.Lon = l.Lon;
                                            }
                                        }
                                        else if (param == "CustomCoordinate")
                                        {
                                            Core.Data.Location l = Utils.Conversion.StringToLocation(GeocacheCustomCoordinate);
                                            if (l != null)
                                            {
                                                gc.CustomLat = l.Lat;
                                                gc.CustomLon = l.Lon;
                                            }
                                            else
                                            {
                                                gc.CustomLat = null;
                                                gc.CustomLon = null;
                                            }
                                        }
                                        else if (param == "Locked")
                                        {
                                            gc.Locked = GeocacheData.Locked;
                                        }
                                        else if (param == "Available")
                                        {
                                            gc.Available = GeocacheData.Available;
                                        }
                                        else if (param == "Archived")
                                        {
                                            gc.Archived = GeocacheData.Archived;
                                        }
                                        else if (param == "MemberOnly")
                                        {
                                            gc.MemberOnly = GeocacheData.MemberOnly;
                                        }
                                        else if (param == "Found")
                                        {
                                            gc.Found = GeocacheData.Found;
                                        }
                                        else if (param == "Country")
                                        {
                                            gc.Country = GeocacheData.Country;
                                        }
                                        else if (param == "State")
                                        {
                                            gc.State = GeocacheData.State;
                                        }
                                        else if (param == "Municipality")
                                        {
                                            gc.Municipality = GeocacheData.Municipality;
                                        }
                                        else if (param == "City")
                                        {
                                            gc.City = GeocacheData.City;
                                        }
                                        else if (param == "GeocacheType")
                                        {
                                            gc.GeocacheType = GeocacheData.GeocacheType;
                                        }
                                        else if (param == "PlacedBy")
                                        {
                                            gc.PlacedBy = GeocacheData.PlacedBy;
                                        }
                                        else if (param == "Owner")
                                        {
                                            gc.Owner = GeocacheData.Owner;
                                        }
                                        else if (param == "OwnerId")
                                        {
                                            gc.OwnerId = GeocacheData.OwnerId;
                                        }
                                        else if (param == "Terrain")
                                        {
                                            gc.Terrain = GeocacheData.Terrain;
                                        }
                                        else if (param == "Difficulty")
                                        {
                                            gc.Difficulty = GeocacheData.Difficulty;
                                        }
                                        else if (param == "EncodedHints")
                                        {
                                            gc.EncodedHints = GeocacheData.EncodedHints;
                                        }
                                        else if (param == "Url")
                                        {
                                            gc.Url = GeocacheData.Url;
                                        }
                                        else if (param == "Favorites")
                                        {
                                            gc.Favorites = GeocacheData.Favorites;
                                        }
                                        else if (param == "PersonalNote")
                                        {
                                            gc.PersonalNote = GeocacheData.PersonalNote;
                                        }
                                        else if (param == "GeocacheDistance")
                                        {
                                            gc.GeocacheDistance = dist;
                                        }
                                        else
                                        {
                                            //oeps
                                        }

                                        index++;
                                        if (DateTime.Now >= nextUpdate)
                                        {
                                            prog.Update("SavingGeocaches", gcList.Count, index);
                                        }
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Core.ApplicationData.Instance.Logger.AddLog(this, e);
                            }
                        });
                    }
                }
            }
        }
Exemple #23
0
        public async Task PerformImport()
        {
            using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase))
            {
                await Task.Run(() =>
                {
                    try
                    {
                        var SearchForGeocachesRequestProperties        = new LiveAPI.LiveV6.SearchForGeocachesRequest();
                        SearchForGeocachesRequestProperties.IsLite     = Core.Settings.Default.LiveAPIMemberTypeId == 1;
                        SearchForGeocachesRequestProperties.MaxPerPage = Core.Settings.Default.LiveAPIImportGeocachesBatchSize;
                        if (!string.IsNullOrEmpty(Core.Settings.Default.LiveAPIGetGCLocation) && string.IsNullOrEmpty(Core.Settings.Default.LiveAPIGetGCCodes))
                        {
                            double dist = Core.Settings.Default.LiveAPIGetGCRadius * 1000.0;
                            if (Core.Settings.Default.LiveAPIGetGCLocationKm == UIControls.GeocacheFilter.BooleanEnum.False)
                            {
                                dist *= 1.6214;
                            }
                            Core.Data.Location l = Utils.Conversion.StringToLocation(Core.Settings.Default.LiveAPIGetGCLocation);

                            SearchForGeocachesRequestProperties.PointRadius = new LiveAPI.LiveV6.PointRadiusFilter();
                            SearchForGeocachesRequestProperties.PointRadius.DistanceInMeters = (long)dist;
                            SearchForGeocachesRequestProperties.PointRadius.Point            = new LiveAPI.LiveV6.LatLngPoint();
                            SearchForGeocachesRequestProperties.PointRadius.Point.Latitude   = l.Lat;
                            SearchForGeocachesRequestProperties.PointRadius.Point.Longitude  = l.Lon;
                        }
                        if (!string.IsNullOrEmpty(Core.Settings.Default.LiveAPIGetGCCodes))
                        {
                            string[] parts = Core.Settings.Default.LiveAPIGetGCCodes.Split(new char[] { ',', ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                            SearchForGeocachesRequestProperties.CacheCode            = new LiveAPI.LiveV6.CacheCodeFilter();
                            SearchForGeocachesRequestProperties.CacheCode.CacheCodes = (from s in parts select s.ToUpper()).ToArray();
                        }
                        SearchForGeocachesRequestProperties.GeocacheLogCount = Core.Settings.Default.LiveAPIGetGCMaximumLogs;
                        if (Core.Settings.Default.LiveAPIMemberTypeId > 1)
                        {
                            SearchForGeocachesRequestProperties.FavoritePoints = new LiveAPI.LiveV6.FavoritePointsFilter();
                            SearchForGeocachesRequestProperties.FavoritePoints.MinFavoritePoints = Core.Settings.Default.LiveAPIGetGCFavMin;
                            SearchForGeocachesRequestProperties.FavoritePoints.MaxFavoritePoints = Core.Settings.Default.LiveAPIGetGCFavMax;
                            SearchForGeocachesRequestProperties.Difficulty = new LiveAPI.LiveV6.DifficultyFilter();
                            SearchForGeocachesRequestProperties.Difficulty.MinDifficulty = Core.Settings.Default.LiveAPIGetGCDifMin;
                            SearchForGeocachesRequestProperties.Difficulty.MaxDifficulty = Core.Settings.Default.LiveAPIGetGCDifMax;
                            SearchForGeocachesRequestProperties.Terrain            = new LiveAPI.LiveV6.TerrainFilter();
                            SearchForGeocachesRequestProperties.Terrain.MinTerrain = Core.Settings.Default.LiveAPIGetGCTerMin;
                            SearchForGeocachesRequestProperties.Terrain.MaxTerrain = Core.Settings.Default.LiveAPIGetGCTerMax;

                            if (Core.Settings.Default.LiveAPIGetGCExcludeArchived != null ||
                                Core.Settings.Default.LiveAPIGetGCExcludeAvailable != null ||
                                Core.Settings.Default.LiveAPIGetGCExcludePMO != null)
                            {
                                SearchForGeocachesRequestProperties.GeocacheExclusions           = new LiveAPI.LiveV6.GeocacheExclusionsFilter();
                                SearchForGeocachesRequestProperties.GeocacheExclusions.Archived  = Core.Settings.Default.LiveAPIGetGCExcludeArchived;
                                SearchForGeocachesRequestProperties.GeocacheExclusions.Available = Core.Settings.Default.LiveAPIGetGCExcludeAvailable;
                                SearchForGeocachesRequestProperties.GeocacheExclusions.Premium   = Core.Settings.Default.LiveAPIGetGCExcludePMO;
                            }
                        }
                        if (!string.IsNullOrEmpty(Core.Settings.Default.LiveAPIGetGCName))
                        {
                            SearchForGeocachesRequestProperties.GeocacheName = new LiveAPI.LiveV6.GeocacheNameFilter();
                            SearchForGeocachesRequestProperties.GeocacheName.GeocacheName = Core.Settings.Default.LiveAPIGetGCName;
                        }
                        if (Core.Settings.Default.LiveAPIMemberTypeId > 1)
                        {
                            long[] gcTypeIds = (from s in cacheTypes.AvailableTypes where s.IsChecked select(long) s.Item.ID).ToArray();
                            if (gcTypeIds.Length < cacheTypes.AvailableTypes.Count)
                            {
                                SearchForGeocachesRequestProperties.GeocacheType = new LiveAPI.LiveV6.GeocacheTypeFilter();
                                SearchForGeocachesRequestProperties.GeocacheType.GeocacheTypeIds = gcTypeIds;
                            }
                            long[] cntTypeIds = (from s in cacheContainers.AvailableTypes where s.IsChecked select(long) s.Item.ID).ToArray();
                            if (cntTypeIds.Length < cacheContainers.AvailableTypes.Count)
                            {
                                SearchForGeocachesRequestProperties.GeocacheContainerSize = new LiveAPI.LiveV6.GeocacheContainerSizeFilter();
                                SearchForGeocachesRequestProperties.GeocacheContainerSize.GeocacheContainerSizeIds = cntTypeIds;
                            }
                            if (!string.IsNullOrEmpty(Core.Settings.Default.LiveAPIGetGCExcludeFoundBy))
                            {
                                SearchForGeocachesRequestProperties.NotFoundByUsers = new LiveAPI.LiveV6.NotFoundByUsersFilter();
                                string[] parts = Core.Settings.Default.LiveAPIGetGCExcludeFoundBy.Split(new char[] { ',', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                                SearchForGeocachesRequestProperties.NotFoundByUsers.UserNames = (from s in parts select s.Trim()).ToArray();
                            }
                            if (!string.IsNullOrEmpty(Core.Settings.Default.LiveAPIGetGCExcludeHiddenBy))
                            {
                                SearchForGeocachesRequestProperties.NotHiddenByUsers = new LiveAPI.LiveV6.NotHiddenByUsersFilter();
                                string[] parts = Core.Settings.Default.LiveAPIGetGCExcludeHiddenBy.Split(new char[] { ',', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                                SearchForGeocachesRequestProperties.NotHiddenByUsers.UserNames = (from s in parts select s.Trim()).ToArray();
                            }
                        }
                        if (!string.IsNullOrEmpty(Core.Settings.Default.LiveAPIGetGCHiddenBy))
                        {
                            SearchForGeocachesRequestProperties.HiddenByUsers = new LiveAPI.LiveV6.HiddenByUsersFilter();
                            string[] parts = Core.Settings.Default.LiveAPIGetGCHiddenBy.Split(new char[] { ',', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                            SearchForGeocachesRequestProperties.HiddenByUsers.UserNames = (from s in parts select s.Trim()).ToArray();
                        }
                        if (Core.Settings.Default.LiveAPIMemberTypeId > 1)
                        {
                            //SearchForGeocachesRequestProperties.TrackableCount = new LiveAPI.LiveV6.TrackableCountFilter();
                            //SearchForGeocachesRequestProperties.TrackableCount.MinTrackables = Core.Settings.Default.LiveAPIGetGCTrackMin;
                            //SearchForGeocachesRequestProperties.TrackableCount.MaxTrackables = Core.Settings.Default.LiveAPIGetGCTrackMax;
                            SearchForGeocachesRequestProperties.TrackableLogCount = 0;
                            if (Core.Settings.Default.LiveAPIGetGCBetweenDates)
                            {
                                SearchForGeocachesRequestProperties.CachePublishedDate                 = new LiveAPI.LiveV6.CachePublishedDateFilter();
                                SearchForGeocachesRequestProperties.CachePublishedDate.Range           = new LiveAPI.LiveV6.DateRange();
                                SearchForGeocachesRequestProperties.CachePublishedDate.Range.StartDate = Core.Settings.Default.LiveAPIGetGCMinDate < Core.Settings.Default.LiveAPIGetGCMaxDate ? Core.Settings.Default.LiveAPIGetGCMinDate : Core.Settings.Default.LiveAPIGetGCMaxDate;
                                SearchForGeocachesRequestProperties.CachePublishedDate.Range.EndDate   = Core.Settings.Default.LiveAPIGetGCMaxDate > Core.Settings.Default.LiveAPIGetGCMinDate ? Core.Settings.Default.LiveAPIGetGCMaxDate : Core.Settings.Default.LiveAPIGetGCMinDate;
                            }
                        }
                        LiveAPI.Import.ImportGeocaches(Core.ApplicationData.Instance.ActiveDatabase, SearchForGeocachesRequestProperties, Core.Settings.Default.LiveAPIGetGCTotalMaximum);
                    }
                    catch (Exception e)
                    {
                        Core.ApplicationData.Instance.Logger.AddLog(this, e);
                    }
                });
            }
        }
Exemple #24
0
 public static Core.Data.Location GetLocationOfAddress(string address)
 {
     Core.Data.Location result = null;
     try
     {
         string s = null;
         HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", HttpUtility.UrlEncode(address)));
         wr.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
         wr.Method = WebRequestMethods.Http.Get;
         using (HttpWebResponse webResponse = (HttpWebResponse)wr.GetResponse())
         {
             using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
             {
                 s = reader.ReadToEnd();
                 webResponse.Close();
             }
         }
         if (s != null && s.Length > 0)
         {
             XmlDocument xdoc = new XmlDocument();
             xdoc.LoadXml(s);
             XmlNode n = xdoc.SelectSingleNode("GeocodeResponse/result/geometry/location");
             result = new Core.Data.Location(Conversion.StringToDouble(n.SelectSingleNode("lat").InnerText), Conversion.StringToDouble(n.SelectSingleNode("lng").InnerText));
         }
     }
     catch
     {
         result = null;
     }
     return result;
 }
Exemple #25
0
        async public Task SelectGeocaches()
        {
            if (Core.ApplicationData.Instance.ActiveDatabase != null)
            {
                using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase))
                {
                    await Task.Run(() =>
                    {
                        List <Core.Data.Geocache> gcList;
                        if (selectionContext.GeocacheSelectionContext == SelectionContext.Context.NewSelection)
                        {
                            gcList = Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection;
                        }
                        else if (selectionContext.GeocacheSelectionContext == SelectionContext.Context.WithinSelection)
                        {
                            gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where a.Selected select a).ToList();
                        }
                        else
                        {
                            gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where !a.Selected select a).ToList();
                        }

                        DateTime nextUpdate = DateTime.Now.AddSeconds(1);
                        using (Utils.ProgressBlock prog = new Utils.ProgressBlock("Searching", "Searching", gcList.Count, 0, true))
                        {
                            string[] foundByUsers = Core.Settings.Default.GeocacheFilterFoundBy == null ? new string[] { } : Core.Settings.Default.GeocacheFilterFoundBy.Split(',');
                            for (int i = 0; i < foundByUsers.Length; i++)
                            {
                                foundByUsers[i] = foundByUsers[i].Trim();
                            }
                            string[] notFoundByUsers = Core.Settings.Default.GeocacheFilterNotFoundBy == null ? new string[] { } : Core.Settings.Default.GeocacheFilterNotFoundBy.Split(',');
                            for (int i = 0; i < notFoundByUsers.Length; i++)
                            {
                                notFoundByUsers[i] = notFoundByUsers[i].Trim();
                            }

                            Core.Data.Location loc = null;
                            double dist            = 0;
                            if (Core.Settings.Default.GeocacheFilterLocationExpanded)
                            {
                                loc  = getLocation();
                                dist = Core.Settings.Default.GeocacheFilterLocationRadius * 1000;
                                if (Core.Settings.Default.GeocacheFilterLocationKm == BooleanEnum.False)
                                {
                                    dist /= 0.621371192237;
                                }
                            }
                            List <int> cacheTypes = new List <int>();
                            if (Core.Settings.Default.GeocacheFilterGeocacheTypesExpanded)
                            {
                                if (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterGeocacheTypes))
                                {
                                    string[] parts = Core.Settings.Default.GeocacheFilterGeocacheTypes.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                                    foreach (string s in parts)
                                    {
                                        cacheTypes.Add(int.Parse(s));
                                    }
                                }
                            }
                            List <int> cacheContainers = new List <int>();
                            if (Core.Settings.Default.GeocacheFilterGeocacheContainersExpanded)
                            {
                                if (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterGeocacheContainers))
                                {
                                    string[] parts = Core.Settings.Default.GeocacheFilterGeocacheContainers.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                                    foreach (string s in parts)
                                    {
                                        cacheContainers.Add(int.Parse(s));
                                    }
                                }
                            }
                            List <int> cacheAttributes = new List <int>();
                            if (Core.Settings.Default.GeocacheFilterGeocacheAttributesExpanded)
                            {
                                if (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterGeocacheAttributes))
                                {
                                    string[] parts = Core.Settings.Default.GeocacheFilterGeocacheAttributes.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                                    foreach (string s in parts)
                                    {
                                        cacheAttributes.Add(int.Parse(s));
                                    }
                                }
                            }

                            if (loc != null || !Core.Settings.Default.GeocacheFilterLocationExpanded)
                            {
                                //set selected within gcList
                                int index = 0;
                                foreach (var gc in gcList)
                                {
                                    gc.Selected = (
                                        (!Core.Settings.Default.GeocacheFilterStatusExpanded || ((Core.Settings.Default.GeocacheFilterGeocacheStatus == GeocacheStatus.Enabled && gc.Available) ||
                                                                                                 (Core.Settings.Default.GeocacheFilterGeocacheStatus == GeocacheStatus.Disabled && !gc.Available && !gc.Archived) ||
                                                                                                 (Core.Settings.Default.GeocacheFilterGeocacheStatus == GeocacheStatus.Archived && gc.Archived))) &&
                                        (!Core.Settings.Default.GeocacheFilterOwnExpanded || ((Core.Settings.Default.GeocacheFilterOwn == BooleanEnum.True) == gc.IsOwn)) &&
                                        (!Core.Settings.Default.GeocacheFilterFoundExpanded || ((Core.Settings.Default.GeocacheFilterFound == BooleanEnum.True) == gc.Found)) &&
                                        (!Core.Settings.Default.GeocacheFilterFoundByExpanded || ((Core.Settings.Default.GeocacheFilterFoundByAll == BooleanEnum.True) && foundByAll(gc, foundByUsers)) ||
                                         ((Core.Settings.Default.GeocacheFilterFoundByAll == BooleanEnum.False) && foundByAny(gc, foundByUsers))) &&
                                        (!Core.Settings.Default.GeocacheFilterNotFoundByExpanded || ((Core.Settings.Default.GeocacheFilterNotFoundByAny == BooleanEnum.True) && !foundByAny(gc, foundByUsers)) ||
                                         ((Core.Settings.Default.GeocacheFilterNotFoundByAny == BooleanEnum.False) && !foundByAll(gc, foundByUsers))) &&
                                        (!Core.Settings.Default.GeocacheFilterLocationExpanded || (Utils.Calculus.CalculateDistance(gc, loc).EllipsoidalDistance <= dist)) &&
                                        (!Core.Settings.Default.GeocacheFilterCountryStateExpanded || (string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterCountry) || (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterCountry) && string.Compare(gc.Country, Core.Settings.Default.GeocacheFilterCountry, true) == 0)) &&
                                         (string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterState) || (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterState) && string.Compare(gc.State, Core.Settings.Default.GeocacheFilterState, true) == 0))) &&
                                        (!Core.Settings.Default.GeocacheFilterMunicipalityCityExpanded || (string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterMunicipality) || (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterMunicipality) && string.Compare(gc.Municipality, Core.Settings.Default.GeocacheFilterMunicipality, true) == 0)) &&
                                         (string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterCity) || (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterCity) && string.Compare(gc.City, Core.Settings.Default.GeocacheFilterCity, true) == 0))) &&
                                        (!Core.Settings.Default.GeocacheFilterGeocacheTypesExpanded || (cacheTypes.Contains(gc.GeocacheType.ID))) &&
                                        (!Core.Settings.Default.GeocacheFilterGeocacheContainersExpanded || (cacheContainers.Contains(gc.Container.ID))) &&
                                        (!Core.Settings.Default.GeocacheFilterFavExpanded || (gc.Favorites >= Core.Settings.Default.GeocacheFilterMinFav && gc.Favorites <= Core.Settings.Default.GeocacheFilterMaxFav)) &&
                                        (!Core.Settings.Default.GeocacheFilterTerrainExpanded || ((gc.Terrain >= Core.Settings.Default.GeocacheFilterMinTerrain) && (gc.Terrain <= Core.Settings.Default.GeocacheFilterMaxTerrain))) &&
                                        (!Core.Settings.Default.GeocacheFilterDifficultyExpanded || ((gc.Difficulty >= Core.Settings.Default.GeocacheFilterMinDifficulty) && (gc.Difficulty <= Core.Settings.Default.GeocacheFilterMaxDifficulty))) &&
                                        (!Core.Settings.Default.GeocacheFilterHiddenDateExpanded || (gc.PublishedTime.Date >= Core.Settings.Default.GeocacheFilterMinHiddenDate.Date && gc.PublishedTime.Date <= Core.Settings.Default.GeocacheFilterMaxHiddenDate.Date)) &&
                                        (!Core.Settings.Default.GeocacheFilterGeocacheAttributesExpanded || attrFilterPass(cacheAttributes, gc))
                                        );

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