Beispiel #1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Start");
            string serviceBusConnectionString = "";
            string storageConnectionString    = "";
            string taskHubName = "devstoreaccount";

            var instanceStore = new AzureTableInstanceStore(taskHubName, storageConnectionString);

            var orchestrationServiceAndClient = new ServiceBusOrchestrationService(serviceBusConnectionString, taskHubName, instanceStore, null, null);

            await orchestrationServiceAndClient.CreateIfNotExistsAsync();

            var taskHubWorker = await new TaskHubWorker(orchestrationServiceAndClient)
                                .AddTaskOrchestrations(typeof(PredicaOrchestration))
                                .AddTaskActivities(new ApproveInvoice())
                                .AddTaskActivities(new RejectInvoice())
                                .AddTaskActivities(new SendInvoice())
                                .StartAsync();


            var taskHubClient = new TaskHubClient(orchestrationServiceAndClient);

            var instanceId = Guid.NewGuid().ToString();
            var instance   = await taskHubClient.CreateOrchestrationInstanceAsync(typeof(PredicaOrchestration), instanceId, $"Predica-Inv-{DateTime.UtcNow.Ticks}");

            await taskHubClient.WaitForOrchestrationAsync(instance, TimeSpan.FromMinutes(15), CancellationToken.None);

            await taskHubWorker.StopAsync(false);
        }
        static void Main(string[] args)
        {
            eventListener = new ObservableEventListener();
            eventListener.LogToConsole();
            eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.LogAlways);

            TraceSource source = new TraceSource("DurableTask");

            source.Listeners.AddRange(Trace.Listeners);

            IOrchestrationServiceInstanceStore instanceStore = new AzureTableInstanceStore(TaskHubName, StorageConnectionString);

            ServiceBusOrchestrationService orchestrationServiceAndClient =
                new ServiceBusOrchestrationService(ServiceBusConnectionString, TaskHubName, instanceStore, null, null);

            orchestrationServiceAndClient.CreateIfNotExistsAsync().Wait();

            TaskHubClient taskHubClient = new TaskHubClient(orchestrationServiceAndClient);
            TaskHubWorker taskHub       = new TaskHubWorker(orchestrationServiceAndClient);

            taskHub.AddTaskOrchestrations(typeof(CounterOrchestration));
            taskHub.AddTaskActivities(typeof(Task1), typeof(Task2));

            var instance = taskHubClient.CreateOrchestrationInstanceAsync(typeof(CounterOrchestration), Guid.NewGuid().ToString(), new TestOrchestrationInput()).Result;

            taskHub.StartAsync().Wait();

            //taskHubClient.WaitForOrchestrationAsync(instance, TimeSpan.MaxValue).Wait();

            Thread.Sleep(int.MaxValue);
        }
