Пример #1
0
        public static IRunner CreateForWorkerRole(Role role, RoleIsolationMode isolation)
        {
            var config = role.Config;

            var assemblyFilePath = config.Assembly;
            var assemblyPath     = Path.GetDirectoryName(assemblyFilePath);

            if (HasBeenReBuilt(assemblyPath) && isolation == RoleIsolationMode.Thread)
            {
                isolation          = RoleIsolationMode.AppDomain;
                role.IsolationMode = isolation;
            }

            switch (isolation)
            {
            case RoleIsolationMode.Thread:
                return(new ThreadRunner(role, assemblyFilePath, ConfigurationLocator.LocateConfigurationFile(config.ConfigurationPath), role.RoleName));

            case RoleIsolationMode.AppDomain:
                var setup = new AppDomainSetup
                {
                    ApplicationBase   = assemblyPath,
                    ConfigurationFile = config.Assembly + ".config",
                };
                return(new AppDomainRunner(role, setup, assemblyFilePath, ConfigurationLocator.LocateConfigurationFile(config.ConfigurationPath), role.RoleName));

            default:
                throw new NotSupportedException();
            }
        }
Пример #2
0
        public static WebHostArgs Create(RoleConfiguration config)
        {
            var assembly = config.Assembly;
            var args     = new WebHostArgs
            {
                Assembly          = assembly,
                Port              = int.Parse(config.Port),
                RoleName          = config.RoleName,
                Title             = config.Title,
                ConfigurationPath = ConfigurationLocator.LocateConfigurationFile(config.ConfigurationPath),
                UseSsl            = bool.Parse(config.UseSsl),
                Hostname          = config.Hostname,
                UseHostedStorage  = false,
                Use64Bit          = false,
            };

            return(args);
        }
Пример #3
0
        public static HostArgs ParseArgs(IEnumerable <string> args)
        {
            string assembly          = null;
            string roleName          = null;
            string title             = null;
            string configurationPath = null;
            var    useHostedStorage  = false;
            var    allowSilentFail   = false;
            var    displayHelp       = false;

            var options = new OptionSet
            {
                {
                    "a|assembly=",
                    "The path to the primary {ASSEMBLY} for the worker role.",
                    v => assembly = v
                },
                {
                    "n|roleName=",
                    "The {NAME} of the role as defined in the configuration file.",
                    v => roleName = v
                },
                {
                    "t|serviceTitle=",
                    "Optional {TITLE} for the role window. Defaults to role name if not specified.",
                    v => title = v
                },
                {
                    "c|configurationPath=",
                    "The {PATH} to the configuration file. Either the directory containing ServiceConfiguration.Local.cscfg or the path to a specific alternate .cscfg file.",
                    v => configurationPath = v
                },
                {
                    "useHostedStorage",
                    "Use hosted storage (Emulator/Actual Azure) inside the LightBlue host.",
                    v => useHostedStorage = true
                },
                {
                    "allowSilentFail",
                    "Allow the host to fail silently instead of throwing an exception when the hosted process exits.",
                    v => allowSilentFail = true
                },
                {
                    "help",
                    "Show this message and exit.",
                    v => displayHelp = true
                }
            };

            try
            {
                options.Parse(args);
            }
            catch (OptionException e)
            {
                DisplayErrorMessage(e.Message);
                return(null);
            }

            if (displayHelp)
            {
                DisplayHelp(options);
                return(null);
            }

            if (string.IsNullOrWhiteSpace(assembly))
            {
                DisplayErrorMessage("Host requires an assembly to run.");
                return(null);
            }
            if (string.IsNullOrWhiteSpace(roleName))
            {
                DisplayErrorMessage("Role Name must be specified.");
                return(null);
            }
            if (string.IsNullOrWhiteSpace(configurationPath))
            {
                DisplayErrorMessage("Configuration path must be specified.");
                return(null);
            }

            var roleAssemblyAbsolutePath = Path.IsPathRooted(assembly)
                ? assembly
                : Path.Combine(Environment.CurrentDirectory, assembly);

            if (!File.Exists(roleAssemblyAbsolutePath))
            {
                DisplayErrorMessage("The specified assembly cannot be found. The assembly must be in the host directory or be specified as an absolute path.");
                return(null);
            }

            var roleConfigurationFile = assembly + ".config";

            if (!File.Exists(roleConfigurationFile))
            {
                DisplayErrorMessage("The configuration file for the role cannot be located.");
                return(null);
            }

            return(new HostArgs
            {
                Assembly = assembly,
                RoleName = roleName,
                Title = string.IsNullOrWhiteSpace(title)
                    ? roleName
                    : title,
                ConfigurationPath = ConfigurationLocator.LocateConfigurationFile(configurationPath),
                ServiceDefinitionPath = ConfigurationLocator.LocateServiceDefinition(configurationPath),
                UseHostedStorage = useHostedStorage,
                AllowSilentFail = allowSilentFail,
                RoleConfigurationFile = roleConfigurationFile
            });
        }
