static void Main(string[] args) { AppSettingsReader reader = new AppSettingsReader(); string servicebusConnectionString = reader.GetValue("Microsoft.ServiceBus.ConnectionString", typeof(string)).ToString(); string taskHubName = reader.GetValue("TaskHubName", typeof(string)).ToString(); TaskHubClient taskHubClient = new TaskHubClient(taskHubName, servicebusConnectionString); TaskHubWorker taskHub = new TaskHubWorker(taskHubName, servicebusConnectionString); taskHub.DeleteHub(); taskHub.CreateHubIfNotExists(); OrchestrationInstance instance = null; string instanceId = "TestTaskHub : " + Guid.NewGuid(); taskHub.AddTaskOrchestrations((typeof(TaskHubProcessingOrchestration))); taskHub.AddTaskActivitiesFromInterface <IActivityFunction>(new ActivityImplementor(), true); taskHub.AddTaskActivities(new GetUserTask()); instance = taskHubClient.CreateOrchestrationInstance(typeof(TaskHubProcessingOrchestration), instanceId, "hello"); taskHub.Start(); Console.WriteLine("Press any key to quit."); Console.ReadLine(); taskHub.Stop(true); }
/// <summary> /// Opens the hosts channels and start execution. /// </summary> /// <param name="resetHub"></param> public void Open(bool resetHub = false) { m_TaskHubWorker.Start(); // Includes details of inner exceptions. // throw new Ex() from task will be attached as serialized Details property of exception. m_TaskHubWorker.TaskActivityDispatcher.IncludeDetails = true; }
private static void run() { string connectionString = ConfigurationManager.AppSettings["SbConnStr"]; string taskHubName = ConfigurationManager.AppSettings["TaskHubName"]; TaskHubClient taskHubClient = new TaskHubClient(taskHubName, connectionString); TaskHubWorker taskHubWorker = new TaskHubWorker(taskHubName, connectionString); taskHubWorker.CreateHub(); OrchestrationInstance instance = taskHubClient.CreateOrchestrationInstance(typeof(WfTaskOrchestration), "Hello"); taskHubWorker.AddTaskOrchestrations(typeof(WfTaskOrchestration)); taskHubWorker.AddTaskActivities(new WOEIDLookupTask(), new WForecastsTask()); taskHubWorker.Start(); Console.WriteLine("Press any key to quit."); Console.ReadLine(); taskHubWorker.Stop(true); }
public static void StartWorker(TaskHubWorker taskHub) { try { Console.WriteLine("Starting DurableTask worker..."); IUtilitySignupActivities utilitySignupActivities = new UtilitySignupActivities(); taskHub.AddTaskActivitiesFromInterface <IUtilitySignupActivities>(utilitySignupActivities); taskHub.AddTaskOrchestrations(typeof(UtilitySignupOrchestration)); taskHub.Start(); Console.WriteLine("DurableTask worker successfully started. Press any key to quit."); Console.ReadLine(); taskHub.Stop(true); } catch (Exception) { // silently eat any unhandled exceptions. } }
static void Main(string[] args) { string tableConnectionString = ConfigurationManager.AppSettings["StorageConnectionString"]; if (CommandLine.Parser.Default.ParseArgumentsStrict(args, options)) { string connectionString = ConfigurationManager.ConnectionStrings["Microsoft.ServiceBus.ConnectionString"].ConnectionString; string taskHubName = ConfigurationManager.AppSettings["TaskHubName"]; TaskHubClient taskHubClient = new TaskHubClient(taskHubName, connectionString, tableConnectionString); TaskHubWorkerSettings settings = new TaskHubWorkerSettings(); settings.TaskOrchestrationDispatcherSettings.CompressOrchestrationState = bool.Parse(ConfigurationManager.AppSettings["CompressOrchestrationState"]); settings.TaskActivityDispatcherSettings.MaxConcurrentActivities = int.Parse(ConfigurationManager.AppSettings["MaxConcurrentActivities"]); settings.TaskOrchestrationDispatcherSettings.MaxConcurrentOrchestrations = int.Parse(ConfigurationManager.AppSettings["MaxConcurrentOrchestrations"]); TaskHubWorker taskHub = new TaskHubWorker(taskHubName, connectionString, tableConnectionString, settings); if (options.CreateHub) { taskHub.CreateHub(); } OrchestrationInstance instance = null; string instanceId = options.StartInstance; if (!string.IsNullOrWhiteSpace(instanceId)) { instance = taskHubClient.CreateOrchestrationInstance(typeof(DriverOrchestration), instanceId, new DriverOrchestrationData { NumberOfIteration = int.Parse(ConfigurationManager.AppSettings["DriverOrchestrationIterations"]), NumberOfParallelTasks = int.Parse(ConfigurationManager.AppSettings["DriverOrchestrationParallelTasks"]), SubOrchestrationData = new TestOrchestrationData { NumberOfParallelTasks = int.Parse(ConfigurationManager.AppSettings["ChildOrchestrationParallelTasks"]), NumberOfSerialTasks = int.Parse(ConfigurationManager.AppSettings["ChildOrchestrationSerialTasks"]), MaxDelayInSeconds = int.Parse(ConfigurationManager.AppSettings["TestTaskMaxDelayInMinutes"]), }, }); } else { instance = new OrchestrationInstance { InstanceId = options.InstanceId }; } Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); TestTask testTask = new TestTask(); taskHub.AddTaskActivities(testTask); taskHub.AddTaskOrchestrations(typeof(DriverOrchestration)); taskHub.AddTaskOrchestrations(typeof(TestOrchestration)); taskHub.Start(); int testTimeoutInSeconds = int.Parse(ConfigurationManager.AppSettings["TestTimeoutInSeconds"]); OrchestrationState state = WaitForInstance(taskHubClient, instance, testTimeoutInSeconds); stopWatch.Stop(); Console.WriteLine("Orchestration Status: " + state.OrchestrationStatus.ToString()); Console.WriteLine("Orchestration Result: " + state.Output); Console.WriteLine("Counter: " + testTask.counter); TimeSpan totalTime = stopWatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", totalTime.Hours, totalTime.Minutes, totalTime.Seconds, totalTime.Milliseconds / 10); Console.WriteLine("Total Time: " + elapsedTime); taskHub.Stop(); } }
static void Main(string[] args) { if (CommandLine.Parser.Default.ParseArgumentsStrict(args, options)) { string servicebusConnectionString = Program.GetSetting("ServiceBusConnectionString"); string storageConnectionString = Program.GetSetting("StorageConnectionString"); string taskHubName = ConfigurationManager.AppSettings["taskHubName"]; TaskHubClient taskHubClient = new TaskHubClient(taskHubName, servicebusConnectionString, storageConnectionString); TaskHubWorker taskHub = new TaskHubWorker(taskHubName, servicebusConnectionString, storageConnectionString); if (options.CreateHub) { taskHub.CreateHub(); } if (!string.IsNullOrWhiteSpace(options.StartInstance)) { string instanceId = options.InstanceId; OrchestrationInstance instance = null; switch (options.StartInstance) { case "Greetings": instance = taskHubClient.CreateOrchestrationInstance(typeof(GreetingsOrchestration), instanceId, null); break; case "Greetings2": if (options.Parameters == null || options.Parameters.Length != 1) { throw new ArgumentException("parameters"); } instance = taskHubClient.CreateOrchestrationInstance(typeof(GreetingsOrchestration2), instanceId, int.Parse(options.Parameters[0])); break; case "Cron": // Sample Input: "0 12 * */2 Mon" instance = taskHubClient.CreateOrchestrationInstance(typeof(CronOrchestration), instanceId, (options.Parameters != null && options.Parameters.Length > 0) ? options.Parameters[0] : null); break; case "Average": // Sample Input: "1 50 10" if (options.Parameters == null || options.Parameters.Length != 3) { throw new ArgumentException("parameters"); } int[] input = options.Parameters.Select(p => int.Parse(p)).ToArray(); instance = taskHubClient.CreateOrchestrationInstance(typeof(AverageCalculatorOrchestration), instanceId, input); break; case "ErrorHandling": instance = taskHubClient.CreateOrchestrationInstance(typeof(ErrorHandlingOrchestration), instanceId, null); break; case "Signal": instance = taskHubClient.CreateOrchestrationInstance(typeof(SignalOrchestration), instanceId, null); break; case "Replat": instance = taskHubClient.CreateOrchestrationInstance(typeof(MigrateOrchestration), instanceId, new MigrateOrchestrationData() { SubscriptionId = "03a1cd39-47ac-4a57-9ff5-a2c2a2a76088", IsDisabled = false }); break; default: throw new Exception("Unsupported Orchestration Name: " + options.StartInstance); } Console.WriteLine("Workflow Instance Started: " + instance); } else if (!string.IsNullOrWhiteSpace(options.Signal)) { if (string.IsNullOrWhiteSpace(options.InstanceId)) { throw new ArgumentException("instantceId"); } if (options.Parameters == null || options.Parameters.Length != 1) { throw new ArgumentException("parameters"); } string instanceId = options.InstanceId; OrchestrationInstance instance = new OrchestrationInstance { InstanceId = instanceId }; taskHubClient.RaiseEvent(instance, options.Signal, options.Parameters[0]); } if (!options.SkipWorker) { try { taskHub.AddTaskOrchestrations(typeof(GreetingsOrchestration), typeof(GreetingsOrchestration2), typeof(CronOrchestration), typeof (AverageCalculatorOrchestration), typeof (ErrorHandlingOrchestration), typeof (SignalOrchestration)); taskHub.AddTaskOrchestrations(typeof(MigrateOrchestration)); taskHub.AddTaskActivities(new GetUserTask(), new SendGreetingTask(), new CronTask(), new ComputeSumTask(), new GoodTask(), new BadTask(), new CleanupTask(), new EmailTask()); taskHub.AddTaskActivitiesFromInterface<IManagementSqlOrchestrationTasks>(new ManagementSqlOrchestrationTasks()); taskHub.AddTaskActivitiesFromInterface<IMigrationTasks>(new MigrationTasks()); taskHub.Start(); Console.WriteLine("Press any key to quit."); Console.ReadLine(); taskHub.Stop(true); } catch (Exception) { // silently eat any unhadled exceptions. } } } }
static void Main(string[] args) { string tableConnectionString = ConfigurationManager.AppSettings["StorageConnectionString"]; if (CommandLine.Parser.Default.ParseArgumentsStrict(args, options)) { string connectionString = ConfigurationManager.ConnectionStrings["Microsoft.ServiceBus.ConnectionString"].ConnectionString; string taskHubName = ConfigurationManager.AppSettings["TaskHubName"]; TaskHubClient taskHubClient = new TaskHubClient(taskHubName, connectionString, tableConnectionString); TaskHubWorkerSettings settings = new TaskHubWorkerSettings(); settings.TaskOrchestrationDispatcherSettings.CompressOrchestrationState = bool.Parse(ConfigurationManager.AppSettings["CompressOrchestrationState"]); settings.TaskActivityDispatcherSettings.MaxConcurrentActivities = int.Parse(ConfigurationManager.AppSettings["MaxConcurrentActivities"]); settings.TaskOrchestrationDispatcherSettings.MaxConcurrentOrchestrations = int.Parse(ConfigurationManager.AppSettings["MaxConcurrentOrchestrations"]); TaskHubWorker taskHub = new TaskHubWorker(taskHubName, connectionString, tableConnectionString, settings); if (options.CreateHub) { taskHub.CreateHub(); } OrchestrationInstance instance = null; string instanceId = options.StartInstance; if (!string.IsNullOrWhiteSpace(instanceId)) { instance = taskHubClient.CreateOrchestrationInstance(typeof(DriverOrchestration), instanceId, new DriverOrchestrationData { NumberOfIteration = int.Parse(ConfigurationManager.AppSettings["DriverOrchestrationIterations"]), NumberOfParallelTasks = int.Parse(ConfigurationManager.AppSettings["DriverOrchestrationParallelTasks"]), SubOrchestrationData = new TestOrchestrationData { NumberOfParallelTasks = int.Parse(ConfigurationManager.AppSettings["ChildOrchestrationParallelTasks"]), NumberOfSerialTasks = int.Parse(ConfigurationManager.AppSettings["ChildOrchestrationSerialTasks"]), MaxDelayInSeconds = int.Parse(ConfigurationManager.AppSettings["TestTaskMaxDelayInMinutes"]), }, }); } else { instance = new OrchestrationInstance { InstanceId = options.InstanceId }; } Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); TestTask testTask = new TestTask(); taskHub.AddTaskActivities(testTask); taskHub.AddTaskOrchestrations(typeof(DriverOrchestration)); taskHub.AddTaskOrchestrations(typeof(TestOrchestration)); taskHub.Start(); int testTimeoutInSeconds = int.Parse(ConfigurationManager.AppSettings["TestTimeoutInSeconds"]); OrchestrationState state = WaitForInstance(taskHubClient, instance, testTimeoutInSeconds); stopWatch.Stop(); Console.WriteLine("Orchestration Status: " + state.OrchestrationStatus.ToString()); Console.WriteLine("Orchestration Result: " + state.Output); Console.WriteLine("Counter: " + testTask.counter); TimeSpan totalTime = stopWatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", totalTime.Hours, totalTime.Minutes, totalTime.Seconds, totalTime.Milliseconds / 10); Console.WriteLine("Total Time: " + elapsedTime); taskHub.Stop(); } }
static void Main(string[] args) { if (CommandLine.Parser.Default.ParseArgumentsStrict(args, options)) { string servicebusConnectionString = Program.GetSetting("ServiceBusConnectionString"); string storageConnectionString = Program.GetSetting("StorageConnectionString"); string taskHubName = ConfigurationManager.AppSettings["taskHubName"]; TaskHubClient taskHubClient = new TaskHubClient(taskHubName, servicebusConnectionString, storageConnectionString); TaskHubWorker taskHub = new TaskHubWorker(taskHubName, servicebusConnectionString, storageConnectionString); if (options.CreateHub) { taskHub.CreateHub(); } if (!string.IsNullOrWhiteSpace(options.StartInstance)) { string instanceId = options.InstanceId; OrchestrationInstance instance = null; switch (options.StartInstance) { case "Greetings": instance = taskHubClient.CreateOrchestrationInstance(typeof(GreetingsOrchestration), instanceId, null); break; case "Greetings2": if (options.Parameters == null || options.Parameters.Length != 1) { throw new ArgumentException("parameters"); } instance = taskHubClient.CreateOrchestrationInstance(typeof(GreetingsOrchestration2), instanceId, int.Parse(options.Parameters[0])); break; case "Cron": // Sample Input: "0 12 * */2 Mon" instance = taskHubClient.CreateOrchestrationInstance(typeof(CronOrchestration), instanceId, (options.Parameters != null && options.Parameters.Length > 0) ? options.Parameters[0] : null); break; case "Average": // Sample Input: "1 50 10" if (options.Parameters == null || options.Parameters.Length != 3) { throw new ArgumentException("parameters"); } int[] input = options.Parameters.Select(p => int.Parse(p)).ToArray(); instance = taskHubClient.CreateOrchestrationInstance(typeof(AverageCalculatorOrchestration), instanceId, input); break; case "ErrorHandling": instance = taskHubClient.CreateOrchestrationInstance(typeof(ErrorHandlingOrchestration), instanceId, null); break; case "Signal": instance = taskHubClient.CreateOrchestrationInstance(typeof(SignalOrchestration), instanceId, null); break; case "Replat": instance = taskHubClient.CreateOrchestrationInstance(typeof(MigrateOrchestration), instanceId, new MigrateOrchestrationData() { SubscriptionId = "03a1cd39-47ac-4a57-9ff5-a2c2a2a76088", IsDisabled = false }); break; default: throw new Exception("Unsupported Orchestration Name: " + options.StartInstance); } Console.WriteLine("Workflow Instance Started: " + instance); } else if (!string.IsNullOrWhiteSpace(options.Signal)) { if (string.IsNullOrWhiteSpace(options.InstanceId)) { throw new ArgumentException("instantceId"); } if (options.Parameters == null || options.Parameters.Length != 1) { throw new ArgumentException("parameters"); } string instanceId = options.InstanceId; OrchestrationInstance instance = new OrchestrationInstance { InstanceId = instanceId }; taskHubClient.RaiseEvent(instance, options.Signal, options.Parameters[0]); } if (!options.SkipWorker) { try { taskHub.AddTaskOrchestrations(typeof(GreetingsOrchestration), typeof(GreetingsOrchestration2), typeof(CronOrchestration), typeof(AverageCalculatorOrchestration), typeof(ErrorHandlingOrchestration), typeof(SignalOrchestration)); taskHub.AddTaskOrchestrations(typeof(MigrateOrchestration)); taskHub.AddTaskActivities(new GetUserTask(), new SendGreetingTask(), new CronTask(), new ComputeSumTask(), new GoodTask(), new BadTask(), new CleanupTask(), new EmailTask()); taskHub.AddTaskActivitiesFromInterface <IManagementSqlOrchestrationTasks>(new ManagementSqlOrchestrationTasks()); taskHub.AddTaskActivitiesFromInterface <IMigrationTasks>(new MigrationTasks()); taskHub.Start(); Console.WriteLine("Press any key to quit."); Console.ReadLine(); taskHub.Stop(true); } catch (Exception) { // silently eat any unhadled exceptions. } } } }