Esempio n. 1
0
		/// <summary>
		/// Sets service routes
		/// </summary>
		public HostBootstrapper Bootstrap(IServiceRoutes routes)
		{
			routes.Add<Api.Messages.Countries>("/countries/{language}", "GET, HEAD");
			routes.Add<Api.Messages.Countries>("/countries", "GET, HEAD");

			return this;
		}
Esempio n. 2
0
 public static void SetRoutes(IServiceRoutes Routes)
 {
     Routes
         .Add<Order>("/order", "GET")
         .Add<Order>("/order/{Id}", "GET")
         .Add<Order>("/order", "PUT");
 }
Esempio n. 3
0
        public static void WithMatchingAttributes(IServiceRoutes routes, Type requestType, string allowedVerbs)
        {
            var membersWithAttribute = (from p in requestType.GetPublicProperties()
                                        let attributes = p.AllAttributes<Attribute>()
                                        where attributes.Any(a => AttributeNamesToMatch.Contains(a.GetType().GetOperationName()))
                                        select "{{{0}}}".Fmt(p.Name)).ToList();

            if (membersWithAttribute.Count == 0) return;

            membersWithAttribute.Insert(0, "/{0}".Fmt(requestType.GetOperationName()));

            var restPath = membersWithAttribute.Join("/");
            routes.Add(requestType, restPath: restPath, verbs: allowedVerbs, priority: AutoGenPriority);
        }
Esempio n. 4
0
        public static void WithMatchingPropertyNames(IServiceRoutes routes, Type requestType, string allowedVerbs)
        {
            var membersWithName = (from property in requestType.GetPublicProperties().Select(p => p.Name)
                                   from name in PropertyNamesToMatch
                                   where property.Equals(name, StringComparison.InvariantCultureIgnoreCase)
                                   select "{{{0}}}".Fmt(property)).ToList();

            if (membersWithName.Count == 0) return;

            membersWithName.Insert(0, "/{0}".Fmt(requestType.GetOperationName()));

            var restPath = membersWithName.Join("/");
            routes.Add(requestType, restPath: restPath, verbs: allowedVerbs, priority: AutoGenPriority);
        }
Esempio n. 5
0
        public static void WithMatchingPropertyNames(IServiceRoutes routes, Type requestType, string allowedVerbs)
        {
            var membersWithName = (from property in requestType.GetPublicProperties().Select(p => p.Name)
                                   from name in PropertyNamesToMatch
                                   where property.Equals(name, StringComparison.InvariantCultureIgnoreCase)
                                   select $"{{{property}}}").ToList();

            if (membersWithName.Count == 0)
            {
                return;
            }

            membersWithName.Insert(0, "/{0}".Fmt(requestType.GetOperationName()));

            var restPath = membersWithName.Join("/");

            routes.Add(requestType, restPath: restPath, verbs: allowedVerbs, priority: AutoGenPriority);
        }