Beispiel #3
0
        private static async Task startAsync()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://127.0.0.1;");

            IOrchestrationServiceInstanceStore store = new AzureTableInstanceStore("TestTaskHub9", "UseDevelopmentStorage=true;DevelopmentStorageProxyUri= http://127.0.0.1;");
            var           settings  = new ServiceBusOrchestrationServiceSettings();
            var           service   = new ServiceBusOrchestrationService("<ServiceBUsConnectionString>", "TestTaskHub9", store, null, settings);
            TaskHubWorker hubWorker = new TaskHubWorker(service);

            hubWorker.AddTaskOrchestrations(typeof(TestOrchestration));
            hubWorker.AddTaskActivities(typeof(TestActivity1));
            hubWorker.AddTaskActivities(typeof(TestActivity2));
            await service.CreateIfNotExistsAsync();

            await hubWorker.StartAsync();
        }
        public void OpenAndStartServiceHostTest()
        {
            eventListener = new ObservableEventListener();
            eventListener.LogToConsole();
            eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.LogAlways);

            TraceSource source = new TraceSource("DurableTask");

            source.Listeners.AddRange(Trace.Listeners);

            IOrchestrationServiceInstanceStore instanceStore = new AzureTableInstanceStore(TaskHubName, StorageConnectionString);
            ServiceBusOrchestrationService     orchestrationServiceAndClient =
                new ServiceBusOrchestrationService(ServiceBusConnectionString, TaskHubName, instanceStore, null, null);

            orchestrationServiceAndClient.CreateIfNotExistsAsync().Wait();

            TaskHubClient taskHubClient = new TaskHubClient(orchestrationServiceAndClient);
            TaskHubWorker taskHub       = new TaskHubWorker(orchestrationServiceAndClient);

            taskHub.AddTaskOrchestrations(typeof(CounterOrchestration));
            taskHub.AddTaskActivities(typeof(Task1), typeof(Task2));

            var rnts = ((AzureTableInstanceStore)instanceStore).GetJumpStartEntitiesAsync(1000).Result;

            var byNameQuery = new OrchestrationStateQuery();

            byNameQuery.AddStatusFilter(OrchestrationStatus.Pending);
            byNameQuery.AddNameVersionFilter(typeof(CounterOrchestration).FullName);

            var results = ((AzureTableInstanceStore)instanceStore).QueryOrchestrationStatesAsync(byNameQuery).Result;

            var instance = taskHubClient.CreateOrchestrationInstanceAsync(typeof(CounterOrchestration), Guid.NewGuid().ToString(), new TestOrchestrationInput()).Result;

            taskHub.StartAsync().Wait();

            var state = instanceStore.GetOrchestrationStateAsync(instance.InstanceId, true).Result;

            var res = taskHubClient.GetOrchestrationHistoryAsync(instance).Result;

            taskHubClient.WaitForOrchestrationAsync(instance, TimeSpan.MaxValue).Wait();
        }
        static void Main(string[] args)
        {
            eventListener = new ObservableEventListener();
            eventListener.LogToConsole();
            eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.LogAlways);

            if (CommandLine.Parser.Default.ParseArgumentsStrict(args, ArgumentOptions))
            {
                string serviceBusConnectionString = GetSetting("ServiceBusConnectionString");
                string storageConnectionString    = GetSetting("StorageConnectionString");
                string taskHubName = ConfigurationManager.AppSettings["taskHubName"];

                IOrchestrationServiceInstanceStore instanceStore = new AzureTableInstanceStore(taskHubName, storageConnectionString);

                var orchestrationServiceAndClient =
                    new ServiceBusOrchestrationService(serviceBusConnectionString, taskHubName, instanceStore, null, null);

                var taskHubClient = new TaskHubClient(orchestrationServiceAndClient);
                var taskHub       = new TaskHubWorker(orchestrationServiceAndClient);

                if (ArgumentOptions.CreateHub)
                {
                    orchestrationServiceAndClient.CreateIfNotExistsAsync().Wait();
                }

                OrchestrationInstance instance = null;

                if (!string.IsNullOrWhiteSpace(ArgumentOptions.StartInstance))
                {
                    string instanceId = ArgumentOptions.InstanceId ?? Guid.NewGuid().ToString();
                    Console.WriteLine($"Start Orchestration: {ArgumentOptions.StartInstance}");
                    switch (ArgumentOptions.StartInstance)
                    {
                    case "Greetings":
                        instance = taskHubClient.CreateOrchestrationInstanceAsync(typeof(GreetingsOrchestration), instanceId, null).Result;
                        break;

                    case "Greetings2":
                        if (ArgumentOptions.Parameters == null || ArgumentOptions.Parameters.Length != 1)
                        {
                            throw new ArgumentException("parameters");
                        }

                        instance = taskHubClient.CreateOrchestrationInstanceAsync(typeof(GreetingsOrchestration2), instanceId,
                                                                                  int.Parse(ArgumentOptions.Parameters[0])).Result;
                        break;

                    case "Cron":
                        // Sample Input: "0 12 * */2 Mon"
                        instance = taskHubClient.CreateOrchestrationInstanceAsync(typeof(CronOrchestration), instanceId,
                                                                                  (ArgumentOptions.Parameters != null && ArgumentOptions.Parameters.Length > 0) ? ArgumentOptions.Parameters[0] : null).Result;
                        break;

                    case "Average":
                        // Sample Input: "1 50 10"
                        if (ArgumentOptions.Parameters == null || ArgumentOptions.Parameters.Length != 3)
                        {
                            throw new ArgumentException("parameters");
                        }

                        int[] input = ArgumentOptions.Parameters.Select(p => int.Parse(p)).ToArray();
                        instance = taskHubClient.CreateOrchestrationInstanceAsync(typeof(AverageCalculatorOrchestration), instanceId, input).Result;
                        break;

                    case "ErrorHandling":
                        instance = taskHubClient.CreateOrchestrationInstanceAsync(typeof(ErrorHandlingOrchestration), instanceId, null).Result;
                        break;

                    case "SumOfSquares":
                        instance = taskHubClient.CreateOrchestrationInstanceAsync(
                            "SumOfSquaresOrchestration",
                            "V1",
                            instanceId,
                            File.ReadAllText("SumofSquares\\BagOfNumbers.json"),
                            new Dictionary <string, string>(1)
                        {
                            { "Category", "testing" }
                        }).Result;
                        break;

                    case "Signal":
                        instance = taskHubClient.CreateOrchestrationInstanceAsync(typeof(SignalOrchestration), instanceId, null).Result;
                        break;

                    case "SignalAndRaise":
                        if (ArgumentOptions.Parameters == null || ArgumentOptions.Parameters.Length != 1)
                        {
                            throw new ArgumentException("parameters");
                        }

                        instance = taskHubClient.CreateOrchestrationInstanceWithRaisedEventAsync(typeof(SignalOrchestration), instanceId, null, ArgumentOptions.Signal, ArgumentOptions.Parameters[0]).Result;
                        break;

                    case "Replat":
                        instance = taskHubClient.CreateOrchestrationInstanceAsync(typeof(MigrateOrchestration), instanceId,
                                                                                  new MigrateOrchestrationData {
                            SubscriptionId = "03a1cd39-47ac-4a57-9ff5-a2c2a2a76088", IsDisabled = false
                        }).Result;
                        break;

                    default:
                        throw new Exception("Unsupported Orchestration Name: " + ArgumentOptions.StartInstance);
                    }

                    Console.WriteLine("Workflow Instance Started: " + instance);
                }
                else if (!string.IsNullOrWhiteSpace(ArgumentOptions.Signal))
                {
                    Console.WriteLine("Run RaiseEvent");

                    if (string.IsNullOrWhiteSpace(ArgumentOptions.InstanceId))
                    {
                        throw new ArgumentException("instanceId");
                    }

                    if (ArgumentOptions.Parameters == null || ArgumentOptions.Parameters.Length != 1)
                    {
                        throw new ArgumentException("parameters");
                    }

                    string instanceId = ArgumentOptions.InstanceId;
                    instance = new OrchestrationInstance {
                        InstanceId = instanceId
                    };
                    taskHubClient.RaiseEventAsync(instance, ArgumentOptions.Signal, ArgumentOptions.Parameters[0]).Wait();

                    Console.WriteLine("Press any key to quit.");
                    Console.ReadLine();
                }

                if (!ArgumentOptions.SkipWorker)
                {
                    try
                    {
                        taskHub.AddTaskOrchestrations(
                            typeof(GreetingsOrchestration),
                            typeof(GreetingsOrchestration2),
                            typeof(CronOrchestration),
                            typeof(AverageCalculatorOrchestration),
                            typeof(ErrorHandlingOrchestration),
                            typeof(SignalOrchestration),
                            typeof(MigrateOrchestration),
                            typeof(SumOfSquaresOrchestration)
                            );

                        taskHub.AddTaskOrchestrations(
                            new NameValueObjectCreator <TaskOrchestration>("SumOfSquaresOrchestration", "V1", typeof(SumOfSquaresOrchestration)));

                        taskHub.AddTaskActivities(
                            new GetUserTask(),
                            new SendGreetingTask(),
                            new CronTask(),
                            new ComputeSumTask(),
                            new GoodTask(),
                            new BadTask(),
                            new CleanupTask(),
                            new EmailTask(),
                            new SumOfSquaresTask()
                            );

                        taskHub.AddTaskActivitiesFromInterface <IManagementSqlOrchestrationTasks>(new ManagementSqlOrchestrationTasks());
                        taskHub.AddTaskActivitiesFromInterface <IMigrationTasks>(new MigrationTasks());

                        taskHub.StartAsync().Wait();

                        Console.WriteLine("Waiting up to 60 seconds for completion.");

                        OrchestrationState taskResult = taskHubClient.WaitForOrchestrationAsync(instance, TimeSpan.FromSeconds(60), CancellationToken.None).Result;
                        Console.WriteLine($"Task done: {taskResult?.OrchestrationStatus}");

                        Console.WriteLine("Press any key to quit.");
                        Console.ReadLine();

                        taskHub.StopAsync(true).Wait();
                    }
                    catch (Exception e)
                    {
                        // silently eat any unhandled exceptions.
                        Console.WriteLine($"worker exception: {e}");
                    }
                }
                else
                {
                    Console.WriteLine("Skip Worker");
                }
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            eventListener = new ObservableEventListener();
            eventListener.LogToFlatFile("Trace.log");
            eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.Warning);

            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"];


                IOrchestrationServiceInstanceStore instanceStore = new AzureTableInstanceStore(taskHubName, tableConnectionString);

                ServiceBusOrchestrationServiceSettings settings = new ServiceBusOrchestrationServiceSettings
                {
                    TaskOrchestrationDispatcherSettings =
                    {
                        CompressOrchestrationState  = bool.Parse(ConfigurationManager.AppSettings["CompressOrchestrationState"]),
                        MaxConcurrentOrchestrations = int.Parse(ConfigurationManager.AppSettings["MaxConcurrentOrchestrations"])
                    },
                    TaskActivityDispatcherSettings =
                    {
                        MaxConcurrentActivities = int.Parse(ConfigurationManager.AppSettings["MaxConcurrentActivities"])
                    }
                };

                ServiceBusOrchestrationService orchestrationServiceAndClient =
                    new ServiceBusOrchestrationService(connectionString, taskHubName, instanceStore, null, settings);


                TaskHubClient taskHubClient = new TaskHubClient(orchestrationServiceAndClient);
                TaskHubWorker taskHub       = new TaskHubWorker(orchestrationServiceAndClient);

                if (options.CreateHub)
                {
                    orchestrationServiceAndClient.CreateIfNotExistsAsync().Wait();
                }

                OrchestrationInstance instance = null;
                string instanceId = options.StartInstance;

                if (!string.IsNullOrWhiteSpace(instanceId))
                {
                    var driverConfig = 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"]),
                            MaxDelayInMinutes     = int.Parse(ConfigurationManager.AppSettings["TestTaskMaxDelayInMinutes"]),
                        }
                    };

                    instance = taskHubClient.CreateOrchestrationInstanceAsync(typeof(DriverOrchestration), instanceId, driverConfig).Result;
                }
                else
                {
                    instance = new OrchestrationInstance {
                        InstanceId = options.InstanceId
                    };
                }

                Console.WriteLine($"Orchestration starting: {DateTime.Now}");
                Stopwatch stopWatch = Stopwatch.StartNew();

                TestTask testTask = new TestTask();
                taskHub.AddTaskActivities(testTask);
                taskHub.AddTaskOrchestrations(typeof(DriverOrchestration));
                taskHub.AddTaskOrchestrations(typeof(TestOrchestration));
                taskHub.StartAsync().Wait();

                int testTimeoutInSeconds = int.Parse(ConfigurationManager.AppSettings["TestTimeoutInSeconds"]);
                OrchestrationState state = WaitForInstance(taskHubClient, instance, testTimeoutInSeconds);
                stopWatch.Stop();
                Console.WriteLine($"Orchestration Status: {state.OrchestrationStatus}");
                Console.WriteLine($"Orchestration Result: {state.Output}");
                Console.WriteLine($"Counter: {testTask.counter}");

                TimeSpan totalTime   = stopWatch.Elapsed;
                string   elapsedTime = $"{totalTime.Hours:00}:{totalTime.Minutes:00}:{totalTime.Seconds:00}.{totalTime.Milliseconds/10:00}";
                Console.WriteLine($"Total Time: {elapsedTime}");
                Console.ReadLine();

                taskHub.StopAsync().Wait();
            }
        }
