Example #1
0
        public DirectMethod GetMethod(string actionName, string methodName)
        {
            DirectMethod method = null;
            DirectAction action = GetAction(actionName);

            if (action != null)
            {
                method = action.GetMethod(methodName);
            }
            return(method);
        }
Example #2
0
        private void ExecuteRequest(RequestContext requestContext, DirectRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request", DirectResources.Common_DirectRequestIsNull);
            }

            HttpContextBase httpContext = requestContext.HttpContext;
            RouteData       routeData   = requestContext.RouteData;

            routeData.Values["controller"] = request.Action;
            routeData.Values["action"]     = request.Method;
            httpContext.Items[DirectRequest.DirectRequestKey] = request;
            var controller = (Controller)_factory.CreateController(requestContext, request.Action);

            DirectAction action = GetAction(request.Action);

            if (action == null)
            {
                throw new NullReferenceException(String.Format(DirectResources.DirectProvider_ActionNotFound, request.Action));
            }

            DirectMethod method = action.GetMethod(request.Method);

            if (method == null)
            {
                throw new NullReferenceException(String.Format(DirectResources.DirectProvider_MethodNotFound, request.Method, action.Name));
            }

            if (!method.IsFormHandler && method.Params == null)
            {
                if (request.Data == null && method.Len > 0 || request.Data != null && request.Data.Length != method.Len)
                {
                    throw new ArgumentException(String.Format(DirectResources.DirectProvider_WrongNumberOfArguments, request.Method, request.Action));
                }
            }

            try {
                controller.ActionInvoker = new DirectMethodInvoker();
                (controller as IController).Execute(requestContext);
            } catch (DirectException exception) {
                var errorResponse = new DirectErrorResponse(request, exception);
                errorResponse.Write(httpContext.Response);
            } finally {
                _factory.ReleaseController(controller);
            }

            httpContext.Items.Remove(DirectRequest.DirectRequestKey);
        }
Example #3
0
        private void ConfigureAssembly(Assembly assembly)
        {
            var types = assembly.GetLoadableTypes().Where(type =>
                                                          type.IsPublic &&
                                                          type.IsSubclassOf(typeof(DirectController)) &&
                                                          !type.HasAttribute <DirectIgnoreAttribute>()
                                                          );

            foreach (Type type in types)
            {
                var action = new DirectAction(type);
                if (_actions.ContainsKey(action.Name))
                {
                    throw new Exception(String.Format(DirectResources.DirectProvider_ActionExists, action.Name));
                }
                _actions.Add(action.Name, action);
            }
        }
 private void Configure() {
     if (_actions == null) {
         _actions = new Dictionary<string, DirectAction>();
         var assemblies = BuildManager.GetReferencedAssemblies();
         foreach (Assembly assembly in assemblies) {
             var types = assembly.GetTypes().Where(type =>
                 type.IsPublic &&
                 type.IsSubclassOf(typeof(DirectController)) &&
                 !type.HasAttribute<DirectIgnoreAttribute>()
             );
             foreach (Type type in types) {
                 var action = new DirectAction(type);
                 if (_actions.ContainsKey(action.Name)) {
                     throw new Exception(String.Format(DirectResources.DirectProvider_ActionExists, action.Name));
                 }
                 _actions.Add(action.Name, action);
             }
         }
     }
 }
Example #5
0
 public void Configure()
 {
     if (!this.Configured) {
         string[] assemblyNames = DirectConfig.Assembly.Split(',');
         for (int i = 0; i < assemblyNames.Length; i++) {
             string assemblyName = assemblyNames[i].Trim();
             Assembly assembly = Assembly.Load(assemblyName);
             var types = assembly.GetTypes();
             foreach (var type in types) {
                 if (type.IsDirectAction()) {
                     var action = new DirectAction(type);
                     if (_actions.ContainsKey(action.Name)) {
                         throw new Exception(String.Format(DirectResources.DirectProvider_ActionExists, action.Name));
                     }
                     _actions.Add(action.Name, action);
                 }
             }
         }
         this.Configured = true;
     }
 }
        private void ConfigureAssembly(Assembly assembly) {
            var types = assembly.GetLoadableTypes().Where(type =>
                type.IsPublic &&
                type.IsSubclassOf(typeof(DirectController)) &&
                !type.HasAttribute<DirectIgnoreAttribute>()
            );

            foreach (Type type in types) {
                var action = new DirectAction(type);
                if (_actions.ContainsKey(action.Name)) {
                    throw new Exception(String.Format(DirectResources.DirectProvider_ActionExists, action.Name));
                }
                _actions.Add(action.Name, action);
            }
        }