Repository navigation
Implement custom resource handlers - #7817
Conversation
| @@ -0,0 +1,53 @@ | |||
| using System; | |||
There was a problem hiding this comment.
It seems that this file is not included in the project file.
There was a problem hiding this comment.
Yes, it is not required by libraryUI. I was trying this for PackageManager and it is a kind of sample implementation for web request.
| { | ||
| url = url.Replace(".json", ""); | ||
| } | ||
| var r = LoadResource(resource); |
There was a problem hiding this comment.
Since LoadResource is not used, it can be removed as well.
There was a problem hiding this comment.
LoadResource has been used to get the resource stream and a resource handler is created using the stream. Please see line 209/216/223.
| } | ||
| finally | ||
| { | ||
| request.Dispose(); |
There was a problem hiding this comment.
Shall we leave it to the creator to dispose it?
There was a problem hiding this comment.
That's a good point, but this is how the base class is implemented so I tried to maintain it.
| var handler = ResourceHandler.FromStream(stream, ResourceHandler.GetMimeType(extension)); | ||
| if (provider.IsStaticResource) | ||
| { | ||
| this.RegisterHandler(request.Url, handler); |
There was a problem hiding this comment.
I may not understand it correctly. But if the handler can be cached, so next time it won't be created and registered again, will this be better? And if Url here can be http://<address>/a.html or http://<address>/b.html, the last part can be trimmed before registering.
There was a problem hiding this comment.
if the request url is http://localhost/package/dynamo/lunchbox, then this method will return a list of all possible sub-path such as /package, /package/dynamo and /package/dynamo/lunchbox, it may happen that we have a resource provider registered for /package/dynamo and not for other urls.
There was a problem hiding this comment.
No, I guess you may have misunderstood me.
What I mean is for the three sub-paths that you have mentioned, you will register three times. Or if the same url is requested again, it will be registered again.
There was a problem hiding this comment.
ResourceHandler is registered only for the requested URL and not for the sub path. When there is a request for the same URL again, then the existing resource will be provided and this method GetResourceHandler(request) will not be called again for that URL.
|
Thanks a bunch! This looks good to me. |
* Recategorizing built-in methods (#7612) * Recategorize built-in methods * Added methods for List.cs, Math.cs and ImportExport.cs * Updated Math.MapTo * Updated List.cs * Icons and test cases - built-in methods are hidden from user's search - test cases moved to DSCoreNodesImages.resx - minor refinement to some methods - added test cases for List.cs and Math.cs * Set copy local in DynamoCoreWpfTests to false * Updated methods and test cases - Implementation for SetUnion, SetIntersection and SetDifference are the same as built-in methods - Edited ImportExport.ImportFromCSV to reuse the implementation from built-in - Added test cases for ImportExport.ImportFromCSV and fixed other test cases - Consolidated List.Contains with List.ContainsItem - Consolidated NormalizeDepth(list, rank) with NormalizeDepth(list) - Hid some of the built-in methods - Public methods and private helper methods are grouped using regions - Overload of List.Flatten is renamed as FlattenCompletely * Fixes for built in method test cases * Hide SortIndexByValue overload from builtin * Edited List, Math and ImportExport functions - consolidated CSV.ReadFromFile with ImportExport.ImportFromCSV - renamed ImportFromCSV to ImportCSV - moved CSV.WriteToFile to ImportExport.ExportCSV - fixed some of the list functions - reused builtin implememtations for Math.Map and Math.MapTo - moved test cases for CSV functions to ImportExport * migrations for csv.writetofile replacement of CSV.WriteToFile to ImportExport.ExportCSV * migrations for builtin nodes * Renamed FlattenCompletely and removed GetValues * updated icon for list.flatten * Update List.Flatten test case and revert migration for File.ExportToCSV * Consolidate Display nodes for re-categorization * Add one test case for migrating the very old ByGeometryColor node * LibraryViewExtension project for hosted library UI (#7756) * LibraryViewExtension project for hosted library UI * Serve library view with local data * Enable Node creation and console log (#7775) * Cleanup the solution file * Details view implementation over Dynamo canvas (#7780) * Details view implementation over Dynamo canvas * Fix visibility of details view * DetailsView integration (#7788) * Add missing resources. * Tabview to show library view and package list view * Provide Javascript hookup to update active package (#7791) * Fix a typo * Method to load installed packages in JSON format (#7789) * installed packages in json format * updated method to obtain installed pkg * removed getInstalledPackagesJSON() * reverted change to library.html * reverted previous changes * Re-fix a typo * Implement Install Package method on controller (#7793) * Update the bundle for latest updates in the UI. (#7794) * Consolidate some nodes from Logic and Formula to Math (#7757) * move some methods from Logic and Formula to Math * add entries to migration xml * add migration testcase * Remove List.Flatten overload (#7772) * remove list.flatten overload * Updated Dynamo.All.Sln * add migration test case * Update resources and js code from library.js and PMUI (#7796) * Recategorize "ColorRange2D" nodes into "ColorRange" (#7763) * Rename "ColorRange2D" to "ColorRange" * Add migration test case for ColorRange nodes * Install integration and style update (#7797) * Fix the issue that one json string may be invalid (#7802) * Library reorg (#7803) * Added 15 more packages to the list. * updated files to show packages. * Consolidate all file paths nodes under Import/Export category (#7776) * move nodes from file to importexport * add a migration testcase * change category name on ui to Import/Export * revert the slash * change namespace back to DSCore * rename namespace back to DSCore.IO * update loadedtypes.json * Cleanup LibraryReorg branch and remove PMUI code (#7804) * Update the library UI to recategorize two nodes * Consolidate all Directory related nodes to Import/Export Category (#7761) * consolidate directory nodes and rename importexport class * updated DirectoryFromPath and added migrations * change namespace from DSCore.IO to ImportExport * rename namespace and move directory methods to files.cs * add migration test cases * add directory.frompath and update nodemigrationtests * resolve conflicts * updated files * Update layoutSpecs and loadedTypes for ColorRange nodes * add nodes to loadedtype (#7806) * update layoutspecs and loadedtypes * Consolidate Excel nodes under Import/Export category (#7809) * recategorize excel methods * added migration and test case * migration for all excel.write node * move excel and csv methods to dsoffice * remove unnecessary attribute * add migration for DSCore.IO.File.ExportToCSV * Implement custom resource handlers (#7817) * add migration for csv.readfromfile * remove csv.readfromfile icons * Implement resource provider for runtime loadedTypes JSON data (#7826) * Implement resource provider for runtime loadedTypes JSON data * Add search keywords to LoadedTypes * Remove empty keywords * Tooltip implementation for library items (#7822) * Tooltip implementation for library items * Update librarie.min.js to include latest changes * Update LayoutSpecs.json and js to support sections (#7833) * Recategorize two GeometryColor nodes * Add ImportExport.CAD nodes under library (#7832) * Add ImportExport.CAD nodes under library * Restore lost changes * add test case for builtin migration (#7830) * Wrap left-over builtins into DS class for categorization and autocomplete (#7819) * wrap builtins into DS class for categorization and autocomplete * code cleanup * code cleanup * address review comments * addressed review comments * add checks for only static FFI classes to be derived from DS class * code cleanup * code cleanup * added migration, tests * revert changes to loadedtypes json file * updated layout spec json file * add test cases for static class and fix some tests * fixed prototest * Re-recategorize ColorRange nodes (#7840) * updated layoutSpecs.json (#7841) * Refactor the code so the LibraryViewController.cs can be tested (#7834) * Refactor the code so the LibraryViewController.cs can be tested Move methods to seperate class EventController, so this class can be used for mock testing. Derived class object LibraryViewController needs parameters which cannot be mocked. * Add moq test for LibraryViewController * To address the review comments from PR #7834 - Modify AssemblySharedInfo.cs to update CopyRight information of assmblies to 2017 - Remove constructor LibraryViewController() - Revert changes to Dynamo.All.sln realted to visual studio version - Add AssemblySharedInfo.cs to ViewExtensionLibraryTests so the assembly version is set to get the standard versioning * Modify the output path in ViewExtensionLibraryTests.csproj to match the properties from props * Add files related to commit -c03544f * Revert changs to AssemblySharedInfo.cs Modify AssemblySharedInfo.tt to update CopyRight information from 2016 to 2017 * Update librarie.js and other resources (#7842) * Revise category icons for library * add parameters for overloads * removed redundant path * merging new LibUI changes to Dynamo side * Implement IconResourceProvider to get icons for library items (#7869) * Implement IconResourceProvider to get icons for library items * remove methods and fields that are not required * Use category as read from customization xml * address review comments * Add unit tests for ResourceProviders (#7879) * Add unit tests for RespurceProviders * Rename ViewExtensionLibraryTests to LibraryResourceProviderTests - Update json file - Address review comments * Ensure that CopyLocal=False for Dynamo binaries (#7881) * Fix Icon resources for library items (#7880) - Rename BuiltIns.ds to BuiltIn.ds so that the icons for nodes from BuiltIn.ds could be resolved from BuiltIn.customization.dll * Update librarie.js and integrate the new API * Update library minimized javascript file to latest * Fix for DYN-870, removed Keys section from Organize group (#7895) * Remove unused LibraryViewExtension font resources (#7893) * Add description (#7904) * Prevent loading LibraryViewExtension in test mode to prevent NUnit crash (#7906) * wrap builtins into DS class for categorization and autocomplete * code cleanup * code cleanup * address review comments * addressed review comments * add checks for only static FFI classes to be derived from DS class * code cleanup * code cleanup * added migration, tests * revert changes to loadedtypes json file * updated layout spec json file * add test cases for static class and fix some tests * fixed prototest * disable library view extension in test mode * update core UI test to run when test mode is set to true and LibraryViewExtension is loaded * Integrate ImportLibrary UI (#7905) * Make it possible to use an external search function * Update library minimized javascript file to latest * Fix the build error in one test module * Disable right-click on LibraryView (#7913) * DYN-862: Implement event notification for libraryDataUpdated (#7896) * Implement event notification for libraryDataUpdated * update documentation * Event Observer * More testc ases * Don't use old results when throttle re-fires * Address review comments * Addressing review comments * Add node icon for Label.ByPointAndString * Addressing more review comments * fix failing excel tests (#7932) * Fixed failing tests on LibraryReorg branch (#7939) * fix failing excel tests * fixed tests * changed comments * Implement IServiceManager interface (#7949) * build fix, update csproj (#7950) * Add List.Equals overload to List BuiltIn class (#7954) * fix failing excel tests * fixed tests * changed comments * added builtin overload for List.Equals * Remove SearchView and LibrarySearchView WPF views and related tests (#7956) * fix failing excel tests * fixed tests * changed comments * added builtin overload for List.Equals * remove SearchView and LibrarySearchView WPF views * restore deleted comments * Remove v0.0.1 from resource path (#7961) * Fixed merge issues * Create DynamoVisualProgramming.DynamoCoreNodes.nuspec * Include assembly name in fully qualified name (#7971) * Include assembly name in fully qualified name * Create ZeroTouchSearchElement.cs * LibraryViewCustomization Service implementation (#7963) * LibraryViewCustomization Service implementation * Address review comments * Address more review comments * Provides support for default icon when resource not found (#7975) * Provides support for default icon when resource not found * Include concurrency test * Update librarie.js minified and resources (#8004) * Update library resources and categorization (#8010) * Update library resource and categorization * Remove ImportExportTests as its already moved to DSOfficeTests * update librarie.min.js * Implement Resource registration and app shutdown notification mechanism (#8014) * Implement Resource registration and app shutdown notification mechanism * Update LibraryViewExtension.Dispose implementation * Address review comments * Update DSCoreNodes.Migrations.xml removed unnecessary migration path for ExportCSV node
Purpose
This PR implements a system to register custom resource providers for a different kind of resources. These resources could be available as DLL resources (e.g. static HTML, Font, CSS etc.) or web resource or some in-memory resource (such as a list of nodes available in Dynamo) etc.
A
ResourceHandlerFactoryis implemented to register some simple resource handler or register resource providers for a given segment of requests.When a request is raised from javascript/HTML page hosted on CEF, the resource factory would receive a call to resolve the request first and if the factory can't resolve it then the resource would be resolved normally. The
ResourceFactoryclass first searches the registered resource handler for a given request URL and if not found it will search for aResourceProviderfor any segment of the request URL.Declarations
Check these if you believe they are true
*.resxfilesReviewers
@benglin
@Randy-Ma