Ejemplo n.º 1
0
        public static IHasResponseFilter[] GetResponseFilterAttributes(Type responseDtoType)
        {
            IHasResponseFilter[] attrs;
            if (responseFilterAttributes.TryGetValue(responseDtoType, out attrs)) return attrs.ShallowCopy();

			var attributes = responseDtoType.AllAttributes<IHasResponseFilter>().ToList();

        	var serviceType = HostContext.Metadata.GetServiceTypeByResponse(responseDtoType);
			if (serviceType != null)
			{
				attributes.AddRange(serviceType.AllAttributes<IHasResponseFilter>());
			}

			attributes.Sort((x, y) => x.Priority - y.Priority);
			attrs = attributes.ToArray();

            Dictionary<Type, IHasResponseFilter[]> snapshot, newCache;
            do
            {
                snapshot = responseFilterAttributes;
                newCache = new Dictionary<Type, IHasResponseFilter[]>(responseFilterAttributes);
				newCache[responseDtoType] = attrs;

            } while (!ReferenceEquals(
            Interlocked.CompareExchange(ref responseFilterAttributes, newCache, snapshot), snapshot));

            return attrs.ShallowCopy();
        }
Ejemplo n.º 2
0
 private static List<ErrorResponseStatus> GetMethodResponseCodes(Type requestType)
 {
     return requestType
         .AllAttributes<IApiResponseDescription>()
         .Select(x => new ErrorResponseStatus {
             StatusCode = x.StatusCode,
             Reason = x.Description
         })
         .OrderBy(x => x.StatusCode)
         .ToList();
 }
Ejemplo n.º 3
0
        private static List<RestRoute> GetRoutesForType(Type requestType)
        {
            var restRoutes = requestType.AllAttributes<RouteAttribute>()
                .Select(attr => new RestRoute(requestType, attr.Path, attr.Verbs, attr.Priority))
                .ToList();

            return restRoutes;
        }
 public List<MetadataAttribute> ToAttributes(Type type)
 {
     return !(type.IsUserType() || type.IsUserEnum() || type.IsInterface()) 
             || type.IsOrHasGenericInterfaceTypeOf(typeof(IEnumerable<>))
         ? null
         : ToAttributes(type.AllAttributes());
 }
Ejemplo n.º 5
0
        private void AddToRequestExecMap(Type requestType, Type serviceType, ServiceExecFn handlerFn)
        {
            if (requestExecMap.ContainsKey(requestType))
            {
                throw new AmbiguousMatchException(
                    string.Format(
                    "Could not register Request '{0}' with service '{1}' as it has already been assigned to another service.\n"
                    + "Each Request DTO can only be handled by 1 service.",
                    requestType.FullName, serviceType.FullName));
            }

            requestExecMap.Add(requestType, handlerFn);

            var requestAttrs = requestType.AllAttributes<RestrictAttribute>();
            if (requestAttrs.Length > 0)
            {
                requestServiceAttrs[requestType] = requestAttrs[0];
            }
            else
            {
                var serviceAttrs = serviceType.AllAttributes<RestrictAttribute>();
                if (serviceAttrs.Length > 0)
                {
                    requestServiceAttrs[requestType] = serviceAttrs[0];
                }
            }
        }
 public virtual bool ExportSoapType(Type type)
 {
     return !type.IsGenericTypeDefinition() && 
            !type.AllAttributes<ExcludeAttribute>()
                 .Any(attr => attr.Feature.HasFlag(Feature.Soap));
 }
Ejemplo n.º 7
0
        public void RegisterRestPaths(Type requestType)
        {
            var attrs = requestType.AllAttributes<RouteAttribute>();
            foreach (RouteAttribute attr in attrs)
            {
                var restPath = new RestPath(requestType, attr.Path, attr.Verbs, attr.Summary, attr.Notes);

                var defaultAttr = attr as FallbackRouteAttribute;
                if (defaultAttr != null)
                {
                    if (appHost.Config.FallbackRestPath != null)
                        throw new NotSupportedException(string.Format(
                            "Config.FallbackRestPath is already defined. Only 1 [FallbackRoute] is allowed."));

                    appHost.Config.FallbackRestPath = (httpMethod, pathInfo, filePath) =>
                    {
                        var pathInfoParts = RestPath.GetPathPartsForMatching(pathInfo);
                        return restPath.IsMatch(httpMethod, pathInfoParts) ? restPath : null;
                    };

                    continue;
                }

                if (!restPath.IsValid)
                    throw new NotSupportedException(string.Format(
                        "RestPath '{0}' on Type '{1}' is not Valid", attr.Path, requestType.GetOperationName()));

                RegisterRestPath(restPath);
            }
        }
Ejemplo n.º 8
0
        private static List<RestRoute> GetRoutesForType(Type requestType)
        {

#if NETFX_CORE
            var restRoutes = requestType.AttributesOfType<RouteAttribute>()
                .Select(attr => new RestRoute(requestType, attr.Path, attr.Verbs))
                .ToList();
#elif WINDOWS_PHONE || SILVERLIGHT
            var restRoutes = requestType.AttributesOfType<RouteAttribute>()
                .Select(attr => new RestRoute(requestType, attr.Path, attr.Verbs))
                .ToList();
#else
            var restRoutes = requestType.AllAttributes<RouteAttribute>()
                .Select(attr => new RestRoute(requestType, attr.Path, attr.Verbs))
                .ToList();
#endif

            return restRoutes;
        }