示例#1
0
        public void DistanceBetweenTest()
        {
            List <GpsLocation> inputs = new List <GpsLocation>()
            {
                new GpsLocation(0.0m, 0.0m),               // Zero GPS coordinates, south of Ghana
                new GpsLocation(40.748456m, -73.985478m),  // Empire State Building, New York, US
                new GpsLocation(36.190970m, -115.122701m), // Hartke Park, Las Vegas, US
                new GpsLocation(73.507778m, 80.537315m),   // Dikson Island, Russia
                new GpsLocation(-23.441061m, 144.251703m), // Anzac Park, Longreach, Australia
                new GpsLocation(40.757961m, -73.985591m),  // Times Square, New York, US
            };

            List <double> expectedDistances = new List <double>()
            {
                // Zero GPS to
                8666100,  // Empire State Building
                12235660, // Hartke Park
                9710095,  // Dikson Island
                15358880, // Anzac Park
                8666310,  // Times Square

                // Empire State Building to
                3583950,  // Hartke Park
                7163460,  // Dikson Island
                15975200, // Anzac Park
                1057,     // Times Square

                // Hartke Park to
                7759500,  // Dikson Island
                12432000, // Anzac Park
                3583840,  // Times Square

                // Dikson Island
                11723525, // Anzac Park
                7162410,  // Times Square

                // Anzac Park
                15974880, // Times Square
            };

            int index = 0;

            for (int i = 0; i < inputs.Count - 1; i++)
            {
                for (int j = i + 1; j < inputs.Count; j++)
                {
                    double distance = GpsLocation.DistanceBetween(inputs[i], inputs[j]);
                    Assert.True(distance.ApproxEqual(expectedDistances[index], 10));
                    index++;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Retrieves a list of profile names that should be found within specific area.
        /// </summary>
        /// <param name="Location">GPS location of the centre of the target area.</param>
        /// <param name="Radius">Radius of the target area in metres.</param>
        /// <returns>List of matchin profile names.</returns>
        public static List <string> GetProfileNamesInLocation(GpsLocation Location, uint Radius)
        {
            List <string> res = new List <string>();

            for (int i = 0; i < ProfileNames.Count; i++)
            {
                string      name            = ProfileNames[i];
                GpsLocation profileLocation = ProfileLocations[i];

                double distance = GpsLocation.DistanceBetween(Location, profileLocation);
                if (distance < (double)Radius)
                {
                    res.Add(name);
                }
            }

            return(res);
        }
示例#3
0
        /// <summary>
        /// Retrieves a list of clients that should be found within specific area.
        /// </summary>
        /// <param name="Location">GPS location of the centre of the target area.</param>
        /// <param name="Radius">Radius of the target area in metres.</param>
        /// <returns>List of matchin profile names.</returns>
        public static Dictionary <string, ProtocolClient> GetClientsInLocation(GpsLocation Location, uint Radius)
        {
            Dictionary <string, ProtocolClient> res = new Dictionary <string, ProtocolClient>(StringComparer.Ordinal);

            for (int i = 0; i < ProfileNames.Count; i++)
            {
                string         name            = ProfileNames[i];
                ProtocolClient client          = TestProfiles[name];
                GpsLocation    profileLocation = ProfileLocations[i];

                double distance = GpsLocation.DistanceBetween(Location, profileLocation);
                if (distance < (double)Radius)
                {
                    res.Add(name, client);
                }
            }

            return(res);
        }
示例#4
0
        /// <summary>
        /// Checks whether the client's identity matches specific search query.
        /// </summary>
        /// <param name="NameFilter">Name filter of the search query, or null if name filtering is not required.</param>
        /// <param name="TypeFilter">Type filter of the search query, or null if type filtering is not required.</param>
        /// <param name="LocationFilter">Location filter of the search query, or null if location filtering is not required.</param>
        /// <param name="Radius">If <paramref name="LocationFilter"/> is not null, this is the radius in metres of the target area.</param>
        /// <returns>true if the identity matches the query, false otherwise.</returns>
        public bool MatchesSearchQuery(string NameFilter, string TypeFilter, GpsLocation LocationFilter, int Radius)
        {
            log.Trace("(NameFilter:'{0}',TypeFilter:'{1}',LocationFilter:'{2}',Radius:{3})", NameFilter, TypeFilter, LocationFilter, Radius);

            bool res = false;

            // Do not include if the profile is unintialized or hosting cancelled.
            if (profileInitialized && hostingActive)
            {
                bool matchType     = false;
                bool useTypeFilter = !string.IsNullOrEmpty(TypeFilter) && (TypeFilter != "*") && (TypeFilter != "**");
                if (useTypeFilter)
                {
                    string value       = type.ToLowerInvariant();
                    string filterValue = TypeFilter.ToLowerInvariant();
                    matchType = value == filterValue;

                    bool valueStartsWith = TypeFilter.EndsWith("*");
                    bool valueEndsWith   = TypeFilter.StartsWith("*");
                    bool valueContains   = valueStartsWith && valueEndsWith;

                    if (valueContains)
                    {
                        filterValue = filterValue.Substring(1, filterValue.Length - 2);
                        matchType   = value.Contains(filterValue);
                    }
                    else if (valueStartsWith)
                    {
                        filterValue = filterValue.Substring(0, filterValue.Length - 1);
                        matchType   = value.StartsWith(filterValue);
                    }
                    else if (valueEndsWith)
                    {
                        filterValue = filterValue.Substring(1);
                        matchType   = value.EndsWith(filterValue);
                    }
                }
                else
                {
                    matchType = true;
                }

                bool matchName     = false;
                bool useNameFilter = !string.IsNullOrEmpty(NameFilter) && (NameFilter != "*") && (NameFilter != "**");
                if (useNameFilter)
                {
                    string value       = name.ToLowerInvariant();
                    string filterValue = NameFilter.ToLowerInvariant();
                    matchName = value == filterValue;

                    bool valueStartsWith = NameFilter.EndsWith("*");
                    bool valueEndsWith   = NameFilter.StartsWith("*");
                    bool valueContains   = valueStartsWith && valueEndsWith;

                    if (valueContains)
                    {
                        filterValue = filterValue.Substring(1, filterValue.Length - 2);
                        matchName   = value.Contains(filterValue);
                    }
                    else if (valueStartsWith)
                    {
                        filterValue = filterValue.Substring(0, filterValue.Length - 1);
                        matchName   = value.StartsWith(filterValue);
                    }
                    else if (valueEndsWith)
                    {
                        filterValue = filterValue.Substring(1);
                        matchName   = value.EndsWith(filterValue);
                    }
                }
                else
                {
                    matchName = true;
                }

                if (matchType && matchName)
                {
                    bool matchLocation = false;
                    if (LocationFilter != null)
                    {
                        double distance = GpsLocation.DistanceBetween(LocationFilter, location);
                        matchLocation = distance <= (double)Radius;
                    }
                    else
                    {
                        matchLocation = true;
                    }

                    res = matchLocation;
                }
            }

            log.Trace("(-):{0}", res);
            return(res);
        }