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);
            }
        }
Ejemplo n.º 2
0
        public async Task ProductProcessChangedAsync(ProductProcessChangedArgs args)
        {
            // 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;
            }

            if (args.NewStatus == ProcessStatus.Finalized.StatusString())
            {
                Log.Information($"Process Finalized.  Deleting ProcessId={args.ProcessId}, Schema={args.SchemaCode}");
                await StopProductWorkflowAsync(args.ProcessId, product.ProjectId, ProductTransitionType.EndWorkflow);
            }
        }
Ejemplo n.º 3
0
 public void ProductProcessChanged(ProductProcessChangedArgs args)
 {
     ProductProcessChangedAsync(args).Wait();
 }
        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);
            }
        }