string m_Xoml = @"<ns:MyActivity xmlns:ns="""
+@"http://daenet.eu/workflow.activities""></ns:MyActivity>";
private void AddReferencedAssemblies(TypeProvider typeProvider)
{
Assembly thisAssembly;
thisAssembly = Assembly.GetAssembly(this.GetType());
foreach (AssemblyName assemblyName
in thisAssembly.GetReferencedAssemblies())
{
typeProvider.AddAssembly(Assembly.Load(assemblyName));
}
}
private Activity GetActivityTypeFromXoml(XmlReader reader)
{
using (WorkflowRuntime runtime = new WorkflowRuntime())
{
using (TypeProvider typeProvider = new TypeProvider(
runtime))
{
AddReferencedAssemblies(typeProvider);
using (ServiceContainer container = new
ServiceContainer())
{
container.AddService(typeof(ITypeProvider),
typeProvider);
DesignerSerializationManager manager =
new DesignerSerializationManager(container);
manager.CreateSession();
WorkflowMarkupSerializationManager
serializationManager =
new WorkflowMarkupSerializationManager(manager);
Activity activity =
new WorkflowMarkupSerializer().Deserialize(
serializationManager,
reader) as Activity;
return activity;
}
}
}
}
public bool ExecuteWorkflowFromXoml(XmlReader reader,
Dictionary<string, object> namedArgumentValues)
{
using (WorkflowRuntime runtime = new WorkflowRuntime())
{
using (Activity activity = GetActivityTypeFromXoml(
reader))
{
ManualWorkflowSchedulerService scheduler =
new ManualWorkflowSchedulerService();
runtime.AddService(scheduler);
WorkflowInstance instance = runtime.CreateWorkflow(
activity.GetType(),
namedArgumentValues);
instance.Start();
return (scheduler.RunWorkflow(instance.InstanceId));
}
}
}
[TestMethod]
public void TestMethod00()
{
Dictionary<string, object> namedArgumentValues
= new Dictionary<string,
object>();
namedArgumentValues.Add("WorkflowArgument", "test");
bool isRunning=ExecuteWorkflowFromXoml(
XmlReader.Create(new StringReader(
m_Xoml)),
namedArgumentValues);
Assert.IsTrue(isRunning, "WorkflowActivity cannot be run.");
}