Exemplo n.º 1
0
        public static Flow GetFlow(int id)
        {
            const string sql = @"
            SELECT  Id ,
            Status ,
            CurrentPath,
            Name
            FROM    dbo.Flow
            WHERE   Id = @id";

            var idParam = new SqlParameter("@id", SqlDbType.Int) { Value = id };

            Flow result = null;

            new DbDao().ExecuteSqlDataReader(ConnectionString, sql, new[] { idParam }, dr =>
            {
                result = new Flow(dr.GetInt32(0))
                {
                    StatusChanged = FlowStatusChanged,
                    EscalationLevelChanged = EsclationLevelChanged,
                    Status = (FlowStatuses)Enum.Parse(typeof(FlowStatuses), dr.GetString(1)),
                    Name = dr.GetString(3)
                };

                PopulateRules(result);
            });

            return result;
        }
Exemplo n.º 2
0
Arquivo: Rule.cs Projeto: mparsin/TBMS
 /// <summary>
 /// Initializes a new instance of the <see cref="Rule"/> class.
 /// </summary>
 /// <param name="flow">The parent flow.</param>
 /// <param name="uid">The unique identifier.</param>
 public Rule(Flow flow, Guid uid)
 {
     _flow = flow;
     Uid = uid;
     TrueActions = new List<Action>();
     FalseActions = new List<Action>();
     _parameters = new Dictionary<string, object>();
     AddSystemParameters();
 }
Exemplo n.º 3
0
        public static IList<Flow> LoadFlowList(bool fake = false)
        {
            var flowList = new List<Flow>();
            if (!fake)
            {
                const string sql = @"
            SELECT Id ,
               Status ,
               CurrentPath FROM dbo.Flow";

                new DbDao().ExecuteSqlDataReader(ConnectionString, sql, dr =>
                {
                    flowList.Add(new Flow(dr.GetInt32(0))
                    {
                        StatusChanged = FlowStatusChanged,
                        EscalationLevelChanged = EsclationLevelChanged,
                        Status = (FlowStatuses)Enum.Parse(typeof(FlowStatuses), dr.GetString(1)),
                    });
                });

                foreach (var flow in flowList)
                {
                    PopulateRules(flow);
                }

                return flowList;

            }
            else
            {

                var flow1 = new Flow(1);
                flow1.Rules.Add(CreateRule1(flow1));
                flowList.Add(flow1);

                return flowList;
            }
        }
Exemplo n.º 4
0
        private static Task ReadTask(int taskId, Flow flow)
        {
            const string sql = @"
            SELECT  t.Id ,
            t.Name ,
            t.TaskTypeId ,
            lat.ExePath ,
            smt.Recipient,
            t.ActionId,
            t.IsPending,
            tea.EscalationActionId,
            t.EscalationLevel
            FROM    dbo.Task t
            LEFT OUTER JOIN dbo.LaunchAppTask lat ON lat.TaskId = t.Id
                                                 AND lat.TaskTypeId = t.TaskTypeId
            LEFT OUTER JOIN dbo.SendMailTask smt ON smt.TaskId = t.Id
                                                AND smt.TaskTypeId = t.TaskTypeId
            LEFT OUTER JOIN dbo.TaskEscalationActions tea ON tea.TaskId = t.Id
            WHERE   t.Id = @taskId
            ORDER BY tea.EscalationLevel";

            var taskIdParam = new SqlParameter("@taskId", SqlDbType.Int) { Value = taskId };

            Task result = null;
            new DbDao().ExecuteSqlDataReader(ConnectionString, sql, new[] { taskIdParam }, dr =>
            {
                var taskType = (TaskTypes)dr.GetInt32(2);
                var actionId = dr.IsDBNull(5) ? (int?)null : dr.GetInt32(5);

                switch (taskType)
                {
                    case TaskTypes.SendMailTask:
                        result = new SendEmailTask(flow, dr.GetString(4));
                        break;
                    case TaskTypes.StartApplicationTask:
                        StartApplicationTask startAppTask;
                        if (result == null)
                            startAppTask = new StartApplicationTask(flow, dr.GetString(3), dr.GetBoolean(6));
                        else
                            startAppTask = (StartApplicationTask)result;
                        if (!dr.IsDBNull(7)) // has escalations
                        {
                            startAppTask.Escalations.Add((EscalationAction)ReadAction(dr.GetInt32(7), flow));
                        }
                        result = startAppTask;
                        break;
                    case TaskTypes.RunDbScriptTask:
                        var runDbScriptTask = new RunDbScriptTask(flow);
                        //TODO: populate properties
                        result = runDbScriptTask;
                        break;
                }

                if (result != null)
                {
                    result.Id = dr.GetInt32(0);
                    result.Name = dr.IsDBNull(1) ? string.Empty : dr.GetString(1);
                    var task = result as AsyncTask;
                    if (task != null && !dr.IsDBNull(8))
                    {
                        task.EscalationLevel = dr.GetInt32(8);
                    }

                    if (actionId.HasValue)
                    {
                        result.Action = ReadAction(actionId, flow);
                    }
                }
            });

            return result;
        }
