예제 #1
0
        public bool TryAddController([NotNull] Type controller, [NotNull] ServicesDefinitions definitions)
        {
            var name = _serviceNameMapper.MapServiceName(controller);

            var methods = (from method in controller.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance)
                           where _actionChecker.IsAvailableAction(method)
                           select method).ToArray();

            if (methods.Length == 0)
            {
                return(false);
            }

            var context = new MethodContexts(definitions);

            definitions.Services.GetOrCreate(name, () =>
            {
                var service = new Service(name);

                foreach (var methodInfo in methods)
                {
                    var method = _serviceMethodMapper.GetMethod(methodInfo, context);

                    if (method != null)
                    {
                        service.Methods.Add(method);
                    }
                }

                return(service);
            });

            return(true);
        }
예제 #2
0
        public override void Execute()
        {
            var container = GetIoCContainer();

            var reader = container.Resolve <IApiControllerReader>();

            var services = new ServicesDefinitions();

            reader.Read(Assembly.LoadFrom(_params.AssemblyPath), services, _params.Options);

            if (String.IsNullOrEmpty(_params.OutputPath))
            {
                _params.OutputPath = Path.ChangeExtension(_params.AssemblyPath, "ts");
            }

            var source = container.Resolve <IFormatterTemplates>().Render(services);

            source = new TypeScriptSimpleFormatter().Format(source);

            var directory = Path.GetDirectoryName(_params.OutputPath);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            File.WriteAllText(_params.OutputPath, source, Encoding.UTF8);
        }
예제 #3
0
        public static string Clients(ServicesDefinitions definitions)
        {
            var writer = new System.IO.StringWriter();

            foreach (var serivce in definitions.Services)
            {
                FormatterTemplates.Current.Render(writer, serivce);
            }

            return(writer.ToString());
        }
예제 #4
0
        public void Read(Assembly assembly, ServicesDefinitions definitions, ApiControllerLoaderOptions options = null)
        {
            options = options ?? new ApiControllerLoaderOptions();

            var controllers = from type in assembly.GetTypes()
                              where _controllerChecker.IsAvailableContoller(type) &&
                              Glob.Glob.IsMatch(type.FullName, options.TypeFilter)
                              select type;

            foreach (var controller in controllers)
            {
                TryAddController(controller, definitions);
            }
        }
예제 #5
0
 public MethodContexts([NotNull] ServicesDefinitions services)
 {
     Services = services;
 }
예제 #6
0
 public static string ClientNames(ServicesDefinitions definitions)
 {
     return(String.Join(",\n", definitions.Services.Select(c => c.Name)));
 }