Esempio n. 1
0
        private string GetCurrentTaskComment(Product product)
        {
            var mostRecentCommand = ProductTransitionRepository.Get()
                                    .Where(pt => pt.ProductId == product.Id && (pt.Command != null || !String.IsNullOrWhiteSpace(pt.Comment)))
                                    .OrderByDescending(a => a.DateTransition)
                                    .FirstOrDefault();

            return(mostRecentCommand == null ? "" : mostRecentCommand.Comment);
        }
Esempio n. 2
0
        protected async Task ClearPreExecuteEntries(Guid processId)
        {
            var emptyItems = ProductTransitionRepository.Get()
                             .Where(pt => pt.WorkflowUserId == null && pt.ProductId == processId && pt.DateTransition == null)
                             .Select(pt => pt.Id).ToList();

            foreach (var item in emptyItems)
            {
                await ProductTransitionRepository.DeleteAsync(item);
            }
        }
        public async Task ProductProcessChangedAsync(ProductProcessChangedArgs args)
        {
            // Clear PreExecute entries
            var emptyItems = ProductTransitionRepository.Get()
                             .Where(pt => pt.WorkflowUserId == null && pt.ProductId == args.ProcessId)
                             .Select(pt => pt.Id).ToList();

            foreach (var item in emptyItems)
            {
                await ProductTransitionRepository.DeleteAsync(item);
            }
            // Create PreExecute entries
            await Runtime.PreExecuteFromCurrentActivityAsync(args.ProcessId);

            // Find the Product assoicated with the ProcessId
            var product = await ProductRepository.Get().Where(p => p.Id == args.ProcessId).FirstOrDefaultAsync();

            if (product == null)
            {
                Log.Error($"Could find Product for ProcessId={args.ProcessId}");
                return;
            }

            await RemoveTasksByProductId(product.Id);

            // Find all users who could perform the current activity and create tasks for them
            var workflowUserIds = Runtime.GetAllActorsForDirectCommandTransitions(args.ProcessId, activityName: args.CurrentActivityName).ToList();
            var users           = UserRepository.Get().Where(u => workflowUserIds.Contains(u.WorkflowUserId.GetValueOrDefault().ToString())).ToList();
            var workflowComment = product.WorkflowComment;

            foreach (var user in users)
            {
                var task = new UserTask
                {
                    UserId       = user.Id,
                    ProductId    = product.Id,
                    ActivityName = args.CurrentActivityName,
                    Status       = args.CurrentState,
                    Comment      = workflowComment
                };
                task = await TaskRepository.CreateAsync(task);

                // TODO: SendNotification to User
                Log.Information($"Notification: user={user.Name}, command={args.ExecutingCommand}, fromActivity:{args.PreviousActivityName}, toActivity:{args.CurrentState}, comment:{product.WorkflowComment}");
            }

            // Clear the WorkflowComment
            if (!String.IsNullOrWhiteSpace(workflowComment))
            {
                // Clear the comment
                product.WorkflowComment = "";
                await ProductRepository.UpdateAsync(product);
            }
        }
        public async Task ProductProcessChangedAsync(ProductProcessChangedArgs args)
        {
            // Clear PreExecute entries
            var emptyItems = ProductTransitionRepository.Get()
                             .Where(pt => pt.WorkflowUserId == null && pt.ProductId == args.ProcessId)
                             .Select(pt => pt.Id).ToList();

            foreach (var item in emptyItems)
            {
                await ProductTransitionRepository.DeleteAsync(item);
            }
            // Create PreExecute entries
            await Runtime.PreExecuteFromCurrentActivityAsync(args.ProcessId);

            // Find the Product assoicated with the ProcessId
            var product = await ProductRepository.Get()
                          .Where(p => p.Id == args.ProcessId)
                          .Include(p => p.ProductDefinition)
                          .Include(p => p.Project)
                          .ThenInclude(pr => pr.Owner)
                          .FirstOrDefaultAsync();

            if (product == null)
            {
                Log.Error($"Could find Product for ProcessId={args.ProcessId}");
                return;
            }

            await RemoveTasksByProductId(product.Id);

            // Find all users who could perform the current activity and create tasks for them
            var workflowUserIds = Runtime.GetAllActorsForDirectCommandTransitions(args.ProcessId, activityName: args.CurrentActivityName).ToList();
            var users           = UserRepository.Get().Where(u => workflowUserIds.Contains(u.WorkflowUserId.GetValueOrDefault().ToString())).ToList();
            var workflowComment = product.WorkflowComment;

            foreach (var user in users)
            {
                var task = new UserTask
                {
                    UserId       = user.Id,
                    ProductId    = product.Id,
                    ActivityName = args.CurrentActivityName,
                    Status       = args.CurrentState,
                    Comment      = workflowComment
                };
                task = await TaskRepository.CreateAsync(task);

                var messageParms = new Dictionary <string, object>()
                {
                    { "activityName", task.ActivityName },
                    { "project", product.Project.Name },
                    { "productName", product.ProductDefinition.Name },
                    { "fromActivity", args.PreviousActivityName ?? "" },
                    { "status", task.Status },
                    { "originator", user.Name },
                    { "to", product.Project.Owner.Name },
                    { "comment", task.Comment ?? "" }
                };
                await SendNotificationService.SendNotificationToUserAsync(user,
                                                                          "userTaskAdded",
                                                                          messageParms);

                Log.Information($"Notification: user={user.Name}, command={args.ExecutingCommand}, fromActivity:{args.PreviousActivityName}, toActivity:{args.CurrentState}, comment:{product.WorkflowComment}");
            }

            // Clear the WorkflowComment
            if (!String.IsNullOrWhiteSpace(workflowComment))
            {
                // Clear the comment
                product.WorkflowComment = "";
                await ProductRepository.UpdateAsync(product);
            }
        }