Example #1
0
        /// <summary>
        /// StartTask a new <c>task</c>.
        /// </summary>
        /// <param name="task">The <c>task</c>.</param>
        /// <returns>The task's identifier.</returns>
        public Int64 StartTask(Expression <Action> task) //TODO: (task, queue)
        {
            if (taskManagerState == TaskManagerState.ServerOnly)
            {
                throw new InvalidOperationException("taskManagerState == TaskManagerState.ServerOnly");
            }

            logger.WriteDebug("Preparing a new task... Getting a default queue...");

            QueueModel defaultQueue = queueManager.GetDefaultQueue();

            logger.WriteTrace("The default queue ({0}) has been got. Converting expression into the task model...");

            ActivationData      activationData = expressionConverter.Convert(task);
            ScheduleInformation schedule       = new ScheduleInformation(maxRerunCount);
            TaskModel           taskModel      = new TaskModel(defaultQueue.Id, activationData, schedule);

            logger.WriteTrace("The expression has been converted. Inserting the task into the database...");

            Int64 taskId = taskDataContext.InsertTask(taskModel);

            logger.WriteDebug("The task has been inserted. Task identifier = {0}", taskId);

            return(taskId);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="converter"></param>
        /// <param name="method"></param>
        /// <returns></returns>
        public override ExpressionElement Convert(IExpressionConverter converter, MethodCallExpression method)
        {
            var index = method.SkipMethodChain(0);
            var args = method.Arguments.Skip(index).Select(e => converter.Convert(e)).ToArray();
            var name = string.IsNullOrEmpty(Name) ? method.Method.Name.ToUpper() : Name;

            var hArgs = new HText(args) { Separator = Separator }.ConcatToBack(")");
            return new HText(Line(name, "("), hArgs) { IsFunctional = true };
        }
 public override ExpressionElement Convert(IExpressionConverter converter, MethodCallExpression method)
 {
     var v = new VText();
     var overMethod = method;
     v.Add(overMethod.Method.Name.ToUpper() + "(");
     v.AddRange(1, overMethod.Arguments.Skip(1).
         Where(e => !(e is ConstantExpression)). //Skip null.
         Select(e => converter.Convert(e)).ToArray());
     return v.ConcatToBack(")");
 }
        public override ExpressionElement Convert(IExpressionConverter converter, MethodCallExpression method)
        {
            var arg = method.Arguments[method.SkipMethodChain(0)];
            var array = arg as NewArrayExpression;

            var orderBy = new VText();
            orderBy.Add("ORDER BY");
            var sort = new VText() { Separator = "," };
            sort.AddRange(1, array.Expressions.Select(e => converter.Convert(e)).ToList());
            orderBy.Add(sort);
            return orderBy;
        }
Example #5
0
        /// <summary>
        /// Start new <c>task</c>.
        /// </summary>
        /// <param name="queueName">The queue's name.</param>
        /// <param name="task">The <see cref="Expression"/> instance.</param>
        /// <param name="scheduleStrategy">Schedule</param>
        /// <returns>The task's identifier.</returns>
        public int StartTask(string queueName, Expression <Action> task, IScheduleStrategy scheduleStrategy)
        {
            using (IUnitOfWork unitOfWork = unitOfWorkFactory.CreateUnitOfWork(contextSettings))
            {
                ActivationData activationData = expressionConverter.Convert(task);

                string[] args = expressionConverter.SerializeArguments(activationData.Arguments);

                TaskInfo entity = new TaskInfo
                {
                    QueueName        = queueName,
                    InstanceType     = jsonConverter.ConvertToJson(activationData.InstanceType),
                    Method           = activationData.Method.Name,
                    ParametersTypes  = jsonConverter.ConvertToJson(activationData.ArgumentTypes),
                    Arguments        = jsonConverter.ConvertToJson(args),
                    TaskState        = TaskStates.New,
                    ExecuteAt        = scheduleStrategy.GetNextExecutionTime(DateTime.UtcNow, TaskStates.New),
                    RepeatCrashCount = 3 //TODO: Settings
                };

                switch (scheduleStrategy.ScheduleType)
                {
                case ScheduleType.Immediately:
                case ScheduleType.ExecuteAt:
                {
                    entity.ScheduleInfoId = -1;
                    break;
                }

                default:
                {
                    ScheduleInfo scheduleInfo = new ScheduleInfo
                    {
                        ScheduleType     = scheduleStrategy.ScheduleType,
                        ScheduleData     = jsonConverter.ConvertToJson(scheduleStrategy),
                        ScheduleDataType = jsonConverter.ConvertToJson(scheduleStrategy.GetType())
                    };
                    unitOfWork.Insert(scheduleInfo);
                    entity.ScheduleInfoId = scheduleInfo.Id;
                    break;
                }
                }

                unitOfWork.Insert(entity);
                unitOfWork.Commit();

                return(entity.Id);
            }
        }
        public override ExpressionElement Convert(IExpressionConverter converter, MethodCallExpression method)
        {
            var partitionBy = new VText();
            partitionBy.Add("PARTITION BY");

            var elements = new VText() { Indent = 1, Separator = "," };
            var array = method.Arguments[0] as NewArrayExpression;
            foreach (var e in array.Expressions.Select(e => converter.Convert(e)))
            {
                elements.Add(e);
            }
            partitionBy.Add(elements);

            return partitionBy;
        }
 public override ExpressionElement Convert(IExpressionConverter converter, MethodCallExpression method)
     => LineSpace(converter.Convert(method.Arguments[0]), method.Method.Name.ToUpper());
 public override ExpressionElement Convert(IExpressionConverter converter, NewExpression exp)
 {
     var obj = converter.ToObject(exp.Arguments[0]);
     return (bool)obj ? converter.Convert(exp.Arguments[1]) : (ExpressionElement)string.Empty;
 }
 public override ExpressionElement Convert(IExpressionConverter converter, MethodCallExpression method)
 {
     var args = method.Arguments.Select(e => converter.Convert(e)).ToArray();
     return Clause(LineSpace(args[0], "BETWEEN"), args[1], "AND", args[2]);
 }
 public override ExpressionElement Convert(IExpressionConverter converter, MethodCallExpression method)
 {
     var args = method.Arguments.Select(e => converter.Convert(e)).ToArray();
     return new DisableBracketsText(Func("ALL", args[0]));
 }
 public override ExpressionElement Convert(IExpressionConverter converter, MethodCallExpression method)
 {
     var text = (string)converter.ToObject(method.Arguments[0]);
     var array = method.Arguments[1] as NewArrayExpression;
     return new StringFormatText(text, array.Expressions.Select(e => converter.Convert(e)).ToArray());
 }
 public override ExpressionElement Convert(IExpressionConverter converter, MethodCallExpression method)
 {
     var args = method.Arguments.Select(e => converter.Convert(e)).ToArray();
     return FuncSpace("CAST", args[0], "AS", args[1].Customize(new CustomizeParameterToObject()));
 }
 public override ExpressionElement Convert(IExpressionConverter converter, NewExpression exp)
 {
     ExpressionElement arg1 = converter.Convert(exp.Arguments[0]).Customize(new CustomizeColumnOnly());
     return new HText(arg1, "=", converter.Convert(exp.Arguments[1])) { Separator = " " };
 }
Example #14
0
        public virtual IEnumerable <Model> FindAll <TKey>(Expression <Func <Model, bool> > where = null, Expression <Func <Model, TKey> > orderBy = null, int skip = 0, int?take = null)
        {
            // Convert the expressions so we can use them with the database.
            Expression <Func <DbModel, bool> > dbWhere = null;

            if (where != null)
            {
                dbWhere = _expressionConverter.Convert <Func <Model, bool>, Func <DbModel, bool> >(where);
            }

            Expression <Func <DbModel, TKey> > dbOrderBy = null;

            if (orderBy != null)
            {
                dbOrderBy = _expressionConverter.Convert <Func <Model, TKey>, Func <DbModel, TKey> >(orderBy);
            }

            // Find the data set to work with.
            IQueryable <DbModel> dbSet = _context.Set <DbModel>();

            // Apply the where clause.
            if (dbWhere != null)
            {
                dbSet = dbSet.Where(dbWhere);
            }

            // Apply order by clause.
            if (dbOrderBy != null)
            {
                dbSet = dbSet.OrderBy(dbOrderBy);
            }

            // Apply skip
            if (skip > 0)
            {
                dbSet = dbSet.Skip(skip);
            }

            // Take only the number of results requested.
            if (take.HasValue)
            {
                dbSet = dbSet.Take(take.Value);
            }

            // Read the data.
            var dbResults = dbSet.AsEnumerable();

            // Convert back to the model format.
            var ret = dbResults.Select(dbModel =>
            {
                Model model;
                if (typeof(Model) == typeof(DbModel))
                {
                    model = (Model)(object)dbModel;
                }
                else
                {
                    model = _modelConverter.CopyProperties(dbModel, new Model());
                }

                foreach (var eventx in _events)
                {
                    eventx.Found(model);
                }

                return(model);
            }).ToList();

            return(ret);
        }