public Asset GetAsset(string rootUrl, string path) { if (!this._pathToAssetMap.ContainsKey(path)) { throw new AssetNotFound(string.Format("Mapping not found - {0}", (object)path)); } EmbeddedAssetDescriptor pathToAsset = this._pathToAssetMap[path]; return(new Asset(this.GetEmbeddedResourceStreamFor(pathToAsset, rootUrl), EmbeddedAssetProvider.InferMediaTypeFrom(pathToAsset.Name))); }
private Stream GetEmbeddedResourceStreamFor(EmbeddedAssetDescriptor resourceDescriptor, string rootUrl) { var stream = resourceDescriptor.Assembly.GetManifestResourceStream(resourceDescriptor.Name); if (stream == null) throw new AssetNotFound(String.Format("Embedded resource not found - {0}", resourceDescriptor.Name)); if (resourceDescriptor.IsTemplate) { var templateParams = _templateParams .Union(new[] { new KeyValuePair<string, string>("%(RootUrl)", rootUrl) }) .ToDictionary(entry => entry.Key, entry => entry.Value); return stream.FindAndReplace(templateParams); } return stream; }
private Stream GetEmbeddedResourceStreamFor(EmbeddedAssetDescriptor resourceDescriptor, string rootUrl) { var stream = resourceDescriptor.Assembly.GetManifestResourceStream(resourceDescriptor.Name); if (stream == null) { throw new AssetNotFound(String.Format("Embedded resource not found - {0}", resourceDescriptor.Name)); } if (resourceDescriptor.IsTemplate) { var templateParams = _templateParams .Union(new[] { new KeyValuePair <string, string>("%(RootUrl)", rootUrl) }) .ToDictionary(entry => entry.Key, entry => entry.Value); return(stream.FindAndReplace(templateParams)); } return(stream); }
private Stream GetEmbeddedResourceStreamFor( EmbeddedAssetDescriptor resourceDescriptor, string rootUrl) { Stream manifestResourceStream = resourceDescriptor.Assembly.GetManifestResourceStream(resourceDescriptor.Name); if (manifestResourceStream == null) { throw new AssetNotFound(string.Format("Embedded resource not found - {0}", (object)resourceDescriptor.Name)); } if (!resourceDescriptor.IsTemplate) { return(manifestResourceStream); } Dictionary <string, string> dictionary = this._templateParams.Union <KeyValuePair <string, string> >((IEnumerable <KeyValuePair <string, string> >) new KeyValuePair <string, string>[1] { new KeyValuePair <string, string>("%(RootUrl)", rootUrl) }).ToDictionary <KeyValuePair <string, string>, string, string>((Func <KeyValuePair <string, string>, string>)(entry => entry.Key), (Func <KeyValuePair <string, string>, string>)(entry => entry.Value)); return(manifestResourceStream.FindAndReplace((IDictionary <string, string>)dictionary)); }
public void CustomAsset(string path, Assembly resourceAssembly, string resourceName) { _pathToAssetMap[path] = new EmbeddedAssetDescriptor(resourceAssembly, resourceName, path == "index"); }
private void MapPathsForSwaggerUiAssets() { var thisAssembly = GetType().Assembly; foreach (var resourceName in thisAssembly.GetManifestResourceNames()) { if (resourceName.Contains("Swashbuckle.SwaggerUi.CustomAssets")) continue; // original assets only var path = resourceName .Replace("\\", "/") .Replace(".", "-"); // extensionless to avoid RUMMFAR _pathToAssetMap[path] = new EmbeddedAssetDescriptor(thisAssembly, resourceName, path == "index"); } }