Exemplo n.º 5
0
        private static Rule ReadRule(int ruleId, Flow flow)
        {
            const string sql = @"
            SELECT  Id ,
            Uid,
            Expression ,
            Query ,
            TrueAction ,
            FalseAction ,
            Name
            FROM    dbo.[Rule] r
            WHERE r.Id = @ruleId";
            var ruleIdParam = new SqlParameter("@ruleId", SqlDbType.Int) {Value = ruleId};
            Rule result = null;
            new DbDao().ExecuteSqlDataReader(ConnectionString, sql, new[] { ruleIdParam }, dr =>
            {
                result = GetRule(flow, dr);
            });

            return result;
        }
Exemplo n.º 6
0
        private static Action ReadAction(int? actionId, Flow flow)
        {
            const string sql = @"
            SELECT  a.Id ,
            a.Name ,
            a.ActionTypeId ,
            eta.ActionId ,
            eta.TaskId ,
            eta.ActionTypeId ,
            era.ActionId ,
            era.RuleId ,
            era.ActionTypeId,
            sra.ActionId ,
            sra.RuleId ,
            sra.ActionTypeId,
            sta.ActionId ,
            sta.TaskId ,
            sta.ActionTypeId,
            ea.TaskId,
            ea.StartTime
            FROM    dbo.Action a
            LEFT OUTER JOIN dbo.ExecuteTaskAction eta ON a.Id = eta.ActionId
            LEFT OUTER JOIN [dbo].[ExecuteRuleAction] era ON a.Id = era.ActionId
            LEFT OUTER JOIN [dbo].[StartRuleAction] sra ON sra.ActionId = a.Id
            LEFT OUTER JOIN [dbo].[StartTaskAction] sta ON sta.ActionId = a.Id
            LEFT OUTER JOIN [dbo].[EscalationAction] ea ON ea.ActionId = a.Id
            WHERE a.Id = @actionId";
            var actionIdParam = new SqlParameter("@actionId", SqlDbType.Int) { Value = actionId };
            Action result = null;

            new DbDao().ExecuteSqlDataReader(ConnectionString, sql, new[] { actionIdParam }, dr =>
            {
                var actionType = (ActionTypes)dr.GetInt32(2);
                switch (actionType)
                {
                    case ActionTypes.ExecuteRuleAction:
                        result = new ExecuteRuleAction(ReadRule(dr.GetInt32(7), flow));
                        break;
                    case ActionTypes.ExecuteTaskAction:
                        result = new ExecuteTaskAction((SyncTask)ReadTask(dr.GetInt32(4), flow));
                        break;
                    case ActionTypes.StartRuleAction:
                        result = new StartRuleAction(ReadRule(dr.GetInt32(10), flow));
                        break;
                    case ActionTypes.StartTaskAction:
                        result = new StartTaskAction((AsyncTask)ReadTask(dr.GetInt32(13), flow));
                        break;
                    case ActionTypes.EscalationAction:
                        result = new EscalationAction((SyncTask)ReadTask(dr.GetInt32(15), flow), dr.GetDateTime(16));
                        break;
                    default:
                        throw new Exception($"Unknown action type {actionType}");
                }
            });

            return result;
        }
