示例#1
0
        private static IMongoQuery CreateMongoQuery(string resourceType, SearchResults results, int level, Dictionary <Criterium, Criterium> closedCriteria)
        {
            IMongoQuery resultQuery = CriteriaMongoExtensions.ResourceFilter(resourceType, level);

            if (closedCriteria.Count() > 0)
            {
                var criteriaQueries = new List <IMongoQuery>();
                foreach (var crit in closedCriteria)
                {
                    if (crit.Value != null)
                    {
                        try
                        {
                            criteriaQueries.Add(crit.Value.ToFilter(resourceType));
                        }
                        catch (ArgumentException ex)
                        {
                            if (results == null)
                            {
                                throw;                  //The exception *will* be caught on the highest level.
                            }
                            results.AddIssue(String.Format("Parameter [{0}] was ignored for the reason: {1}.", crit.Key.ToString(), ex.Message), OperationOutcome.IssueSeverity.Warning);
                            results.UsedCriteria.Remove(crit.Key);
                        }
                    }
                }
                if (criteriaQueries.Count > 0)
                {
                    IMongoQuery criteriaQuery = M.Query.And(criteriaQueries);
                    resultQuery = M.Query.And(resultQuery, criteriaQuery);
                }
            }

            return(resultQuery);
        }
示例#2
0
        private List <BsonValue> CollectKeys(string resourceType, IEnumerable <Criterium> criteria, SearchResults results)
        {
            //Mapping of original criterium and closed criterium, the former to be able to exclude it if it errors.
            var closedCriteria = new Dictionary <Criterium, Criterium>();

            foreach (var c in criteria)
            {
                if (c.Type == Operator.CHAIN)
                {
                    closedCriteria.Add(c, CloseCriterium(c, resourceType));
                }
                else
                {
                    closedCriteria.Add(c, c);
                }
            }

            IMongoQuery resultQuery = CriteriaMongoExtensions.ResourceFilter(resourceType);

            if (closedCriteria.Count() > 0)
            {
                var criteriaQueries = new List <IMongoQuery>();
                foreach (var crit in closedCriteria)
                {
                    try
                    {
                        criteriaQueries.Add(crit.Value.ToFilter(resourceType));
                    }
                    catch (ArgumentException ex)
                    {
                        if (results == null)
                        {
                            throw;
                        }
                        results.AddIssue(String.Format("Parameter [{0}] was ignored for the reason: {1}.", crit.Key.ToString(), ex.Message), OperationOutcome.IssueSeverity.Warning);
                        results.UsedCriteria.Remove(crit.Key);
                    }
                }
                if (criteriaQueries.Count > 0)
                {
                    IMongoQuery criteriaQuery = M.Query.And(criteriaQueries);
                    resultQuery = M.Query.And(resultQuery, criteriaQuery);
                }
            }

            return(CollectKeys(resultQuery));
        }
示例#3
0
        private List <BsonValue> CollectKeys(string resourceType, IEnumerable <Criterium> criteria, SearchResults results, int level)
        {
            //Mapping of original criterium and closed criterium, the former to be able to exclude it if it errors later on.
            var closedCriteria = new Dictionary <Criterium, Criterium>();

            foreach (var c in criteria)
            {
                if (c.Operator == Operator.CHAIN)
                {
                    try
                    {
                        closedCriteria.Add(c.Clone(), CloseCriterium(c, resourceType, level));
                        //CK: We don't pass the SearchResults on to the (recursive) CloseCriterium. We catch any exceptions only on the highest level.
                    }
                    catch (ArgumentException ex)
                    {
                        if (results == null)
                        {
                            throw;                  //The exception *will* be caught on the highest level.
                        }
                        results.AddIssue(String.Format("Parameter [{0}] was ignored for the reason: {1}.", c.ToString(), ex.Message), OperationOutcome.IssueSeverity.Warning);
                        results.UsedCriteria.Remove(c);
                    }
                }
                else
                {
                    //If it is not a chained criterium, we don't need to 'close' it, so it is said to be 'closed' already.
                    closedCriteria.Add(c, c);
                }
            }

            //All chained criteria are 'closed' or 'rolled up' to something like subject IN (id1, id2, id3), so now we AND them with the rest of the criteria.
            IMongoQuery resultQuery = CriteriaMongoExtensions.ResourceFilter(resourceType, level);

            if (closedCriteria.Count() > 0)
            {
                var criteriaQueries = new List <IMongoQuery>();
                foreach (var crit in closedCriteria)
                {
                    try
                    {
                        criteriaQueries.Add(crit.Value.ToFilter(resourceType));
                    }
                    catch (ArgumentException ex)
                    {
                        if (results == null)
                        {
                            throw;                  //The exception *will* be caught on the highest level.
                        }
                        results.AddIssue(String.Format("Parameter [{0}] was ignored for the reason: {1}.", crit.Key.ToString(), ex.Message), OperationOutcome.IssueSeverity.Warning);
                        results.UsedCriteria.Remove(crit.Key);
                    }
                }
                if (criteriaQueries.Count > 0)
                {
                    IMongoQuery criteriaQuery = M.Query.And(criteriaQueries);
                    resultQuery = M.Query.And(resultQuery, criteriaQuery);
                }
            }

            return(CollectKeys(resultQuery));
        }