Пример #1
0
        /// <summary>
        /// Extrait une collection d'objet Com trouvé sur la machine
        /// </summary>
        /// <param name="minHangTime">temps (ms) minimum pour marqué une application comme gelé</param>
        /// <returns>collections</returns>
        public ComApps GetCOMs(long minHangTime)
        {
            //Match des Clés pour trouvé le nom de l'application
            ComApps comName = new ComApps();
            comName = GetNameListCom();

            // Get the call statistics
            //HACK pour Windows 2000
            EGILHCOMTRACKERLib.IComTracker comTracker = (EGILHCOMTRACKERLib.IComTracker)Activator.CreateInstance(Type.GetTypeFromProgID("Egilh.ComTracker.1"));

            string statistics = comTracker.getStatistics();

            // Load the statistics in a DOM and loop on the call times
            XmlDocument xmlDoc = new XmlDocument();
            #region Exemple du XML retourné
            //<application>
            //<guid>{02D4B3F1-FD88-11D1-960D-00805FC79235}</guid>
            //<ID>2</ID>
            //<processID>2312</processID>
            //<statistics>
            //    <callsPerSecond>0</callsPerSecond>
            //    <totalCalls>0</totalCalls>
            //    <totalClasses>3</totalClasses>
            //    <totalInstances>2</totalInstances>
            //</statistics>
            //<classes>
            //<class>
            //    <progID>COMSVCS.TrackerServer</progID>
            //    <bound>3</bound>
            //    <inCall>0</inCall>
            //    <pooled>-1</pooled>
            //    <references>3</references>
            //    <responseTime>0</responseTime>
            //    <callsCompleted>0</callsCompleted>
            //    <callsFailed>0</callsFailed>
            //</class>
            //</classes>
            //</application>
            #endregion

            xmlDoc.LoadXml(statistics);

            ComApps appComs = new ComApps();

            //=== Pour chacune des applications trouvé dans le XML
            foreach (XmlNode appNode in xmlDoc.SelectNodes("//applications/application"))
            {
                // Get class info
                ComApp appComFound = new ComApp();
                ComApp appCom = new ComApp();

                string applicationName = "";
                string applicationKey = appNode.SelectSingleNode("guid").InnerText.ToUpper();

                //== Trouve le nom de l'application selon la clé
                appComFound = comName.Find(delegate(ComApp t) { return t.ApplicationKey.ToUpper() == applicationKey.ToUpper(); });

                //=== Si l'application est trouvé on l'ajoute à la collection
                if (appComFound != null)
                {
                    applicationName = appComFound.ApplicationName;

                    appCom.ApplicationKey = applicationKey;
                    appCom.ApplicationName = applicationName;
                    appCom.MinHangTime = minHangTime;

                    //TODO === Une classe COM devrait devenir une collection qui apartient à la classe ComApp
                    //=== Cumule chaque classe par application
                    foreach (XmlNode classNode in appNode.SelectNodes(".//classes/class"))
                    {
                        appCom.NbClass++;
                        appCom.TotalInCall += System.Convert.ToInt32(classNode.SelectSingleNode("inCall").InnerText);
                        appCom.TotalResponseTime += System.Convert.ToInt64(classNode.SelectSingleNode("responseTime").InnerText);
                    }
                    appComs.Add(appCom);
                }
            }
            return appComs;
        }