Exemplo n.º 1
0
        public static IRunner CreateForWorkerRole(Role role, RoleIsolationMode isolation)
        {
            var config = role.Config;
            var configurationPath = config.ConfigurationPath;
            var configurationFilePath = ConfigurationLocator.LocateConfigurationFile(configurationPath);
            var serviceDefinitionPath = ConfigurationLocator.LocateServiceDefinition(configurationPath);

            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, configurationFilePath, serviceDefinitionPath, role.RoleName);
                case RoleIsolationMode.AppDomain:
                    var setup = new AppDomainSetup
                    {
                        ApplicationBase = assemblyPath,
                        ConfigurationFile = config.Assembly + ".config",
                    };
                    return new AppDomainRunner(role, setup, assemblyFilePath, configurationFilePath, serviceDefinitionPath, role.RoleName);
                default:
                    throw new NotSupportedException();
            }
        }
Exemplo n.º 2
0
        public static IRunner CreateForWebRole(Role role, RoleIsolationMode isolation)
        {
            var args = WebConfigHelper.Create(role.Config);

            var assemblyPath = Path.GetDirectoryName(args.Assembly);
            if (HasBeenReBuilt(assemblyPath) && isolation == RoleIsolationMode.Thread)
            {
                isolation = RoleIsolationMode.AppDomain;
                role.IsolationMode = isolation;
            }

            switch (isolation)
            {
                case RoleIsolationMode.Thread:
                    return new ThreadRunner(role, args.Assembly, args.ConfigurationPath, args.ServiceDefinitionPath, args.RoleName);
                case RoleIsolationMode.AppDomain:
                    var setup = new AppDomainSetup
                    {
                        ApplicationBase = args.SiteBinDirectory,
                        ConfigurationFile = WebConfigHelper.DetermineWebConfigPath(args.Assembly)
                    };
                    return new AppDomainRunner(role, setup, args.Assembly, args.ConfigurationPath, args.ServiceDefinitionPath, args.RoleName);
                default:
                    throw new NotSupportedException();
            }
        }
Exemplo n.º 3
0
 public static void CopyStubAssemblyToRoleDirectory(string applicationBase, Role role)
 {
     var destinationHostStubPath = Path.Combine(applicationBase, Path.GetFileName(typeof(HostStub).Assembly.Location));
     try
     {
         File.Copy(typeof(HostStub).Assembly.Location, destinationHostStubPath, true);
     }
     catch (IOException)
     {
         role.TraceWriteLine("Could not copy Host Stub. Assuming this is because it already exists and continuing.");
     }
 }
Exemplo n.º 4
0
 public AppDomainRunner(Role role,
     AppDomainSetup appDomainSetup,
     string assemblyPath,
     string configurationFilePath,
     string serviceDefinitionFilePath,
     string roleName)
 {
     _role = role;
     _appDomainSetup = appDomainSetup;
     _assemblyFilePath = assemblyPath;
     _configurationFilePath = configurationFilePath;
     _serviceDefinitionFilePath = serviceDefinitionFilePath;
     _roleName = roleName;
 }
Exemplo n.º 5
0
        public ThreadRunner(Role role,
            string assemblyPath,
            string configurationFilePath,
            string serviceDefinitionFilePath,
            string roleName)
        {
            _role = role;
            _assemblyFilePath = assemblyPath;
            _configurationFilePath = configurationFilePath;
            _serviceDefinitionFilePath = serviceDefinitionFilePath;
            _roleName = roleName;

            _assemblyFilePath = Path.Combine(ThreadRunnerAssemblyCache.AssemblyCacheFolder, Path.GetFileName(_assemblyFilePath));
        }
Exemplo n.º 6
0
        public MainWindow()
        {
            InitializeComponent();

            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                string msg = null;
                try
                {
                    msg = e.ExceptionObject.ToString();
                }
                catch (Exception ex)
                {
                    msg = "Couldn't get exception details: " + ex.Message;
                }

                try
                {
                    MessageBox.Show(msg);
                }
                catch
                {
                    Debugger.Launch();
                    Debugger.Break();
                }
            };
            App.Current.DispatcherUnhandledException += (s, e) =>
            {
                string msg = null;
                try
                {
                    msg = e.Exception.ToString();
                }
                catch (Exception ex)
                {
                    msg = "Couldn't get exception details: " + ex.Message;
                }

                try
                {
                    MessageBox.Show(msg);
                }
                catch
                {
                    Debugger.Launch();
                    Debugger.Break();
                }
            };

            CollectionViewSource = new CollectionViewSource();

            Services = new ObservableCollection<Role>();

            foreach (var h in App.Configuration.Roles)
            {
                var r = new Role(h);
                Services.Add(r);
                r.PropertyChanged += (s, e) =>
                {
                    if (e.PropertyName == "Status") CollectionViewSource.View.Refresh();
                };
            }

            CollectionViewSource.Filter += CollectionViewSource_Filter;

            CollectionViewSource.Source = Services;

            DataContext = this;

            var autos = Services.Where(x => x.Status == RoleStatus.Sequenced).ToArray();
            BeginAutoStart(autos);
        }
Exemplo n.º 7
0
        private void EditConfiguration_OnClick(object sender, RoutedEventArgs e)
        {
            if (VerifiySingleSelection())
            {
                var role = (Role)listView.SelectedItem;
                if (role.Status == RoleStatus.Stopped)
                {
                    var service = new RoleConfigurationService();
                    var changed = service.Edit(role.Title, App.MultiHostConfigurationFilePath);
                    if (changed != null)
                    {
                        changed.EnabledOnStartup = false;

                        var configDir = Path.GetDirectoryName(App.MultiHostConfigurationFilePath);
                        changed.ConfigurationPath = Path.GetFullPath(Path.Combine(configDir, changed.ConfigurationPath));
                        changed.Assembly = Path.GetFullPath(Path.Combine(configDir, changed.Assembly));

                        var newRole = new Role(changed);
                        newRole.Logs = role.Logs;
                        
                        var index = listView.SelectedIndex;
                        Services.RemoveAt(index);
                        Services.Insert(index, newRole);

                        listView.SelectedIndex = index;
                    }
                }
                else
                {
                    MessageBox.Show(role.Title + " must be stopped if you want to edit its configuration.");
                }
            }
        }
Exemplo n.º 8
0
 async void BeginAutoStart(Role[] roles)
 {
     await Task.Delay(TimeSpan.FromSeconds(0.2));
     foreach (var r in roles) r.StartAutomatically();
 }
Exemplo n.º 9
0
 async void BeginAutoStart(Role[] roles)
 {
     await Task.Delay(TimeSpan.FromSeconds(0.2));
     foreach (var r in roles) r.StartAutomatically();
     //foreach (var r in roles.Take(10))
     //    r.StartAutomatically();
     //foreach (var r in roles.Skip(10))
     //{
     //    await TaskHelpers.AfterComputeOpportunities(1000000000, 500, CancellationToken.None);
     //    r.StartAutomatically();
     //}
 }
Exemplo n.º 10
0
 public IisExpressRunner(Role role)
 {
     _role = role;
     _args = WebConfigHelper.Create(role.Config);
     WebConfigHelper.PatchWebConfig(_args);
 }
Exemplo n.º 11
0
 public static IRunner CreateForWebSite(Role role)
 {
     return new IisExpressRunner(role);
 }
Exemplo n.º 12
0
 public RoleRunner(Role role)
 {
     _role = role;
 }