コード例 #1
0
        public override MaxComplexityVisitorContext AddField(
            IOutputField fieldDefinition,
            FieldNode fieldSelection)
        {
            IDirective directive = fieldDefinition.Directives
                                   .FirstOrDefault(t => t.Type is CostDirectiveType);
            int complexity;

            CostDirective cost = directive == null
                ? DefaultCost
                : directive.ToObject <CostDirective>();

            complexity = Complexity + CalculateComplexity(
                new ComplexityContext(
                    fieldDefinition, fieldSelection,
                    FieldPath, _variables, cost));

            if (complexity > MaxComplexity)
            {
                MaxComplexity = complexity;
            }

            return(new MaxComplexityWithMultipliersVisitorContext(
                       FragmentPath,
                       FieldPath.Add(fieldDefinition),
                       this));
        }
コード例 #2
0
 public Context AddField(FieldNode field)
 {
     return(new Context(
                FragmentPath,
                FieldPath.Add(field),
                _violatingFields,
                Fragments));
 }
コード例 #3
0
        public void Invalid_add_relation_field_path()
        {
            var aw   = new AdventureWorks();
            var path = new FieldPath(aw.Products["ProductCategoryID"]);

            // no link between relation field product.category and normal field contact.name
            Assert.Throws <ArgumentException>(() => { path.Add(aw.Contacts.DefaultField); });
        }
コード例 #4
0
        public void Invalid_add_field_path()
        {
            var aw   = new AdventureWorks();
            var path = new FieldPath(aw.Products.DefaultField);

            // no link between normal field product.name and normal field contact.name
            Assert.Throws <InvalidOperationException>(() => { path.Add(aw.Contacts.DefaultField); });
        }
コード例 #5
0
        void SelectedFieldChanged(object sender, EventArgs e)
        {
            var d    = ((FieldPathComboItem)sender);
            var path = new FieldPath();

            foreach (var f in Items)
            {
                path.Add(f.SelectedField);
                if (f == d) // end of the road (either truncated or the last field changed)
                {
                    SelectedPath = path;
                    return;
                }
            }
        }
コード例 #6
0
        public virtual IFieldPath Restore(FieldPathDTO dto)
        {
            var path       = new FieldPath();
            var curSubject = _configuration[dto.SubjectIndex];

            foreach (var name in dto.SourceNames)
            {
                var field = curSubject[name];
                path.Add(field);
                if (field is IRelationField)
                {
                    curSubject = ((IRelationField)field).RelatedSubject;
                }
            }
            return(path);
        }
コード例 #7
0
        /// <summary>
        /// Parse text containing placeholders for fields delimited by bracket.
        /// The first stop delimits the subject.field, subsequent stops traverse relationships.
        /// For example:
        /// [Products.Name] is the "Products" subject, field "Name"
        /// [Products.ProductCategoryID.Name] is the "Products" subject, field "ProductCategoryID" which is a RelationField to subject "Product Category" with a field "Name".
        /// </summary>
        /// <param name="subject"></param>
        /// <param name="texts"></param>
        /// <returns></returns>
        public virtual Dictionary <string, IFieldPath> Parse(IConfiguration config, params string[] texts)
        {
            var fields = new Dictionary <string, IFieldPath>();

            foreach (var t in texts)
            {
                var matches = Regex.Matches(t, @"\[((?<subject>[^\]\.]+)(\.([^\]\.]+))+)\]");
                foreach (Match m in matches)
                {
                    // represent the entire path as the key to the dictionary
                    if (!fields.ContainsKey(m.Groups[1].Value))
                    {
                        // now create the FieldPath based on the Regex
                        var path    = new FieldPath();
                        var subject = config[m.Groups["subject"].Value];
                        if (subject != null)
                        {
                            foreach (Capture capture in m.Groups[3].Captures)
                            {
                                var field = subject[capture.Value];
                                if (field == null)
                                {
                                    path.Clear();
                                    break;
                                }

                                path.Add(field);
                                if (field is IRelationField)
                                {
                                    subject = ((IRelationField)field).RelatedSubject;
                                }
                            }

                            if (path.Count > 0)
                            {
                                fields.Add(m.Groups[0].Value, path);
                            }
                        }
                    }
                }
            }

            return(fields);
        }