Exemplo n.º 1
0
        public override async Task <(string outputLocation, Dictionary <string, string> outputValues, string errorMessage)> Generate()
        {
            AdditionalConfigs.TryGetValue("AdminEmail", out var adminEmail);

            Config.OutputLocation = Config.OutputLocation ?? Config.WorkingLocation;

            var generator = new CodeGenerator(ProjectName, Config.OutputLocation, Models, adminEmail, Logger);

            await generator.InitSolution();

            await generator.InitProjects();

            await generator.GenerateModels();

            await generator.GenerateDbContext();

            await generator.GenerateRepositories();

            await generator.GenerateServices();

            await generator.GenerateControllers();

            await generator.GenerateViews();

            await generator.UpdateMigrationScript();

            await generator.GenerateRepositoryFiles();

            return(Config.OutputLocation, null, "");
        }
Exemplo n.º 2
0
        public async override Task <(string successMessage, Dictionary <string, string> outputValues, string errorMessage)> GenericExecution()
        {
            string commandTool = null;

            if (AdditionalConfigs.ContainsKey("CommandTool") && !string.IsNullOrEmpty(AdditionalConfigs["CommandTool"]))
            {
                commandTool = AdditionalConfigs["CommandTool"];
            }

            // set default value for command tool
            if (string.IsNullOrEmpty(commandTool))
            {
                bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

                if (isWindows)
                {
                    commandTool = "cmd.exe";
                }
                else
                {
                    commandTool = "/bin/bash";
                }
            }

            var commands = new List <string>();

            if (AdditionalConfigs.ContainsKey("CommandText") && !string.IsNullOrEmpty(AdditionalConfigs["CommandText"]))
            {
                commands.Add(AdditionalConfigs["CommandText"]);
            }

            string commandScript = null;

            if (AdditionalConfigs.ContainsKey("CommandScriptPath") && !string.IsNullOrEmpty(AdditionalConfigs["CommandScriptPath"]))
            {
                commandScript = AdditionalConfigs["CommandScriptPath"];
                commands.AddRange(commandScript.SplitOnNewLine());
            }

            if (commands.Count == 0)
            {
                return(null, null, "Either Command text or Command script path should be provided.");
            }

            if (!Directory.Exists(Config.WorkingLocation))
            {
                Directory.CreateDirectory(Config.WorkingLocation);
            }

            var result = await CommandHelper.Execute(commandTool, commands.ToArray(), Config.WorkingLocation, Logger);

            string successMessage = null;

            if (string.IsNullOrEmpty(result.error))
            {
                successMessage = "The commands has been run successfully";
            }

            return(successMessage, null, result.error);
        }
Exemplo n.º 3
0
        public override async Task <(string databaseLocation, Dictionary <string, string> outputValues, string errorMessage)> DeployDatabase()
        {
            var normalizedProjectName = TextHelper.GetNormalizedName(ProjectName);
            var startupProjectName    = normalizedProjectName;

            if (AdditionalConfigs != null && AdditionalConfigs.ContainsKey("StartupProjectName") && !string.IsNullOrEmpty(AdditionalConfigs["StartupProjectName"]))
            {
                startupProjectName = AdditionalConfigs["StartupProjectName"];
            }
            startupProjectName = $"{startupProjectName}.dll";

            var migrationLocation = Config.MigrationLocation ?? Path.Combine(Config.WorkingLocation, "publish");

            var startupProjectPath = Path.Combine(migrationLocation, startupProjectName);

            if (!Path.IsPathRooted(startupProjectPath))
            {
                startupProjectPath = Path.Combine(Config.WorkingLocation, startupProjectPath);
            }

            var dataProjectName = $"{normalizedProjectName}.Data";

            if (AdditionalConfigs != null && AdditionalConfigs.ContainsKey("DatabaseProjectName") && !string.IsNullOrEmpty(AdditionalConfigs["DatabaseProjectName"]))
            {
                dataProjectName = AdditionalConfigs["DatabaseProjectName"];
            }
            dataProjectName = $"{dataProjectName}.dll";

            var dataProjectPath = Path.Combine(migrationLocation, dataProjectName);

            if (!Path.IsPathRooted(dataProjectPath))
            {
                dataProjectPath = Path.Combine(Config.WorkingLocation, dataProjectPath);
            }

            string connectionString = "";

            if (AdditionalConfigs != null && AdditionalConfigs.ContainsKey("ConnectionString") && !string.IsNullOrEmpty(AdditionalConfigs["ConnectionString"]))
            {
                connectionString = AdditionalConfigs["ConnectionString"];
            }

            if (_databaseCommand == null)
            {
                _databaseCommand = new DatabaseCommand(Logger, connectionString);
            }

            var error = await _databaseCommand.Update(dataProjectPath, startupProjectPath);

            if (!string.IsNullOrEmpty(error))
            {
                return("", null, error);
            }

            return(GetDatabaseLocation(connectionString), null, "");
        }
