Exemple #1
0
        public override void Apply(PropertyConfiguration edmProperty,
                                   StructuralTypeConfiguration structuralTypeConfiguration,
                                   Attribute attribute,
                                   ODataConventionModelBuilder model)
        {
            if (edmProperty == null)
            {
                throw Error.ArgumentNull("edmProperty");
            }

            if (!edmProperty.AddedExplicitly)
            {
                SelectAttribute         selectAttribute = attribute as SelectAttribute;
                ModelBoundQuerySettings querySettings   =
                    edmProperty.QueryConfiguration.GetModelBoundQuerySettingsOrDefault();
                if (querySettings.SelectConfigurations.Count == 0)
                {
                    querySettings.CopySelectConfigurations(selectAttribute.SelectConfigurations);
                }
                else
                {
                    foreach (var property in selectAttribute.SelectConfigurations.Keys)
                    {
                        querySettings.SelectConfigurations[property] =
                            selectAttribute.SelectConfigurations[property];
                    }
                }

                if (selectAttribute.SelectConfigurations.Count == 0)
                {
                    querySettings.DefaultSelectType = selectAttribute.DefaultSelectType;
                }
            }
        }
 private static void NotNullExpression(SelectAttribute selector)
 {
     if (string.IsNullOrWhiteSpace(selector.Expression))
     {
         throw new SpiderArgumentException($"Expression of {selector} should not be null/empty");
     }
 }
Exemple #3
0
        /// <summary>
        /// 构造方法
        /// </summary>
        public Model()
        {
            var type = typeof(T);

            TypeName = type.FullName;
            var entitySelector =
                type.GetCustomAttributes(typeof(EntitySelectAttribute), true).FirstOrDefault() as EntitySelectAttribute;
            int             take         = 0;
            bool            takeFromHead = true;
            SelectAttribute selector     = null;

            if (entitySelector != null)
            {
                take         = entitySelector.Take;
                takeFromHead = entitySelector.TakeFromHead;
                selector     = new SelectAttribute {
                    Expression = entitySelector.Expression, Type = entitySelector.Type
                };
            }

            var followSelectors = type.GetCustomAttributes(typeof(FollowSelectAttribute), true).Select(x => (FollowSelectAttribute)x)
                                  .ToList();

            var sharedValueSelectors = type.GetCustomAttributes(typeof(ValueSelectAttribute), true)
                                       .Select(x => (ValueSelectAttribute)x).ToList();

            var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);

            var valueSelectors = new HashSet <ValueSelectAttribute>();

            foreach (var property in properties)
            {
                var valueSelector = property.GetCustomAttributes(typeof(ValueSelectAttribute), true).FirstOrDefault() as ValueSelectAttribute;

                if (valueSelector == null)
                {
                    continue;
                }

                if (string.IsNullOrWhiteSpace(valueSelector.Name))
                {
                    valueSelector.Name = property.Name;
                }

                valueSelector.FormatBaseAttributes = property.GetCustomAttributes(typeof(FormatBaseAttribute), true)
                                                     .Select(p => (FormatBaseAttribute)p).ToArray();
                valueSelector.PropertyInfo = property;
                valueSelector.NotNull      = property.GetCustomAttributes(typeof(Required), false).Any();
                valueSelectors.Add(valueSelector);
            }

            Selector            = selector;
            ValueSelectors      = valueSelectors;
            FollowSelectors     = new HashSet <FollowSelectAttribute>(followSelectors);
            ShareValueSelectors = new HashSet <ValueSelectAttribute>(sharedValueSelectors);
            Take         = take;
            TakeFromHead = takeFromHead;
        }
        /// <summary>
        /// 把 BaseSelector 转换成真正的查询器
        /// </summary>
        /// <param name="selector">BaseSelector</param>
        /// <returns>查询器</returns>
        public static ISelector ToSelector(this SelectAttribute selector)
        {
            if (selector != null)
            {
                string expression = selector.Expression;

                switch (selector.Type)
                {
                case SelectorType.Css:
                {
                    NotNullExpression(selector);
                    return(Selectors.Css(expression));
                }

                case SelectorType.JsonPath:
                {
                    NotNullExpression(selector);
                    return(Selectors.JsonPath(expression));
                }

                case SelectorType.Regex:
                {
                    NotNullExpression(selector);
                    if (string.IsNullOrEmpty(selector.Arguments))
                    {
                        return(Selectors.Regex(expression));
                    }

                    if (int.TryParse(selector.Arguments, out var group))
                    {
                        return(Selectors.Regex(expression, group));
                    }
                    throw new SpiderArgumentException($"Regex argument should be a number set to group: {selector}");
                }

                case SelectorType.XPath:
                {
                    NotNullExpression(selector);
                    return(Selectors.XPath(expression));
                }

                default:
                {
                    throw new NotSupportedException($"{selector} unsupported");
                }
                }
            }

            return(null);
        }
