Example #1
0
        private static void ApproveTask(TaskInfo task, string workflowId, string result)
        {
            var rnd  = new Random((int)DateTime.Now.Ticks);
            var user = rnd.Next(2) == 0 ? "rredford" : "pnewman";

            var assignTaskRequest = new AssignTaskToRequest
            {
                TaskOid = task.TaskOid,
                User    = user
            };

            var approveTaskRequest = new ApproveTaskRequest
            {
                TaskId        = task.TaskOid.ToString(),
                CorrelationId = task.TaskCorrelationId,
                TaskCode      = task.TaskCode,
                Result        = result,
                UserName      = user,
                WorkflowId    = workflowId
            };

            using (var src = new FlowTasksService())
            {
                src.AssignTaskTo(assignTaskRequest);
                src.ApproveTask(approveTaskRequest);
            }
        }
Example #2
0
        protected override void Execute(NativeActivityContext context)
        {
            Log.Debug("CompleteExpiredApproveTask -> Start");

            var workflowStatus = context.Properties.Find(WorkflowStateData.Name) as WorkflowStateData;

            if (workflowStatus == null)
            {
                throw new Exception("Cannot find WorkflowStateData");
            }

            using (var proxy = new FlowTasksService())
            {
                proxy.CompleteTask(new CompleteTaskRequest
                {
                    TaskId = workflowStatus.Tasks[TaskCode.Get(context)].TaskInfo.TaskOid.ToString(),
                    Result = DefaultResult.Get(context),
                    User   = ""
                });
            }

            Log.Debug("CompleteExpiredApproveTask -> End");

            Result.Set(context, DefaultResult.Get(context));
        }
Example #3
0
        private static void CheckResult(string workflowId, string name)
        {
            GetTraceForWorkflowResponse traces = null;

            using (var src = new FlowTasksService())
            {
                traces = src.GetTraceForWorkflow(new GetTraceForWorkflowRequest {
                    WorkflowOids = new[] { Guid.Parse(workflowId) }
                });
            }

            bool found = false;

            foreach (var trace in traces.Traces.Where(t => t.Type == TraceEventType.Activity.ToString()))
            {
                if (trace.Action == ActionTrace.WorkflowCompleted.ToString())
                {
                    found = true;
                }
            }
            if (!found)
            {
                throw new Exception(name + ": workflow has not been completed");
            }
        }
Example #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);
        }
Example #5
0
 public void CallWcfSvc()
 {
     using (FlowTasksService proxy = new FlowTasksService("FlowTasksService_Endpoint"))
     {
         proxy.GetNextTasksForUser(new GetNextTasksForUserRequest {
             Domain = "google", User = "******"
         });
     }
 }
Example #6
0
 public static void SetHoliday(TaskStateData taskStatus, HolidayStatus res)
 {
     using (var proxy = new FlowTasksService())
     {
         proxy.UpdateHoliday(new UpdateHolidayRequest
         {
             HolidayId = int.Parse(taskStatus.Parameters["HolidayId"]),
             Status    = res
         });
     }
 }
Example #7
0
        /// <summary>
        /// Calculate expiry date time
        /// </summary>
        /// <param name="context">Context</param>
        /// <param name="when">DateTime</param>
        /// <param name="at">number of days/minutes</param>
        private void SetExpiry(NativeActivityContext context, DateTime?when, string at)
        {
            GetExpiryTimeSpanResponse resp;

            using (var proxy = new FlowTasksService())
            {
                resp = proxy.GetExpiryTimeSpan(new GetExpiryTimeSpanRequest
                {
                    ExpiresWhen = when,
                    ExpiresIn   = at
                });
            }

            // Set the expiry delay. User can have change it.
            DelaySpan.Set(context, resp.Expires);
        }
Example #8
0
 /// <summary>
 /// Send Notification
 /// </summary>
 /// <param name="workflowOid">WorkflowOid</param>
 /// <param name="taskOid">TaskOid</param>
 /// <param name="subject">Subject</param>
 /// <param name="message">Message</param>
 /// <param name="user">User. Support place holder</param>
 static public void SendNotification(Guid workflowOid, Guid taskOid, string subject, string message, string user)
 {
     using (var proxy = new FlowTasksService())
     {
         proxy.CreateNotification(new CreateNotificationRequest {
             WorkflowId       = workflowOid.ToString(),
             NotificationInfo = new NotificationInfo {
                 AssignedToUsers = user,
                 Description     = message,
                 Title           = subject,
                 TaskOid         = taskOid,
                 WorkflowOid     = workflowOid
             }
         });
     }
 }
Example #9
0
        private static GetWorkflowChildrenResponse GetChildren(string workflowId)
        {
            var getWorkflowChildrenRequest = new GetWorkflowChildrenRequest
            {
                WorkflowOid = workflowId
            };

            GetWorkflowChildrenResponse children = null;

            using (var src = new FlowTasksService())
            {
                children = src.GetWorkflowChildren(getWorkflowChildrenRequest);
            }

            return(children);
        }
Example #10
0
        private static GetNextTasksForUserResponse GetTasks(string workflowId)
        {
            var getNextTasksForUserRequest = new GetNextTasksForUserRequest
            {
                User        = "******",
                WorkflowOid = Guid.Parse(workflowId)
            };

            GetNextTasksForUserResponse tasks = null;

            using (var src = new FlowTasksService("FlowTasksService_Endpoint"))
            {
                tasks = src.GetNextTasksForUser(getNextTasksForUserRequest);
            }

            return(tasks);
        }
Example #11
0
        protected override void Execute(NativeActivityContext context)
        {
            Log.Debug("CreateResponseForApproveTask -> Start");

            var workflowStatus = context.Properties.Find(WorkflowStateData.Name) as WorkflowStateData;

            if (workflowStatus == null)
            {
                throw new Exception("Cannot find WorkflowStateData");
            }

            var task = workflowStatus.Tasks[Request.Get(context).TaskCode];

            task.Result       = Request.Get(context).Result;
            task.AssignedUser = Request.Get(context).UserName;

            var parameters = Request.Get(context).Parameters;

            if (parameters != null)
            {
                foreach (var item in parameters)
                {
                    task.AddParameter(item.Name, item.Value);
                }
            }

            using (var proxy = new FlowTasksService())
            {
                proxy.CompleteTask(new CompleteTaskRequest
                {
                    TaskId = Request.Get(context).TaskId,
                    Result = Request.Get(context).Result,
                    User   = Request.Get(context).UserName
                });
            }

            Log.Debug("CreateResponseForApproveTask -> End");

            Result.Set(context, new ApproveTaskResponse
            {
                WorkflowId = Request.Get(context).WorkflowId,
                TaskId     = Request.Get(context).TaskId
            });
        }
Example #12
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);
            }
        }
Example #13
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);
            }
        }