private static bool IsUserScopedApi(IAttributeProvider controller)
        {
            var route    = controller.GetAttributes(TypeInfo.From <RouteAttribute>()).SingleOrDefault();
            var template = route?.GetValue <string?>("Template", null);

            return(template?.StartsWith("v1/user/{userId}") ?? false);
        }
Example #2
0
        /// <summary>
        /// Convert java annotations into text
        /// </summary>
        internal static string LoadAnnotations(IAttributeProvider provider)
        {
            var annAttributes = provider.Attributes.OfType <AnnotationsAttribute>().ToList();

            if (annAttributes.Count == 0)
            {
                return("-");
            }

            var sb = new StringBuilder();
            var nl = Environment.NewLine;

            foreach (var attr in annAttributes)
            {
                sb.Append("\t");
                sb.Append(attr.Name);
                sb.Append(nl);

                foreach (var ann in attr.Annotations)
                {
                    sb.Append("\t\t");
                    sb.Append(ann.AnnotationTypeName);
                    sb.Append(nl);

                    foreach (var pair in ann.ValuePairs)
                    {
                        sb.Append("\t\t\t");
                        sb.AppendFormat("{0} \t - {1}{2}", pair.ElementName, pair.Value, nl);
                    }
                }
            }
            return(sb.ToString());
        }
Example #3
0
        public TempList <AttributeVariable> GetAttributeVariables(IAttributeProvider attributeProvider)
        {
            var list = TempList <AttributeVariable> .Alloc();

            if (Attributes != null && Attributes.Length > 0)
            {
                switch (Type)
                {
                case AttributeSetType.NORMAL:
                    foreach (AttributeMetadata attribute in Attributes)
                    {
                        AttributeVariable v = new AttributeVariable((int)attribute.Type, new AttributeValue(attribute.ModifyType, attribute.Value));
                        list.Add(v);
                    }
                    break;

                case AttributeSetType.CHANGE:
                    AttributeVariable variable = attributeProvider.GetAttributeVariable((int)ChangeType);
                    if (!variable.Value.Value1.IsZero())
                    {
                        double d = variable.Value.Value1 / ChangeValue;
                        foreach (AttributeMetadata attribute in Attributes)
                        {
                            AttributeVariable v = new AttributeVariable((int)attribute.Type, new AttributeValue(AttributeModifyType.ABSOLUTE, attribute.Value * d));
                            list.Add(v);
                        }
                    }
                    break;
                }
            }
            return(list);
        }
            public AttributeCache(IAttributeProvider element)
            {
                Ensure.That(nameof(element)).IsNotNull(element);

                try
                {
                    inheritedAttributes = element.GetCustomAttributes(true);
                }
                catch (UnityException)
                {
                    // Likely a main thread API call
                }
                catch (Exception ex)
                {
                    Debug.LogWarning($"Failed to fetch inherited attributes on {element}.\n{ex}");
                }

                try
                {
                    inheritedAttributes = element.GetCustomAttributes(false);
                }
                catch (UnityException)
                {
                    // Likely a main thread API call
                }
                catch (Exception ex)
                {
                    Debug.LogWarning($"Failed to fetch defined attributes on {element}.\n{ex}");
                }

                FallbackAttributes();
            }
