Beispiel #1
0
        private static void getAllEvent(IAsyncResult result)
        {
            try
            {
                HttpWebRequest httpRequest = (HttpWebRequest)result.AsyncState;
                WebResponse webResponse = httpRequest.EndGetResponse(result);

                Stream stream = webResponse.GetResponseStream();
                StreamReader streamReader = new StreamReader(stream);
                string text = streamReader.ReadToEnd();

                if (text == "Brak ostatnich lokalizacji znajomych.")
                {
                    isThereFriendsLoc = false;
                    WhenNoFriends();
                }
                else
                {
                    List<UnknownUser> unknownList = new List<UnknownUser>();
                    string[] words = text.Split('{');
                    const string patternForClassify = @".*user_id"":(.*),""latitude"":""(.*)"",""longitude"":""(.*)"",""created_at.*";
                    Regex rExtractToClassify = new Regex(patternForClassify, RegexOptions.IgnoreCase);
                    Match mExtract;
                    Group g0;
                    Group g1;
                    Group g2;
                    Group g3;

                    for (int i = 1; i < words.Length; i++)
                    {
                        mExtract = rExtractToClassify.Match(words[i]);
                        g1 = mExtract.Groups[1];
                        g2 = mExtract.Groups[2];
                        g3 = mExtract.Groups[3];
                        int usrID = Int16.Parse(g1.ToString());
                        Double usrLat = Double.Parse(g2.ToString());
                        Double usrLong = Double.Parse(g3.ToString());
                        UnknownUser unkUs = new UnknownUser(usrID, usrLong, usrLat);
                        unknownList.Add(unkUs);
                    }
                    WhenAllLoc(unknownList);
                }
                streamReader.Dispose();
            }
            catch (WebException ex)
            {
                WhenErrorOccurs(ex.ToString());
            }
        }
Beispiel #2
0
        private bool IsInRange(GeoCoordinate geoCoordinate, UnknownUser unknUs, int range)
        {
            bool result;
            double distance = 0.0;
            GeoCoordinate unknUsCoord = new GeoCoordinate();
            unknUsCoord.Latitude = unknUs.os_lastLat;
            unknUsCoord.Longitude = unknUs.os_lastLong;
            distance = geoCoordinate.GetDistanceTo(unknUsCoord);

            if (distance > double.Parse(range.ToString()))
                result = false;
            else
                result = true;
            return result;
        }