private RelationshipCheckResponse Check(ICypherFluentQuery q, IRelationshipCheckRequest request)
        {
            q = q.With("ID(e) as nodeId, count(rel) as relationshipCount");

            switch (request.ThresholdType)
            {
                case RelationshipThresholdType.ReturnIfGreaterThan:
                    q = q.Where($"relationshipCount > {request.Threshold}");
                    break;

                case RelationshipThresholdType.ReturnIfNotExact:
                    q = q.Where($"relationshipCount <> {request.Threshold}");
                    break;
                case RelationshipThresholdType.ReturnIfEqual:
                    q = q.Where($"relationshipCount = {request.Threshold}");
                    break;

                default:
                    throw new Exception("<INSERT PR HERE>");
            }

            var responses = q.Return((nodeId, relationshipCount) =>
            new Violation
            {
                NodeId = nodeId.As<long>()
            });

            var response = new RelationshipCheckResponse();
            response.Request = request;
            response.Violations.AddRange(responses.Results.ToList());
            return response;
        }
Exemple #2
0
        public static ICypherFluentQuery Where(this ICypherFluentQuery query, string matchText, bool onlyLive = false)
        {
            if (!onlyLive)
            {
                return(query.Where(matchText));
            }

            return(query
                   .Where(matchText)
                   .AndWhere(string.Format("p.title in [{0}]", string.Join(", ", PathwaysConfigurationManager.GetLivePathwaysElements().Select(p => string.Format("'{0}'", p.Title))))));
        }
Exemple #3
0
        public static ICypherFluentQuery AppendWhereClause <TSearchHeadEnum>(
            ICypherFluentQuery q
            , List <SearchPredicate <TSearchHeadEnum> > predicates
            , Func <SearchTerm <TSearchHeadEnum>, string> termToWhereText
            , bool whereAdded = false)
            where TSearchHeadEnum : struct, IConvertible
        {
            var firstWhereAdded = whereAdded;

            foreach (var predicate in predicates)
            {
                var whereText = PredicateToWhereText(predicate, termToWhereText);

                if (!firstWhereAdded)
                {
                    q = q.Where(whereText);
                    firstWhereAdded = true;
                }
                else
                {
                    q = q.AndWhere(whereText);
                }
            }

            return(q);
        }
    public ICollection <T> Find <T>(Expression <Func <T, bool> > filter) where T : IEntity
    {
        ICypherFluentQuery queryWithoutReturn = _graphClient.Cypher
                                                .Match(String.Format("(n:{0})", typeof(T).Name));

        if (filter != null)
        {
            queryWithoutReturn = queryWithoutReturn.Where(filter);
        }

        var query = queryWithoutReturn.Return(n => n.As <T>());

        QueryDebugText(MethodBase.GetCurrentMethod().Name, query);

        return(query.ResultsAsync.Result.ToList());
    }
        public void Execute(ICypherFluentQuery cypher)
        {

            ProcessStacks();

            foreach (var query in _queryStack)
            {

                if (query.QueryType == QueryTypeEnum.Match)
                {
                    cypher = cypher.Match(query.QueryString);
                    continue;
                }
                if (query.QueryType == QueryTypeEnum.OptionalMatch)
                {
                    cypher = cypher.OptionalMatch(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.Where)
                {
                    cypher = cypher.Where(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.Create)
                {
                    cypher = cypher.Create(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.Merge)
                {
                    cypher = cypher.Merge(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.Delete)
                {
                    cypher = cypher.Delete(query.QueryString);
                    continue;
                }

                if (query.QueryType == QueryTypeEnum.With)
                {
                    cypher = cypher.With(query.QueryString);
                    continue;
                }

            }

            cypher.ExecuteWithoutResults();
        }
Exemple #6
0
 /// <summary>
 /// Returns a WHERE statement that performs a case-insensitive partial match on <paramref name="value"/>.
 /// </summary>
 /// <param name="query"></param>
 /// <param name="prop"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static ICypherFluentQuery WhereLike(this ICypherFluentQuery query, string prop, string value)
 {
     return(query.Where($"{prop} =~ '{PartialMatch(value)}'"));
 }
Exemple #7
0
 public static ICypherFluentQuery Where(this ICypherFluentQuery query, string prop, Guid?value)
 {
     return(query.Where($"{prop} = '{value.Value}'"));
 }
Exemple #8
0
 /// <summary>
 /// Returns a WHERE statement that always evaluates to true, so that dynamic AND WHERE clauses can be added to it.
 /// </summary>
 /// <param name="query"></param>
 /// <returns></returns>
 public static ICypherFluentQuery Where(this ICypherFluentQuery query)
 {
     return(query.Where("1 = 1"));
 }