Caliburn Micro
The framework makes extensive use of MVVM patterns (
Model View ViewModel). To facilitate the user of MVVM the framework uses an open source framework Caliburn Micro. There are three main parts of the caliburn framework that are used: MVVM support, Coroutines, and Conductors.
Coroutines
Caliburn Micro
Coroutines help solve the problem of asynchronous calls needing to happen in synchronous workflow. Coroutines are implemented through an interface Caliburn.Micro.IResult. The Gis Framework has created two implementation of IResult to simplify it's use for framework developers.
ResultBase
Name | Abstract | Description |
---|
Execute(ActionExecutionContext) | True | This is where the code needs to be written to be run when the coroutine executes in the workflow. |
Success() | False | Once the asynchronous call has been successful completed this method should be called for the next coroutine to be begin executing in the workflow. |
Failure(Exception) | False | This should be called once an exception that is handled occurs in the coroutine. |
ResultBase Implementation Example:
public class IdentifyWorkflow : ResultBase
{
public IEnumerable<FindOperationResult> Result { get; internal set; }
public IdentifyWorkflow(IdentifyOptions options, string url)
{
_options = options;
_url = url;
}
private readonly string _url;
private readonly IdentifyOptions _options;
public override void Execute(ActionExecutionContext context)
{
try
{
var svs = ServiceClients.GetQueryServiceClient();
svs.IdentifyCompressedCompleted += svs_IdentifyCompleted;
svs.IdentifyCompressedAsync(_options, _url);
}
catch (Exception ex)
{
Failure(ex);
}
}
private void svs_IdentifyCompleted(object sender, IdentifyCompressedCompletedEventArgs e)
{
e.Result.Decompress<FindOperationResults>(result =>
{
result.Results.ToList().ForEach(x => x.Url = _url);
Result = result.Results;
Success();
});
}
}
Creating a Workflow
Coroutines are executed in the context of a workflow. Workflows methods return an IEnumerble
that enumerates through the coroutines in the workflow. In the workflow method instances of the coroutines are created then the yield return keyword is called on the couroutine.
Example of workflow being created and executed:
public void RunWorkflow()
{
var executionContext = new ActionExecutionContext();
Coroutine.BeginExecute(GetSampleWorkflow().GetEnumerator(), executionContext, Complete);
}
private static void Complete(object sender, ResultCompletionEventArgs e)
{
if (e.Error != null)
throw new Exception("Error on SampleWorkflow",e.Error);
}
private IEnumerable<IResult> GetSampleWorkflow()
{
var coroutine1 = new SampleCoroutines();
yield return coroutine1;
//Do something with the result
var coroutine2 = new SampleCoroutines2();
yield return coroutine2;
yield break;
}
See Also
MVVM Support
Caliburn Micro framework allows developers to easily implement a MVVM pattern in there application. When Caliburn Micro is used to set the binding between the view and view model conventions and actions can be used.
Example of Binding View and ViewModel:
var view = new ReportView();
var viewModel = new ReportViewModel();
Caliburn.Micro.View.SetModel(view, viewModel);
Conventions
Caliburn Micro supports convention based bindings. Examples of this include are creating a button in the xaml view name SaveButton. When a method is also named SaveButton in the viewModel the onclick event is automatically wired up to the viewModel's method.
View's XAML:
<Button x:Name="SaveButton" Content="Save"/>
ViewModel cs:
public void SaveButton()
{
//Do Something
}
There are many more options for the convention based binding can be found in the following article In Depth Look at Conventions.
Actions
Caliburn Micro allow developers to wire up events from the view to methods in the view models. See more about actions in the following article In Depth Look at Actions.
Screens and Conductors ¶
In Depth Look at Screens and Conductors
See Also