public HttpResponseMessage Operations(string op, string woid, string wcode, [FromBody] IEnumerable <WfProperty> props)
        {
            Guid oid;

            if (!string.IsNullOrWhiteSpace(woid) && !Guid.TryParse(woid, out oid))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            try
            {
                if (op.Equals(WorkflowOperation.Start.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    var startWorkflowRequest = new StartWorkflowRequest
                    {
                        Domain          = ConfigHelper.WorkflowDomain,
                        WorkflowCode    = wcode,
                        WfRuntimeValues = props.ToArray()
                    };

                    TasksService.StartWorkflow(startWorkflowRequest);
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 2
0
        public async Task Send_workflow_start_request_to_amazon_swf()
        {
            var response = new StartWorkflowExecutionResponse()
            {
                Run = new Run()
            };

            _amazonWorkflowClient.Setup(c => c.StartWorkflowExecutionAsync(
                                            It.IsAny <StartWorkflowExecutionRequest>(),
                                            It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(response));
            var startRequest = new StartWorkflowRequest("workflowName", "version", "workflowId")
            {
                ChildPolicy  = ChildPolicy.Abandon,
                TaskListName = "tlist",
                ExecutionStartToCloseTimeout = TimeSpan.FromSeconds(10),
                Input      = "input",
                LambdaRole = "lrole",
                Tags       = new List <string> {
                    "tag1", "tag2"
                },
                TaskPriority            = 2,
                TaskStartToCloseTimeout = TimeSpan.FromSeconds(23)
            };

            await _domain.StartWorkflowAsync(startRequest);

            AssertThatAmazonSwfIsSend(startRequest);
        }
 public void Invalid_argument_tests()
 {
     Assert.Throws <ArgumentException>(() => new StartWorkflowRequest("", "1.0", "id"));
     Assert.Throws <ArgumentException>(() => new StartWorkflowRequest("name", "", "id"));
     Assert.Throws <ArgumentException>(() => new StartWorkflowRequest("name", "1.0", ""));
     Assert.Throws <ArgumentException>(() => StartWorkflowRequest.For <TestWorkflow>(null));
 }
Ejemplo n.º 4
0
        private static string Start(string workflowCode)
        {
            string workflowId;
            var    startWorkflowRequest = new StartWorkflowRequest
            {
                Domain          = "google",
                WorkflowCode    = workflowCode,
                WfRuntimeValues = new[]
                {
                    new WfProperty
                    {
                        Name  = "Prop1",
                        Type  = "S",
                        Value = "Val1"
                    }
                }
            };

            StartWorkflowResponse startWorkflowResponse = null;

            using (var src = new FlowTasksService())
            {
                startWorkflowResponse = src.StartWorkflow(startWorkflowRequest);
            }

            System.Threading.Thread.Sleep(1000);

            workflowId = startWorkflowResponse.WorkflowId;

            return(workflowId);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Start a workflow in Amazon SWF. This workflow must be already registered with Amazon SWF.
        /// </summary>
        /// <param name="startRequest"></param>
        /// <returns></returns>
        public async Task <string> StartWorkflowAsync(StartWorkflowRequest startRequest)
        {
            Ensure.NotNull(startRequest, nameof(startRequest));
            var response = await _simpleWorkflowClient.StartWorkflowExecutionAsync(startRequest.SwfFormat(_name));

            return(response.Run.RunId);
        }
        public void Populates_properties_from_workflow_description()
        {
            var request = StartWorkflowRequest.For <TestWorkflow>("workflowId");

            Assert.That(request.WorkflowName, Is.EqualTo("TestWorkflow"));
            Assert.That(request.Version, Is.EqualTo("1.0"));
            Assert.That(request.WorkflowId, Is.EqualTo("workflowId"));
        }
        public void Serialize_complex_input_to_json_format()
        {
            var request = StartWorkflowRequest.For <TestWorkflow>("workflowId");

            request.Input = new { Id = 10 };

            var swfRequest = request.SwfFormat("domain");

            Assert.That(swfRequest.Input, Is.EqualTo("{\"Id\":10}"));
        }
Ejemplo n.º 8
0
        public async Task <string> StartWorkflow <TWorkflow>(string input, string taskListName) where TWorkflow : Workflow
        {
            var workflowId   = Guid.NewGuid().ToString();
            var startRequest = StartWorkflowRequest.For <TWorkflow>(workflowId);

            startRequest.TaskListName = taskListName;
            startRequest.Input        = input;
            await _domain.StartWorkflowAsync(startRequest);

            return(workflowId);
        }
Ejemplo n.º 9
0
        public HttpResponseMessage Deploy(string fname)
        {
            try
            {
                //return new HttpResponseMessage(HttpStatusCode.Created);

                var sketches = TasksService.GetSketchForFilter(new GetSketchForFilterRequest
                {
                    Name     = fname,
                    Statuses = new[] { SketchStatusType.Saved }
                });

                if (sketches.Sketches.Any())
                {
                    var startWorkflowRequest = new StartWorkflowRequest
                    {
                        Domain          = ConfigHelper.WorkflowDomain,
                        WorkflowCode    = ConfigHelper.WorkflowCodeSketch,
                        WfRuntimeValues = new[]
                        {
                            new WfProperty
                            {
                                Name  = ConfigHelper.WorkflowPropertyDocumentOid,
                                Type  = PropertyType.FlowDoc.ToString(),
                                Value = sketches.Sketches[0].XamlxOid.ToString()
                            },
                            new WfProperty
                            {
                                Name  = ConfigHelper.WorkflowPropertyCode,
                                Type  = PropertyType.String.ToString(),
                                Value = fname
                            }
                        }
                    };

                    TasksService.StartWorkflow(startWorkflowRequest);
                }

                TasksService.SketchWorkflow(new SketchWorkflowRequest
                {
                    Name      = fname,
                    ChangedBy = User.Identity.Name,
                    Status    = SketchStatusType.DeployedDev
                });

                return(new HttpResponseMessage(HttpStatusCode.Created));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Start Workflow
        /// </summary>
        /// <param name="request">Request</param>
        /// <returns>StartWorkflowResponse</returns>
        public StartWorkflowResponse StartWorkflow(StartWorkflowRequest request)
        {
            var proxy = _proxyManager.GetProxyForWorkflow(request.WorkflowCode);
            var resp  = proxy.StartWorkflow1(request);

            var toDispose = proxy as System.ServiceModel.ClientBase <IFlowTasksOperations>;

            if (toDispose != null)
            {
                toDispose.Close();
            }

            return(resp);
        }
Ejemplo n.º 11
0
        [HttpPost] //
        public ActionResult DeployWorkflow(string fname, string content)
        {
            if (ModelState.IsValid)
            {
                var sketches = TasksService.GetSketchForFilter(new GetSketchForFilterRequest
                {
                    Name     = fname,
                    Statuses = new[] { SketchStatusType.Saved }
                });

                if (sketches.Sketches.Any())
                {
                    var startWorkflowRequest = new StartWorkflowRequest
                    {
                        Domain          = ConfigHelper.WorkflowDomain,
                        WorkflowCode    = ConfigHelper.WorkflowCodeSketch,
                        WfRuntimeValues = new[]
                        {
                            new WfProperty
                            {
                                Name  = ConfigHelper.WorkflowPropertyDocumentOid,
                                Type  = PropertyType.FlowDoc.ToString(),
                                Value = sketches.Sketches[0].XamlxOid.ToString()
                            },
                            new WfProperty
                            {
                                Name  = ConfigHelper.WorkflowPropertyCode,
                                Type  = PropertyType.String.ToString(),
                                Value = fname
                            }
                        }
                    };

                    TasksService.StartWorkflow(startWorkflowRequest);
                }

                TasksService.SketchWorkflow(new SketchWorkflowRequest
                {
                    Name      = fname,
                    ChangedBy = User.Identity.Name,
                    Status    = SketchStatusType.DeployedDev
                });

                return(Json("WorkFlow Deployed!"));
            }
            return(Json("Error"));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Get Parameters From Request
        /// </summary>
        /// <param name="request">StartWorkflowRequest</param>
        /// <returns>List of PropertyInfo</returns>
        private IEnumerable <Contract.Message.PropertyInfo> GetParametersFromRequest(StartWorkflowRequest request)
        {
            var res = new List <Contract.Message.PropertyInfo>();

            if (request.WfRuntimeValues == null)
            {
                return(res);
            }

            foreach (var d in request.WfRuntimeValues)
            {
                res.Add(new Contract.Message.PropertyInfo {
                    Name = d.Name, Value = d.Value, Type = d.Type
                });
            }

            return(res);
        }
Ejemplo n.º 13
0
        public string UploadFile()
        {
            try
            {
                var info = new DocumentInfo {
                    DocumentName = Path.GetFileName(FileName), Path = Path.GetDirectoryName(FileName), Description = "desc-test", Owner = "owner", Version = 1
                };

                var oid = _processDocs.UploadDocument(info, FileName, DocumentUploadMode.NewVersion);

                var startWorkflowRequest = new StartWorkflowRequest
                {
                    Domain          = ConfigHelper.WorkflowDomain,
                    WorkflowCode    = ConfigHelper.WorkflowCode,
                    WfRuntimeValues = new WfProperty[]
                    {
                        new WfProperty
                        {
                            Name  = ConfigHelper.WorkflowProperty,
                            Type  = PropertyType.FlowDoc.ToString(),
                            Value = oid.ToString()
                        }
                    }
                };

                if (_serviceTasks != null)
                {
                    _serviceTasks.StartWorkflow(startWorkflowRequest);
                }
                else
                {
                    using (FlowTasksService proxy = new FlowTasksService())
                    {
                        var startWorkflowResponse = proxy.StartWorkflow(startWorkflowRequest);
                    }
                }

                return(null);
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Ejemplo n.º 14
0
        public async Task RunAction(
            [ActivityTrigger] IDurableActivityContext context,
            ILogger logger)
        {
            WorkflowMessageEnvelope envelope =
                context.GetInputWithCustomSerializationSettings <WorkflowMessageEnvelope>(this.serializerSettingsProvider.Instance);

            logger.LogInformation(
                $"Making function call for StartWorkflowInstanceRequest {envelope.StartWorkflowInstanceRequest.RequestId}");

            var body = new StartWorkflowRequest
            {
                Context            = envelope.StartWorkflowInstanceRequest.Context,
                WorkflowId         = envelope.StartWorkflowInstanceRequest.WorkflowId,
                WorkflowInstanceId = envelope.StartWorkflowInstanceRequest.WorkflowInstanceId,
                RequestId          = envelope.StartWorkflowInstanceRequest.RequestId,
            };

            await this.engineClient.StartWorkflowInstanceAsync(envelope.TenantId, body);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Invoke Workflow
        /// </summary>
        /// <remarks>
        /// Start a new WorkflowCode workflow.
        /// </remarks>
        /// <param name="parentWorkflowId">Parent Workflow Id</param>
        /// <param name="workflowCode">Workflow Code</param>
        /// <param name="domain">Domain</param>
        /// <param name="properties">Properties</param>
        /// <param name="async">async</param>
        /// <returns>Workflow Id</returns>
        private string InvokeWorkflow(Guid parentWorkflowId, string workflowCode, string domain, Dictionary <string, string> properties, bool async)
        {
            var startWorkflowRequest = new StartWorkflowRequest
            {
                ParentWorkflowId = parentWorkflowId.ToString(),
                Domain           = domain,
                WorkflowCode     = workflowCode,
                WfRuntimeValues  = CreatePropertiesFromDictionary(properties),
                CorrelationId    = CorrelationId,
                WaitForChild     = !async
            };

            StartWorkflowResponse startWorkflowResponse;

            using (var proxy = new Proxy.FlowTasksService())
            {
                startWorkflowResponse = proxy.StartWorkflow(startWorkflowRequest);
            }

            string workflowId = startWorkflowResponse.WorkflowId;

            return(workflowId);
        }
Ejemplo n.º 16
0
        private void AssertThatAmazonSwfIsSend(StartWorkflowRequest request)
        {
            Func <StartWorkflowExecutionRequest, bool> startRequest = s =>
            {
                Assert.That(request.WorkflowId, Is.EqualTo(s.WorkflowId));
                Assert.That(request.WorkflowName, Is.EqualTo(s.WorkflowType.Name));
                Assert.That(request.Version, Is.EqualTo(s.WorkflowType.Version));
                Assert.That(request.Input, Is.EqualTo(s.Input));
                Assert.That(request.ChildPolicy, Is.EqualTo(s.ChildPolicy.Value));
                Assert.That(request.LambdaRole, Is.EqualTo(s.LambdaRole));
                Assert.That(request.TaskListName, Is.EqualTo(s.TaskList.Name));
                Assert.That(request.TaskPriority, Is.EqualTo(int.Parse(s.TaskPriority)));
                Assert.That(request.Tags, Is.EqualTo(s.TagList));
                Assert.That(request.TaskStartToCloseTimeout, Is.EqualTo(TimeSpan.FromSeconds(int.Parse(s.TaskStartToCloseTimeout))));
                Assert.That(request.ExecutionStartToCloseTimeout, Is.EqualTo(TimeSpan.FromSeconds(int.Parse(s.ExecutionStartToCloseTimeout))));
                Assert.That(_domainName, Is.EqualTo(s.Domain));
                return(true);
            };

            _amazonWorkflowClient.Verify(c => c.StartWorkflowExecutionAsync(
                                             It.Is <StartWorkflowExecutionRequest>((start) => startRequest(start)),
                                             It.IsAny <CancellationToken>()),
                                         Times.Once);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Start Workflow
 /// </summary>
 /// <param name="request">Request</param>
 /// <returns>StartWorkflowResponse</returns>
 public StartWorkflowResponse StartWorkflow(StartWorkflowRequest request)
 {
     return(Channel.StartWorkflow(request));
 }
 /// <summary>
 /// Start a new instance of a workflow
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='tenantId'>
 /// The tenant within which the request should operate
 /// </param>
 /// <param name='body'>
 /// </param>
 public static void StartWorkflowInstance(this IMarainWorkflowEngine operations, string tenantId, StartWorkflowRequest body)
 {
     operations.StartWorkflowInstanceAsync(tenantId, body).GetAwaiter().GetResult();
 }
Ejemplo n.º 19
0
        public void DoProcess()
        {
            DateTime last;

            try
            {
                var tweets = _tweet.GetLatestTwitterForWorkflow(out last);

                DateTime lastRun = DateTime.MinValue;
                foreach (var t in tweets)
                {
                    var startWorkflowRequest = new StartWorkflowRequest
                    {
                        Domain          = ConfigHelper.WorkflowDomain,
                        WorkflowCode    = ConfigHelper.WorkflowCode,
                        WfRuntimeValues = new WfProperty[]
                        {
                            new WfProperty
                            {
                                Name  = ConfigHelper.WorkflowProperty,
                                Type  = "S",
                                Value = t.Text
                            }
                        }
                    };

                    StartWorkflowResponse startWorkflowResponse = null;
                    if (_flowTasksService == null)
                    {
                        using (FlowTasksService proxy = new FlowTasksService())
                        {
                            startWorkflowResponse = proxy.StartWorkflow(startWorkflowRequest);
                        }
                    }
                    else
                    {
                        startWorkflowResponse = _flowTasksService.StartWorkflow(startWorkflowRequest);
                    }

                    // check for errors
                    if (string.IsNullOrWhiteSpace(startWorkflowResponse.WorkflowId) ||
                        startWorkflowResponse.WorkflowId == Guid.Empty.ToString())
                    {
                        if (lastRun != DateTime.MinValue)
                        {
                            _tweet.SetLastTweetData(lastRun);
                        }

                        _log.Error("DoProcess: Start workflow failed!");

                        return;
                    }

                    // last tweet processed
                    lastRun = t.CreatedDate;
                }

                _tweet.SetLastTweetData(last);
            }
            catch (Exception e)
            {
                // log the error
                _log.Error("DoProcess: exception. ", e);
            }
        }
 /// <summary>
 /// Start a new instance of a workflow
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='tenantId'>
 /// The tenant within which the request should operate
 /// </param>
 /// <param name='body'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task StartWorkflowInstanceAsync(this IMarainWorkflowEngine operations, string tenantId, StartWorkflowRequest body, CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.StartWorkflowInstanceWithHttpMessagesAsync(tenantId, body, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
Ejemplo n.º 21
0
        /// <summary>
        /// ReStart Workflow
        /// </summary>
        /// <param name="request">Request</param>
        /// <returns>ReStartWorkflowResponse</returns>
        public ReStartWorkflowResponse ReStartWorkflow(ReStartWorkflowRequest request)
        {
            // Cancell workflow
            var resp = CancelWorkflow(new ControlWorkflowRequest
            {
                WorkflowOid = request.OldWorkflowId
            });

            if (resp.Message != Library.Properties.Resources.SUCCESS_RESULT)
            {
                return(new ReStartWorkflowResponse
                {
                    Message = resp.Message,
                    WorkflowId = request.OldWorkflowId
                });
            }

            // Wait for workflow to terminate
            WorkflowInfo oldWf = WaitForWorkflowTerminate(request);

            if (oldWf == null || oldWf.Status == WorkflowStatusType.InProgress.ToString())
            {
                return(new ReStartWorkflowResponse
                {
                    Message = "Workflow still running",
                    WorkflowId = request.OldWorkflowId
                });
            }

            // Get workflow parameters
            var props = _workflow.GetWorkflowParameters(Guid.Parse(request.OldWorkflowId));

            var startWorkflowRequest = new StartWorkflowRequest
            {
                Domain          = oldWf.Domain,
                WorkflowCode    = oldWf.WorkflowCode,
                WfRuntimeValues = props.Select(p => new WfProperty
                {
                    Name  = p.Name,
                    Type  = p.Type,
                    Value = p.Value
                }).ToArray()
            };

            // Restart workflow
            var startWorkflowResponse = StartWorkflow(startWorkflowRequest);

#if RESTART_SAME_AS_OLD
            // The code below can be used when we want to restart a workflow and forward its
            // execution till the existing one.
            // Usefull when we make changes which are not back compatible. We need to terminate all
            // the existing workflows and start new ones without having users to start from the begin
            // the process.
            // TODO:
            // can go till the old point of execution
            if (request.RestartMode == "SAME_AS_OLD")
            {
                // TODO: need to find the way to wait until wf activity finishes.
                System.Threading.Thread.Sleep(3000);

                var traces = _workflow.GetTraceForWorkflow(new[] { Guid.Parse(request.OldWorkflowId) })
                             .Where(t => t.Action == ActionTrace.TaskCompleted.ToString());

                foreach (var trace in traces)
                {
                    var task = _task.GetNextTasksForWorkflow(Guid.Parse(startWorkflowResponse.WorkflowId))
                               .Where(t => t.TaskCode == trace.Code)
                               .FirstOrDefault();

                    if (task != null)
                    {
                        ApproveTask(new ApproveTaskRequest
                        {
                            TaskId        = task.TaskOid.ToString(),
                            CorrelationId = task.TaskCorrelationId,
                            Result        = trace.Result,
                            TaskCode      = trace.Code,
                            WorkflowId    = task.WorkflowOid.ToString()
                        });
                    }
                }
            }
#endif

            return(new ReStartWorkflowResponse
            {
                WorkflowId = startWorkflowResponse.WorkflowId,
                Message = Library.Properties.Resources.SUCCESS_RESULT
            });
        }
Ejemplo n.º 22
0
 public StartWorkflowResponse StartWorkflow5(StartWorkflowRequest request)
 {
     return(new StartWorkflowResponse {
         WorkflowId = ""
     });
 }