示例#1
0
        public static UriErrorPair BuildFourSquareUri(string method, GeoMethodType geoType, params string[] components)
        {
            Exception er = null;
            var       d  = new Dictionary <string, string>();

            EnsureCredentials();

            if (geoType != GeoMethodType.None)
            {
                var la = LocationAssistant.Instance.LastKnownLocation;
                if (la == null)
                {
                    string error =
                        "The location service has been turned off, so this feature is unfortunately not available.";

                    // TODO: Consider whether this is a fatal condition or not. 4S seems to indicate that it isn't really a big deal.
                    if (geoType == GeoMethodType.Required)
                    {
                        // Want this to get handled outside this scope.
                        // TODO: Understand if this is a good idea or not.
                        Debug.WriteLine("GeoMethodType Required, check failed.");

                        /*PriorityQueue.AddUiWorkItem(() =>
                         *  {
                         *      throw new UserIntendedException(error, "GeoMethodType was Required.");
                         *  });*/
                        er = new UserIntendedException(error, "GeoMethodType was Required.");
                    }
                    else
                    {
                        Debug.WriteLine(error);
                    }
                }
                else
                {
                    if (!double.IsNaN(la.Latitude) && !double.IsNaN((la.Longitude)))
                    {
                        d["ll"] = la.Latitude.ToString(CultureInfo.InvariantCulture) +
                                  "," + la.Longitude.ToString(CultureInfo.InvariantCulture);
                        if (!double.IsNaN(la.HorizontalAccuracy))
                        {
                            d["llAcc"] = la.HorizontalAccuracy.ToString(CultureInfo.InvariantCulture);
                        }
                        if (!double.IsNaN(la.VerticalAccuracy) && la.VerticalAccuracy != 0.0 && !double.IsNaN(la.Altitude))
                        {
                            d["altAcc"] = la.VerticalAccuracy.ToString(CultureInfo.InvariantCulture);
                            d["alt"]    = la.Altitude.ToString(CultureInfo.InvariantCulture);
                        }
                    }
                }
            }

            // API version.
            d["v"] = _apiVersion;

            // Will allow for override from the method inputs:))
            if (components != null && components.Length > 0)
            {
                // Can overrun if not even number. Messy code!
                for (int i = 0; i < components.Length; i += 2)
                {
                    d[components[i]] = components[i + 1];
                }
            }

            var sb = new StringBuilder();

            sb.Append(FourSquarePrefix);

            // Method name. Should have .json after for json return types.
            sb.Append(method);

            // I always expect this since I add an oauth_token afterwards.
            sb.Append("?");
            foreach (var c in d)
            {
                sb.Append(c.Key);
                sb.Append("=");
                sb.Append(Uri.EscapeDataString(c.Value));
                sb.Append("&");
            }

            Uri uri = new Uri(sb.ToString(), UriKind.Absolute);

            return(new UriErrorPair(uri, er));
        }
        public static UriErrorPair BuildFourSquareUri(string method, GeoMethodType geoType, params string[] components)
        {
            Exception er = null;
            var d = new Dictionary<string, string>();

            EnsureCredentials();

            if (geoType != GeoMethodType.None)
            {
                var la = LocationAssistant.Instance.LastKnownLocation;
                if (la == null)
                {
                    string error =
                        "The location service has been turned off, so this feature is unfortunately not available.";

                    // TODO: Consider whether this is a fatal condition or not. 4S seems to indicate that it isn't really a big deal.
                    if (geoType == GeoMethodType.Required)
                    {
                        // Want this to get handled outside this scope.
                        // TODO: Understand if this is a good idea or not.
                        Debug.WriteLine("GeoMethodType Required, check failed.");
                        /*PriorityQueue.AddUiWorkItem(() =>
                            {
                                throw new UserIntendedException(error, "GeoMethodType was Required.");
                            });*/
                        er = new UserIntendedException(error, "GeoMethodType was Required.");
                    }
                    else
                    {
                        Debug.WriteLine(error);
                    }
                }
                else
                {
                    if (!double.IsNaN(la.Latitude) && !double.IsNaN((la.Longitude)))
                    {
                        d["ll"] = la.Latitude.ToString(CultureInfo.InvariantCulture) +
                            "," + la.Longitude.ToString(CultureInfo.InvariantCulture);
                        if (!double.IsNaN(la.HorizontalAccuracy))
                        {
                            d["llAcc"] = la.HorizontalAccuracy.ToString(CultureInfo.InvariantCulture);
                        }
                        if (!double.IsNaN(la.VerticalAccuracy) && la.VerticalAccuracy != 0.0 && !double.IsNaN(la.Altitude))
                        {
                            d["altAcc"] = la.VerticalAccuracy.ToString(CultureInfo.InvariantCulture);
                            d["alt"] = la.Altitude.ToString(CultureInfo.InvariantCulture);
                        }
                    }
                }
            }

            // API version.
            d["v"] = _apiVersion;

            // Will allow for override from the method inputs:))
            if (components != null && components.Length > 0)
            {
                // Can overrun if not even number. Messy code!
                for (int i = 0; i < components.Length; i += 2)
                {
                    d[components[i]] = components[i + 1];
                }
            }

            var sb = new StringBuilder();
            sb.Append(FourSquarePrefix);

            // Method name. Should have .json after for json return types.
            sb.Append(method);

            // I always expect this since I add an oauth_token afterwards.
            sb.Append("?");
            foreach (var c in d)
            {
                sb.Append(c.Key);
                sb.Append("=");
                sb.Append(Uri.EscapeDataString(c.Value));
                sb.Append("&");
            }

            Uri uri = new Uri(sb.ToString(), UriKind.Absolute);

            return new UriErrorPair(uri, er);
        }