Exemplo n.º 1
0
        IScheduledResource TryCreateScheduledResource(IDev2Task arg)
        {
            ITrigger      trigger;
            DateTime      nextDate;
            List <string> output;

            using (var action = ConvertorFactory.CreateExecAction(arg.Action))
            {
                trigger  = arg.Trigger;
                nextDate = trigger.StartBoundary;
                output   = action.Arguments.Split(ArgWrapper).Where(a => !String.IsNullOrEmpty(a.Trim())).ToList();
            }
            if (output.Count == ArgCount && output.All(a => a.Contains(NameSeperator)))
            {
                var split = output.SelectMany(a => a.Split(NameSeperator)).ToList();
                try
                {
                    return(CreateScheduledResource(arg, trigger, nextDate, split));
                }
                finally
                {
                    arg.Dispose();
                }
            }
            if (output.Count == ArgCountOld && output.All(a => a.Contains(NameSeperator)))
            {
                var split = output.SelectMany(a => a.Split(NameSeperator)).ToList();
                try
                {
                    return(new ScheduledResource(arg.Definition.Data,
                                                 arg.Definition.Settings.Enabled ? SchedulerStatus.Enabled : SchedulerStatus.Disabled,
                                                 nextDate,
                                                 new ScheduleTrigger(arg.State, _factory.SanitiseTrigger(trigger),
                                                                     _taskService, _factory), split[1], Guid.Empty.ToString())
                    {
                        Status = arg.Definition.Settings.Enabled ? SchedulerStatus.Enabled : SchedulerStatus.Disabled,
                        RunAsapIfScheduleMissed = arg.Definition.Settings.StartWhenAvailable,
                        UserName = arg.Definition.UserName
                    });
                }
                finally
                {
                    arg.Dispose();
                }
            }

            throw new Exception($"Invalid resource found:{arg.Definition.Data}"); // this should not be reachable because isvaliddev2task checks same conditions
        }
        private IScheduledResource CreateScheduledResource(IDev2Task arg)
        {

            ITrigger trigger;
            DateTime nextDate;
            List<string> output;
            using(var action = ConvertorFactory.CreateExecAction(arg.Action))
            {
                trigger = arg.Trigger;
                nextDate = trigger.StartBoundary;
                output = action.Arguments.Split(ArgWrapper).Where(a => !String.IsNullOrEmpty(a.Trim())).ToList();
            }
            if(output.Count == 2 && output.All(a => a.Contains(NameSeperator)))
            {

                var split = output.SelectMany(a => a.Split(NameSeperator)).ToList();
                try
                {


                    return new ScheduledResource(arg.Definition.Data,
                                                 arg.Definition.Settings.Enabled
                                                     ? SchedulerStatus.Enabled
                                                     : SchedulerStatus.Disabled,
                                                 nextDate,
                                                 new ScheduleTrigger(arg.State, _factory.SanitiseTrigger(trigger),
                                                                     _taskService, _factory), split[1])
                        {
                            Status =
                                arg.Definition.Settings.Enabled
                                    ? SchedulerStatus.Enabled
                                    : SchedulerStatus.Disabled,
                            RunAsapIfScheduleMissed = arg.Definition.Settings.StartWhenAvailable,
                            UserName = arg.Definition.UserName
                        };
                }
                finally
                {
                    arg.Dispose();
                }
            }
            throw new InvalidScheduleException(String.Format("Invalid resource found:{0}", arg.Definition.Data)); // this should not be reachable because isvaliddev2task checks same conditions


        }
Exemplo n.º 3
0
        private IScheduledResource CreateScheduledResource(IDev2Task arg)
        {
            ITrigger      trigger;
            DateTime      nextDate;
            List <string> output;

            using (var action = ConvertorFactory.CreateExecAction(arg.Action))
            {
                trigger  = arg.Trigger;
                nextDate = trigger.StartBoundary;
                output   = action.Arguments.Split(ArgWrapper).Where(a => !String.IsNullOrEmpty(a.Trim())).ToList();
            }
            if (output.Count == ArgCount && output.All(a => a.Contains(NameSeperator)))
            {
                var split = output.SelectMany(a => a.Split(NameSeperator)).ToList();
                try
                {
                    var  id = split[5];
                    Guid resourceId;
                    Guid.TryParse(id, out resourceId);

                    var res = new ScheduledResource(arg.Definition.Data,
                                                    arg.Definition.Settings.Enabled ? SchedulerStatus.Enabled : SchedulerStatus.Disabled,
                                                    nextDate,
                                                    new ScheduleTrigger(arg.State, _factory.SanitiseTrigger(trigger),
                                                                        _taskService, _factory), split[1], split[5])
                    {
                        Status = arg.Definition.Settings.Enabled ? SchedulerStatus.Enabled : SchedulerStatus.Disabled,
                        RunAsapIfScheduleMissed = arg.Definition.Settings.StartWhenAvailable,
                        UserName = arg.Definition.UserName,
                    };

                    string resWorkflowName;
                    if (resourceId == Guid.Empty)
                    {
                        resWorkflowName = split[1];
                    }
                    else
                    {
                        try
                        {
                            resWorkflowName = _pathResolve(res);
                        }
                        catch (NullReferenceException)
                        {
                            resWorkflowName = split[1];
                            res.Errors.AddError($"Workflow: {resWorkflowName} not found. Task is invalid.");
                        }
                    }
                    res.WorkflowName = resWorkflowName;

                    return(res);
                }
                finally
                {
                    arg.Dispose();
                }
            }
            if (output.Count == ArgCountOld && output.All(a => a.Contains(NameSeperator)))
            {
                var split = output.SelectMany(a => a.Split(NameSeperator)).ToList();
                try
                {
                    return(new ScheduledResource(arg.Definition.Data,
                                                 arg.Definition.Settings.Enabled ? SchedulerStatus.Enabled : SchedulerStatus.Disabled,
                                                 nextDate,
                                                 new ScheduleTrigger(arg.State, _factory.SanitiseTrigger(trigger),
                                                                     _taskService, _factory), split[1], Guid.Empty.ToString())
                    {
                        Status = arg.Definition.Settings.Enabled ? SchedulerStatus.Enabled : SchedulerStatus.Disabled,
                        RunAsapIfScheduleMissed = arg.Definition.Settings.StartWhenAvailable,
                        UserName = arg.Definition.UserName
                    });
                }
                finally
                {
                    arg.Dispose();
                }
            }

            throw new InvalidScheduleException($"Invalid resource found:{arg.Definition.Data}"); // this should not be reachable because isvaliddev2task checks same conditions
        }