Ejemplo n.º 1
0
        public override bool Execute()
        {
            InitializeServices();

            var apiControllers = TypeService.GetControllers(Config.WebApiModuleFileName);

            var endpointBlock = EndpointsService.CreateEndpointBlock();
            var serviceBlock  = AngularEndpointsService.CreateServiceBlock();

            StartAnalysis("controllers and actions");

            foreach (var apiController in apiControllers)
            {
                var webApiController = new WebApiController(apiController);

                EndpointsService.WriteEndpointClassToBlock(endpointBlock, webApiController);
                AngularEndpointsService.WriteServiceObjectToBlock(serviceBlock.Children.First() as TypeScriptBlock, webApiController);
            }

            StopAnalysis();

            CreateFileForBlock(endpointBlock, Config.EndpointsOutputDirectory, Config.EndpointsFileName);
            CreateFileForBlock(serviceBlock, Config.ServiceOutputDirectory, Config.ServiceFileName);

            var enumsBlock      = EnumsService.CreateEnumsBlock();
            var interfacesBlock = InterfaceService.CreateInterfacesBlock();

            if (Config.GenerateInterfaces)
            {
                StartAnalysis("interfaces");

                InterfaceService.AddMatchingInterfaces();
                InterfaceService.WriteInterfacesToBlock(interfacesBlock);

                StopAnalysis();

                CreateFileForBlock(interfacesBlock, Config.InterfacesOutputDirectory, Config.InterfacesFileName);
            }

            if (Config.GenerateEnums)
            {
                StartAnalysis("enumerations");

                EnumsService.WriteEnumsToBlock(enumsBlock);

                StopAnalysis();

                CreateFileForBlock(enumsBlock, Config.EnumsOutputDirectory, Config.EnumsFileName);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public override bool Execute()
        {
            InitializeServices();

            var apiControllers = Config.WebApiModuleFileNames
                                 .SelectMany(f => TypeService.GetControllers(f))
                                 .ToArray();

            if (Config.GenerateViews)
            {
                StartAnalysis("views");

                foreach (var viewsBlock in ViewsService.GetBlocksForViews())
                {
                    CreateFileForBlock(viewsBlock.TypeScriptBlock, Config.ViewsOutputDirectory, viewsBlock.Filename);
                }

                StopAnalysis();
            }

            if (Config.GenerateResources)
            {
                StartAnalysis("resources");

                foreach (var resourceBlock in ResourceService.GetBlocksForResources())
                {
                    CreateFileForBlock(resourceBlock.TypeScriptBlock, Config.ResourcesOutputDirectory, resourceBlock.Filename);
                }

                StopAnalysis();
            }

            if (Config.GenerateEndpoints || Config.GenerateService)
            {
                StartAnalysis("controllers and actions");

                var endpointBlock       = EndpointsService.CreateEndpointBlock();
                var mobileEndpointBlock = MobileEndpointsService.CreateEndpointBlock();
                var serviceBlock        = AngularEndpointsService.CreateServiceBlock();

                foreach (var apiController in apiControllers)
                {
                    var webApiController = new WebApiController(apiController);

                    if (Config.GenerateEndpoints || Config.GenerateService)
                    {
                        EndpointsService.WriteEndpointClassToBlock(endpointBlock, webApiController);
                    }

                    if (Config.GenerateMobileEndpoints && webApiController.Actions.Any(a => a.IsMobileAction))
                    {
                        MobileEndpointsService.WriteEndpointClassToBlock(mobileEndpointBlock, webApiController);
                    }

                    if (Config.GenerateService)
                    {
                        var classBlock = serviceBlock.Children
                                         .OfType <TypeScriptBlock>()
                                         .First();

                        AngularEndpointsService.WriteServiceObjectToBlock(classBlock, webApiController);
                    }
                }

                if (Config.GenerateEndpoints || Config.GenerateService)
                {
                    CreateFileForBlock(endpointBlock, Config.EndpointsOutputDirectory, Config.EndpointsFileName);
                }

                if (Config.GenerateMobileEndpoints)
                {
                    CreateFileForBlock(mobileEndpointBlock, Config.MobileEndpointsOutputDirectory, Config.MobileEndpointsFileName);
                }

                if (Config.GenerateService)
                {
                    CreateFileForBlock(serviceBlock, Config.ServiceOutputDirectory, Config.ServiceFileName);
                }

                StopAnalysis();
            }

            if (Config.GenerateInterfaces)
            {
                StartAnalysis("interfaces");

                var interfacesBlock = InterfaceService.CreateInterfacesBlock();
                InterfaceService.AddMatchingInterfaces();
                InterfaceService.WriteInterfacesToBlock(interfacesBlock);

                StopAnalysis();

                CreateFileForBlock(interfacesBlock, Config.InterfacesOutputDirectory, Config.InterfacesFileName);
            }

            if (Config.GenerateEnums)
            {
                StartAnalysis("enumerations");

                var enumsBlock = EnumsService.CreateEnumsBlock();
                EnumsService.AddMatchingEnums();
                EnumsService.WriteEnumsToBlock(enumsBlock);

                StopAnalysis();

                CreateFileForBlock(enumsBlock, Config.EnumsOutputDirectory, Config.EnumsFileName);
            }

            WriteServiceLogMessages();

            return(true);
        }