private SelectionField BuildSelectionField(Node selNode, NamedRequestObject parentItem)
        {
            var selFld = new SelectionField()
            {
                Parent = parentItem, SourceLocation = selNode.GetLocation()
            };
            var nameNode = selNode.FindChild(TermNames.AliasedName);

            AssignNameAlias(selFld, nameNode);
            try {
                _path.Push(selFld.Key);
                // arguments
                // the actual arg list is 2 levels below
                var argsListOptNode = selNode.FindChild(TermNames.ArgListOpt);
                // TODO: refactor, this is temp fix
                var argNodes = (argsListOptNode != null) ? argsListOptNode.ChildNodes : new List <ParseTreeNode>();
                selFld.Args = BuildArguments(argNodes, selFld);

                // directives
                var dirListNode = selNode.FindChild(TermNames.DirListOpt);
                selFld.Directives = BuildDirectives(dirListNode, DirectiveLocation.Field, selFld);
                // If the field is an object/interface itself, it should have it's own selection set
                var selSubSetNode = selNode.FindChild(TermNames.SelSet);
                if (selSubSetNode != null && selSubSetNode.ChildNodes.Count > 0)
                {
                    var items = BuildSelectionItemsList(selSubSetNode, selFld);
                    selFld.SelectionSubset = new SelectionSubset(selFld, items, selSubSetNode.GetLocation());
                }
                return(selFld);
            } finally {
                _path.Pop();
            }
        }
        private void AssignNameAlias(SelectionField fld, ParseTreeNode nameNode)
        {
            var cn = nameNode.ChildNodes;

            switch (cn.Count)
            {
            case 1:
                fld.Name = cn[0].GetText();
                return;

            case 2:
                fld.Alias = cn[0].GetText();
                fld.Name  = cn[1].GetText();
                return;
            }
        }
Exemplo n.º 3
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            var sf = new SelectionField();

            sf.ItemStyle.CssClass = "GridViewIcon";
            InternalGridView.Columns.Add(sf);

            var nf = new System.Web.UI.WebControls.BoundField();

            nf.DataField          = "Number";
            nf.ItemStyle.CssClass = "GridViewIcon";
            InternalGridView.Columns.Add(nf);

            var imgf = new ImageField();

            imgf.DataImageUrlField        = "EntityType";
            imgf.DataImageUrlFormatString = "~/Icons/Small/{0}.gif";
            imgf.ItemStyle.CssClass       = "GridViewIcon";
            InternalGridView.Columns.Add(imgf);

            var namefield = new HyperLinkField();

            namefield.HeaderText                  = "Name";
            namefield.DataTextField               = "Name";
            namefield.ItemStyle.CssClass          = "GridViewSpan";
            namefield.DataNavigateUrlFields       = new[] { "EntityType", "Guid" };
            namefield.DataNavigateUrlFormatString = "~/" + entityGroup.ToString() + "/{0}Details.aspx?guid={1}";
            InternalGridView.Columns.Add(namefield);

            foreach (DataControlField col in columns)
            {
                InternalGridView.Columns.Add(col);
            }
        }
Exemplo n.º 4
0
        private void MapSelectionFieldSubsetIfPresent(SelectionField selField, TypeDefBase fieldType)
        {
            var selSubset = selField.SelectionSubset;

            switch (fieldType)
            {
            case ScalarTypeDef _:
            case EnumTypeDef _:
                if (selSubset != null)
                {
                    AddError($"Field '{selField.Key}' of type '{fieldType.Name}' may not have a selection subset.", selSubset);
                }
                break;

            default: // ObjectType, Union or Interface
                if (selSubset == null)
                {
                    AddError($"Field '{selField.Key}' of type '{fieldType.Name}' must have a selection subset.", selField);
                    return;
                }
                MapSelectionSubSet(selSubset, fieldType);
                break;
            }
        }
Exemplo n.º 5
0
        public FormElement TryBuild(IFormProperty property, Func <string, object> deserializer)
        {
            var selectFrom = property.GetCustomAttribute <SelectFromAttribute>();

            if (selectFrom == null)
            {
                return(null);
            }

            var type  = property.PropertyType;
            var field = new SelectionField(property.Name, property.PropertyType);

            if (selectFrom.DisplayPath != null)
            {
                field.DisplayPath = BoundExpression.ParseSimplified(selectFrom.DisplayPath);
            }

            if (selectFrom.ValuePath != null)
            {
                field.ValuePath = BoundExpression.ParseSimplified(selectFrom.ValuePath);
            }

            if (selectFrom.ItemStringFormat != null)
            {
                field.ItemStringFormat = BoundExpression.ParseSimplified(selectFrom.ItemStringFormat);
            }

            field.SelectionType = Utilities.GetResource <SelectionType>(selectFrom.SelectionType, SelectionType.ComboBox, Deserializers.Enum <SelectionType>());

            switch (selectFrom.ItemsSource)
            {
            case string expr:
                var value = BoundExpression.Parse(expr);
                if (!value.IsSingleResource)
                {
                    throw new InvalidOperationException("ItemsSource must be a single resource reference.");
                }

                field.ItemsSource = value.Resources[0];
                break;

            case IEnumerable <object> enumerable:
                field.ItemsSource = new LiteralValue(enumerable.ToList());
                break;

            case Type enumType:
                if (!enumType.IsEnum)
                {
                    throw new InvalidOperationException("A type argument for ItemsSource must be an enum.");
                }

                var values     = Enum.GetValues(enumType);
                var collection = new List <KeyValuePair <ValueType, IValueProvider> >();
                foreach (Enum enumValue in values)
                {
                    var            enumName   = enumValue.ToString();
                    var            memInfo    = enumType.GetMember(enumName);
                    var            attributes = memInfo[0].GetCustomAttributes(typeof(EnumDisplayAttribute), false);
                    IValueProvider name;
                    if (attributes.Length > 0)
                    {
                        var attr = (EnumDisplayAttribute)attributes[0];
                        name = BoundExpression.ParseSimplified(attr.Name);
                    }
                    else
                    {
                        name = new LiteralValue(enumName.Humanize());
                    }

                    collection.Add(new KeyValuePair <ValueType, IValueProvider>(enumValue, name));
                }

                field.ItemsSource = new EnumerableStringValueProvider(collection);
                field.DisplayPath = new LiteralValue(nameof(StringProxy.Value));
                field.ValuePath   = new LiteralValue(type == typeof(string)
                        ? nameof(StringProxy.Value)
                        : nameof(StringProxy.Key));
                break;
            }

            return(field);
        }
Exemplo n.º 6
0
 public OrderInputs()
 {
     _currencyPair = new SelectionField <CurrencyPair>();
     _notional     = new Field <decimal?>();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SelectionPage"/> class.
 /// </summary>
 /// <param name="selectionFields">Bitwise mask of fields to be fetched for contacts.</param>
 /// <param name="pageLength">Length of the contacts page.</param>
 /// <param name="pageReady">Callback to trigger if request succeeds.</param>
 /// <param name="pageFailed">Callback to trigger if request fails.</param>
 public SelectionPage(SelectionField selectionFields, uint pageLength, ListPage.OnPageReadyDelegate pageReady = null, ListPage.OnPageFailedDelegate pageFailed = null)
     : base(pageLength, pageReady, pageFailed)
 {
     this.selectionFields = selectionFields;
 }