Example #5
0
        /// <summary>
        /// Convert java annotations into text
        /// </summary>
        internal static string LoadAnnotations(IAttributeProvider provider)
        {
            var annAttributes = provider.Attributes.OfType<AnnotationsAttribute>().ToList();
            if (annAttributes.Count == 0)
                return "-";

            var sb = new StringBuilder();
            var nl = Environment.NewLine;
            foreach (var attr in annAttributes)
            {
                sb.Append("\t");
                sb.Append(attr.Name);
                sb.Append(nl);

                foreach (var ann in attr.Annotations)
                {
                    sb.Append("\t\t");
                    sb.Append(ann.AnnotationTypeName);
                    sb.Append(nl);

                    foreach (var pair in ann.ValuePairs)
                    {
                        sb.Append("\t\t\t");
                        sb.AppendFormat("{0} \t - {1}{2}", pair.ElementName, pair.Value, nl);
                    }
                }
            }
            return sb.ToString();
        }
        public wfQueryControlSelectorResult Attr <T>(string name, T value)
        {
            if (0 == Length)
            {
                return(this);
            }
            IAttributeProvider provider = wfQueryContext.DefaultAttributeProvider;

            _wfQuery.Control.SuspendLayout();
            foreach (Control control in Results)
            {
                PropertyInfo property = GetProperty(control, name);
                if (null == property)
                {
                    provider.SetAttributeValue(control, name, value);
                }
                else
                {
                    property.SetValue(control, value);
                }
            }
            _wfQuery.Control.ResumeLayout();

            return(this);
        }
        public wfQueryControlSelectorResult Attr <T>(string name, Func <int, Control, T> func)
        {
            if (0 == Length)
            {
                return(this);
            }
            IAttributeProvider       provider = wfQueryContext.DefaultAttributeProvider;
            LinkedListNode <Control> node     = Results.First;

            _wfQuery.Control.SuspendLayout();
            for (int index = 0; index < Length; index++)
            {
                Control      control  = node.Value;
                PropertyInfo property = GetProperty(control, name);

                if (null == property)
                {
                    provider.SetAttributeValue(control, name, func(index, control));
                }
                else
                {
                    property.SetValue(control, func(index, control));
                }
                node = node.Next;
            }
            _wfQuery.Control.ResumeLayout();

            return(this);
        }
        private void RenderAttributes(IAttributeProvider provider)
        {
            var attrs = provider.Attributes.Where(a => !a.IsSeparated).ToList();

            if (attrs.Count > 0)
            {
                Write("[");

                var first = provider.Attributes.First();
                foreach (var attr in provider.Attributes)
                {
                    if (attr != first)
                    {
                        Write(", ");
                    }
                    RenderAttributeBody(attr);
                }

                WriteLine("]");
            }

            attrs = provider.Attributes.Where(a => a.IsSeparated).ToList();

            foreach (var attr in attrs)
            {
                Write("[");
                RenderAttributeBody(attr);
                WriteLine("]");
            }
        }
        private static IEnumerable <KeyValuePair <string, object> > GetSchemaLookupProperties
            (IAttributeProvider attributeProvider)
        {
            var attribute = attributeProvider.GetAttributes(typeof(DynamicSchemaLookupAttribute), true).SingleOrDefault() as DynamicSchemaLookupAttribute;

            return(attribute.GetSwaggerExtensions());
        }
Example #10
0
 public void AddAttributes(BuildingContext context, IAttributeProvider destination, IExtraAttributeProvider provider)
 {
     foreach (var attribute in provider.ExtraAttributes)
     {
         attribute.Value.NameIndex = (ushort)ConstantPoolBuffer.GetUtf8Index(attribute.Key);
         destination.Attributes.Add(attribute.Value);
     }
 }
Example #11
0
        /// <summary>
        /// Create a proxy with provided target
        /// </summary>
        /// <param name="decorated"></param>
        /// <param name="contextProvider"></param>
        /// <param name="attributeProvider"></param>
        /// <returns></returns>
        public static T Create(T decorated, IContextProvider contextProvider, IAttributeProvider attributeProvider)
        {
            object proxy = Create <T, MethodInterceptor <T> >();

            ((MethodInterceptor <T>)proxy).SetParameters(decorated, contextProvider, attributeProvider);

            return((T)proxy);
        }
