private static IDiagnosable GetInstance(DiagnosticsComponent component) { Type type = Type.GetType(component.Implementation, false); IDiagnosable result = null; if (type != null) { MethodInfo method = type.GetMethod(component.MethodName, BindingFlags.Static | BindingFlags.Public); if (!string.IsNullOrEmpty(component.Argument)) { result = (method.Invoke(null, new object[] { component.Argument }) as IDiagnosable); } else { result = (method.Invoke(null, null) as IDiagnosable); } ExTraceGlobals.CommonTracer.TraceDebug <string>(0L, "ExchangeDiagnosticsHelper::GetInstance - instance of {0} created successfully", component.Implementation); } else { ExTraceGlobals.CommonTracer.TraceDebug <string>(0L, "ExchangeDiagnosticsHelper::GetInstance - could not find {0}", component.Implementation); } return(result); }
internal static void RegisterDiagnosticsComponents() { ExchangeDiagnosticsSection config = ExchangeDiagnosticsSection.GetConfig(); ExTraceGlobals.CommonTracer.TraceInformation <int>(0, 0L, "ExchangeDiagnosticsHelper::RegisterDiagnosticsComponents called. No of Component:{0}", config.DiagnosticComponents.Count); foreach (object obj in config.DiagnosticComponents) { DiagnosticsComponent diagnosticsComponent = (DiagnosticsComponent)obj; ExTraceGlobals.CommonTracer.TraceDebug(0L, "ExchangeDiagnosticsHelper::RegisterDiagnosticsComponents ComponentName:{0}, Type:{1}, MethodName:{2}, Argument:{3}", new object[] { diagnosticsComponent.Name, diagnosticsComponent.Implementation, diagnosticsComponent.MethodName, diagnosticsComponent.Argument }); IDiagnosable instance = ExchangeDiagnosticsHelper.GetInstance(diagnosticsComponent); if (diagnosticsComponent.Data != null) { IDiagnosableExtraData diagnosableExtraData = instance as IDiagnosableExtraData; if (diagnosableExtraData != null) { diagnosableExtraData.SetData(diagnosticsComponent.Data); } } ExchangeDiagnosticsHelper.RegisterDiagnosticsComponents(instance); } }
public static void UnregisterComponent(IDiagnosable diagnosable) { if (diagnosable == null) { throw new ArgumentNullException("diagnosable"); } string diagnosticComponentName = diagnosable.GetDiagnosticComponentName(); if (string.IsNullOrEmpty(diagnosticComponentName)) { throw new ArgumentNullException("diagnosable.GetDiagnosticComponentName()"); } lock (ProcessAccessManager.RpcServerLockObject) { ProcessAccessManager.diagnosableComponents.Remove(diagnosticComponentName); if (ProcessAccessManager.diagnosableComponents.Count == 0 && ProcessAccessManager.RpcServer != null) { RpcServerBase.StopServer(ProcessAccessRpcServer.RpcIntfHandle); ProcessAccessManager.RpcServer = null; } } IDiagnosableExtraData diagnosableExtraData = diagnosable as IDiagnosableExtraData; if (diagnosableExtraData != null) { diagnosableExtraData.OnStop(); } }
public static void RegisterAgentFactory(AgentFactory agentFactory) { IDiagnosable diagnosable = agentFactory as IDiagnosable; if (diagnosable != null) { ProcessAccessManager.RegisterComponent(diagnosable); } }
protected override void InternalDispose(bool disposing) { if (disposing) { if (this.RegisteredDiagnosable != null) { ProcessAccessManager.UnregisterComponent(this.RegisteredDiagnosable); } this.RegisteredDiagnosable = null; } }
internal static void UnRegisterDiagnosticsComponents(IDiagnosable component) { if (component != null) { try { ProcessAccessManager.UnregisterComponent(component); } catch (RpcException ex) { ExTraceGlobals.CommonTracer.TraceError <string>(0L, "ExchangeDiagnosticsHelper::UnRegisterDiagnosticsComponents. Exception:{0}", ex.ToString()); } } }
public static void RegisterComponent(IDiagnosable diagnosable) { if (diagnosable == null) { throw new ArgumentNullException("diagnosable"); } string diagnosticComponentName = diagnosable.GetDiagnosticComponentName(); if (string.IsNullOrEmpty(diagnosticComponentName)) { throw new ArgumentNullException("diagnosable.GetDiagnosticComponentName()"); } lock (ProcessAccessManager.RpcServerLockObject) { ProcessAccessManager.diagnosableComponents[diagnosticComponentName] = diagnosable; if (ProcessAccessManager.RpcServer == null) { ObjectSecurity serverAdminSecurity = ProcessAccessManager.GetServerAdminSecurity(); if (serverAdminSecurity != null) { using (Process currentProcess = Process.GetCurrentProcess()) { string annotation; if (string.Equals(currentProcess.ProcessName, "w3wp", StringComparison.InvariantCultureIgnoreCase)) { annotation = currentProcess.Id + '\t' + Environment.GetEnvironmentVariable("APP_POOL_ID", EnvironmentVariableTarget.Process); } else { annotation = currentProcess.Id + '\t' + currentProcess.ProcessName; } ProcessAccessManager.RpcServer = (ProcessAccessManager)ProcessAccessRpcServer.RegisterServer(typeof(ProcessAccessManager), serverAdminSecurity, 1, Guid.NewGuid(), annotation, false, 8U); } } } } }
internal static void RegisterDiagnosticsComponents(IDiagnosable instance) { if (instance != null) { try { ProcessAccessManager.RegisterComponent(instance); } catch (RpcException ex) { FaultDiagnosticsComponent faultDiagnosticsComponent = new FaultDiagnosticsComponent(); faultDiagnosticsComponent.SetComponentNameAndMessage(instance.GetDiagnosticComponentName(), -998, ex.ToString()); ExTraceGlobals.CommonTracer.TraceError <string>(0L, "ExchangeDiagnosticsHelper::RegisterDiagnosticsComponents Exception:{0}", ex.ToString()); try { ProcessAccessManager.RegisterComponent(faultDiagnosticsComponent); } catch (RpcException ex2) { ExTraceGlobals.CommonTracer.TraceError <string>(0L, "ExchangeDiagnosticsHelper::RegisterDiagnosticsComponents Exception while registering FaultDiagnosticsComponent. {0}", ex2.ToString()); } } } }
public ExchangeDiagnostics(IDiagnosable diagnosable) { ProcessAccessManager.RegisterComponent(diagnosable); this.RegisteredDiagnosable = diagnosable; }
public void Add(IDiagnosable obj) { if (!objects.Contains(obj)) objects.Add(obj); }
public void Remove(IDiagnosable obj) { objects.Remove(obj); }
public DiagnosableSettings(IDiagnosable diagnosable) { DiagnosticName = diagnosable.DiagnosticName; Settings = diagnosable.GetSettings(); }
private static string RunComponentCommand(string componentName, DiagnosableParameters componentParameters) { XDocument xdocument = new XDocument(); XElement xelement = new XElement("Diagnostics"); xdocument.Add(xelement); if (string.Equals(componentName, "ProcessLocator", StringComparison.OrdinalIgnoreCase)) { XElement xelement2 = new XElement("ProcessLocator"); xelement.Add(xelement2); List <KeyValuePair <Guid, string> > registeredProcessGuids = ProcessAccessRpcServer.GetRegisteredProcessGuids(); int num = 0; if (string.Equals(componentParameters.Argument, "debug", StringComparison.OrdinalIgnoreCase)) { using (List <KeyValuePair <Guid, string> > .Enumerator enumerator = registeredProcessGuids.GetEnumerator()) { while (enumerator.MoveNext()) { KeyValuePair <Guid, string> pair = enumerator.Current; ProcessAccessManager.AddAsXmlElement(xelement2, pair); num++; } goto IL_117; } } HashSet <string> hashSet = new HashSet <string>(registeredProcessGuids.Count); foreach (KeyValuePair <Guid, string> pair2 in registeredProcessGuids) { if (pair2.Key != ProcessAccessRpcServer.ProcessLocatorGuid && !hashSet.Contains(pair2.Value)) { ProcessAccessManager.AddAsXmlElement(xelement2, pair2); num++; hashSet.Add(pair2.Value); } } IL_117: xelement2.AddFirst(new XElement("count", num)); } else { using (Process currentProcess = Process.GetCurrentProcess()) { DateTime dateTime = currentProcess.StartTime.ToUniversalTime(); DateTime utcNow = DateTime.UtcNow; XElement content = new XElement("ProcessInfo", new object[] { new XElement("id", currentProcess.Id), new XElement("serverName", Environment.MachineName), new XElement("startTime", dateTime), new XElement("currentTime", utcNow), new XElement("lifetime", (utcNow - dateTime).ToString()), new XElement("threadCount", currentProcess.Threads.Count), new XElement("handleCount", currentProcess.HandleCount), new XElement("workingSet", ByteQuantifiedSize.FromBytes((ulong)currentProcess.WorkingSet64)) }); xelement.Add(content); } bool flag = string.IsNullOrEmpty(componentName); bool flag2 = componentName == "?"; if (!flag2 && !flag && !ProcessAccessManager.diagnosableComponents.ContainsKey(componentName)) { XElement content2 = new XElement(componentName, new XElement("message", string.Format("Component \"{0}\" is not supported by this process.", componentName))); xelement.Add(content2); flag2 = true; } XElement xelement3 = new XElement("Components"); xelement.Add(xelement3); lock (ProcessAccessManager.RpcServerLockObject) { if (flag) { using (IEnumerator <KeyValuePair <string, IDiagnosable> > enumerator3 = ProcessAccessManager.diagnosableComponents.GetEnumerator()) { while (enumerator3.MoveNext()) { KeyValuePair <string, IDiagnosable> keyValuePair = enumerator3.Current; xelement3.Add(keyValuePair.Value.GetDiagnosticInfo(componentParameters)); } goto IL_3C2; } } if (flag2) { using (IEnumerator <KeyValuePair <string, IDiagnosable> > enumerator4 = ProcessAccessManager.diagnosableComponents.GetEnumerator()) { while (enumerator4.MoveNext()) { KeyValuePair <string, IDiagnosable> keyValuePair2 = enumerator4.Current; xelement3.Add(new XElement("Component", keyValuePair2.Key)); } goto IL_3C2; } } IDiagnosable diagnosable = ProcessAccessManager.diagnosableComponents[componentName]; XElement diagnosticInfo = diagnosable.GetDiagnosticInfo(componentParameters); xelement3.Add(diagnosticInfo); IL_3C2 :; } } string result; try { using (StringWriter stringWriter = new StringWriter()) { using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter)) { xmlTextWriter.Formatting = Formatting.None; xdocument.Save(xmlTextWriter); } result = stringWriter.ToString(); } } catch (XmlException ex) { foreach (XElement xelement4 in xdocument.Descendants()) { ex.Data[xelement4.Name] = xelement4.Value; } throw; } return(result); }