Esempio n. 1
0
        private string ValidateAndGetOutputPath(MvcModel model, string outputFileName)
        {
            var outputFolder = applicationInfo.ApplicationBasePath;
            var outputPath   = Path.Combine(outputFolder, outputFileName);

            if (File.Exists(outputPath) && !model.Force)
            {
                //Todo Need improvement this message
                throw new InvalidOperationException("Existing files");
            }
            return(outputPath);
        }
Esempio n. 2
0
        public async Task GenerateAsync(MvcModel model)
        {
            logger.LogMessage("creating controller");
            model.ControllerName = string.Concat(model.ModelClass, Constants.ControllerSuffix);

            logger.LogMessage("creating model controller");

            var templateModel = new ClassNameModel(className: model.ControllerName, namespaceName: NameSpaceUtilities.GetSafeNameSpaceFromPath(applicationInfo.ApplicationBasePath));

            logger.LogMessage("creating files");
            var outputPath = ValidateAndGetOutputPath(model, string.Concat(model.ControllerName, Constants.CodeFileExtension));
            await codeGeneratorActionsService.AddFileFromTemplateAsync(outputPath, Constants.EmptyControllerTemplate, TemplateFolders, templateModel);
        }
        public async Task GenerateCode(MvcModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (string.IsNullOrEmpty(model.ModelClass))
            {
                throw new ArgumentNullException(nameof(model.ModelClass));
            }

            var generator = ActivatorUtilities.CreateInstance <MvcController>(_serviceProvider);
            await generator.GenerateAsync(model);
        }