Beispiel #1
0
 private static void Initialise()
 {
     if (_context == null)
     {
         _context = LightBlueConfiguration.GetConfiguredContext();
     }
 }
Beispiel #2
0
        public bool Start(HostControl hc)
        {
            var hostDirectory = LightBlueConfiguration.SetAsWindowsHost(_settings.ServiceTitle,
                                                                        _settings.ConfigurationPath,
                                                                        _settings.RoleName);

            Trace.TraceInformation("Worker host service LightBlue context created at directory {0}", hostDirectory);

            var assemblyPath = Path.IsPathRooted(_settings.Assembly)
                ? _settings.Assembly
                : Path.Combine(Environment.CurrentDirectory, _settings.Assembly);

            return(RunConsoleApplication(assemblyPath));
        }
        public string this[string index]
        {
            get
            {
                if (!_settings.ContainsKey(index))
                {
                    throw  LightBlueConfiguration.RoleEnvironmentExceptionCreator(string.Format(
                                                                                      CultureInfo.InvariantCulture,
                                                                                      "Unknown setting '{0}'",
                                                                                      index));
                }

                return(_settings[index]);
            }
        }
Beispiel #4
0
        public void Run(
            string workerRoleAssembly,
            string configurationPath,
            string roleName,
            bool useHostedStorage)
        {
            LightBlueConfiguration.SetAsLightBlue(
                configurationPath: configurationPath,
                roleName: roleName,
                lightBlueHostType: LightBlueHostType.Direct,
                useHostedStorage: useHostedStorage);

            var assembly = Assembly.LoadFrom(workerRoleAssembly);

            assembly.EntryPoint.Invoke(null, new object[] { null });
        }
Beispiel #5
0
        public bool Start(HostControl hc)
        {
            _hostControl = hc;

            var hostDirectory = LightBlueConfiguration.SetAsWindowsHost(_settings.ServiceTitle,
                                                                        _settings.Cscfg,
                                                                        _settings.Csdef,
                                                                        _settings.RoleName);

            Trace.TraceInformation("Worker host service LightBlue context created at directory {0}", hostDirectory);

            var assemblyPath = Path.IsPathRooted(_settings.Assembly)
                ? _settings.Assembly
                : Path.Combine(Environment.CurrentDirectory, _settings.Assembly);
            var entryPoint = Assembly.LoadFrom(assemblyPath)
                             .GetTypes()
                             .Single(t => typeof(RoleEntryPoint).IsAssignableFrom(t));

            _role = (RoleEntryPoint)Activator.CreateInstance(entryPoint);

            Trace.TraceInformation("Worker host service role entry point {0} located at {1}", entryPoint.FullName, assemblyPath);

            if (!_role.OnStart())
            {
                Trace.TraceError("Worker host service role entry point {0} start failed", entryPoint.FullName);
                _hostControl.Restart();
                return(true);
            }

            Task.Run(() =>
            {
                try
                {
                    _role.Run();
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Worker host service errored with exception: {0}", ex);
                    _hostControl.Restart();
                }
            });

            Trace.TraceInformation("Worker host service role entry point {0} running", entryPoint.FullName);

            return(true);
        }
Beispiel #6
0
        public void Run(
            string workerRoleAssembly,
            string configurationPath,
            string serviceDefinitionPath,
            string roleName,
            bool useHostedStorage)
        {
            LightBlueConfiguration.SetAsLightBlue(
                configurationPath: configurationPath,
                serviceDefinitionPath: serviceDefinitionPath,
                roleName: roleName,
                lightBlueHostType: LightBlueHostType.Direct,
                useHostedStorage: useHostedStorage);

            var workerRoleType = LoadWorkerRoleType(workerRoleAssembly);

            RunRole(workerRoleType);
        }
        public IAzureLocalResource this[string index]
        {
            get
            {
                if (!_localResources.ContainsKey(index))
                {
                    throw LightBlueConfiguration.RoleEnvironmentExceptionCreator(string.Format(
                                                                                     CultureInfo.InvariantCulture,
                                                                                     "Unknown resource '{0}'",
                                                                                     index));
                }

                var localResource = _localResources[index];

                Directory.CreateDirectory(localResource.RootPath);

                return(localResource);
            }
        }
Beispiel #8
0
        protected override void OnStartup(StartupEventArgs e)
        {
            try
            {
                MultiHostConfigurationFilePath = null;

                if (e.Args.Length != 1)
                {
                    var d = new OpenFileDialog();
                    d.Title           = "LightBlue MultiHost: please select multi-host configuration file (.json)";
                    d.Filter          = "MultiHost Configuration Files (.json)|*.json";
                    d.CheckFileExists = true;
                    if (d.ShowDialog().GetValueOrDefault())
                    {
                        MultiHostConfigurationFilePath = d.FileName;
                    }
                }
                else
                {
                    MultiHostConfigurationFilePath = e.Args.Single();
                }

                if (string.IsNullOrWhiteSpace(MultiHostConfigurationFilePath))
                {
                    Configuration = new MultiHostConfiguration
                    {
                        Roles = new[]
                        {
                            new RoleConfiguration {
                                Title = "Demo Web Site", RoleName = "WebRole"
                            },
                            new RoleConfiguration
                            {
                                Title             = "Demo Web Site 2",
                                RoleName          = "WebRole",
                                RoleIsolationMode = "AppDomain"
                            },
                            new RoleConfiguration {
                                Title = "Demo Domain", RoleName = "CommandProcessor"
                            },
                            new RoleConfiguration
                            {
                                Title             = "Demo Domain 2",
                                RoleName          = "ReadModelPopulator",
                                RoleIsolationMode = "AppDomain"
                            }
                        },
                    };
                }
                else
                {
                    var configDir = Path.GetDirectoryName(MultiHostConfigurationFilePath);
                    var json      = File.ReadAllText(MultiHostConfigurationFilePath);
                    Configuration = JsonConvert.DeserializeObject <MultiHostConfiguration>(json);

                    foreach (var c in Configuration.Roles)
                    {
                        c.ConfigurationPath = Path.GetFullPath(Path.Combine(configDir, c.ConfigurationPath));
                        c.Assembly          = Path.GetFullPath(Path.Combine(configDir, c.Assembly));
                    }

                    var query =
                        from c in Configuration.Roles
                        let relativePath = c.Assembly.ToLowerInvariant().EndsWith(".dll") ||
                                           c.Assembly.ToLowerInvariant().EndsWith(".exe")
                            ? Path.GetDirectoryName(c.Assembly)
                            : c.Assembly
                                           select relativePath;

                    var assemblyLocations = query.ToArray();

                    ThreadRunnerAssemblyCache.Initialise(assemblyLocations);
                    IisExpressHelper.KillIisExpressProcesses();
                    LightBlueConfiguration.SetAsMultiHost();
                }

                base.OnStartup(e);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not start multi-host: " + ex.ToTraceMessage());
            }
        }