Exemple #1
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public virtual void Execute(IJobExecutionContext context)
        {
            List <int> people;
            int        count = 0;

            //
            // Create a list of every Person Id that has a signal.
            //
            using (var rockContext = new RockContext())
            {
                people = new PersonSignalService(rockContext).Queryable()
                         .Select(s => s.PersonId)
                         .Distinct()
                         .ToList();
            }

            //
            // Operate in batches of 250 so we don't lag the context too much.
            //
            while (people.Any())
            {
                var batch = people.Take(250).ToList();
                people.RemoveRange(0, batch.Count);

                using (var rockContext = new RockContext())
                {
                    new PersonService(rockContext).Queryable()
                    .Where(p => batch.Contains(p.Id))
                    .ToList()
                    .ForEach(p => p.CalculateSignals());

                    rockContext.SaveChanges();

                    count += batch.Count;
                }
            }

            context.Result = string.Format("{0} people processed", count);
        }
Exemple #2
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection)
        {
            string[] selectionValues = selection.Split('|');
            if (selectionValues.Length >= 1)
            {
                int signalTypeId = selectionValues[0].AsInteger();

                var signalQry = new PersonSignalService(( RockContext )serviceInstance.Context).Queryable();

                if (signalTypeId != 0)
                {
                    signalQry = signalQry.Where(x => x.SignalTypeId == signalTypeId);
                }

                var qry = new PersonService(( RockContext )serviceInstance.Context).Queryable()
                          .Where(p => signalQry.Any(x => x.PersonId == p.Id));

                return(FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p"));
            }

            return(null);
        }