Exemplo n.º 1
0
        public static void RegisterAgentFactory(AgentFactory agentFactory)
        {
            IDiagnosable diagnosable = agentFactory as IDiagnosable;

            if (diagnosable != null)
            {
                ProcessAccessManager.RegisterComponent(diagnosable);
            }
        }
Exemplo n.º 2
0
 protected override void InternalDispose(bool disposing)
 {
     if (disposing)
     {
         if (this.RegisteredDiagnosable != null)
         {
             ProcessAccessManager.UnregisterComponent(this.RegisteredDiagnosable);
         }
         this.RegisteredDiagnosable = null;
     }
 }
Exemplo n.º 3
0
 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());
         }
     }
 }
Exemplo n.º 4
0
        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);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
 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());
             }
         }
     }
 }
Exemplo n.º 6
0
 public ExchangeDiagnostics(IDiagnosable diagnosable)
 {
     ProcessAccessManager.RegisterComponent(diagnosable);
     this.RegisteredDiagnosable = diagnosable;
 }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public override byte[] RunProcessCommand(byte[] inBlob)
        {
            string componentName       = null;
            string argument            = null;
            bool   allowRestrictedData = false;
            bool   unlimited           = false;
            string userIdentity        = null;
            string text = null;
            MdbefPropertyCollection mdbefPropertyCollection = MdbefPropertyCollection.Create(inBlob, 0, inBlob.Length);
            object obj;

            if (mdbefPropertyCollection.TryGetValue(2466316319U, out obj) && obj is string)
            {
                argument = (string)obj;
            }
            if (mdbefPropertyCollection.TryGetValue(2466250783U, out obj) && obj is string)
            {
                componentName = (string)obj;
            }
            if (mdbefPropertyCollection.TryGetValue(2466381835U, out obj) && obj is bool)
            {
                allowRestrictedData = (bool)obj;
            }
            if (mdbefPropertyCollection.TryGetValue(2466512907U, out obj) && obj is bool)
            {
                unlimited = (bool)obj;
            }
            if (mdbefPropertyCollection.TryGetValue(2466447391U, out obj) && obj is string)
            {
                userIdentity = (string)obj;
            }
            try
            {
                DiagnosableParameters componentParameters = DiagnosableParameters.Create(argument, allowRestrictedData, unlimited, userIdentity);
                text = ProcessAccessManager.RunComponentCommand(componentName, componentParameters);
            }
            catch (XmlException ex)
            {
                StringBuilder stringBuilder = new StringBuilder(100 * ex.Data.Count);
                foreach (object obj2 in ex.Data)
                {
                    KeyValuePair <object, object> keyValuePair = (KeyValuePair <object, object>)obj2;
                    stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}:{1}{2}", new object[]
                    {
                        keyValuePair.Key,
                        keyValuePair.Value,
                        Environment.NewLine
                    });
                }
                text = string.Format(CultureInfo.InvariantCulture, "Message={0}{1}Data={2}{1}Stack={3}", new object[]
                {
                    ex.Message,
                    Environment.NewLine,
                    stringBuilder,
                    ex.StackTrace
                });
            }
            catch (Exception ex2)
            {
                text = ex2.ToString();
            }
            MdbefPropertyCollection mdbefPropertyCollection2 = new MdbefPropertyCollection();

            if (text != null)
            {
                mdbefPropertyCollection2.Add(2471559199U, text);
            }
            return(mdbefPropertyCollection2.GetBytes());
        }
Exemplo n.º 9
0
        public static string ClientRunProcessCommand(string server, string process, string componentName, string componentArgument, bool componentRestrictedData, bool componentUnlimited, string userIdentity)
        {
            if (string.IsNullOrEmpty(server))
            {
                server = Environment.MachineName;
            }
            string result;

            try
            {
                string text;
                try
                {
                    text = ProcessAccessManager.ClientRunProcessCommand(server, ProcessAccessRpcServer.ProcessLocatorGuid, "ProcessLocator", null, false, false, null);
                }
                catch (RpcException rpcException)
                {
                    return(ProcessAccessManager.ReturnFromRpcException(server, "Query registered processes", rpcException));
                }
                if (text == null)
                {
                    result = new XElement("Diagnostics", new XElement("error", string.Format("No processes have registered on {0} to support this task.", server))).ToString(SaveOptions.DisableFormatting);
                }
                else
                {
                    XDocument xdocument;
                    try
                    {
                        xdocument = XDocument.Parse(text);
                    }
                    catch (XmlException)
                    {
                        return(new XElement("Diagnostics", new object[]
                        {
                            new XElement("error", "Xml parsing error"),
                            new XElement("failedXml", text)
                        }).ToString(SaveOptions.DisableFormatting));
                    }
                    XElement root     = xdocument.Root;
                    XElement xelement = root.Element("ProcessLocator");
                    if (string.IsNullOrEmpty(process))
                    {
                        result = root.ToString(SaveOptions.DisableFormatting);
                    }
                    else
                    {
                        Guid processGuid = Guid.Empty;
                        int  num         = 0;
                        foreach (XElement xelement2 in xelement.Elements("Process"))
                        {
                            Guid guid;
                            if (GuidHelper.TryParseGuid(xelement2.Element("guid").Value, out guid))
                            {
                                if (string.Equals(xelement2.Element("id").Value, process, StringComparison.OrdinalIgnoreCase))
                                {
                                    processGuid = guid;
                                    num++;
                                }
                                else if (string.Equals(xelement2.Element("name").Value, process, StringComparison.OrdinalIgnoreCase))
                                {
                                    processGuid = guid;
                                    num++;
                                }
                            }
                        }
                        if (num < 1)
                        {
                            xelement.AddFirst(new XElement("error", string.Format("Specified process is not registered. Currently registered on {0}.", server)));
                            result = root.ToString(SaveOptions.DisableFormatting);
                        }
                        else if (num > 1)
                        {
                            xelement.AddFirst(new XElement("error", string.Format("Specified process matches more than one registered process on {0}.", server)));
                            result = root.ToString(SaveOptions.DisableFormatting);
                        }
                        else
                        {
                            try
                            {
                                result = ProcessAccessManager.ClientRunProcessCommand(server, processGuid, componentName, componentArgument, componentRestrictedData, componentUnlimited, userIdentity);
                            }
                            catch (RpcException rpcException2)
                            {
                                result = ProcessAccessManager.ReturnFromRpcException(server, "Query process diagnostics", rpcException2);
                            }
                        }
                    }
                }
            }
            catch (Exception arg)
            {
                result = new XElement("Diagnostics", new XElement("error", string.Format("ProcessAccessManager Exception: {0}", arg))).ToString(SaveOptions.DisableFormatting);
            }
            return(result);
        }