Exemplo n.º 4
0
        public override async Task <(string outputArtifact, Dictionary <string, string> outputValues, string errorMessage)> Build()
        {
            var csprojLocation = Path.Combine(Config.SourceLocation ?? Config.WorkingLocation, ProjectName, $"{ProjectName}.csproj");

            if (AdditionalConfigs != null && AdditionalConfigs.ContainsKey("CsprojLocation") && !string.IsNullOrEmpty(AdditionalConfigs["CsprojLocation"]))
            {
                csprojLocation = AdditionalConfigs["CsprojLocation"];
            }
            if (!Path.IsPathRooted(csprojLocation))
            {
                csprojLocation = Path.Combine(Config.WorkingLocation, csprojLocation);
            }

            var buildConfiguration = "Release";

            if (AdditionalConfigs != null && AdditionalConfigs.ContainsKey("Configuration") && !string.IsNullOrEmpty(AdditionalConfigs["Configuration"]))
            {
                buildConfiguration = AdditionalConfigs["Configuration"];
            }

            var buildOutputLocation = Path.Combine(Config.WorkingLocation, "publish");

            var artifactLocation = "artifact";

            if (!string.IsNullOrEmpty(Config.OutputArtifactLocation))
            {
                artifactLocation = Config.OutputArtifactLocation;
            }
            if (!Path.IsPathRooted(artifactLocation))
            {
                artifactLocation = Path.Combine(Config.WorkingLocation, artifactLocation);
            }

            if (_builder == null)
            {
                _builder = new Builder();
            }

            var error = await _builder.Build(csprojLocation, buildOutputLocation, buildConfiguration);

            if (!string.IsNullOrEmpty(error))
            {
                return("", null, error);
            }

            var destinationArtifact = Path.Combine(artifactLocation, $"{ProjectName}.zip");

            error = await _builder.CreateArtifact(buildOutputLocation, destinationArtifact);

            if (!string.IsNullOrEmpty(error))
            {
                return("", null, error);
            }

            return(destinationArtifact, null, "");
        }
        /// <summary>
        /// Add "additional" sql parser configuration
        /// </summary>
        /// <param name="dbConnectionKind">A kind of DB connection</param>
        /// <param name="dbParameterCreator">Delegate for create <see cref="IDbDataParameter"/> instance.</param>
        /// <param name="configName">A name of configuration</param>
        public static void AddAdditional(DbConnectionKind dbConnectionKind, Func <IDbDataParameter> dbParameterCreator,
                                         string configName)
        {
            ValidateParameter(dbConnectionKind, dbParameterCreator);
            if (string.IsNullOrEmpty(configName))
            {
                throw new InvalidSqlParserConfigException(ExceptionMessageId.EspD004);
            }

            if (!AdditionalConfigs.ContainsKey(configName))
            {
                AdditionalConfigs.Add(configName, CreateConfig(dbConnectionKind, dbParameterCreator));
            }
        }