Beispiel #7
0
        // ReSharper disable once UnusedMember.Local
        static void Main(string[] args)
        {
            using (DiagnosticPipelineFactory.CreatePipeline("eventFlowConfig.json"))
            {
                var    config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                string tableConnectionString        = config.AppSettings.Settings["StorageConnectionString"].Value;
                ParserResult <Options> parserResult = Parser.Default.ParseArguments <Options>(args);
                parserResult.WithParsed(
                    options =>
                {
                    string connectionString = config.ConnectionStrings.ConnectionStrings["Microsoft.ServiceBus.ConnectionString"].ConnectionString;
                    string taskHubName      = config.AppSettings.Settings["TaskHubName"].Value;


                    IOrchestrationServiceInstanceStore instanceStore = new AzureTableInstanceStore(taskHubName, tableConnectionString);

                    var settings = new ServiceBusOrchestrationServiceSettings
                    {
                        TaskOrchestrationDispatcherSettings =
                        {
                            CompressOrchestrationState  = bool.Parse(config.AppSettings.Settings["CompressOrchestrationState"].Value),
                            MaxConcurrentOrchestrations = int.Parse(config.AppSettings.Settings["MaxConcurrentOrchestrations"].Value)
                        },
                        TaskActivityDispatcherSettings =
                        {
                            MaxConcurrentActivities = int.Parse(config.AppSettings.Settings["MaxConcurrentActivities"].Value)
                        }
                    };

                    var orchestrationServiceAndClient =
                        new ServiceBusOrchestrationService(connectionString, taskHubName, instanceStore, null, settings);


                    var taskHubClient = new TaskHubClient(orchestrationServiceAndClient);
                    var taskHub       = new TaskHubWorker(orchestrationServiceAndClient);

                    if (options.CreateHub)
                    {
                        orchestrationServiceAndClient.CreateIfNotExistsAsync().Wait();
                    }

                    OrchestrationInstance instance;
                    string instanceId = options.StartInstance;

                    if (!string.IsNullOrWhiteSpace(instanceId))
                    {
                        var driverConfig = new DriverOrchestrationData
                        {
                            NumberOfIteration     = int.Parse(config.AppSettings.Settings["DriverOrchestrationIterations"].Value),
                            NumberOfParallelTasks = int.Parse(config.AppSettings.Settings["DriverOrchestrationParallelTasks"].Value),
                            SubOrchestrationData  = new TestOrchestrationData
                            {
                                NumberOfParallelTasks = int.Parse(config.AppSettings.Settings["ChildOrchestrationParallelTasks"].Value),
                                NumberOfSerialTasks   = int.Parse(config.AppSettings.Settings["ChildOrchestrationSerialTasks"].Value),
                                MaxDelayInMinutes     = int.Parse(config.AppSettings.Settings["TestTaskMaxDelayInMinutes"].Value),
                            }
                        };

                        instance = taskHubClient.CreateOrchestrationInstanceAsync(typeof(DriverOrchestration), instanceId, driverConfig).Result;
                    }
                    else
                    {
                        instance = new OrchestrationInstance {
                            InstanceId = options.InstanceId
                        };
                    }

                    Console.WriteLine($"Orchestration starting: {DateTime.Now}");
                    Stopwatch stopWatch = Stopwatch.StartNew();

                    var testTask = new TestTask();
                    taskHub.AddTaskActivities(testTask);
                    taskHub.AddTaskOrchestrations(typeof(DriverOrchestration));
                    taskHub.AddTaskOrchestrations(typeof(TestOrchestration));
                    taskHub.StartAsync().Wait();

                    int testTimeoutInSeconds = int.Parse(config.AppSettings.Settings["TestTimeoutInSeconds"].Value);
                    OrchestrationState state = WaitForInstance(taskHubClient, instance, testTimeoutInSeconds);
                    stopWatch.Stop();
                    Console.WriteLine($"Orchestration Status: {state.OrchestrationStatus}");
                    Console.WriteLine($"Orchestration Result: {state.Output}");
                    Console.WriteLine($"Counter: {testTask.Counter}");

                    TimeSpan totalTime = stopWatch.Elapsed;
                    string elapsedTime = $"{totalTime.Hours:00}:{totalTime.Minutes:00}:{totalTime.Seconds:00}.{totalTime.Milliseconds / 10:00}";
                    Console.WriteLine($"Total Time: {elapsedTime}");
                    Console.ReadLine();

                    taskHub.StopAsync().Wait();
                })
                .WithNotParsed(errors => Console.Error.WriteLine(Options.GetUsage(parserResult)));
            }
        }