private void LoadManifest(ref string instanceId) { // Get the manifest from the factory TraceFactory.Logger.Debug("Attempting to get the manifest from the Factory Service"); SystemManifest manifest = null; using (var clientController = ClientControllerServiceConnection.Create(Environment.MachineName)) { var data = clientController.Channel.GetManifest(instanceId); manifest = SystemManifest.Deserialize(data); } // Cache the definition that corresponds to the resourceId var definition = manifest.Resources.GetByType(VirtualResourceType.PerfMonCollector).FirstOrDefault(); if (definition == null) { throw new InvalidOperationException("Resource Definition is null."); } manifest.PushToGlobalSettings(); manifest.PushToGlobalDataStore(definition.Name); _sessionId = manifest.SessionId; // get all the resources which are of type perfmoncollector var perfMonResources = manifest.Resources.Where(c => c.ResourceType == VirtualResourceType.PerfMonCollector); // if we have permoncounter collectors then we read manifest if (perfMonResources.Count() > 0) { ReadManifest(perfMonResources); } else { throw new InvalidOperationException("No performance counters to monitor"); } TraceFactory.Logger.Info(Environment.NewLine + manifest.ToString()); }
/// <summary> /// Starts this instance of the <see cref=" VirtualClientController"/> to work with the Dispatcher, /// then creates the virtual resources based on the provided <see cref="SystemManifest"/>. /// </summary> /// <remarks> /// Creates a <see cref="SessionProxyBackendConnection"/> that is used to communicate with the /// Dispatcher to provide status updates. Loads the <see cref="SystemManifest"/> into /// the <see cref="GlobalDataStore"/> and into the <see cref="GlobalSettings"/>. /// </remarks> public void Start(string sessionId) { _sessionId = sessionId; // Contact the dispatcher and register. string manifestData = string.Empty; TraceFactory.Logger.Debug("Registering with Dispatcher {0}, SessionId: {1}".FormatWith(_dispatcherAddress, _sessionId)); using (var proxyClient = SessionProxyBackendConnection.Create(_dispatcherAddress, _sessionId)) { manifestData = proxyClient.Channel.RegisterMachine(Environment.MachineName); } _manifest = SystemManifest.Deserialize(manifestData); string resourceInstanceId = string.Empty; switch (_manifest.ResourceType) { case VirtualResourceType.AdminWorker: case VirtualResourceType.OfficeWorker: case VirtualResourceType.SolutionTester: // These types don't use the resource instance Id as there can be multiple instances // of the worker within the client controller process. _manifest.PushToGlobalDataStore(); //The following code monitors the local host VM client event logs. if (_manifest.CollectEventLogs) { EventLogCollectorDetail detail = new EventLogCollectorDetail(); detail.ComponentsData = Resources.ClientEventLogComponents; detail.EntryTypesData = Resources.ClientEventLogEntryTypes; detail.Description = "Client VM Event Collector"; detail.Enabled = true; detail.HostName = Environment.MachineName; detail.Name = Environment.MachineName; detail.ResourceType = VirtualResourceType.EventLogCollector; detail.PollingInterval = 15; _manifest.Resources.Add(detail); resourceInstanceId = _manifest.Resources.OfType <EventLogCollectorDetail>().First().HostName; _manifest.PushToGlobalDataStore(resourceInstanceId); } break; case VirtualResourceType.CitrixWorker: case VirtualResourceType.LoadTester: // These resources use credentials like the workers above, but run in the // client controller process, so the data store needs the resource instance Id set. resourceInstanceId = _manifest.Resources.Credentials.First().ResourceInstanceId; _manifest.PushToGlobalDataStore(resourceInstanceId); break; case VirtualResourceType.EventLogCollector: // This resource is unique as it uses the hostname as its unique name. It also // runs within the client controller process so it needs its instance Id set. // This event log collector monitors target machines rather than the local VM running the client controller resourceInstanceId = _manifest.Resources.OfType <EventLogCollectorDetail>().First().HostName; _manifest.PushToGlobalDataStore(resourceInstanceId); break; default: // All other resources also run in the client controller process, but they use Name // as their unique id. var type = GetDetailType(_manifest.ResourceType); resourceInstanceId = _manifest.Resources.Where(x => x.GetType().Equals(type)).First().Name; TraceFactory.Logger.Debug("Resource Instance Id: {0}".FormatWith(resourceInstanceId)); _manifest.PushToGlobalDataStore(resourceInstanceId); break; } TraceFactory.Logger.Debug("Resource Instance Id: {0}".FormatWith(resourceInstanceId)); _manifest.PushToGlobalSettings(); GlobalSettings.SetDispatcher(_dispatcherAddress); TraceFactory.Logger.Debug(_manifest.ToString()); InstallPrintingCertficates(); InstallClientSoftware(); // Creates all the virtual resources specified in the provided manifest. _handlers = VirtualResourceHandlerFactory.Create(_manifest); foreach (var handler in _handlers) { handler.Start(); } }