Пример #4
0
        public static WebHostArgs ParseArgs(IEnumerable <string> args)
        {
            string assembly           = null;
            int?   port               = null;
            string roleName           = null;
            string title              = null;
            string configurationPath  = null;
            bool?  useSsl             = null;
            var    hostname           = "localhost";
            var    useHostedStorage   = false;
            var    allowSilentFail    = false;
            string iisExpressTemplate = null;
            var    displayHelp        = false;
            bool   use64Bit           = false;

            var options = new OptionSet
            {
                {
                    "a|assembly=",
                    "The path to the primary {ASSEMBLY} for the web role.",
                    v => assembly = v
                },
                {
                    "p|port=",
                    "The {PORT} on which the website should be available. Must be specified if useSsl is specified.",
                    (int v) => port = v
                },
                {
                    "n|roleName=",
                    "The {NAME} of the role as defined in the configuration file.",
                    v => roleName = v
                },
                {
                    "t|serviceTitle=",
                    "Optional {TITLE} for the role window. Defaults to role name if not specified.",
                    v => title = v
                },
                {
                    "c|configurationPath=",
                    "The {PATH} to the configuration file. Either the directory containing ServiceConfiguration.Local.cscfg or the path to a specific alternate .cscfg file.",
                    v => configurationPath = v
                },
                {
                    "s|useSsl=",
                    "Indicates whether the site should be started with SSL. Defaults to false. Must be specified in port is specified.",
                    (bool v) => useSsl = v
                },
                {
                    "h|hostname=",
                    "The {HOSTNAME} the site should be started with. Defaults to localhost",
                    v => hostname = v
                },
                {
                    "useHostedStorage",
                    "Use hosted storage (Emulator/Actual Azure) inside the LightBlue host.",
                    v => useHostedStorage = true
                },
                {
                    "allowSilentFail",
                    "Allow the host to fail silently instead of throwing an exception when the hosted process exits. Applies only to the background process not the website.",
                    v => allowSilentFail = true
                },
                {
                    "iet|iisExpressTemplate=",
                    "Path to an alternate {TEMPLATE} for IIS Express. If not specified the inbuilt default is used.",
                    v => iisExpressTemplate = v
                },
                {
                    "help",
                    "Show this message and exit.",
                    v => displayHelp = true
                },
                {
                    "u|use64bit=",
                    "Indicates whether to use IISExpress 64 bit. Defaults to false.",
                    (bool v) => use64Bit = v
                }
            };

            try
            {
                options.Parse(args);
            }
            catch (OptionException e)
            {
                DisplayErrorMessage(e.Message);
                return(null);
            }

            if (displayHelp)
            {
                DisplayHelp(options);
                return(null);
            }

            if (string.IsNullOrWhiteSpace(assembly))
            {
                DisplayErrorMessage("Host requires an assembly to run.");
                return(null);
            }
            if (string.IsNullOrWhiteSpace(roleName))
            {
                DisplayErrorMessage("Role Name must be specified.");
                return(null);
            }
            if (string.IsNullOrWhiteSpace(configurationPath))
            {
                DisplayErrorMessage("Configuration path must be specified.");
                return(null);
            }
            if (string.IsNullOrWhiteSpace(hostname))
            {
                DisplayErrorMessage(
                    "The hostname cannot be blank. Do not specify this option if you wish to use the default (localhost).");
                return(null);
            }

            var roleAssemblyAbsolutePath = Path.IsPathRooted(assembly)
                ? assembly
                : Path.Combine(Environment.CurrentDirectory, assembly);

            if (!File.Exists(roleAssemblyAbsolutePath))
            {
                DisplayErrorMessage("The specified site assembly cannot be found.");
                return(null);
            }

            if (port.HasValue != useSsl.HasValue)
            {
                DisplayErrorMessage("If either port or useSsl is specified both must be specified.");
                return(null);
            }

            var serviceDefinitionPath = ConfigurationLocator.LocateServiceDefinition(configurationPath);

            if (!port.HasValue)
            {
                var endpoint = GetEndpoint(serviceDefinitionPath, roleName);
                if (endpoint == null)
                {
                    DisplayErrorMessage(
                        "Cannot locate endpoint in ServiceDefinition.csdef. Verify that an endpoint is defined.");
                    return(null);
                }

                port   = endpoint.Item1;
                useSsl = endpoint.Item2;
            }

            if (!string.IsNullOrWhiteSpace(iisExpressTemplate) && !File.Exists(iisExpressTemplate))
            {
                DisplayErrorMessage("The specified IIS Express template cannot be located.");
                return(null);
            }

            if (use64Bit && (!Environment.Is64BitOperatingSystem && string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ProgramW6432"))))
            {
                DisplayErrorMessage("Use64Bit flag cannot be true on a 32bit platform");
                return(null);
            }

            return(new WebHostArgs
            {
                Assembly = assembly,
                Port = port.Value,
                RoleName = roleName,
                Title = string.IsNullOrWhiteSpace(title)
                    ? roleName
                    : title,
                ConfigurationPath = ConfigurationLocator.LocateConfigurationFile(configurationPath),
                ServiceDefinitionPath = serviceDefinitionPath,
                UseSsl = useSsl.Value,
                Hostname = hostname,
                UseHostedStorage = useHostedStorage,
                AllowSilentFail = allowSilentFail,
                IisExpressTemplate = iisExpressTemplate,
                Use64Bit = use64Bit
            });
        }