public HistoryResult HistoryFor(HistoryRequest request, IHistoryBuilder builder)
        {
            var activityCodes = new List <int>();
            var gatherer      = new ActEntryGatherer(activityCodes, request.ShowAllActivities, request.WorkflowObject, _services, _user, _privileges);
            var map           = _models.Find(request.WorkflowObject);

            map.Accept(gatherer);

            var options = new ActEntryOptions
            {
                FocusType = _schema.GetTableNumber(request.WorkflowObject.Type),
                FocusId   = int.Parse(request.WorkflowObject.Id)
            };
            var actEntries = IdsFor(request, options, activityCodes.ToArray());

            var items = actEntries.Ids.Any()
                                ? builder.GetAll(request, options, generic => generic.Filter(_ => _.IsIn("objid", actEntries.Ids.ToArray())))
                                : new ModelData[0];

            return(new HistoryResult
            {
                HistoryItemLimit = request.HistoryItemLimit,
                Since = request.Since,
                TotalResults = actEntries.Count,
                Items = request.ReverseOrder
                                        ? items.OrderBy(_ => _.Get <DateTime>("timestamp")).ThenBy(_ => _.Get <int>("id")).ToArray()
                                        : items.OrderByDescending(_ => _.Get <DateTime>("timestamp")).ThenByDescending(_ => _.Get <int>("id")).ToArray(),
                NextTimestamp = HistoryResult.DetermineNextTimestamp(request, actEntries)
            });
        }
        public HistoryResult HistoryFor(HistoryRequest request, IHistoryBuilder builder)
        {
            var activityCodes = new List <int>();
            var gatherer      = new ActEntryGatherer(activityCodes, request.ShowAllActivities, request.WorkflowObject, _services, _user, _privileges);
            var map           = _models.Find(request.WorkflowObject);

            map.Accept(gatherer);

            var policy     = _policies.LastOrDefault(_ => _.Matches(request)) ?? _default;
            var actEntries = policy.IdsFor(request, activityCodes.ToArray());

            var items = actEntries.Ids.Any()
                                ? builder.GetAll(request, generic => generic.Filter(_ => _.IsIn("objid", actEntries.Ids.ToArray())))
                                : new ModelData[0];

            return(new HistoryResult
            {
                HistoryItemLimit = request.HistoryItemLimit,
                Since = request.Since,
                TotalResults = actEntries.Count,
                Items = request.ReverseOrder
                                        ? items.OrderBy(_ => _.Get <DateTime>("timestamp")).ThenBy(_ => _.Get <int>("id")).ToArray()
                                        : items.OrderByDescending(_ => _.Get <DateTime>("timestamp")).ThenByDescending(_ => _.Get <int>("id")).ToArray(),
                NextTimestamp = HistoryResult.DetermineNextTimestamp(request, actEntries)
            });
        }
        private IEnumerable <int> determineActCodes(WorkflowObject workflowObject, bool showAllActivities)
        {
            var activityCodes = new List <int>();
            var gatherer      = new ActEntryGatherer(activityCodes, showAllActivities, workflowObject, _services, _user, _privileges);
            var map           = _models.Find(workflowObject);

            map.Accept(gatherer);

            return(activityCodes);
        }