Exemplo n.º 6
0
        public async override Task <(string deletedHostLocation, string errorMessage)> DeleteHostingResources()
        {
            if (_azure == null)
            {
                _azure = new AzureAutomation(GetAzureAppServiceConfig(AdditionalConfigs), _azureUtils, _deployUtils, Logger);
            }

            var subscriptionId = "";

            if (AdditionalConfigs.ContainsKey("SubscriptionId") && !string.IsNullOrEmpty(AdditionalConfigs["SubscriptionId"]))
            {
                subscriptionId = AdditionalConfigs["SubscriptionId"];
            }
            else
            {
                return(null, "Subscription Id is not provided");
            }

            var resourceGroupName = "";

            if (AdditionalConfigs.ContainsKey("ResourceGroupName") && !string.IsNullOrEmpty(AdditionalConfigs["ResourceGroupName"]))
            {
                resourceGroupName = AdditionalConfigs["ResourceGroupName"];
            }
            else
            {
                return(null, "Resource group name is not provided");
            }

            var appServiceName = ProjectName;

            if (AdditionalConfigs.ContainsKey("AppServiceName") && !string.IsNullOrEmpty(AdditionalConfigs["AppServiceName"]))
            {
                appServiceName = AdditionalConfigs["AppServiceName"];
            }

            var deploymentSlot = "";

            if (AdditionalConfigs.ContainsKey("DeploymentSlot") && !string.IsNullOrEmpty(AdditionalConfigs["DeploymentSlot"]))
            {
                deploymentSlot = AdditionalConfigs["DeploymentSlot"];
            }

            return(await _azure.DeleteWebsite(subscriptionId, resourceGroupName, appServiceName, deploymentSlot));
        }
        public override async Task <(string outputLocation, Dictionary <string, string> outputValues, string errorMessage)> Generate()
        {
            string projectTitle = ProjectName.Humanize(); // set the default title to project name

            if (AdditionalConfigs != null && AdditionalConfigs.ContainsKey("Title") && !string.IsNullOrEmpty(AdditionalConfigs["Title"]))
            {
                projectTitle = AdditionalConfigs["Title"];
            }

            Config.OutputLocation = Config.OutputLocation ?? Config.WorkingLocation;

            var error = await _codeGenerator.Generate(ProjectName, projectTitle, Config.OutputLocation, Models);

            if (!string.IsNullOrEmpty(error))
            {
                return("", null, error);
            }

            return(Config.OutputLocation, null, "");
        }
Exemplo n.º 8
0
        public override async Task <(string outputLocation, Dictionary <string, string> outputValues, string errorMessage)> Generate()
        {
            var installedSdk = await CommandHelper.RunDotnet("--list-sdks");

            if (string.IsNullOrWhiteSpace(installedSdk) || !installedSdk.Contains("2.2."))
            {
                return(null, null, $"Task Provider {TaskProviderName} require minimum dotnet sdk 2.2 to be installed");
            }

            AdditionalConfigs.TryGetValue("AdminEmail", out var adminEmail);

            Config.OutputLocation = Config.OutputLocation ?? Config.WorkingLocation;

            var generator = new CodeGenerator(ProjectName, Config.OutputLocation, Models, adminEmail, Logger);

            await generator.InitSolution();

            await generator.InitProjects();

            await generator.GenerateModels();

            await generator.GenerateDbContext();

            await generator.GenerateRepositories();

            await generator.GenerateServices();

            await generator.GenerateControllers();

            await generator.GenerateViews();

            await generator.UpdateMigrationScript();

            await generator.GenerateRepositoryFiles();

            return(Config.OutputLocation, null, "");
        }
