Пример #1
0
        public void GenerateDataContextInputs(bool isDryRun)
        {
            // Migrate to Version 1.3.2
            if (_configFile.Config.Project.Output.DataContext.Inputs == null)
            {
                var defaultConfig = _spocr.GetDefaultConfiguration();
                _configFile.Config.Project.Output.DataContext.Inputs = defaultConfig.Project.Output.DataContext.Inputs;
            }

            var schemas = _configFile.Config.Schema
                          .Where(i => i.Status == SchemaStatusEnum.Build && (i.StoredProcedures?.Any() ?? false))
                          .Select(i => Definition.ForSchema(i));

            foreach (var schema in schemas)
            {
                var storedProcedures = schema.StoredProcedures;

                if (!(storedProcedures.Any()))
                {
                    continue;
                }

                var dataContextInputPath = DirectoryUtils.GetWorkingDirectory(_configFile.Config.Project.Output.DataContext.Path, _configFile.Config.Project.Output.DataContext.Inputs.Path);
                var path = Path.Combine(dataContextInputPath, schema.Path);
                if (!Directory.Exists(path) && !isDryRun)
                {
                    Directory.CreateDirectory(path);
                }

                foreach (var storedProcedure in storedProcedures)
                {
                    if (!storedProcedure.HasInputs())
                    {
                        continue;
                    }
                    var fileName         = $"{storedProcedure.Name}.cs";
                    var fileNameWithPath = Path.Combine(path, fileName);
                    var sourceText       = GetInputTextForStoredProcedure(schema, storedProcedure);

                    _output.Write(fileNameWithPath, sourceText, isDryRun);
                }
            }
        }
Пример #2
0
        public ExecuteResultEnum Create(ICreateCommandOptions options)
        {
            RunAutoUpdate(options);

            if (_configFile.Exists())
            {
                _reportService.Error($"File already exists: {Configuration.ConfigurationFile}");
                _reportService.Output($"\tPlease run: {Configuration.Name} status");
                return(ExecuteResultEnum.Error);
            }

            if (!options.Silent && !options.Force)
            {
                var proceed = Prompt.GetYesNo("Create a new SpocR Config?", true);
                if (!proceed)
                {
                    return(ExecuteResultEnum.Aborted);
                }
            }

            var targetFramework = options.TargetFramework;

            if (!options.Silent)
            {
                targetFramework = Prompt.GetString("TargetFramework:", targetFramework);
            }

            var appNamespace = options.Namespace;

            if (!options.Silent)
            {
                appNamespace = Prompt.GetString("Your Namespace:", appNamespace);
            }

            // var configurationFileExists = _configuration.FileExists();
            // if(!configurationFileExists)
            // {
            //     var fileName = Extensions.ConfigurationExtensions.FileName;
            //     var proceedAppsettings = Prompt.GetYesNo("Create a new SpocR Config?", true);
            //     if (!proceedAppsettings) return ExecuteResultEnum.Aborted;
            // }

            // Prompt.OnSelection("Please choose an option", )
            // var optionKey = 1;
            // foreach(var identifier in _configuration.GetSection("ConnectionStrings").GetChildren()) {
            //     _reportService.Output($"{optionKey}");
            // }
            var connectionString = "";
            var roleKindString   = options.Role;

            if (!options.Silent)
            {
                roleKindString = Prompt.GetString("SpocR Role [Default, Lib, Extension]:", "Default");
            }
            var roleKind = default(ERoleKind);

            Enum.TryParse(roleKindString, true, out roleKind);

            var libNamespace = options.LibNamespace;

            if (!options.Silent)
            {
                libNamespace = roleKind == ERoleKind.Extension
                        ? Prompt.GetString("SpocR Lib Namespace:", "Nuts.DbContext")
                        : null;
            }

            // var identityKindString = options.Identity;
            // if (!options.Silent)
            // {
            //     identityKindString = Prompt.GetString("SpocR Identity [WithUserId, None]:", "WithUserId");
            // }

            // var identityKind = default(EIdentityKind);
            // Enum.TryParse(identityKindString, true, out identityKind);

            var config = _spocr.GetDefaultConfiguration(targetFramework, appNamespace, connectionString, roleKind, libNamespace /*, identityKind*/);

            if (options.DryRun)
            {
                _reportService.PrintConfiguration(config);
                _reportService.PrintDryRunMessage();
            }
            else
            {
                _configFile.Save(config);
                _projectManager.Create(options);

                if (!options.Silent)
                {
                    _reportService.Output($"{Configuration.Name} successfully created.");
                }
            }

            return(ExecuteResultEnum.Succeeded);
        }
Пример #3
0
        public static IServiceCollection AddSpocR(this IServiceCollection services)
        {
#if DEBUG
            //var globalConfigurationFileName = Path.Combine(DirectoryUtils.GetAppDataDirectory(), Configuration.GlobalConfigurationFile);
            var globalConfigurationFileName = Path.Combine(DirectoryUtils.GetWorkingDirectory(), Configuration.GlobalConfigurationFile);
#else
            var globalConfigurationFileName = Path.Combine(DirectoryUtils.GetAppDataDirectory(), Configuration.GlobalConfigurationFile);
#endif

            var spocrService   = new SpocrService();
            var commandOptions = new CommandOptions(null);

            services.AddSingleton <SpocrService>(spocrService);
            services.AddSingleton <IPackageManager, NugetService>();
            services.AddSingleton <AutoUpdaterService>();
            services.AddSingleton <OutputService>();
            services.AddSingleton <SchemaManager>();
            services.AddSingleton <SpocrManager>();
            services.AddSingleton <SpocrProjectManager>();
            services.AddSingleton <SpocrSchemaManager>();
            services.AddSingleton <SpocrStoredProcdureManager>();
            services.AddSingleton <SpocrConfigManager>();
            services.AddSingleton <FileManager <GlobalConfigurationModel> >(new FileManager <GlobalConfigurationModel>(spocrService, globalConfigurationFileName, spocrService.GetGlobalDefaultConfiguration()));
            services.AddSingleton <FileManager <ConfigurationModel> >(new FileManager <ConfigurationModel>(spocrService, Configuration.ConfigurationFile, spocrService.GetDefaultConfiguration()));
            services.AddSingleton <Generator>();
            services.AddSingleton <IReportService>(new ReportService(new ColoredConsoleReporter(PhysicalConsole.Singleton, true, false), commandOptions));

            return(services);
        }