Useful Code Snippets

CodeSnippets.UsefulCodeSnippets History

Hide minor edits - Show changes to output

February 03, 2010, at 02:19 PM by 136.159.7.119 -
Deleted lines 0-1:
%define=bluebox box bgcolor=#f4fbff border='1px solid #a1cae6'%
Changed lines 3-34 from:
* [[RuntimeDllLoader|Runtime DLL Loader]]

!!Runtime DLL Loader
'''By:''' Rob Diaz-Marino

'''Date:''' Jan 27, 2010

'''Download:''' [[Attach:ModuleManager.cs|ModuleManager.cs]]

'''Purpose:''' At some point you may want to create a program that can handle an array of plugins. You want plugins able to be added or remove without requiring the original program to be recompiled. This means the plugins cannot be directly referenced by your main program, and must implement a common interface. Developers who want to create their own plugins for your program may do so by implementing your module interface and dropping the resulting DLL into the main program directory. Then your program, as it loads, can find all the plugins that are present, load them accordingly, and have their functionality available within your program.

Examples of programs that do this are:
* Notification Collage
* [[Demos/CommunityBar|Community Bar]]
* [[Demos/Cambience|Cambience]]

'''Description:''' This file contains the code for a class that handles runtime DLL loading for your own plug-in modules. Each module must have one class that implements the IModule interface. The ModuleManager finds this class and stores an instance of it. This instance is used to dispatch further interfaces for your program to interact with your module, so design accordingly.

ModuleManager assumes all your module DLLs are in a single directory and are named using a particular pattern so that they can be distinguished from other support DLLs. It is built to expect that your program will store a list of known modules, however this can be optional. Notifications are thrown at each step of the module discovery process to offer your program (or your user) the chance to disable loading of any particular modules.

ModuleManager supports synchronous and asynchronous loading, however note that when using asynchronous loading and updating GUI components, you must use thread safe calling techniques to avoid illegal cross-thread operations. For your convenience, static ThreadSafeCall and ThreadSafeComponentCall methods are included in the ModuleManager class. These can be used to invoke methods or set properties on a target Control or Component.

>>bluebox<<
!!! Tutorials and Examples

'''ModuleManagerSample Project'''
* [[Attach:ModuleManagerSample.zip|ModuleManagerSample.zip]]
* Demonstrates the basic structure of a project, and synchronous loading
* ModuleManagerSample does not directly reference Module (this is the whole point)
* Both ModuleManagerSample and Module reference CommonLibrary, which contains the IModule interface definition. This structure is necessary so that Module can implement an interface that ModuleManagerSample recognizes, without the need for a direct reference to Module.
* In the build settings for Module, I have the output directed to the ModuleManagerSample's bin/Debug directory so that it is adjacent to the application and CommonLibrary.dll.
>><<
to:
* [[RuntimeDllLoader|Runtime DLL Loader]] - load DLL files and integrate them into your program at runtime.
* [[SingletonApplication|Singleton Application]] - code to make sure only one instance of your program is running at a time. If another one is requested, the existing one comes up instead.
* [[SharedDictionaryWrapper|Shared Dictionary Wrapper]] - code that provides a robust wrapper around a Grouplab.Networking.SharedDictionary object to handle a variety of error conditions in a much more logical way.
February 03, 2010, at 09:56 AM by 136.159.7.119 -
Changed lines 3-4 from:
If this section grows too large, please split off each snippet to its own page. Otherwise I'm just leaving this as a linear list for now.
to:
This selection contains a catalog of code snippets that others may find useful. Feel free to post your own, but please ensure what you post is well documented both in the code and on this page.

* [[RuntimeDllLoader|Runtime DLL Loader]]
January 28, 2010, at 10:03 AM by 136.159.7.119 -
Changed lines 17-18 from:
* [[Demos/CambienceCambience|Cambience]]
to:
* [[Demos/Cambience|Cambience]]
January 28, 2010, at 10:02 AM by 136.159.7.119 -
Changed lines 12-15 from:
'''Purpose:'''

