ResourceMgr ClassCleanCode C# Libraries v1.2.03 API
Provides support for the IResourceUser interface as well as providing access to an application-specific subfolder of the system-defined OnlineApplicationData folder path.
Inheritance Hierarchy

OnlineSystem Object
  CleanCode.IO ResourceMgr

Namespace: CleanCode.IO
Assembly: CleanCode (in CleanCode.dll) Version: (1.2.03)

public class ResourceMgr

The ResourceMgr class, in conjunction with the IResourceUser interface, provides a powerful mechanism for your application to purge and refresh external file resources embedded in your binaries. Often an application includes files other than just the executable and associated DLLs, perhaps an XML file, text files, languages files, etc. One approach to file management is to package these files with an installer for your application. A second approach, taken here, is to include these files as resources packaged within your executable or DLL, which are then unpackaged not by an installer but at runtime by the application itself and only if needed. Often you may allow or even encourage users to edit such externalized files; that is a common reason for making them external. But as an application designer you must decide wisely when—or if—to regenerate these files. You do not, for example, want to recreate them every time the application starts; otherwise your users would lose any changes they might have manually made. A good compromise that I use is this: when a new version of an application runs for the first time it overwrites the previous file if it exists and only if it is not protected with the read-only attribute. This allows each user to decide between keeping user changes from version to version and getting a fresh (possibly updated) version with a new release. Furthermore, I only externalize a file just when it is about to be used; if it is not needed in a given run of the application (and it does not yet exist) I do not create it yet. This class provides the ResetAllResources( Form ) and InstantiateResource(String, String) methods as your main application API, and ResetResources(String, Boolean ) for instrumenting any child controls and forms as needed.

Since CleanCode 0.9.26.


Use code like this to detect a new version and reset all file resources for all controls embedded in any subcontrols and subforms.
if (Properties.Settings.Default.NewVersion)
    // migrate settings from previous version, if any

   // deactivate the NewVersion flag for subsequent invocations
    Properties.Settings.Default.NewVersion = false;

    // Include this here or during your shutdown code to save the above changes

   // Reset all file resources associated with this WinForm application
    Collection<string> l = ResourceMgr.ResetAllResources(this);
string fileName = ResourceMgr.InstantiateResource(
    "QueryLibrary.xml", Properties.Resources.QueryLibrary);
To later externalize a particular file from a resource, use code like this:
See Also