public void VerifyIconsForLibraryItems() { var iconProvider = new IconResourceProvider(GetModel().PathManager); var request = new Mock <IRequest>(); var resource = "ViewExtensionLibraryTests.resources.libraryItems.json"; using (var s = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource)) { var data = GetLoadedTypesFromJson(s); var types = data.loadedTypes; var unresolved = new List <LoadedTypeItem>(); foreach (var item in types) { request.Setup(r => r.Url).Returns(item.iconUrl); string extension = "txt"; using (var stream = iconProvider.GetResource(request.Object, out extension)) { Assert.AreEqual("png", extension); if (stream == null || stream.Length == 0) { unresolved.Add(item); } } } var sb = new StringBuilder(); unresolved.ForEach(e => { var url = new IconUrl(new Uri(e.iconUrl)); sb.AppendFormat("Node: {0}, Image: {1}/{2}\n", e.fullyQualifiedName, url.Name, url.Path); }); Assert.AreEqual(0, unresolved.Count, sb.ToString()); } }
/// <summary> /// creates the resource providers that are used throughout the extensions lifetime /// to retrieve images and other resource files from disk. /// </summary> /// <param name="model"></param> /// <param name="customization"></param> private void InitializeResourceProviders(DynamoModel model, LibraryViewCustomization customization) { var dllProvider = new DllResourceProvider("http://localhost/dist", "Dynamo.LibraryViewExtensionMSWebBrowser.web.library"); iconProvider = new IconResourceProvider(model.PathManager, dllProvider, customization); nodeProvider = new NodeItemDataProvider(model.SearchModel, iconProvider); searchResultDataProvider = new SearchResultDataProvider(model.SearchModel, iconProvider); layoutProvider = new LayoutSpecProvider(customization, iconProvider, "Dynamo.LibraryViewExtensionMSWebBrowser.web.library.layoutSpecs.json"); }
private string getBase64ImageString(LayoutIncludeInfo item, IconResourceProvider iconProvider) { var ext = string.Empty; var iconAsBase64 = iconProvider.GetResourceAsString(item.iconUrl, out ext); if (string.IsNullOrEmpty(iconAsBase64)) { return(""); } if (ext.Contains("svg")) { ext = "svg+xml"; } return($"data:image/{ext};base64, {iconAsBase64}"); }
public void ConcurrentIconRequest() { var resetevent = new AutoResetEvent(false); var requests = (new[] { "A", "B", "C", "D", "E" }) .Select(s => new IconUrl(s, s)) .Select(icon => { var req = new Mock <IRequest>(); req.Setup(r => r.Url).Returns(icon.Url); return(req); }).ToList(); var pathmanager = new Mock <IPathManager>(); var provider = new IconResourceProvider(pathmanager.Object); string ext; var result = Parallel.ForEach(requests, r => Assert.IsNotNull(provider.GetResource(r.Object, out ext))); resetevent.WaitOne(250); Assert.IsTrue(result.IsCompleted); }
//layoutSpec helpers /// <summary> /// Serializes the layout specification to json stream and /// optionally replaces icon urls with image data as base64 encoded strings /// </summary> /// <returns></returns> private Stream ToJSONStream(LayoutSpecification spec, bool replaceIconURLWithData, IconResourceProvider iconProvider = null) { var ms = new MemoryStream(); var sw = new StreamWriter(ms); if (replaceIconURLWithData && iconProvider != null) { //foreach section update all nested children and nested includes, and root iconurls to image data. spec.sections.ForEach(section => { section.iconUrl = getBase64ImageString(section, iconProvider); section.EnumerateChildren().ToList().ForEach(child => child.iconUrl = getBase64ImageString(child, iconProvider)); section.EnumerateIncludes().ToList().ForEach(child => child.iconUrl = getBase64ImageString(child, iconProvider)); }); } var serializer = new JsonSerializer() { Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore }; serializer.Serialize(sw, spec); sw.Flush(); ms.Position = 0; return(ms); }
/// <summary> /// Serializes the current specification to JSON stream and optionally replaces icon urls with images as base64 data /// </summary> public Stream ToJSONStream(bool replaceIconURLWithData, IconResourceProvider iconResourceProvider = null) { return(ToJSONStream(root, replaceIconURLWithData, iconResourceProvider)); }
public NodeItemDataProvider(NodeSearchModel model, IconResourceProvider iconProvider) { this.model = model; this.iconProvider = iconProvider; }