private static string GetProfileText(EnvironmentGateway env)
     {
         if (env.EnvironmentName == "Development")
         {
             return($@"
 ""{env.ProfileName}"": {{
   ""commandName"": ""Project"",
   ""launchBrowser"": true,
   ""launchUrl"": ""swagger"",
   ""environmentVariables"": {{
     ""ASPNETCORE_ENVIRONMENT"": ""{env.EnvironmentName}""
   }},
   ""applicationUrl"": ""{env.GatewayUrl}""
 }},");
         }
         else if (env.EnvironmentName == "Startup")
         {
             return($@"
 ""{env.ProfileName}"": {{
   ""commandName"": ""Project"",
   ""launchBrowser"": false
 }},");
         }
         else
         {
             return($@"
 ""{env.ProfileName}"": {{
   ""commandName"": ""Project"",
   ""launchBrowser"": false,
   ""environmentVariables"": {{
     ""ASPNETCORE_ENVIRONMENT"": ""{env.EnvironmentName}""
   }}
 }},");
         }
     }
Beispiel #2
0
        private static string GetAppSettingsText(EnvironmentGateway env, List <Microservice> microservices)
        {
            var serilogSettings = GetSerilogSettings(env.EnvironmentName);
            var gatewayRoute    = "";

            env.GatewayResources.ForEach(template => gatewayRoute += GetGatewayRoutes(template, microservices));

            if (env.EnvironmentName == "Development")
            {
                return(@$ "{{
  " "AllowedHosts" ": " "*" ",
  " "GlobalConfiguration" ": {{
    " "BaseUrl" ": " "https://localhost:5050" "
  }},
Beispiel #3
0
        public void ForEnvironment([SelectionValues("environments")] string name)
        {
            var className = "{0}.{1}, {0}".ToFormat(typeof(EnvironmentThatBlowsUpInStartUp).Assembly.GetName().Name,
                                                    name);

            var applicationBase = Path.GetFullPath(@"src/FubuTestApplication/bin");

            Debug.WriteLine("Setting the Application Base to " + applicationBase);

            var run = new EnvironmentRun {
                ApplicationBase      = applicationBase,
                EnvironmentClassName = className
            };

            var domain = new EnvironmentGateway(run);

            _installLogs     = domain.Install();
            _environmentLogs = domain.CheckEnvironment();
            _allLogs         = domain.InstallAndCheckEnvironment();
        }
        public static void AddProfile(string solutionDirectory, EnvironmentGateway env, string gatewayProjectName)
        {
            var classPath = ClassPathHelper.GatewayLaunchSettingsClassPath(solutionDirectory, $"launchSettings.json", gatewayProjectName);

            if (!Directory.Exists(classPath.ClassDirectory))
            {
                Directory.CreateDirectory(classPath.ClassDirectory);
            }

            if (!File.Exists(classPath.FullClassPath))
            {
                throw new FileNotFoundException($"The `{classPath.FullClassPath}` file could not be found.");
            }

            var tempPath = $"{classPath.FullClassPath}temp";

            using (var input = File.OpenText(classPath.FullClassPath))
            {
                using (var output = new StreamWriter(tempPath))
                {
                    string line;
                    while (null != (line = input.ReadLine()))
                    {
                        var newText = $"{line}";
                        if (line.Contains(@$ "" "profiles" ""))
                        {
                            newText += GetProfileText(env);
                        }

                        output.WriteLine(newText);
                    }
                }
            }

            // delete the old file and set the name of the new one to the original name
            File.Delete(classPath.FullClassPath);
            File.Move(tempPath, classPath.FullClassPath);

            GlobalSingleton.AddUpdatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
        }
Beispiel #5
0
        /// <summary>
        /// this build will create environment based app settings files.
        /// </summary>
        public static void CreateAppSettings(string solutionDirectory, EnvironmentGateway env, string gatewayProjectName, List <Microservice> microservices)
        {
            try
            {
                var appSettingFilename = Utilities.GetAppSettingsName(env.EnvironmentName);
                var classPath          = ClassPathHelper.GatewayAppSettingsClassPath(solutionDirectory, $"{appSettingFilename}", gatewayProjectName);

                if (!Directory.Exists(classPath.ClassDirectory))
                {
                    Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (File.Exists(classPath.FullClassPath))
                {
                    File.Delete(classPath.FullClassPath);
                }

                using (FileStream fs = File.Create(classPath.FullClassPath))
                {
                    var data = "";
                    data = GetAppSettingsText(env, microservices);
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }