Example #1
0
        /// <summary>
        /// Gets the url for the given resource path and configuration.
        /// </summary>
        /// <remarks>
        /// Note that the resource url (e.g. <c>http://icons.com/myicon.svg</c>) does not equal the resource uri (e.g. <c>rsrc:myicon</c>).
        /// </remarks>
        /// <param name="resourcePath">The path of the resource.</param>
        /// <param name="configuration">The (source) configuration for the resource.</param>
        private string GetResourceUrl(string resourcePath, IconSourceConfiguration configuration)
        {
            // Remove preceding slashes
            resourcePath = resourcePath.TrimStart('/');

            switch (configuration.Source)
            {
            case IconSource.SymbolFile:
                return(configuration.SymbolFile + "#" + resourcePath);

            case IconSource.Directory:

                // Prepare base path
                var basePath = configuration.Directory;
                if (!string.IsNullOrEmpty(basePath) &&
                    !basePath.EndsWith("/"))
                {
                    basePath += "/";
                }

                return(basePath + (Path.HasExtension(resourcePath) ? resourcePath : resourcePath + ".svg"));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #2
0
        /// <summary>
        /// Gets the (source) configuration for the given resource.
        /// </summary>
        /// <param name="resourceUri">An uri pointing to a resource.</param>
        /// <param name="configuration">The (source) configuration for the resource.</param>
        private bool TryGetResourceSource(Uri?resourceUri, [MaybeNullWhen(false)] out IconSourceConfiguration configuration)
        {
            configuration = null;

            return(resourceUri != null &&
                   resourceUri.IsAbsoluteUri &&
                   resourceUri.Scheme == "rsrc" &&
                   !string.IsNullOrEmpty(resourceUri.AbsolutePath.Trim('/')) &&
                   _options.TryGetSource(resourceUri.Authority, out configuration));
        }