Example #1
0
        public static void PatchWebConfig(WebHostArgs args)
        {
            var webConfigFilePath = DetermineWebConfigPath(args.Assembly);
            if (!File.Exists(webConfigFilePath))
            {
                throw new ArgumentException("No web.config could be located for the site");
            }

            ConfigurationManipulation.RemoveAzureTraceListenerFromConfiguration(webConfigFilePath);
        }
Example #2
0
        public static void GenerateIisExpressConfigurationFile(WebHostArgs webHostArgs, string configurationFilePath)
        {
            var template = ObtainIisExpressConfigurationTemplate(webHostArgs);

            template = template.Replace("__SITEPATH__", webHostArgs.SiteDirectory);
            template = template.Replace("__PROTOCOL__", webHostArgs.UseSsl ? "https" : "http");
            template = template.Replace("__PORT__", webHostArgs.Port.ToString(CultureInfo.InvariantCulture));
            template = template.Replace("__HOSTNAME__", webHostArgs.Hostname);

            File.WriteAllText(configurationFilePath, template);
        }
Example #3
0
        private static string ObtainIisExpressConfigurationTemplate(WebHostArgs webHostArgs)
        {
            if (!string.IsNullOrWhiteSpace(webHostArgs.IisExpressTemplate))
            {
                return File.ReadAllText(webHostArgs.IisExpressTemplate);
            }

            var executingAssembly = Assembly.GetExecutingAssembly();
            var manifestResourceStream = executingAssembly.GetManifestResourceStream("LightBlue.MultiHost.IISExpress.Configuration.template");
            if (manifestResourceStream == null)
            {
                throw new InvalidOperationException("Unable to retrieve IIS Express configuration template.");
            }

            var template = new StreamReader(manifestResourceStream).ReadToEnd();
            return template;
        }
Example #4
0
        public static ProcessStartInfo BuildProcessStartInfo(WebHostArgs webHostArgs, string configurationFilePath)
        {
            string path = webHostArgs.Use64Bit
                ? Path.Combine(Environment.GetEnvironmentVariable("ProgramW6432"), @"IIS Express\iisexpress.exe")
                : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"IIS Express\iisexpress.exe");

            var processStartInfo = new ProcessStartInfo
            {
                FileName = path,
                Arguments = string.Format(
                    CultureInfo.InvariantCulture,
                    "/config:\"{0}\" /site:LightBlue",
                    configurationFilePath),
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                UseShellExecute = false,
                CreateNoWindow = true,
            };

            processStartInfo.EnvironmentVariables.Add("LightBlueHost", "true");
            processStartInfo.EnvironmentVariables.Add("LightBlueConfigurationPath", webHostArgs.ConfigurationPath);
            processStartInfo.EnvironmentVariables.Add("LightBlueServiceDefinitionPath", webHostArgs.ServiceDefinitionPath);
            processStartInfo.EnvironmentVariables.Add("LightBlueRoleName", webHostArgs.RoleName);
            processStartInfo.EnvironmentVariables.Add("LightBlueUseHostedStorage", webHostArgs.UseHostedStorage.ToString());

            var processId = webHostArgs.RoleName
                            + "-web-"
                            + Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture);

            var temporaryDirectory = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                "LightBlue",
                "temp",
                processId);

            Directory.CreateDirectory(temporaryDirectory);
            processStartInfo.EnvironmentVariables["TMP"] = temporaryDirectory;
            processStartInfo.EnvironmentVariables["TEMP"] = temporaryDirectory;

            return processStartInfo;
        }
Example #5
0
 public static WebHostArgs Create(RoleConfiguration config)
 {
     var configurationPath = config.ConfigurationPath;
     var configurationFilePath = ConfigurationLocator.LocateConfigurationFile(configurationPath);
     var serviceDefinitionPath = ConfigurationLocator.LocateServiceDefinition(configurationPath);
     var assembly = config.Assembly;
     var args = new WebHostArgs
     {
         Assembly = assembly,
         Port = int.Parse(config.Port),
         RoleName = config.RoleName,
         Title = config.Title,
         ConfigurationPath = configurationFilePath,
         ServiceDefinitionPath = serviceDefinitionPath,
         UseSsl = bool.Parse(config.UseSsl),
         Hostname = config.Hostname,
         UseHostedStorage = false,
         Use64Bit = false,
     };
     return args;
 }
Example #6
0
 public IisExpressRunner(Role role)
 {
     _role = role;
     _args = WebConfigHelper.Create(role.Config);
     WebConfigHelper.PatchWebConfig(_args);
 }
Example #7
0
 public IisExpressRunner(Role role)
 {
     _role = role;
     _args = WebConfigHelper.Create(role.Config);
     WebConfigHelper.PatchWebConfig(_args);
 }