Esempio n. 6
0
        public static void WithMatchingAttributes(IServiceRoutes routes, Type requestType, string allowedVerbs)
        {
            var membersWithAttribute = (from p in requestType.GetPublicProperties()
                                        let attributes = p.AllAttributes <Attribute>()
                                                         where attributes.Any(a => AttributeNamesToMatch.Contains(a.GetType().GetOperationName()))
                                                         select $"{{{p.Name}}}").ToList();

            if (membersWithAttribute.Count == 0)
            {
                return;
            }

            membersWithAttribute.Insert(0, "/{0}".Fmt(requestType.GetOperationName()));

            var restPath = membersWithAttribute.Join("/");

            routes.Add(requestType, restPath: restPath, verbs: allowedVerbs, priority: AutoGenPriority);
        }
        public static void WithMatchingAttributes(IServiceRoutes routes, Type requestType, string allowedVerbs)
        {
            var membersWithAttribute = (from p in requestType.GetPublicProperties()
                                        let attributes = p.CustomAttributes(inherit: false).Cast <Attribute>()
                                                         where attributes.Any(a => AttributeNamesToMatch.Contains(a.GetType().Name))
                                                         select "{{{0}}}".Fmt(p.Name)).ToList();

            if (membersWithAttribute.Count == 0)
            {
                return;
            }

            membersWithAttribute.Insert(0, "/{0}".Fmt(requestType.Name));

            var restPath = membersWithAttribute.Join("/");

            routes.Add(requestType, restPath: restPath, verbs: allowedVerbs);
        }
 public static void Register(IServiceRoutes serviceRoutes)
 {
     serviceRoutes
         .Add<GetSupportedServicesRequest>(RestPaths.SupportedServices)
         .Add<GetRegistrationHtmlRequest>(RestPaths.RegistrationHtml)
         .Add<IsRegisteredForServiceRequest>(RestPaths.IsRegistered)
         .Add<GetServiceTokenForPrincipalIdRequest>(RestPaths.ServiceProviderToken)
         .Add<RegisterServiceTokenRequest>(RestPaths.ReceivedToken)
         .Add<RegisterServiceProviderRequest>(RestPaths.ReceivedServiceProvider)
         .Add<BrowseApplicationsRequest>(RestPaths.Applications)
         .Add<GetApplicationRequest>(RestPaths.Application, "GET")
         .Add<AddApplicationRequest>(RestPaths.Application, "PUT")
         .Add<DeleteApplicationRequest>(RestPaths.Application, "DELETE")
         .Add<BrowseApplicationServicesRequest>(RestPaths.ApplicationServices)
         .Add<AddApplicationServiceRequest>(RestPaths.ApplicationServices, "PUT")
         .Add<DeleteApplicationServiceRequest>(RestPaths.ApplicationServices, "DELETE")
         .Add<RegisterAccountRequest>(RestPaths.RegisterAccount, "POST")
         .Add<RegisterAccountUserRequest>(RestPaths.RegisterUser, "POST")
         .Add<BrowseAccountUsersRequest>(RestPaths.AccountUsers, "GET")
         .Add<GetUserRequest>(RestPaths.AccountUser, "GET");
 }
Esempio n. 9
0
 public static IServiceRoutes Add <T>(this IServiceRoutes serviceRoutes, string restPath, ApplyTo verbs, params Expression <Func <T, object> >[] propertyExpressions)
 {
     return(serviceRoutes.Add <T>(FormatRoute(restPath, propertyExpressions), verbs));
 }
Esempio n. 10
0
 public static IServiceRoutes Add <TRequest>(this IServiceRoutes routes, string restPath, ApplyTo verbs)
 {
     return(routes.Add <TRequest>(restPath, verbs.ToVerbsString()));
 }
        public static void InitDatabaseRoutes(this Funq.Container container, IServiceRoutes routes)
        {
            if (container.InitMongoDB())
            {
                routes.Add<MongoDBDbRequest>("/mongodb/db", "GET");
                routes.Add<MongoDBQueriesRequest>("/mongodb/queries/{queries}", "GET");
                routes.Add<MongoDBFortunesRequest>("/mongodb/fortunes", "GET");
                routes.Add<MongoDBUpdatesRequest>("/mongodb/updates/{queries}", "GET");
                routes.Add<MongoDBCachedDbRequest>("/mongodb/cached/db", "GET");
            }

            if (container.InitMySQL())
            {
                routes.Add<MySqlDbRequest>("/mysql/db", "GET");
                routes.Add<MySqlQueriesRequest>("/mysql/queries/{queries}", "GET");
                routes.Add<MySqlFortunesRequest>("/mysql/fortunes", "GET");
                routes.Add<MySqlUpdatesRequest>("/mysql/updates/{queries}", "GET");
                routes.Add<MySqlCachedDbRequest>("/mysql/cached/db", "GET");
            }

            if (container.InitPostgreSQL())
            {
                routes.Add<PostgreSqlDbRequest>("/postgresql/db", "GET");
                routes.Add<PostgreSqlQueriesRequest>("/postgresql/queries/{queries}", "GET");
                routes.Add<PostgreSqlFortunesRequest>("/postgresql/fortunes", "GET");
                routes.Add<PostgreSqlUpdatesRequest>("/postgresql/updates/{queries}", "GET");
                routes.Add<PostgreSqlCachedDbRequest>("/postgresql/cached/db", "GET");
            }

            if (container.InitSQLServer())
            {
                routes.Add<SqlServerDbRequest>("/sqlserver/db", "GET");
                routes.Add<SqlServerQueriesRequest>("/sqlserver/queries/{queries}", "GET");
                routes.Add<SqlServerFortunesRequest>("/sqlserver/fortunes", "GET");
                routes.Add<SqlServerUpdatesRequest>("/sqlserver/updates/{queries}", "GET");
                routes.Add<SqlServerCachedDbRequest>("/sqlserver/cached/db", "GET");
            }
        }