Example #12
0
 public static SecurityPermission GetSecurityPermission <TAttribute>(this IAttributeProvider parent)
     where TAttribute : SecurityAttribute =>
 !parent.HasAttribute <TAttribute>()
     ? new SecurityPermission()
 : new SecurityPermission(
     level : parent.GetAttributeValue <TAttribute, SecurityPermissionLevels>(a => a.PermissionLevel) ?? SecurityPermissionLevels.AllowAuthorized,
     roles : parent.GetAttributeValue <TAttribute>(a => a.Roles),
     name : typeof(TAttribute).Name.Replace("Attribute", string.Empty)
     );
        /// <summary>
        /// Determines whether <paramref name="provider"/> contains any attributes
        /// </summary>
        /// <typeparam name="TType">The type</typeparam>
        /// <typeparam name="TAttribute">The attribute type</typeparam>
        /// <param name="provider">The provider</param>
        /// <returns>true if the <paramref name="provider"/> contains any attributes; otherwise, false</returns>
        public static bool Any <TType, TAttribute>(this IAttributeProvider <TType, TAttribute> provider)
            where TAttribute : Attribute
        {
            Argument.NotNull(provider, nameof(provider));

            bool any = provider.Count > 0;

            return(any);
        }
        private static NullabilityInfo From(IAttributeProvider?type, IAttributeProvider member)
        {
            var typeAttributes   = type?.GetAttributes(inherit: true) ?? new IAttributeInfo[0];
            var memberAttributes = member.GetAttributes(inherit: true);

            return(new NullabilityInfo(GetNullableContextFlag(memberAttributes) ?? GetNullableContextFlag(typeAttributes),
                                       GetNullableFlagsInternal(memberAttributes),
                                       memberAttributes));
        }
        public BrokerFactoryBase(ServiceBusConfiguration configuration, IAttributeProvider <A> attributeProvider = null)
        {
            _configuration     = configuration ?? throw new ArgumentNullException(nameof(configuration));
            _attributeProvider = attributeProvider ?? new SimpleAttributeProvider <A>();

            _lazyManagementClient = new Lazy <ManagementClient>(new ManagementClient(configuration.ConnectionString));

            _senderClientsDic = new ConcurrentDictionary <string, ISenderClient>();
            _semaphoresDic    = new ConcurrentDictionary <string, SemaphoreSlim>();
            _attributesDic    = new ConcurrentDictionary <Type, A>();
        }
        private static string AppendRoutePrefix(string routeTemplate, IAttributeProvider controllerType)
        {
            var routeAttribute = controllerType.GetAttributes(TypeInfo.From <RouteAttribute>()).SingleOrDefault();
            var fullRoute      = (routeAttribute == null ? "" : routeAttribute.GetValue("Template", "") + "/") + routeTemplate;

            if (IsUserScopedApi(controllerType))
            {
                return(fullRoute.Substring("v1/user/{userId}/".Length));
            }
            return(fullRoute.Substring("v1/".Length));
        }
        public wfQueryControlSelectorResult Data <T>(string name, T value)
        {
            if (0 == Length)
            {
                return(this);
            }
            IAttributeProvider provider = wfQueryContext.DefaultAttributeProvider;

            Attr("data-" + name, value);

            return(this);
        }
Example #18
0
        public static T?GetAttributeValue <TAttribute, T>(this IAttributeProvider obj, string valueName)
            where TAttribute : Attribute
            where T : struct
        {
            var result = obj.GetAttributeValue <TAttribute>(valueName);

            if (result == null)
            {
                return(null);
            }
            return(new T?((T)result));
        }
Example #19
0
        public static TAttribute GetAttribute <TAttribute>(this IAttributeProvider source)
            where TAttribute : Attribute
        {
            var attributes = source.GetAttributes(typeof(TAttribute), true);

            if (!attributes.Any())
            {
                return(null);
            }

            return((TAttribute)attributes.FirstOrDefault());
        }
        public wfQueryControlSelectorResult Data <T>(string name, Func <int, Control, T> func)
        {
            if (0 == Length)
            {
                return(this);
            }
            IAttributeProvider       provider = wfQueryContext.DefaultAttributeProvider;
            LinkedListNode <Control> node     = Results.First;

            Attr("data-" + name, func);

            return(this);
        }
Example #21
0
        private static bool CanBeNull(IAttributeProvider attributeProvider, NullabilityMode nullabilityMode)
        {
            if (nullabilityMode == NullabilityMode.NullableReference)
            {
                var flags = GetNullableFlags(attributeProvider);
                return(flags[0] == 2);
            }

            return
                (nullabilityMode == NullabilityMode.Pessimistic
                    ? !attributeProvider.IsNameDefined(AnnotationsNames.NotNull) && !attributeProvider.IsNameDefined(AnnotationsNames.Required)
                    : attributeProvider.IsNameDefined(AnnotationsNames.CanBeNull));
        }
        /// <summary>
        /// Throws <see cref="InvalidOperationException"/> when <paramref name="provider"/> contains not one attributes
        /// </summary>
        /// <typeparam name="TType">The type</typeparam>
        /// <typeparam name="TAttribute">The attribute type</typeparam>
        /// <param name="provider">The provider</param>
        /// <returns>The provider</returns>
        /// <exception cref="InvalidOperationException"><paramref name="provider"/> contains not one attributes</exception>
        public static IAttributeProvider <TType, TAttribute> ThrowIfNotOne <TType, TAttribute>(
            this IAttributeProvider <TType, TAttribute> provider)

            where TAttribute : Attribute
        {
            Argument.NotNull(provider, nameof(provider));

            if (provider.Count != 1)
            {
                Throw(provider, "Number of {0} attributes on type {1} is not equal to one");
            }

            return(provider);
        }
        /// <summary>
        /// Throws <see cref="InvalidOperationException"/> when <paramref name="provider"/> contains any attributes
        /// </summary>
        /// <typeparam name="TType">The type</typeparam>
        /// <typeparam name="TAttribute">The attribute type</typeparam>
        /// <param name="provider">The provider</param>
        /// <returns>The provider</returns>
        /// <exception cref="InvalidOperationException"><paramref name="provider"/> contains any attributes</exception>
        public static IAttributeProvider <TType, TAttribute> ThrowIfAny <TType, TAttribute>(
            this IAttributeProvider <TType, TAttribute> provider)

            where TAttribute : Attribute
        {
            Argument.NotNull(provider, nameof(provider));

            if (provider.Count > 0)
            {
                Throw(provider, "Number of {0} attributes on type {1} is greater than zero");
            }

            return(provider);
        }
