示例#1
0
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the value to convert into an instance of <see cref="TaskPollResponse" />.</param>
 /// <returns>
 /// an instance of <see cref="TaskPollResponse" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public static object ConvertFrom(dynamic sourceValue)
 {
     if (null == sourceValue)
     {
         return(null);
     }
     try
     {
         TaskPollResponse.FromJsonString(typeof(string) == sourceValue.GetType() ? sourceValue : sourceValue.ToJsonString());
     }
     catch
     {
         // Unable to use JSON pattern
     }
     try
     {
         return(new TaskPollResponse
         {
             Entities = sourceValue.Entities,
             HasPollTimedOut = sourceValue.HasPollTimedOut,
         });
     }
     catch
     {
     }
     return(null);
 }
示例#2
0
        internal async Task <string> ProcessAsync(string baseAddress)
        {
            using (var httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri(baseAddress);

                // TODO create a stop mechanism. Ugly but it will work for now. If you want to stop it just close the application.
                while (true)
                {
                    HttpResponseMessage pollResponseMessage;
                    do
                    {
                        pollResponseMessage = await httpClient.GetAsync("api/tasks/poll/task_10");

                        Thread.Sleep(1000);
                    } while (pollResponseMessage.StatusCode == System.Net.HttpStatusCode.NoContent);

                    if (!pollResponseMessage.IsSuccessStatusCode)
                    {
                        System.Console.WriteLine($"A problem has occurred during task 10 polling. Status code: {pollResponseMessage.StatusCode}");
                        continue;
                    }

                    string task1PollJsonResponse = await pollResponseMessage?.Content?.ReadAsStringAsync();

                    TaskPollResponse taskPollResponse = JsonConvert.DeserializeObject <TaskPollResponse>(task1PollJsonResponse);

                    var taskUpdateRequest = new TaskUpdateRequest();

                    taskUpdateRequest.TaskId             = taskPollResponse.TaskId;
                    taskUpdateRequest.WorkflowInstanceId = taskPollResponse.WorkflowInstanceId;
                    taskUpdateRequest.OutputData         = new OutputData
                    {
                        Mod     = taskPollResponse?.InputData?.Mod,
                        OddEven = taskPollResponse?.InputData?.OddEven
                    };
                    taskUpdateRequest.Status = Constants.TaskStatuses.COMPLETED;

                    var stringContent = new StringContent(JsonConvert.SerializeObject(taskUpdateRequest), Encoding.UTF8, "application/json");

                    HttpResponseMessage responseMessage = await httpClient.PostAsync("api/tasks/", stringContent);

                    if (!responseMessage.IsSuccessStatusCode)
                    {
                        System.Console.WriteLine($"A problem has occurred during task 10 update. Status code: {pollResponseMessage.StatusCode}");
                        continue;
                    }

                    System.Console.WriteLine($"Task10 Worker Processed task: {await responseMessage.Content.ReadAsStringAsync()}");

                    Thread.Sleep(1000);
                }

                // TODO Send the received ID through an event
                return(null);
            }
        }
        public async Task ProcessAsync(string baseAddress)
        {
            using (var httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri(baseAddress);

                // TODO create a stop mechanism. Ugly but it will work for now. If you want to stop it just close the application.
                while (true)
                {
                    HttpResponseMessage pollResponseMessage;
                    do
                    {
                        pollResponseMessage = await httpClient.GetAsync("api/tasks/poll/task_1");

                        Thread.Sleep(1000);
                    } while (pollResponseMessage.StatusCode == System.Net.HttpStatusCode.NoContent);

                    if (!pollResponseMessage.IsSuccessStatusCode)
                    {
                        System.Console.WriteLine($"A problem has occurred during task 1 polling. Status code: {pollResponseMessage.StatusCode}");
                        continue;
                    }

                    string task1PollJsonResponse = await pollResponseMessage?.Content?.ReadAsStringAsync();

                    TaskPollResponse taskPollResponse = JsonConvert.DeserializeObject <TaskPollResponse>(task1PollJsonResponse);

                    int?oddEven           = taskPollResponse?.InputData?.OddEven;
                    var taskUpdateRequest = new TaskUpdateRequest();

                    switch (oddEven)
                    {
                    case 0:
                        const string TASK_1   = "task_1";
                        const string TASK_1_1 = "task_1_1";
                        const string WF_DYN   = "wf_dyn";

                        var dynamicForkOutputData = new DynamicForkOutputData();
                        dynamicForkOutputData.TaskToExecute = TASK_1;
                        dynamicForkOutputData.DynamicTasks  = new List <DynamicTask>();
                        dynamicForkOutputData.DynamicTasks.Add(new SimpleDynamicTask
                        {
                            Name = TASK_1,
                            TaskReferenceName = TASK_1_1,
                        });
                        dynamicForkOutputData.DynamicTasks.Add(new SubWorkFlowDynamicTask
                        {
                            Name = "sub_workflow_4",
                            TaskReferenceName = WF_DYN,
                            SubWorkflowParam  = new SubWorkFlowParameter
                            {
                                Name = "sub_flow_1"
                            }
                        });
                        dynamicForkOutputData.Inputs = new JRaw($"{{\"{TASK_1_1}\": {{}}, \"{WF_DYN}\": {{}}}}");
                        taskUpdateRequest.OutputData = dynamicForkOutputData;
                        break;

                    case 1:
                        taskUpdateRequest.OutputData     = new OutputData();
                        taskUpdateRequest.OutputData.Mod = taskPollResponse?.InputData?.Mod;
                        break;

                    default:
                        taskUpdateRequest.OutputData = new OutputData();
                        break;
                    }
                    taskUpdateRequest.TaskId             = taskPollResponse.TaskId;
                    taskUpdateRequest.WorkflowInstanceId = taskPollResponse.WorkflowInstanceId;
                    taskUpdateRequest.Status             = Constants.TaskStatuses.COMPLETED;
                    taskUpdateRequest.OutputData.OddEven = oddEven;

                    var stringContent = new StringContent(JsonConvert.SerializeObject(taskUpdateRequest), Encoding.UTF8, "application/json");

                    HttpResponseMessage responseMessage = await httpClient.PostAsync("api/tasks/", stringContent);

                    if (!responseMessage.IsSuccessStatusCode)
                    {
                        System.Console.WriteLine($"A problem has occurred during task 1 update. Status code: {pollResponseMessage.StatusCode}");
                        continue;
                    }

                    System.Console.WriteLine($"Task1 Worker Processed task: {await responseMessage.Content.ReadAsStringAsync()}");

                    Thread.Sleep(1000);
                }
            }
        }
        internal async Task <string> ProcessAsync(string baseAddress)
        {
            using (var httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri(baseAddress);

                // TODO create a stop mechanism. Ugly but it will work for now. If you want to stop it just close the application.
                while (true)
                {
                    HttpResponseMessage pollResponseMessage;
                    do
                    {
                        pollResponseMessage = await httpClient.GetAsync("api/tasks/poll/task_5");

                        Thread.Sleep(1000);
                    } while (pollResponseMessage.StatusCode == System.Net.HttpStatusCode.NoContent);

                    if (!pollResponseMessage.IsSuccessStatusCode)
                    {
                        System.Console.WriteLine($"A problem has occurred during task 5 polling. Status code: {pollResponseMessage.StatusCode}");
                        continue;
                    }

                    string task1PollJsonResponse = await pollResponseMessage?.Content?.ReadAsStringAsync();

                    TaskPollResponse taskPollResponse = JsonConvert.DeserializeObject <TaskPollResponse>(task1PollJsonResponse);

                    int?oddEven           = taskPollResponse?.InputData?.OddEven;
                    var taskUpdateRequest = new TaskUpdateRequest();

                    switch (oddEven)
                    {
                    case 0:
                        var dynamicForkOutputData = new DynamicForkOutputData();
                        dynamicForkOutputData.DynamicTasks = taskPollResponse.InputData.DynamicTasks;
                        dynamicForkOutputData.Inputs       = taskPollResponse.InputData.Inputs;

                        taskUpdateRequest.OutputData = dynamicForkOutputData;
                        break;

                    case 1:
                        taskUpdateRequest.OutputData     = new OutputData();
                        taskUpdateRequest.OutputData.Mod = taskPollResponse?.InputData?.Mod;
                        break;

                    default:
                        taskUpdateRequest.OutputData = new OutputData();
                        break;
                    }
                    taskUpdateRequest.TaskId             = taskPollResponse.TaskId;
                    taskUpdateRequest.WorkflowInstanceId = taskPollResponse.WorkflowInstanceId;
                    taskUpdateRequest.Status             = Constants.TaskStatuses.COMPLETED;
                    taskUpdateRequest.OutputData.OddEven = oddEven;

                    // TODO Remove fixed address from code
                    taskUpdateRequest.OutputData.ElasticSearchHost = "192.168.137.93";

                    var stringContent = new StringContent(JsonConvert.SerializeObject(taskUpdateRequest), Encoding.UTF8, "application/json");

                    HttpResponseMessage responseMessage = await httpClient.PostAsync("api/tasks/", stringContent);

                    if (!responseMessage.IsSuccessStatusCode)
                    {
                        System.Console.WriteLine($"A problem has occurred during task 5 update. Status code: {pollResponseMessage.StatusCode}");
                        continue;
                    }

                    System.Console.WriteLine($"Task5 Worker Processed task: {await responseMessage.Content.ReadAsStringAsync()}");

                    Thread.Sleep(1000);
                }

                // TODO Send the received ID through an event
                return(null);
            }
        }