Exemplo n.º 7
0
        private static void PopulateRules(Flow flow)
        {
            const string sql = @"
            SELECT  Id ,
            Uid,
            Expression ,
            Query ,
            TrueAction ,
            FalseAction ,
            Name
            FROM    dbo.[Rule] r
            INNER JOIN dbo.FlowRules fr ON fr.RuleId = r.Id
            WHERE   fr.FlowId = @flowId";

            var flowIdParam = new SqlParameter("@flowId", SqlDbType.Int) { Value = flow.Id };
            new DbDao().ExecuteSqlDataReader(ConnectionString, sql, new[] { flowIdParam }, dr =>
            {
                flow.Rules.Add(GetRule(flow, dr));
            });
        }
Exemplo n.º 8
0
        private static Rule GetRule(Flow flow, SqlDataReader dr)
        {
            var rule = new Rule(flow, dr.GetGuid(1))
            {
                Id = dr.GetInt32(0),
                Expression = dr.GetString(2),
                Query = dr.IsDBNull(3) ? string.Empty : dr.GetString(3).Replace("\r\n", " "),
                Description = dr.IsDBNull(6) ? string.Empty : dr.GetString(6)
            };
            var trueActionId = dr.IsDBNull(4) ? (int?)null : dr.GetInt32(4);
            var falseActionId = dr.IsDBNull(5) ? (int?)null : dr.GetInt32(5);

            if (trueActionId.HasValue)
            {
                rule.TrueActions.Add(ReadAction(trueActionId, flow));
            }
            if (falseActionId.HasValue)
            {
                rule.FalseActions.Add(ReadAction(falseActionId, flow));
            }

            return rule;
        }
Exemplo n.º 9
0
        private static Rule CreateRule2(Flow flow)
        {
            var rule = new Rule(flow, new Guid("93E93AD7-B2C0-4574-B813-3B01290D8F79"))
            {
                Query = @"
            SELECT  [LoanType] ,
            LoanUnits
            FROM    [COBALT_Test].[dbo].[tbLoans]
            WHERE   LoanNumber = '0001016575'
              ",
                Expression = "('$(LoanType)' === 'FHLM') && ($(LoanUnits) > 1)"
            };

            var asyncTask = CreateAsyncTask1(flow);
            asyncTask.Action = new ExecuteTaskAction(new SendEmailTask(flow, "*****@*****.**"));
            rule.TrueActions.Add(new StartTaskAction(asyncTask));
            return rule;
        }
Exemplo n.º 10
0
        private static Rule CreateRule1(Flow flow)
        {
            var rule = new Rule(flow, new Guid("3F7D75DA-FA32-405C-A227-BC40EFF4EB6D"))
            {
                Query = @"
            SELECT  grasscanceldate
            FROM    dbo.tbLoans
            WHERE   LoanNumber = '0000000274'",
                Expression = "new Date('$(grasscanceldate)') > new Date('$(CurrentDate)')"
            };

            rule.Description = "GrassCancelDate is less then today";

            rule.TrueActions.Add(new ExecuteTaskAction(new SendEmailTask(flow, "Serguei Vassiliev <*****@*****.**>")));
            rule.FalseActions.Add(new ExecuteRuleAction(CreateRule2(flow)));

            return rule;
        }
Exemplo n.º 11
0
 private static AsyncTask CreateAsyncTask1(Flow flow)
 {
     return new StartApplicationTask(flow,
         @"C:\Development\FiveBrothers\Prototypes\TBMS\Tests\ExternalAppTest\Bin\Debug\ExternalAppTest.exe");
 }