示例#1
0
        public async Task <string> GetFile(string relativePath)
        {
            int    attempts = 0;
            string uri      = BaseUrl.EndsWith("/") ? $"{BaseUrl}{relativePath}" : $"{BaseUrl}/{relativePath}";

            while (attempts < 3)
            {
                attempts++;

                try
                {
                    HttpResponseMessage response = await HttpClient.GetAsync(uri);

                    if (!response.IsSuccessStatusCode)
                    {
                        continue;
                    }

                    return(await response.Content.ReadAsStringAsync());
                }
                catch
                {
                    continue;
                }
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// Set the default config values
        /// </summary>
        public void SetDefaultValues()
        {
            if (Server != null && Server.Count > 0)
            {
                string s;

                for (int i = 0; i < Server.Count; i++)
                {
                    s = Server[i];

                    // make it easier to pass server value
                    if (!s.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                    {
                        if (s.StartsWith("localhost", StringComparison.OrdinalIgnoreCase) || s.StartsWith("127.0.0.1", StringComparison.OrdinalIgnoreCase))
                        {
                            Server[i] = $"http://{s}";
                        }
                        else
                        {
                            Server[i] = $"https://{s}.azurewebsites.net";
                        }
                    }
                }
            }

            // add a trailing slash if necessary
            if (!string.IsNullOrWhiteSpace(BaseUrl) && !BaseUrl.EndsWith('/'))
            {
                BaseUrl += "/";
            }
        }
示例#3
0
        private string BuildEndpoint()
        {
            var sb = new StringBuilder(50);

            sb.Append(BaseUrl);

            if (string.IsNullOrWhiteSpace(Controller))
            {
                return(sb.ToString());
            }

            if (!BaseUrl.EndsWith("/"))
            {
                sb.Append("/");
            }

            sb.Append(Controller.ToLower());

            if (!Controller.EndsWith("/"))
            {
                sb.Append("/");
            }

            if (!string.IsNullOrWhiteSpace(Id) && !string.IsNullOrEmpty(Id))
            {
                sb.Append(Id.ToLower());
            }

            if (!string.IsNullOrWhiteSpace(Action))
            {
                sb.Append("/").Append(Action.ToLower());
            }

            return(sb.ToString());
        }
示例#4
0
        public override async Task <Uri> GetInitialUrl()
        {
            var scope     = string.Join("%20", Scope.Select(HttpUtility.UrlEncode));
            var delimiter = BaseUrl.EndsWith("?", StringComparison.CurrentCultureIgnoreCase) ? "" : "?";
            var url       = $"{BaseUrl}{delimiter}client_id={ClientId}&scope={scope}&response_type=token&redirect_url={RedirectUrl.AbsoluteUri}";

            return(new Uri(url));
        }
示例#5
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        public virtual async Task <Uri> GetInitialUrl()
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            var scope     = string.Join("%20", Scope.Select(HttpUtility.UrlEncode));
            var delimiter = BaseUrl.EndsWith("?", StringComparison.CurrentCultureIgnoreCase) ? "" : "?";
            var url       = $"{BaseUrl}{delimiter}client_id={ClientId}&scope={scope}&response_type=code&redirect_uri={RedirectUrl.AbsoluteUri}";

            return(new Uri(url));
        }
示例#6
0
 public PdfDocument(string baseUrl = null, PdfSettings settings = null)
 {
     Settings = settings ?? new PdfSettings();
     BaseUrl  = baseUrl ?? Environment.CurrentDirectory;
     // make sure baseUrl always ends with directory seperator
     if (!BaseUrl.EndsWith(Path.DirectorySeparatorChar.ToString()))
     {
         BaseUrl += Path.DirectorySeparatorChar;
     }
 }
        public virtual IGeocodingQuery FindLocation()
        {
            if (string.IsNullOrEmpty(BaseUrl))
            {
                throw new ArgumentException("BaseUrl");
            }

            string template = BaseUrl.EndsWith("/") ? "{0}{1}" : "{0}/{1}";
            var    baseUrl  = string.Format(template, BaseUrl, Format);

            return(new GeocodingQuery(baseUrl, ApiKey));
        }
示例#8
0
        /// <summary>
        /// Set the default config values
        /// </summary>
        public void SetDefaultValues()
        {
            if (Server != null && Server.Count > 0)
            {
                string s;

                for (int i = 0; i < Server.Count; i++)
                {
                    s = Server[i];

                    // make it easier to pass server value
                    if (!s.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                    {
                        if (s.StartsWith("localhost", StringComparison.OrdinalIgnoreCase) || s.StartsWith("127.0.0.1", StringComparison.OrdinalIgnoreCase))
                        {
                            Server[i] = $"http://{s}";
                        }
                        else
                        {
                            Server[i] = $"https://{s}.azurewebsites.net";
                        }
                    }
                }
            }

            // add a trailing slash if necessary
            if (!string.IsNullOrWhiteSpace(BaseUrl) && !BaseUrl.EndsWith('/'))
            {
                BaseUrl += "/";
            }

            // set json options based on --strict-json
            App.JsonSerializerOptions = new JsonSerializerOptions
            {
                PropertyNamingPolicy        = JsonNamingPolicy.CamelCase,
                PropertyNameCaseInsensitive = !StrictJson,
                AllowTrailingCommas         = !StrictJson,
                ReadCommentHandling         = StrictJson ? JsonCommentHandling.Disallow : JsonCommentHandling.Skip,
            };

            Zone   = string.IsNullOrWhiteSpace(Zone) ? string.Empty : Zone;
            Region = string.IsNullOrWhiteSpace(Region) ? string.Empty : Region;
        }
示例#9
0
        /// <summary>
        /// Creates a url <see cref="string"/> by combining <see cref="BaseUrl"/> with <paramref name="path"/>.
        /// Resorts to using <see cref="DefaultPath"/> if <paramref name="path"/> is <c>null</c> or
        /// <see cref="string.Empty"/>.
        /// </summary>
        /// <param name="path">The path to be appended to <see cref="BaseUrl"/> if provided, otherwise
        /// <see cref="DefaultPath"/> will be used.</param>
        /// <returns>A url <see cref="string"/> consisting of <see cref="BaseUrl"/> and <paramref name="path"/> or
        /// <see cref="DefaultPath"/>.</returns>
        /// <remarks>Inserts a slash (/) between <see cref="BaseUrl"/> and <paramref name="path"/> if
        /// <see cref="BaseUrl"/> does not end with one and <paramref name="path"/> does not begin with one.</remarks>
        private static string GetCompleteUrl(string path)
        {
            if (string.IsNullOrEmpty(BaseUrl))
            {
                Debug.LogError("BaseUrl must be set.");
                return(null);
            }

            if (string.IsNullOrEmpty(path))
            {
                path = DefaultPath ?? string.Empty;
            }
            var shouldInsertSlash = !path.StartsWith("/", StringComparison.OrdinalIgnoreCase) ||
                                    !BaseUrl.EndsWith("/", StringComparison.OrdinalIgnoreCase);

            var url = string.Format("{0}{1}{2}", BaseUrl, shouldInsertSlash ? "/" : string.Empty, path);

            return(url);
        }
示例#10
0
        public void SetDefaultValues()
        {
            // make it easier to pass server value
            if (!Server.StartsWith("http", StringComparison.OrdinalIgnoreCase))
            {
                if (Server.StartsWith("localhost", StringComparison.OrdinalIgnoreCase) || Server.StartsWith("127.0.0.1", StringComparison.OrdinalIgnoreCase))
                {
                    Server = "http://" + Server;
                }
                else
                {
                    Server = string.Format(CultureInfo.InvariantCulture, $"https://{Server}.azurewebsites.net");
                }
            }

            // add a trailing slash if necessary
            if (!string.IsNullOrEmpty(BaseUrl) && !BaseUrl.EndsWith('/'))
            {
                BaseUrl += "/";
            }
        }
示例#11
0
        public Configuration(Ini ini)
        {
            BaseUrl = ini.ReadString("Config", "BaseUrl");
            if (!BaseUrl.EndsWith("/"))
            {
                BaseUrl += "/";
            }
            if (!BaseUrl.EndsWith("api/v1/"))
            {
                BaseUrl += "api/v1/";
            }
            ApiSecretHash  = Sha1(ini.ReadString("Config", "APISecret"));
            UpdateInterval = ini.ReadInt("Config", "UpdateInterval");
            High           = ini.ReadFloat("Config", "High");
            Low            = ini.ReadFloat("Config", "Low");
            try
            {
                Unit = ini.ReadEnum <Unit>("Config", "Unit");
            }
            catch
            {
                // backward compatibility
                Unit = Unit.mgdl;
            }
            UseColor      = ini.ReadBool("Config", "UseColor");
            UseAlarm      = ini.ReadBool("Config", "UseAlarm");
            AlarmInterval = ini.ReadInt("Config", "AlarmInterval");
            TimeRange     = Math.Min(ini.ReadInt("Config", "TimeRange"), 6);
            StyleKey styleKey = ini.ReadEnum <StyleKey>("Config", "Style");

            Style      = (BaseStyle)Activator.CreateInstance(_styles[styleKey]);
            Width      = ini.ReadInt("Config", "Width");
            Height     = ini.ReadInt("Config", "Height");
            FontFamily = ini.ReadString("Config", "FontFamily");
            FontSize   = ini.ReadInt("Config", "FontSize");
        }
示例#12
0
        public Uri GetBaseAddress()
        {
            var withTrailingSlash = BaseUrl + (BaseUrl.EndsWith("/") ? "" : "/");

            return(new Uri(withTrailingSlash));
        }