예제 #1
0
        /// <summary>
        /// Configuration
        /// </summary>
        /// <param name="app"></param>
        public void Configuration(IAppBuilder app)
        {
            // Web API Configuration
            GlobalConfiguration.Configure(WebApiConfig.Register);

            HttpConfiguration config = new HttpConfiguration();

            // Newtonsoft.JSON kütüphanesinde nested nesnelerin birbirlerine dönüşümünde yaşanan StackOverFlow exception için eklenmiştir.
            config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

            // Custom Filters
            // config.Filters.Add(new SessionAuthorizeAttribute());
            config.Filters.Add(new WebApiActionLoggerAttribute());

            // Message Handlers (For Logging)
            config.MessageHandlers.Add(new ApiLogHandler(GetType().Namespace));

            // Controller and Actions persisting
            ControllerPersister persister = new ControllerPersister();

            persister.PersistControllerActions(typeof(Controllers.ClientsController));

            ConfigureOAuth(app);

            // Register OWIN Middleware
            app.Use <GlobalExceptionMiddleware>();
            //Register other middlewares
            config.Services.Replace(typeof(IExceptionHandler), new GlobalExceptionHandler(GetType().Namespace));

            // Constructor Injection Installer
            config.Services.Replace(typeof(System.Web.Http.Dispatcher.IHttpControllerActivator), WebApiInstaller.Installer());

            // WebApiConfig.Register(config);
            app.UseCors(CorsOptions.AllowAll);
            app.UseWebApi(config);
        }
예제 #2
0
        /// <summary>
        /// Configuration
        /// </summary>
        /// <param name="app"></param>
        public void Configuration(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

            //Newtonsoft.JSON kütüphanesinde nested nesnelerin birbirlerine dönüşümünde yaşanan StackOverFlow exception için eklenmiştir.
            config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

            ConfigureOAuth(app);

            //Dependency Injection Installer
            config.Services.Replace(typeof(System.Web.Http.Dispatcher.IHttpControllerActivator), WebApiInstaller.Installer());

            //WebApiConfig.Register(config);
            app.UseCors(CorsOptions.AllowAll);

            // Attribute routing
            config.MapHttpAttributeRoutes();

            Assembly asm = Assembly.GetAssembly(typeof(Controllers.EmpEmployeePkController));

            app.UseWebApi(config);

            var controllerActionsService = WebApiInstaller.Resolve <IControllerActionsService>();

            var controlleractionlist = asm.GetTypes()
                                       .Where(type => typeof(ApiController).IsAssignableFrom(type))
                                       .SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public))
                                       .Select(x => new
            {
                Controller       = x.DeclaringType.Name,
                Action           = x.Name,
                CustomAttributes = x.GetCustomAttributes(false)
                                   // Description = x.GetCustomAttributes(typeof(DescriptionAttribute), false).Cast<DescriptionAttribute>().FirstOrDefault() != null ? x.GetCustomAttributes(typeof(DescriptionAttribute), false).Cast<DescriptionAttribute>().FirstOrDefault().Description : string.Empty
            });

            foreach (var controller in controlleractionlist)
            {
                string description = controller.CustomAttributes.OfType <DescriptionAttribute>().FirstOrDefault() != null?controller.CustomAttributes.OfType <DescriptionAttribute>().FirstOrDefault().Description : string.Empty;

                OperationType type;

                if (controller.CustomAttributes.OfType <HttpGetAttribute>().FirstOrDefault() != null)
                {
                    type = OperationType.Read;
                }
                else if (controller.CustomAttributes.OfType <HttpPostAttribute>().FirstOrDefault() != null)
                {
                    type = OperationType.Create;
                }
                else if (controller.CustomAttributes.OfType <HttpPutAttribute>().FirstOrDefault() != null)
                {
                    type = OperationType.Update;
                }
                else if (controller.CustomAttributes.OfType <HttpDeleteAttribute>().FirstOrDefault() != null)
                {
                    type = OperationType.Delete;
                }
                else
                {
                    type = OperationType.Operation;
                }

                Business.Model.Auth.ControllerActionsModel model = new Business.Model.Auth.ControllerActionsModel()
                {
                    Controller    = controller.Controller,
                    Action        = controller.Action,
                    Description   = description, // controller.Description,
                    InsertedBy    = 1,
                    InsertedDate  = System.DateTime.Now,
                    UpdatedBy     = 1,
                    UpdatedDate   = System.DateTime.Now,
                    OperationType = type
                };

                //controllerActionsService.SaveOrUpdateAsync(model);
            }
        }