Exemplo n.º 9
0
        public override async Task <(string hostLocation, Dictionary <string, string> outputValues, string errorMessage)> Deploy()
        {
            if (_azure == null)
            {
                _azure = new AzureAutomation(GetAzureAppServiceConfig(AdditionalConfigs), _azureUtils, _deployUtils, Logger);
            }

            var subscriptionId = "";

            if (AdditionalConfigs.ContainsKey("SubscriptionId") && !string.IsNullOrEmpty(AdditionalConfigs["SubscriptionId"]))
            {
                subscriptionId = AdditionalConfigs["SubscriptionId"];
            }

            var resourceGroupName = "";

            if (AdditionalConfigs.ContainsKey("ResourceGroupName") && !string.IsNullOrEmpty(AdditionalConfigs["ResourceGroupName"]))
            {
                resourceGroupName = AdditionalConfigs["ResourceGroupName"];
            }

            bool allowAutomaticRename = true;

            if (AdditionalConfigs.ContainsKey("AllowAutomaticRename"))
            {
                bool.TryParse(AdditionalConfigs["AllowAutomaticRename"], out allowAutomaticRename);
            }

            var appServiceName = ProjectName;

            if (AdditionalConfigs.ContainsKey("AppServiceName") && !string.IsNullOrEmpty(AdditionalConfigs["AppServiceName"]))
            {
                appServiceName = AdditionalConfigs["AppServiceName"];
            }
            else
            {
                // if the app service name is not defined, the allow rename should always be true
                allowAutomaticRename = true;
            }

            var deploymentSlot = "";

            if (AdditionalConfigs.ContainsKey("DeploymentSlot") && !string.IsNullOrEmpty(AdditionalConfigs["DeploymentSlot"]))
            {
                deploymentSlot = AdditionalConfigs["DeploymentSlot"];
            }

            var connectionString = "";

            if (AdditionalConfigs.ContainsKey("ConnectionString") && !string.IsNullOrEmpty(AdditionalConfigs["ConnectionString"]))
            {
                connectionString = AdditionalConfigs["ConnectionString"];
            }

            var region = "southcentralus";

            if (AdditionalConfigs.ContainsKey("Region") && !string.IsNullOrEmpty(AdditionalConfigs["Region"]))
            {
                region = AdditionalConfigs["Region"];
            }

            var appServicePlan = "";

            if (AdditionalConfigs.ContainsKey("AppServicePlan") && !string.IsNullOrEmpty(AdditionalConfigs["AppServicePlan"]))
            {
                appServicePlan = AdditionalConfigs["AppServicePlan"];
            }

            var artifactLocation = Config.ArtifactLocation ?? Path.Combine(Config.WorkingLocation, "artifact", $"{ProjectName}.zip");

            if (!Path.IsPathRooted(artifactLocation))
            {
                artifactLocation = Path.Combine(Config.WorkingLocation, artifactLocation);
            }

            var(hostLocation, error) = await _azure.DeployWebsite(artifactLocation, subscriptionId, resourceGroupName, appServiceName, deploymentSlot, connectionString, region, appServicePlan, allowAutomaticRename);

            if (!string.IsNullOrEmpty(error))
            {
                return("", null, error);
            }

            return(hostLocation, null, "");
        }
Exemplo n.º 10
0
        public override async Task <(string outputArtifact, Dictionary <string, string> outputValues, string errorMessage)> Build()
        {
            var(outputVersion, err) = await CommandHelper.Execute("dotnet", "--list-sdks");

            if (string.IsNullOrWhiteSpace(outputVersion) || !string.IsNullOrEmpty(err))
            {
                return(null, null, $"Task Provider {TaskProviderName} require dotnet sdk to be installed");
            }

            var normalizedProjectName = TextHelper.GetNormalizedName(ProjectName);

            var csprojLocation = Path.Combine(Config.SourceLocation ?? Config.WorkingLocation, normalizedProjectName, $"{normalizedProjectName}.csproj");

            if (AdditionalConfigs != null && AdditionalConfigs.ContainsKey("CsprojLocation") && !string.IsNullOrEmpty(AdditionalConfigs["CsprojLocation"]))
            {
                csprojLocation = AdditionalConfigs["CsprojLocation"];
            }
            if (!Path.IsPathRooted(csprojLocation))
            {
                csprojLocation = Path.Combine(Config.WorkingLocation, csprojLocation);
            }

            var buildConfiguration = "Release";

            if (AdditionalConfigs != null && AdditionalConfigs.ContainsKey("Configuration") && !string.IsNullOrEmpty(AdditionalConfigs["Configuration"]))
            {
                buildConfiguration = AdditionalConfigs["Configuration"];
            }

            var buildOutputLocation = Path.Combine(Config.WorkingLocation, "publish");

            var artifactLocation = "artifact";

            if (!string.IsNullOrEmpty(Config.OutputArtifactLocation))
            {
                artifactLocation = Config.OutputArtifactLocation;
            }
            if (!Path.IsPathRooted(artifactLocation))
            {
                artifactLocation = Path.Combine(Config.WorkingLocation, artifactLocation);
            }

            if (_builder == null)
            {
                _builder = new Builder(Logger);
            }

            var error = await _builder.Build(csprojLocation, buildOutputLocation, buildConfiguration);

            if (!string.IsNullOrEmpty(error))
            {
                return("", null, error);
            }

            var destinationArtifact = Path.Combine(artifactLocation, $"{ProjectName}.zip");

            error = await _builder.CreateArtifact(buildOutputLocation, destinationArtifact);

            if (!string.IsNullOrEmpty(error))
            {
                return("", null, error);
            }

            return(destinationArtifact, null, "");
        }