public void GetWorkflowTemplatesRequestHandler(GetWorkflowTemplatesRequest message)
        {
            GetWorkflowTemplatesResponse response = null;
            try
            {
                response = new GetWorkflowTemplatesResponse();
                response.AuditContext = message.AuditContext;
                response.TenantId = message.TenantId;
                response.CorrelationId = message.CorrelationId;
                response.WorkflowTemplates = new List<GetWorkflowTemplatesResponse.WorkflowTemplateSummary>();

                using (var dataContext = new DataContext(message.TenantId, message.AuditContext))
                {
                    var data = dataContext.WorkflowTemplates.Where(x => x.TargetObjectType == message.TargetObjectType).Select(x => new GetWorkflowTemplatesResponse.WorkflowTemplateSummary()
                    {
                        OpenWorkflowsRunning = x.WorkflowInstances.Count(c => c.Completed == false),
                        WorkflowsCompleted = x.WorkflowInstances.Count(c => c.Completed == true),
                        WorkflowTemplateDescription = x.WorkflowDescription,
                        WorkflowTemplateId = x.Id,
                        WorkflowTemplateName = x.WorkflowName,
                    }).ToList();
                    response.WorkflowTemplates = data;
                }

                _bus.Reply(response);
            }
            catch (Exception exc)
            {
                response = null;
                _bus.Reply(response, 0);
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            IMessagingService bus = IoCContext.Current.Container.Resolve<IMessagingService>();
            IDictionary<string, string> settings = new Dictionary<string, string>();
            settings.Add("EndpointName", "PocketBoss_Test_Client");
            settings.Add("HandlersAssembly", "PocketBoss.TestingCLI.exe");
            bus.OpenConnection(settings);
            bus.AddSubscription<WorkflowStateNotification>();
            bus.AddSubscription<WorkflowTaskNotification>();

            System.Console.WriteLine("Press enter to start workflow");
            var templatesRequest = new GetWorkflowTemplatesRequest()
            {
                AuditContext = "Console App",
                CorrelationId = Guid.NewGuid(),
                TargetObjectType = "PocketBoss.Samples.User",
                TenantId = System.Guid.Empty
            };

            GetWorkflowTemplatesResponse templateLookupData = null;
            long workflowTemplateId;

            templateLookupData = bus.Send<GetWorkflowTemplatesRequest, GetWorkflowTemplatesResponse>(templatesRequest).Result;

            System.Console.WriteLine("Workflows Registered:" + templateLookupData.WorkflowTemplates.Count());

            if (!templateLookupData.WorkflowTemplates.Exists(t => t.WorkflowTemplateName.Contains("Sample Workflow")))
            {
                System.Console.WriteLine("Test Workflow not seeded");
                System.Console.Read();
                return;
            }
            else
            {
                workflowTemplateId = templateLookupData.WorkflowTemplates[0].WorkflowTemplateId;
            }

            while (Console.ReadLine() != null)
            {
                WorkflowTemplate workflowTemplate = new WorkflowTemplate();
                GetSingleWorkflowTemplateRequest templateRequest = new GetSingleWorkflowTemplateRequest()
                {
                    AuditContext = "Console App",
                    CorrelationId = Guid.NewGuid(),
                    TenantId = System.Guid.Empty,
                    WorkflowTemplateId = workflowTemplateId
                };
                GetSingleWorkflowTemplateResponse searchResponse = bus.Send<GetSingleWorkflowTemplateRequest, GetSingleWorkflowTemplateResponse>(templateRequest).Result;
                workflowTemplate = searchResponse.WorkflowTemplate;

                var startWorkflowInstance = new InitiateWorkflowRequest()
                {
                    AuditContext = "Console App",
                    CorrelationId = Guid.NewGuid(),
                    TargetObjectId = DateTime.Now.Ticks.ToString(),
                    TargetObjectType = workflowTemplate.TargetObjectType,
                    TenantId = System.Guid.Empty,
                    WorkflowTemplateName = workflowTemplate.WorkflowName
                };

                long workflowInstanceId = 0;
                InitiateWorkflowResponse initializeResponse = bus.Send<InitiateWorkflowRequest, InitiateWorkflowResponse>(startWorkflowInstance).Result;
                workflowInstanceId = initializeResponse.WorkflowInstanceId;
                System.Console.WriteLine("Workflow InstanceId = " + workflowInstanceId.ToString());
            }
        }