internal void ShowTaskSummary(ITaskSummary summary)
        {
            string summaryText;

            if (summary == null)
            {
                summaryText = "No summary.";
            }
            else if (summary is StringTaskSummary)
            {
                summaryText = (StringTaskSummary)summary;
            }
            else if (summary is DictionaryTaskSummary)
            {
                summaryText = string.Join(Environment.NewLine,
                                          ((DictionaryTaskSummary)summary).Select(p => "{0} = {1}".FormatInvariant(p.Key, p.Value)));
            }
            else
            {
                summaryText = string.Concat(summary, Environment.NewLine, Environment.NewLine,
                                            string.Join(Environment.NewLine,
                                                        summary.GetType().GetProperties()
                                                        .Select(p => "{0} = {1}".FormatInvariant(p.Name, p.GetValue(summary)))));
            }

            MessageBox.Show(summaryText, "Task Summary", MessageBoxButton.OK, MessageBoxImage.Information);
        }
        /// <inheritdoc />
        public void Add(Guid taskId, ITaskSummary summary)
        {
            Trace.WriteLine("ENTER: Adding summary '{0}' for task '{1}' ...".FormatInvariant(summary, taskId));

            if (summary == null)
            {
                throw new ArgumentNullException(nameof(summary));
            }

            string taskIdAsString = RedisConverter.ToString(taskId);

            byte[] content = this.serializer.Serialize(summary);

            if (this.serializer.CanDetermineEntityTypeFromContent)
            {
                this.provider.SetHashValue(RedisTaskSummaryRepository.RedisTaskSummaryHashKey, taskIdAsString, content);
            }
            else
            {
                using (IRedisTransaction transaction = this.provider.CreateTransaction())
                {
                    transaction.SetHashValue(RedisTaskSummaryRepository.RedisTaskSummaryHashKey, taskIdAsString, content);
                    transaction.SetHashValue(RedisTaskSummaryRepository.RedisTaskSummaryHashKey, taskIdAsString + "$Type", RedisConverter.ToString(summary.GetType(), false));

                    transaction.Commit();
                }
            }

            Trace.WriteLine("EXIT: Summary '{0}' added for task '{1}'.".FormatInvariant(summary, taskId));
        }
        /// <summary>
        /// Submits a task with the specified parameters.
        /// </summary>
        /// <param name="taskId">The unique ID of the task.</param>
        /// <param name="task">The task to submit.</param>
        /// <param name="summary">The summary to associated with the task, if any.</param>
        /// <param name="priority">The priority of the task.</param>
        internal void SubmitTask(Guid taskId, ITask task, ITaskSummary summary, TaskPriority priority)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }

            Trace.WriteLine("ENTER: Submitting '{0}' with priority '{1}' ...".FormatInvariant(task.GetType().Name, priority));

            string pollingQueueKey = this.configuration.GetPollingQueueKey(task.GetType());

            this.repository.Tasks.Add(taskId, task);

            if (summary != null)
            {
                this.repository.TaskSummary.Add(taskId, summary);
            }

            ITaskRuntimeInfo taskInfo = this.repository.TaskRuntimeInfo.Create(taskId, task.GetType(), this.dateTimeProvider.UtcNow, priority, pollingQueueKey);

            this.repository.TaskRuntimeInfo.Add(taskInfo);

            ITaskMessageBusSender taskMessageBus = this.messageBus.Tasks.GetSender(task.GetType());

            taskMessageBus.NotifyTaskSubmitted(taskId, this.dateTimeProvider.UtcNow, !string.IsNullOrEmpty(pollingQueueKey));

            Trace.WriteLine("EXIT: Task '{0}' submitted with ID '{1}' ...".FormatInvariant(task, taskId));
        }
        private void OnTaskSummaryButtonClick(object sender, RoutedEventArgs e)
        {
            TaskViewModel taskViewModel = (TaskViewModel)((FrameworkElement)sender).DataContext;

            ITaskSummary summary = this.viewModel.TaskProcessorFacade.GetTaskSummary(taskViewModel.TaskId);

            taskViewModel.ShowTaskSummary(summary);
        }
        /// <inheritdoc />
        public Guid SubmitTask(ITask task, ITaskSummary summary, TaskPriority priority)
        {
            Guid taskId = Guid.NewGuid();

            this.SubmitTask(taskId, task, summary, priority);

            return(taskId);
        }
        public void PrepareNextTask()
        {
            int totalSeconds = this.randomizer.Next(this.MinDurationInSeconds, this.MaxDurationInSeconds);

            this.nextTask = new DemoTask(totalSeconds);

            this.nextSummary = this.nextTask.CreateTaskSummary(SummaryType.Text, true);

            this.nextPriority = this.nextPriority == TaskPriority.VeryHigh ? TaskPriority.Low : (TaskPriority)this.nextPriority++;
        }
Beispiel #7
0
        private void OnSubmitDemoTaskButtonClick(object sender, RoutedEventArgs e)
        {
            SubmitTaskWindow dialog = new SubmitTaskWindow();

            if (dialog.ShowDialog() == true)
            {
                DemoTask demoTask = new DemoTask((int)dialog.TaskDuration.TotalSeconds)
                {
                    ThrowError = dialog.ThrowError
                };

                if (dialog.SummaryType.HasValue)
                {
                    ITaskSummary summary = demoTask.CreateTaskSummary(dialog.SummaryType.Value, false);

                    if (dialog.TaskPriority.HasValue)
                    {
                        this.ViewModel.TaskProcessorFacade.SubmitTask(demoTask, summary, dialog.TaskPriority.Value);
                    }
                    else
                    {
                        this.ViewModel.TaskProcessorFacade.SubmitTask(demoTask, summary);
                    }
                }
                else
                {
                    if (dialog.TaskPriority.HasValue)
                    {
                        this.ViewModel.TaskProcessorFacade.SubmitTask(demoTask, dialog.TaskPriority.Value);
                    }
                    else
                    {
                        this.ViewModel.TaskProcessorFacade.SubmitTask(demoTask);
                    }
                }
            }
        }
        public Guid SubmitTask(ITask task, ITaskSummary summary, TaskPriority priority)
        {
            this.RecordMethodCall(task, summary, priority);

            return(Guid.NewGuid());
        }
 public Guid SubmitTask(ITask task, ITaskSummary summary)
 {
     throw new NotImplementedException();
 }
Beispiel #10
0
        public void Add(Guid taskId, ITaskSummary summary)
        {
            this.RecordMethodCall(taskId, summary);

            this.summaries.Add(taskId, summary);
        }
 /// <inheritdoc />
 public Guid SubmitTask(ITask task, ITaskSummary summary)
 {
     return(this.SubmitTask(task, summary, TaskPriority.Normal));
 }