Exemple #5
0
        public JsonResult Select(string value, string type)
        {
            Type            tType = Type.GetType(type);
            var             attrs = tType.GetCustomAttributes(typeof(SelectAttribute), true);
            SelectAttribute attr  = (SelectAttribute)attrs[0];

            return(new JsonResult
            {
                Data = new
                {
                    Action = attr.Action,
                    Controller = attr.Controller,
                    Title = ASE.ResourceHelper.GetResourceLookup(attr.ResourceType, attr.ResourceName)
                }
            });
        }
        /// <summary>
        /// Set whether the $select can be applied on those properties of this structural type.
        /// </summary>
        /// <param name="edmTypeConfiguration">The structural type to configure.</param>
        /// <param name="model">The edm model that this type belongs to.</param>
        /// <param name="attribute">The <see cref="Attribute"/> found on this type.</param>
        public override void Apply(StructuralTypeConfiguration edmTypeConfiguration, ODataConventionModelBuilder model,
                                   Attribute attribute)
        {
            if (edmTypeConfiguration == null)
            {
                throw Error.ArgumentNull("edmTypeConfiguration");
            }

            if (model == null)
            {
                throw Error.ArgumentNull("model");
            }

            if (!edmTypeConfiguration.AddedExplicitly)
            {
                SelectAttribute selectAttribute = attribute as SelectAttribute;

                /*
                 * ModelBoundQuerySettings querySettings =
                 *  edmTypeConfiguration.QueryConfiguration.GetModelBoundQuerySettingsOrDefault();
                 * if (querySettings.SelectConfigurations.Count == 0)
                 * {
                 *  querySettings.CopySelectConfigurations(
                 *      selectAttribute.SelectConfigurations);
                 * }
                 * else
                 * {
                 *  foreach (var property in selectAttribute.SelectConfigurations.Keys)
                 *  {
                 *      querySettings.SelectConfigurations[property] =
                 *          selectAttribute.SelectConfigurations[property];
                 *  }
                 * }
                 *
                 * if (selectAttribute.SelectConfigurations.Count == 0)
                 * {
                 *  querySettings.DefaultSelectType =
                 *      selectAttribute.DefaultSelectType;
                 * }
                 */
            }
        }
Exemple #7
0
        private static void SetSelect(ExpandoObject field, SelectAttribute @select)
        {
            field.TryAdd("type", ReactFormItemType.Select);
            field.TryAdd("dataAction", select.DataAction);

            var selectOptions = new ExpandoObject();

            selectOptions.TryAdd("Mode", select.Mode);
            selectOptions.TryAdd("Placeholder", select.Placeholder);
            selectOptions.TryAdd("Disabled", select.Disabled);

            if (select.AllowClear)
            {
                selectOptions.TryAdd("AllowClear", select.AllowClear);
            }

            if (select.ShowSearch)
            {
                selectOptions.TryAdd("ShowSearch", select.ShowSearch);
            }

            field.TryAdd("select", selectOptions);
        }
        public override void DrawInspectorGUI()
        {
            referenceType = (ReferenceType)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("Reference Type",
                                                                                                "This is how you will provide the response access to a specific transform. You can either use a reference, name or use the gameobject that collides with this trigger box."), referenceType);

            switch (referenceType)
            {
            case ReferenceType.TransformReference:
                targetTransform = (Transform)UnityEditor.EditorGUILayout.ObjectField(new GUIContent("Target Transform",
                                                                                                    "The target transform that will be modified."), targetTransform, typeof(Transform), true);
                break;

            case ReferenceType.TransformName:
                targetTransformName = UnityEditor.EditorGUILayout.TextField(new GUIContent("Transform Name",
                                                                                           "If you cannot get a reference for a transform you can the gameobject's name here and it will be found (GameObject.Find()) and modified."), targetTransformName);
                break;
            }

            targetAttribute = (SelectAttribute)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("Target Attribute",
                                                                                                    "The attribute on the target transform you want to modify. This can be either Transform, Rotation or Scale."), targetAttribute);

            targetAxis = (Axis)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("Target Axis",
                                                                                    "The Axis that you want to modify on this attribute on this transform. This can be either X, Y or Z."), targetAxis);

            localSpace = UnityEditor.EditorGUILayout.Toggle(new GUIContent("Local Space",
                                                                           "If this value is true, the modifications will be done in local space rather than world space."), localSpace);

            valueType = (ValueType)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("Target Value Type",
                                                                                        "The type of value that the new value is. If it is set, the transform value will be set to that value. If it is additive, the transform value will be incremented by that value. ."), valueType);

            targetValue = UnityEditor.EditorGUILayout.FloatField(new GUIContent("Target Value",
                                                                                "The value you would like to set this attribute to."), targetValue);

            duration = UnityEditor.EditorGUILayout.FloatField(new GUIContent("Change Duration",
                                                                             "The duration that the selected change will happen over in seconds. If you leave it as 0 it will perform the changes instantly."), duration);
        }