Esempio n. 12
0
 /// <summary>With request dto name.</summary>
 ///
 /// <param name="routes">      The routes.</param>
 /// <param name="requestType"> Type of the request.</param>
 /// <param name="allowedVerbs">The allowed verbs.</param>
 public static void WithRequestDtoName(IServiceRoutes routes, Type requestType, string allowedVerbs)
 {
     routes.Add(requestType, restPath: "/{0}".Fmt(requestType.Name), verbs: allowedVerbs);
 }
Esempio n. 13
0
 public static void WithRequestDtoName(IServiceRoutes routes, Type requestType, string allowedVerbs)
 {
     routes.Add(requestType, restPath: "/{0}".Fmt(requestType.GetOperationName()), verbs: allowedVerbs, priority: AutoGenPriority);
 }
Esempio n. 14
0
 public static void WithRequestDtoName(IServiceRoutes routes, Type requestType, string allowedVerbs)
 {
     routes.Add(requestType, restPath: "/{0}".Fmt(requestType.Name), verbs: allowedVerbs);
 }
 public static IServiceRoutes Add <TRequest>(this IServiceRoutes routes, string path, string verbs)
 {
     return(routes.Add(new RestPath(typeof(TRequest), path, verbs)));
 }
Esempio n. 16
0
        /// <summary>
        ///     Scans the supplied Assemblies to infer REST paths and HTTP verbs.
        /// </summary>
        ///<param name="routes">The <see cref="IServiceRoutes"/> instance.</param>
        ///<param name="assembliesWithServices">
        ///     The assemblies with REST services.
        /// </param>
        /// <returns>The same <see cref="IServiceRoutes"/> instance;
        ///		never <see langword="null"/>.</returns>
        public static IServiceRoutes AddFromAssembly(this IServiceRoutes routes,
                                                     params Assembly[] assembliesWithServices)
        {
            foreach (Assembly assembly in assembliesWithServices)
            {
                IEnumerable <Type> services =
                    from t in assembly.GetExportedTypes()
                    where
                    !t.IsAbstract &&
                    t.IsSubclassOfRawGeneric(typeof(ServiceBase <>))
                    select t;

                foreach (Type service in services)
                {
                    Type baseType = service.BaseType;
                    //go up the hierarchy to the first generic base type
                    while (!baseType.IsGenericType)
                    {
                        baseType = baseType.BaseType;
                    }

                    Type requestType = baseType.GetGenericArguments()[0];

                    string allowedVerbs = null; //null == All Routes

                    if (service.IsSubclassOfRawGeneric(typeof(RestServiceBase <>)))
                    {
                        //find overriden REST methods
                        var allowedMethods = new List <string>();
                        if (service.GetMethod("OnGet").DeclaringType == service)
                        {
                            allowedMethods.Add(HttpMethods.Get);
                        }

                        if (service.GetMethod("OnPost").DeclaringType == service)
                        {
                            allowedMethods.Add(HttpMethods.Post);
                        }

                        if (service.GetMethod("OnPut").DeclaringType == service)
                        {
                            allowedMethods.Add(HttpMethods.Put);
                        }

                        if (service.GetMethod("OnDelete").DeclaringType == service)
                        {
                            allowedMethods.Add(HttpMethods.Delete);
                        }

                        if (service.GetMethod("OnPatch").DeclaringType == service)
                        {
                            allowedMethods.Add(HttpMethods.Patch);
                        }

                        if (allowedMethods.Count == 0)
                        {
                            continue;
                        }
                        allowedVerbs = string.Join(" ", allowedMethods.ToArray());
                    }

                    routes.Add(requestType, requestType.Name, allowedVerbs);

                    var hasIdField = requestType.GetProperty(IdUtils.IdField) != null;
                    if (hasIdField)
                    {
                        var routePath = requestType.Name + "/{" + IdUtils.IdField + "}";
                        routes.Add(requestType, routePath, allowedVerbs);
                    }
                }
            }

            return(routes);
        }
