public FactoryTable(IEnumerable agents, FactoryInitializer factoryInitializer) { this.factoriesByAgentId = new Dictionary <string, AgentFactory>(); this.agentManagersByAgentId = new Dictionary <string, AgentManager>(); Dictionary <string, AgentFactory> dictionary = new Dictionary <string, AgentFactory>(); DateTime utcNow = DateTime.UtcNow; StringBuilder stringBuilder = new StringBuilder(); foreach (object obj in agents) { AgentInfo agentInfo = (AgentInfo)obj; if (this.factoriesByAgentId.ContainsKey(agentInfo.Id)) { throw new ExchangeConfigurationException(MExRuntimeStrings.DuplicateAgentName(agentInfo.AgentName)); } DateTime utcNow2 = DateTime.UtcNow; AgentFactory agentFactory; if (!dictionary.TryGetValue(agentInfo.FactoryTypeName, out agentFactory)) { agentFactory = FactoryTable.CreateAgentFactory(agentInfo); if (factoryInitializer != null) { factoryInitializer(agentFactory); } dictionary.Add(agentInfo.FactoryTypeName, agentFactory); } this.factoriesByAgentId.Add(agentInfo.Id, agentFactory); AgentManager agentManagerInstance = FactoryTable.GetAgentManagerInstance(agentInfo); if (agentManagerInstance != null) { this.agentManagersByAgentId.Add(agentInfo.Id, agentManagerInstance); } TimeSpan timeSpan = DateTime.UtcNow - utcNow2; stringBuilder.AppendLine(); stringBuilder.Append(agentInfo.AgentName); stringBuilder.Append(": "); stringBuilder.Append(timeSpan); } this.startupDiagnosticInfo = stringBuilder.ToString(); TimeSpan timeSpan2 = DateTime.UtcNow - utcNow; if (timeSpan2 > FactoryTable.StartupThreshold) { MExDiagnostics.EventLog.LogEvent(EdgeExtensibilityEventLogConstants.Tuple_MExAgentFactoryStartupDelay, null, new object[] { timeSpan2, this.startupDiagnosticInfo }); } this.factories = new AgentFactory[this.factoriesByAgentId.Count]; this.factoriesByAgentId.Values.CopyTo(this.factories, 0); }
public RuntimeSettings(MExConfiguration config, string agentGroup, FactoryInitializer factoryInitializer) { AgentInfo[] enabledAgentsByType = config.GetEnabledAgentsByType(agentGroup); this.factoryTable = new FactoryTable(enabledAgentsByType, factoryInitializer); this.agentsInDefaultOrder = new AgentRecord[enabledAgentsByType.Length]; this.monitoringOptions = config.MonitoringOptions; for (int i = 0; i < this.agentsInDefaultOrder.Length; i++) { AgentInfo agentInfo = enabledAgentsByType[i]; this.agentsInDefaultOrder[i] = new AgentRecord(agentInfo.Id, agentInfo.AgentName, agentInfo.BaseTypeName, i, agentInfo.IsInternal); } string[] agents; string[][] eventTopics; AgentRecord[] array; RuntimeSettings.InitializeAgentsAndSubscriptions(config, agentGroup, false, out agents, out eventTopics, out array); this.agentSubscription = new AgentSubscription(agentGroup, agents, eventTopics); RuntimeSettings.InitializeAgentsAndSubscriptions(config, agentGroup, true, out agents, out eventTopics, out this.publicAgentsInDefaultOrder); this.disposeAgents = config.DisposeAgents; }
public void Initialize(string configFile, string agentGroup, ProcessTransportRole processTransportRole, string installPath, FactoryInitializer factoryInitializer = null) { if (this.runtimeState != 0) { ExTraceGlobals.InitializeTracer.TraceError <int>((long)this.GetHashCode(), this.InstanceNameFormatted + "invalid state for initialization: {0}", this.runtimeState); throw new InvalidOperationException(MExRuntimeStrings.InvalidState); } this.config = new MExConfiguration(processTransportRole, installPath); this.config.Load(configFile); this.settings = new RuntimeSettings(this.config, agentGroup, factoryInitializer); this.perfCounters = new MExPerfCounters(processTransportRole, this.settings.CreateDefaultAgentOrder()); Interlocked.CompareExchange(ref this.runtimeState, 1, 0); ExTraceGlobals.InitializeTracer.TraceDebug <string, string>((long)this.GetHashCode(), this.InstanceNameFormatted + "initialized ('{0}', '{1}')", configFile, agentGroup); }