Ejemplo n.º 1
0
        static ServiceHost GetServiceHost(ServiceHostProvider provider)
        {
            var sh = provider.Queryable().Single(q => q.Machine == Environment.MachineName);

            while (string.IsNullOrWhiteSpace(sh.CommandMessageQueue))
            {
                Thread.Sleep(500);
                sh = provider.Queryable().Single(q => q.Machine == Environment.MachineName);
            }

            return sh;
        }
Ejemplo n.º 2
0
 private void UpdateCmdMsgQ(EnvironmentComponents envConfig, string publicationAddress)
 {
     var mongoEnv = envConfig.Config.Where(kvp => kvp.Key.StartsWith("Mongo"));
     var provider = new ServiceHostProvider(mongoEnv);
     var sh = provider.Queryable().Single(q => q.Machine == Environment.MachineName);
     sh.CommandMessageQueue = publicationAddress;
     sh = provider.Update(sh);
 }
Ejemplo n.º 3
0
        private void ManageServiceComponents(EnvironmentComponents envComponents)
        {
            var environment = envComponents.Environment;
            var mongoEnv = envComponents.Config.Where(kvp => kvp.Key.StartsWith("Mongo"));

            var provider = new ServiceHostProvider(mongoEnv);
            var sh = provider.Queryable().Single(q => q.Machine == Environment.MachineName);
            var configuredComponents = sh.Components;

            var configuredIds = configuredComponents.Select(c => c.Id);
            var existingIds = envComponents.Components.Select(c => c.Id);

            // newly configured components
            foreach (var newlyConfiguredId in configuredIds.Except(existingIds))
                envComponents.Components.Add(new RunningServiceComponent(environment, this.ConfigURL, configuredComponents.Single(c => c.Id == newlyConfiguredId), envComponents.Config));

            // newly removed components
            foreach (var newlyDeletedId in existingIds.Except(configuredIds))
            {
                RunningServiceComponent rsc = envComponents.Components.Single(c => c.Id == newlyDeletedId);
                rsc.Stop(envComponents.EventProducer);
                envComponents.Components.Remove(rsc);
            }

            // not new, not deleted, possibly updated
            foreach (var possiblyUpdatedId in configuredIds.Intersect(existingIds))
            {
                var rsc = envComponents.Components.Single(c => c.Id == possiblyUpdatedId);
                var sc = configuredComponents.Single(c => c.Id == possiblyUpdatedId);

                if (rsc.RowVersion != sc.RowVersion)
                    rsc.Update(envComponents.EventProducer, sc);
            }
        }