Example #24
0
        public static TypeViewModel GetAttributeValue <TAttribute>(this IAttributeProvider obj, Expression <Func <TAttribute, Type> > propertyExpression)
            where TAttribute : Attribute
        {
            var value = obj.GetAttributeValue <TAttribute>(propertyExpression.GetExpressedProperty().Name);

            if (value is Type reflectionValue)
            {
                return(new ReflectionTypeViewModel(reflectionValue));
            }
            if (value is ITypeSymbol symbolValue)
            {
                return(new SymbolTypeViewModel(symbolValue));
            }
            return(null);
        }
        public T Attr <T>(string name)
        {
            Control            control  = Results.First();
            IAttributeProvider provider = wfQueryContext.DefaultAttributeProvider;
            T value = default(T);

            if (provider.HasAttributeValue(control, name))
            {
                value = provider.GetAttributeValue <T>(control, name);
            }
            else
            {
                value = GetPropertyValue <T>(control, name);
            }
            return(value);
        }
Example #26
0
        private static Attribute GetAttributeByName(IAttributeProvider attributeProvider, string name)
        {
            if (attributeProvider != null)
            {
                IList <Attribute> attributes = attributeProvider.GetAttributes(true);
                foreach (Attribute attribute in attributes)
                {
                    if (string.Equals(attribute.GetType().FullName, name, StringComparison.Ordinal))
                    {
                        return(attribute);
                    }
                }
            }

            return(null);
        }
        private static void Throw <TType, TAttribute>(
            IAttributeProvider <TType, TAttribute> provider,
            string format)

            where TAttribute : Attribute
        {
            _ = provider;

            string message = string.Format(
                CultureInfo.InvariantCulture,
                format,
                typeof(TAttribute).Name,
                typeof(TType).Name);

            throw new InvalidOperationException(message);
        }
        private static Attribute GetAttributeByName(IAttributeProvider attributeProvider, string name, out Type matchingType)
        {
            if (attributeProvider != null)
            {
                IList <Attribute> attributes = attributeProvider.GetAttributes(true);
                foreach (Attribute attribute in attributes)
                {
                    if (IsMatchingAttribute(attribute.GetType(), name, out matchingType))
                    {
                        return(attribute);
                    }
                }
            }

            matchingType = null;
            return(null);
        }
