Framework:Rave.Common
From RaveWiki
This assembly contains common utilities and concepts shared among others assemblies of the framework.
Contents |
Logger
Implements a file and event based logging.
![]() |
Sample Code
Logger.Configure("Rave.log", LogLevel.DEBUG);
Logger.Debug("Testing logging...");
|
Worker
The Worker component implements a simple manner to run an asynchronous task with event based monitoring. The task can be also cancelled at any moment.
We have a Runnable code that implements the task to be executed, and an Observer that monitors the task in execution. The Observer usually is a view component like a Windows Form or an User Control.
An Observer can implement 3 event handlers to monitor the status of the thread. These handlers are called by the Worker:
- When the task method that is running needs to report a status of the work.
- When the task method is completed.
The required Runnable method is the method that implements the task. This method cannot call directly the methods of the Observer because this lies in a different thread, specially if it is a Windows Forms component.
The event handlers should use the EventArgs shown below:
Sample Code for the Observer
private void ProgressChanged(object sender, ProgressChangedEventArgs args)
{
// updates the progress bar
}
private void WorkReported(object sender, WorkReportedEventArgs args)
{
// analyze the level and process the message if needed
}
private void WorkCompleted(object sender, WorkCompletedEventArgs args)
{
// check the result and do some action
}
Sample Code for the Runnable
public void Run(object sender, DoWorkEventArgs args)
{
this.worker = (Worker) sender;
while (!worker.CancellationPending)
{
// execute a task
}
}
References
- A tryst with Whidbey: Background operations in Windows Forms (The Code Project)
- Asynchronous Windows Forms Programming (CoDe Magazine)
Discovery and Locator
We use these classes to find an interface implementation in an application context that we don't know (or don't want to know) what class implements the interface and how the class implements it.
The idea is to find one or more instances of a known interface assuming that the instances were created and bound (as seen below) in some point of the application.
- We use the Discovery class when the interface can have only one related instace.
- We use the Locator to map custom names in instances of the interface, so the interface supports more than one instance.
Sample Code:
// here we know that Soccer implements ISport ISport soccer = new Soccer(); // this code bind the Soccer instance Discovery<ISport> discovery = new Discovery<ISport>(); discovery.Bind(soccer);
// getting the instance in another context Discovery<ISport> discovery = new Discovery<ISport>(); ISport sport = discovery.Lookup();
To do: show how to use the OnBind/OnUnbind events to bind others objects like SoccerTeamManager (ITeamManager), SoccerGameManager (IGameManager), etc.
Model
This is the basic model for data produced and consumed by the applications developed over the framework.
Here is a basic description of the classes and interfaces:
- Context .:. This class represents an application context. In a context we find a set of entities and structured data, so the context is like a namespace to the data representation.
- IElement .:. Represents an entity in the application. This interface is extended for each data concept with additional properties and methods. Each element instance has:
- a unique symbol (like a code) for all elements in a context
- a name for visual identification
- a XML document for maintain metadata and custom properties
- Tag .:. It is just a label to categorize the elements in an application context.
- IComposite .:. This interface represents a set or list of elements of a context. It supports a parent branch to permit hierarchical composites.
- IBranch .:. It is just a generalization for the composite parent property, so that a composite can have another composite or a context as parent.
Some relevant characteristics:
- An element can have multiple tags. These tags can be defined implicitly in the application or by the user.
- A composite implementation can have several ways to establish their elements:
- The elements can be selected by type (class/interface)
- Can be selected by the user
- Can be selected by a filter definition, using properties values or tags
Provider
A provider is a service interface that expose specific functionalities of an application, decoupling the application's business logic from the applications's consumers code.
The IRepositoryProvider is a generic persistence service.
Sample Code:
List<IRepositoryProvider> providers = new List<IRepositoryProvider>();
...
public void Save(object instance)
{
foreach (IRepositoryProvider provider in providers)
{
if (provider.Accept(instance))
{
provider.Commit(instance);
return;
}
}
}
SqlProvider is an abstract class that implements a IRepositoryProvider with a database connection and methods to help read and write operations.
References