At some point you may want to create a program that can handle an array of plugins. You want plugins able to be added or remove without requiring the original program to be recompiled. This means the plugins cannot be directly referenced by your main program, and must implement a common interface. Developers who want to create their own plugins for your program may do so by implementing your module interface and dropping the resulting DLL into the main program directory. Then your program, as it loads, can find all the plugins that are present, load them accordingly, and have their functionality available within your program.
to:
'''Purpose:''' At some point you may want to create a program that can handle an array of plugins. You want plugins able to be added or remove without requiring the original program to be recompiled. This means the plugins cannot be directly referenced by your main program, and must implement a common interface. Developers who want to create their own plugins for your program may do so by implementing your module interface and dropping the resulting DLL into the main program directory. Then your program, as it loads, can find all the plugins that are present, load them accordingly, and have their functionality available within your program.
Changed lines 19-22 from:
'''Description:'''

This file contains the code for a class that handles runtime DLL loading for your own plug-in modules. Each module must have one class that implements the IModule interface. The ModuleManager finds this class and stores an instance of it. This instance is used to dispatch further interfaces for your program to interact with your module, so design accordingly.
to:
'''Description:''' This file contains the code for a class that handles runtime DLL loading for your own plug-in modules. Each module must have one class that implements the IModule interface. The ModuleManager finds this class and stores an instance of it. This instance is used to dispatch further interfaces for your program to interact with your module, so design accordingly.
January 28, 2010, at 10:02 AM by 136.159.7.119 -
Added lines 12-20:
'''Purpose:'''

At some point you may want to create a program that can handle an array of plugins. You want plugins able to be added or remove without requiring the original program to be recompiled. This means the plugins cannot be directly referenced by your main program, and must implement a common interface. Developers who want to create their own plugins for your program may do so by implementing your module interface and dropping the resulting DLL into the main program directory. Then your program, as it loads, can find all the plugins that are present, load them accordingly, and have their functionality available within your program.