Esempio n. 17
0
 public static IServiceRoutes Add(this IServiceRoutes routes, Type requestType, string restPath, ApplyTo verbs)
 {
     return(routes.Add(requestType, restPath, verbs.ToVerbsString()));
 }
 public static IServiceRoutes Add <TRequest>(this IServiceRoutes routes, string path, ApplyTo applyTo)
 {
     return(routes.Add(new RestPath(typeof(TRequest), path, applyTo.ToVerbsString())));
 }
 public static void Add <T>(this IServiceRoutes serviceRoutes, string httpMethod, string url, params Expression <Func <T, object> >[] propertyExpressions)
 {
     serviceRoutes.Add <T>(FormatRoute(url, propertyExpressions), httpMethod);
 }
Esempio n. 20
0
 public static IServiceRoutes Add <TRequest>(this IServiceRoutes routes, string restPath, ApplyTo verbs, string defaultContentType)
 {
     return(routes.Add <TRequest>(restPath, verbs.ToVerbsString(), defaultContentType));
 }
 public static IServiceRoutes Add(this IServiceRoutes routes, Type requestType, string path, ApplyTo applyTo)
 {
     return(routes.Add(new RestPath(requestType, path, applyTo.ToVerbsString())));
 }
        /// <summary>
        /// The configure routes.
        /// </summary>
        /// <param name="routes">
        /// The routes.
        /// </param>
        public virtual void ConfigureRoutes(IServiceRoutes routes)
        {
            routes.Add<NewsRequest>("/" + SiteIdToken + this.GetNewsServiceRestPath());
            routes.Add<NewsRequest>("/" + SiteIdToken + this.GetNewsByIdNewsServiceRestPath());
            routes.Add<NewsRequest>("/" + SiteIdToken + this.GetNewsByCategoryIdNewsServiceRestPath());

            routes.Add<NewsRequest>(this.GetNewsServiceRestPath());
            routes.Add<NewsRequest>(this.GetNewsByIdNewsServiceRestPath());
            routes.Add<NewsRequest>(this.GetNewsByCategoryIdNewsServiceRestPath());
        }
Esempio n. 23
0
 public static IServiceRoutes Add <T>(this IServiceRoutes routes, string restPath, string verbs, string summary, string notes)
 {
     return(routes.Add(typeof(T), restPath, verbs, summary, notes));
 }
Esempio n. 24
0
 public static void WithRequestDtoName(IServiceRoutes routes, Type requestType, string allowedVerbs)
 {
     routes.Add(requestType, restPath: "/{0}".Fmt(requestType.GetOperationName()), verbs: allowedVerbs, priority:AutoGenPriority);
 }
Esempio n. 25
0
        public static void InitDatabaseRoutes(this Funq.Container container, IServiceRoutes routes)
        {
            if (container.InitMySQL())
            {
                routes.Add <MySqlDbRequest>("/mysql/db", "GET");
                routes.Add <MySqlQueriesRequest>("/mysql/queries/{queries}", "GET");
                routes.Add <MySqlFortunesRequest>("/mysql/fortunes", "GET");
                routes.Add <MySqlUpdatesRequest>("/mysql/updates/{queries}", "GET");
                routes.Add <MySqlCachedDbRequest>("/mysql/cached/db", "GET");
            }

            if (container.InitPostgreSQL())
            {
                routes.Add <PostgreSqlDbRequest>("/postgresql/db", "GET");
                routes.Add <PostgreSqlQueriesRequest>("/postgresql/queries/{queries}", "GET");
                routes.Add <PostgreSqlFortunesRequest>("/postgresql/fortunes", "GET");
                routes.Add <PostgreSqlUpdatesRequest>("/postgresql/updates/{queries}", "GET");
                routes.Add <PostgreSqlCachedDbRequest>("/postgresql/cached/db", "GET");
            }

            if (container.InitSQLServer())
            {
                routes.Add <SqlServerDbRequest>("/sqlserver/db", "GET");
                routes.Add <SqlServerQueriesRequest>("/sqlserver/queries/{queries}", "GET");
                routes.Add <SqlServerFortunesRequest>("/sqlserver/fortunes", "GET");
                routes.Add <SqlServerUpdatesRequest>("/sqlserver/updates/{queries}", "GET");
                routes.Add <SqlServerCachedDbRequest>("/sqlserver/cached/db", "GET");
            }
        }