Example #29
0
        private static AttributeCache GetAttributeCache(IAttributeProvider element)
        {
            Ensure.That(nameof(element)).IsNotNull(element);

            var key = element;

            lock (optimizedCaches)
            {
                if (!optimizedCaches.TryGetValue(key, out var cache))
                {
                    cache = new AttributeCache(element);
                    optimizedCaches.Add(key, cache);
                }

                return(cache);
            }
        }
        // Methods
        internal AttributedMetaAssociation(AttributedMetaDataMember member, AssociationAttribute attr)
        {
            this.attributeProvider = member.MetaModel.AttributeProvider;

            this.thisMember = member;
            this.isMany     = TypeSystem.IsSequenceType(thisMember.Type);
            Type type = this.isMany ? TypeSystem.GetElementType(thisMember.Type) : thisMember.Type;

            this.otherType            = this.thisMember.DeclaringType.Model.GetMetaType(type);
            this.thisKey              = (attr.ThisKey != null) ? MakeKeys(thisMember.DeclaringType, attr.ThisKey) : thisMember.DeclaringType.IdentityMembers;
            this.otherKey             = (attr.OtherKey != null) ? MakeKeys(otherType, attr.OtherKey) : this.otherType.IdentityMembers;
            this.thisKeyIsPrimaryKey  = AreEqual(this.thisKey, thisMember.DeclaringType.IdentityMembers);
            this.otherKeyIsPrimaryKey = AreEqual(this.otherKey, otherType.IdentityMembers);
            this.isForeignKey         = attr.IsForeignKey;
            this.isUnique             = attr.IsUnique;
            this.deleteRule           = attr.DeleteRule;
            this.deleteOnNull         = attr.DeleteOnNull;
            foreach (MetaDataMember member2 in this.thisKey)
            {
                if (!member2.CanBeNull)
                {
                    this.isNullable = false;
                    break;
                }
            }
            if (this.deleteOnNull && ((!this.isForeignKey || this.isMany) || this.isNullable))
            {
                throw Mapping.Error.InvalidDeleteOnNullSpecification(member);
            }
            if (((this.thisKey.Count != this.otherKey.Count) && (this.thisKey.Count > 0)) && (this.otherKey.Count > 0))
            {
                throw Mapping.Error.MismatchedThisKeyOtherKey(member.Name, member.DeclaringType.Name);
            }
            foreach (MetaDataMember member3 in this.otherType.PersistentDataMembers)
            {
                /* var customAttribute = (AssociationAttribute)Attribute.GetCustomAttribute(member3.Member, typeof(AssociationAttribute)); */
                var customAttribute = this.attributeProvider.GetAssociationAttribute(member3.Member);

                if (((customAttribute != null) && (member3 != this.thisMember)) && (customAttribute.Name == attr.Name))
                {
                    this.otherMember = member3;
                    break;
                }
            }
        }
        public void SetUp()
        {
            var instanceIdGenerator = new InstanceIdGenerator();

            _htmlParserProvider    = new DefaultHtmlParserProvider();
            _movementProvider      = new DefaultMovementProvider(instanceIdGenerator);
            _moveProvider          = new DefaultMoveProvider(instanceIdGenerator);
            _pageDownloader        = new DefaultPageDownloader();
            _webClientProvider     = new DefaultWebClientProvider();
            _attributeProvider     = new DefaultAttributeProvider(instanceIdGenerator);
            _imageScrapingProvider = new DefaultImageScrapingProvider();
            _imageScrapingService  = new DefaultImageScrapingService(_imageScrapingProvider);
            _uniqueDataProvider    = new DefaultUniqueDataProvider(instanceIdGenerator);
            _webServices           = new DefaultWebServices(_htmlParserProvider, _webClientProvider, _pageDownloader);

            _attributeScrapingServices  = new DefaultAttributeScrapingServices(_attributeProvider, _webServices);
            _moveScrapingServices       = new DefaultMoveScrapingServices(_moveProvider, _webServices);
            _movementScrapingServices   = new DefaultMovementScrapingServices(_movementProvider, _webServices);
            _uniqueDataScrapingServices = new DefaultUniqueDataScrapingServices(_uniqueDataProvider, _webServices);

            _groundMoveScraper    = new GroundMoveScraper(_moveScrapingServices);
            _aerialMoveScraper    = new AerialMoveScraper(_moveScrapingServices);
            _specialMoveScraper   = new SpecialMoveScraper(_moveScrapingServices);
            _throwMovesScraper    = new ThrowMoveScraper(_moveScrapingServices);
            _characterMoveScraper = new DefaultCharacterMoveScraper(new List <IMoveScraper>
            {
                _groundMoveScraper, _aerialMoveScraper, _specialMoveScraper, _throwMovesScraper
            });

            var attributeScrapers = new List <IAttributeScraper>
            {
                new AirSpeedScraper(_attributeScrapingServices),
                new AirDodgeScraper(_attributeScrapingServices)
            };

            _movementScraper = new DefaultMovementScraper(_movementScrapingServices);

            _characterDataScrapingServices = new DefaultCharacterDataScrapingServices(_imageScrapingService, _movementScraper,
                                                                                      attributeScrapers, _characterMoveScraper, _uniqueDataScrapingServices, _webServices, instanceIdGenerator);

            _characterDataScraper = new DefaultCharacterDataScraper(_characterDataScrapingServices);
        }
 /// <summary>
 /// Initialize a dynamic attribute provider with extra attributes for selected method info
 /// </summary>
 /// <param name="original"></param>
 /// <param name="extraAttributes"></param>
 public DynamicAttributeProvider(IAttributeProvider original, Func<List<Tuple<MethodInfo, Attribute>>> extraAttributes)
 {
     _original = original;
     _extraAttributes = extraAttributes;
 }
 /// <summary>
 /// Initializes an instance of <see cref="MethodInterceptorAdaptor"/>
 /// </summary>
 /// <param name="contextProvider"></param>
 /// <param name="attributeProvider"></param>
 public MethodInterceptorAdaptor(IAttributeProvider attributeProvider, IContextProvider contextProvider) 
     : base(attributeProvider, contextProvider)
 {
 }