Examples of programs that do this are:
* Notification Collage
* [[Demos/CommunityBar|Community Bar]]
* [[Demos/CambienceCambience|Cambience]]
January 28, 2010, at 09:50 AM by 136.159.7.119 -
Changed lines 27-28 from:
* Both ModuleManagerSample and Module reference CommonLibrary, which contains the IModule interface definition.
* This structure is necessary so that Module can implement an interface that ModuleManagerSample recognizes, without the need for a direct reference to Module.
to:
* Both ModuleManagerSample and Module reference CommonLibrary, which contains the IModule interface definition. This structure is necessary so that Module can implement an interface that ModuleManagerSample recognizes, without the need for a direct reference to Module.
January 28, 2010, at 09:49 AM by 136.159.7.119 -
Deleted lines 19-24:
'''Notes:'''
* ModuleManagerSample does not directly reference Module (this is the whole point)
* Both ModuleManagerSample and Module reference CommonLibrary, which contains the IModule interface definition.
* This structure is necessary so that Module can implement an interface that ModuleManagerSample recognizes, without the need for a direct reference to Module.
* In the build settings for Module, I have the output directed to the ModuleManagerSample's bin/Debug directory so that it is adjacent to the application and CommonLibrary.dll.
Added lines 26-29:
* ModuleManagerSample does not directly reference Module (this is the whole point)
* Both ModuleManagerSample and Module reference CommonLibrary, which contains the IModule interface definition.
* This structure is necessary so that Module can implement an interface that ModuleManagerSample recognizes, without the need for a direct reference to Module.
* In the build settings for Module, I have the output directed to the ModuleManagerSample's bin/Debug directory so that it is adjacent to the application and CommonLibrary.dll.
January 28, 2010, at 09:49 AM by 136.159.7.119 -
Changed lines 20-25 from:
[[#tutorials]]
to:
'''Notes:'''
* ModuleManagerSample does not directly reference Module (this is the whole point)
* Both ModuleManagerSample and Module reference CommonLibrary, which contains the IModule interface definition.
* This structure is necessary so that Module can implement an interface that ModuleManagerSample recognizes, without the need for a direct reference to Module.
* In the build settings for Module, I have the output directed to the ModuleManagerSample's bin/Debug directory so that it is adjacent to the application and CommonLibrary.dll.
January 28, 2010, at 09:47 AM by 136.159.7.119 -
Added lines 1-2:
%define=bluebox box bgcolor=#f4fbff border='1px solid #a1cae6'%
Changed lines 18-27 from:
ModuleManager supports synchronous and asynchronous loading, however note that when using asynchronous loading and updating GUI components, you must use thread safe calling techniques to avoid illegal cross-thread operations. For your convenience, static ThreadSafeCall and ThreadSafeComponentCall methods are included in the ModuleManager class. These can be used to invoke methods or set properties on a target Control or Component.
to:
ModuleManager supports synchronous and asynchronous loading, however note that when using asynchronous loading and updating GUI components, you must use thread safe calling techniques to avoid illegal cross-thread operations. For your convenience, static ThreadSafeCall and ThreadSafeComponentCall methods are included in the ModuleManager class. These can be used to invoke methods or set properties on a target Control or Component.

[[#tutorials]]
>>bluebox<<
!!! Tutorials and Examples

'''ModuleManagerSample Project'''
* [[Attach:ModuleManagerSample.zip|ModuleManagerSample.zip]]
* Demonstrates the basic structure of a project, and synchronous loading
>><<
January 27, 2010, at 10:48 AM by 136.159.7.119 -
Changed line 3 from:
!Runtime DLL Loader
to:
!!Runtime DLL Loader
January 27, 2010, at 10:47 AM by 136.159.7.119 -
Changed lines 8-9 from:
'''Download:''' [[Attach:ModuleManager.cs]]
to:
'''Download:''' [[Attach:ModuleManager.cs|ModuleManager.cs]]
January 27, 2010, at 10:37 AM by 136.159.7.119 -
Changed lines 8-9 from:
'''Download:''' [[ModuleManager.cs]]
to:
'''Download:''' [[Attach:ModuleManager.cs]]
January 27, 2010, at 10:34 AM by 136.159.7.119 -
Added lines 8-9:
'''Download:''' [[ModuleManager.cs]]
Changed lines 16-18 from:
ModuleManager supports synchronous and asynchronous loading, however note that when using asynchronous loading and updating GUI components, you must use thread safe calling techniques to avoid illegal cross-thread operations. For your convenience, static ThreadSafeCall and ThreadSafeComponentCall methods are included in the ModuleManager class. These can be used to invoke methods or set properties on a target Control or Component.

[[ModuleManager.cs]]
to:
ModuleManager supports synchronous and asynchronous loading, however note that when using asynchronous loading and updating GUI components, you must use thread safe calling techniques to avoid illegal cross-thread operations. For your convenience, static ThreadSafeCall and ThreadSafeComponentCall methods are included in the ModuleManager class. These can be used to invoke methods or set properties on a target Control or Component.
January 27, 2010, at 10:34 AM by 136.159.7.119 -
Added lines 1-16:
If this section grows too large, please split off each snippet to its own page. Otherwise I'm just leaving this as a linear list for now.

!Runtime DLL Loader
'''By:''' Rob Diaz-Marino

'''Date:''' Jan 27, 2010

'''Description:'''

This file contains the code for a class that handles runtime DLL loading for your own plug-in modules. Each module must have one class that implements the IModule interface. The ModuleManager finds this class and stores an instance of it. This instance is used to dispatch further interfaces for your program to interact with your module, so design accordingly.

ModuleManager assumes all your module DLLs are in a single directory and are named using a particular pattern so that they can be distinguished from other support DLLs. It is built to expect that your program will store a list of known modules, however this can be optional. Notifications are thrown at each step of the module discovery process to offer your program (or your user) the chance to disable loading of any particular modules.

ModuleManager supports synchronous and asynchronous loading, however note that when using asynchronous loading and updating GUI components, you must use thread safe calling techniques to avoid illegal cross-thread operations. For your convenience, static ThreadSafeCall and ThreadSafeComponentCall methods are included in the ModuleManager class. These can be used to invoke methods or set properties on a target Control or Component.

[[ModuleManager.cs]]