Beispiel #1
0
        public static FieldPath FromDefault(IField field)
        {
            var path = new FieldPath();
            var cur  = field;

            while (cur is IRelationField)
            {
                path.Add(cur);
                cur = ((IRelationField)cur).RelatedSubject.DefaultField;
            }
            path.Add(cur);
            return(path);
        }
Beispiel #2
0
        public static FieldPath operator +(FieldPath path, IField field)
        {
            var path2 = new FieldPath(path);

            path2.Add(field);
            return(path2);
        }
Beispiel #3
0
        public static FieldPath operator +(FieldPath path1, FieldPath path2)
        {
            var path3 = new FieldPath(path1);

            path3.Add(path2);
            return(path3);
        }
Beispiel #4
0
        public IFieldPath this[int from, int?to]
        {
            get
            {
                var f = new FieldPath();
                if (from < 0)
                {
                    from = 0;
                }
                if (!to.HasValue)
                {
                    to = _fields.Count;
                }
                else if (to < 0)
                {
                    to += _fields.Count;
                }

                for (int i = from; i < _fields.Count && i < to; i++)
                {
                    f.Add(_fields[i]);
                }
                return(f);
            }
        }
Beispiel #5
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); });
        }
Beispiel #6
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); });
        }
Beispiel #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;
        }
Beispiel #8
0
 public static FieldPath FromDefault(IField field)
 {
     var path = new FieldPath();
     var cur = field;
     while (cur is IRelationField)
     {
         path.Add(cur);
         cur = ((IRelationField)cur).RelatedSubject.DefaultField;
     }
     path.Add(cur);
     return path;
 }
Beispiel #9
0
 public static FieldPath operator +(FieldPath path, IField field)
 {
     var path2 = new FieldPath(path);
     path2.Add(field);
     return path2;
 }
Beispiel #10
0
 public static FieldPath operator +(FieldPath path1, FieldPath path2)
 {
     var path3 = new FieldPath(path1);
     path3.Add(path2);
     return path3;
 }
Beispiel #11
0
        public IFieldPath this[int from, int? to]
        {
            get
            {
                var f = new FieldPath();
                if (from < 0)
                    from = 0;
                if (!to.HasValue)
                    to = _fields.Count;
                else if (to < 0)
                    to += _fields.Count;

                for (int i = from; i < _fields.Count && i < to; i++)
                    f.Add(_fields[i]);
                return f;
            }
        }
 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;
         }
     }
 }