-
Notifications
You must be signed in to change notification settings - Fork 2
Project Setup
This section assumes you obtained a compiled version of DistrEx, and that you have at least one worker running on your local machine, with the following exposed endpoints:
http://localhost:8000/assemblymanagerhttp://localhost:8000/executor
Here you can read about how to set that up.
What you'll need is Visual Studio 2010 SP1. Maybe VS2010 without SP1 will work, and maybe even VS2012, but those are not tested. This tutorial assumes you'll be using C#, but since DistrEx is managed (.NET) code, it should be inter-operable with other Visual Studio languages as well.
1) Create any type of C# project, such as a Windows Console Application project, and add references to DistrEx.Coordinator.Interface.dll and DistrEx.Coordinator.dll.
2) Now add an Application Configuration file to your new project and edit it.
Pay attention to the following sections:
Section <configuration><appSettings> (assembly deployment):
<configuration>
<appSettings>
<add key="DependencyResolver.assembly-path" value="..."/>
</appSettings>
<!-- ... -->
</configuration>Adding a DependencyResolver.assembly-path is optional, and it can be a list of paths (separated by ;), each relative to the app's base path. These paths will be searched through for assemblies that cannot be found in the app's regular assembly search path. This search occurs whenever an instruction is to be executed on a worker; which is preceded by deploying the assembly (and all of its dependencies) to that worker.
Section <configuration><system.serviceModel> (WCF):
Information for this section is described in WCF Setup
3) Add a method to a class in your project where you want to use DistrEx.
using DistrEx.Coordinator;
using DistrEx.Coordinator.Interface;
using DistrEx.Coordinator.TargetSpecs;
using DistrEx.Communication.Service.Executor;
class SomeClass {
int CalulationWithDistrEx() {
//some setting up
IExecutorCallback callbackService = new ExecutorCallbackService();
TargetSpec worker1 = OnWorker.FromEndpointConfigNames("Worker1-AssemblyManager", "Worker1-Executor", callbackService);
Instruction<int, int> increase = (cancellationToken, reportProgress, argument) => argument + 1;
Instruction<int, int> decrease = (cancellationToken, reportProgress, argument) => argument - 1;
//actual DistrEx program
int input = 0;
Tuple<int, int> result =
Coordinator.Do(worker1.Do(increase), input)
.ThenDo(worker1.Do(increase), worker1.Do(decrease))
.ResultValue;
//result of DistrEx program:
// result.Item1 == 2
// result.Item2 == 0
//some cleanup
worker1.ClearEverything();
return result.Item1 + result.Item2;
}
}