//public static IList<string> GetPropertyValues(Connection WMIConnection,
        //                                              string SelectQuery,
        //                                              string className)
        public static IList<Dictionary<string, string>> GetPropertyValues(Connection WMIConnection,
                                              string SelectQuery,
                                              string className)
        {
            ManagementScope connectionScope = WMIConnection.GetConnectionScope;
            //List<string> alProperties = new List<string>();
            SelectQuery msQuery = new SelectQuery(SelectQuery);
            ManagementObjectSearcher searchProcedure = new ManagementObjectSearcher(connectionScope, msQuery);
            //Dictionary<string, string> paM = new Dictionary<string, string>();
            List<Dictionary<string, string>> allContent = new List<Dictionary<string, string>>();
            try
            {
                foreach (ManagementObject item in searchProcedure.Get())
                {
                    Dictionary<string, string> paM = new Dictionary<string, string>();
                    foreach (string property in XMLConfig.GetSettings(className))
                    {
                        try
                        {
                          paM.Add(property, item[property].ToString());
                          //alProperties.Add(property + ": " + item[property].ToString());
                        }
                        catch (SystemException) { /* ignore error */ }
                    }
                    allContent.Add(paM);
                }
            }
            catch (ManagementException e)
            {
                /* Do Nothing */
            }

            //return alProperties;
            return allContent;
        }
        private Dictionary<string, string> getProcessMemoryUsage(Connection wmiConnection)
        {
            Win32_Process p = new Win32_Process(wmiConnection);
              IList<Dictionary<string, string>> mUsed = p.GetPropertyValues();
              //List<string> memoryUsed = new List<string>();
              Dictionary<string, string> memoryUsed = new Dictionary<string, string>();
              string memUse = string.Empty;
              string parentPID = string.Empty;
              foreach (Dictionary<string, string> processInfo in mUsed)
              {
            if (processInfo.ContainsValue("javaw.exe"))
            {
              processInfo.TryGetValue("ParentProcessId", out parentPID);
              if (parentPID != null && parentPID != string.Empty)
              {
            string parentPName = string.Empty;
            string pid = string.Empty;
            bool isCSDMProcess = false;
            foreach (Dictionary<string, string> processInfo1 in mUsed)
            {
              processInfo1.TryGetValue("Caption", out parentPName);
              processInfo1.TryGetValue("ProcessId", out pid);
              if (parentPName == "DM.exe" && pid == parentPID)
              {
                isCSDMProcess = true;
                break;
              }
            }
            if (isCSDMProcess)
              processInfo.TryGetValue("PageFileUsage", out memUse);
            if (memUse != string.Empty && isCSDMProcess)
            {
              string strCommandLine = string.Empty;
              processInfo.TryGetValue("CommandLine", out strCommandLine);
              if (strCommandLine.Contains("derbyrun.jar"))
                memoryUsed.Add(memUsagepList.derby, memUse);
              if (strCommandLine.Contains("pas_server") || strCommandLine.Contains("pas_client"))
                memoryUsed.Add(memUsagepList.jetty, memUse);
            }
              }
            }

            if (processInfo.ContainsValue("CSAcqDmn.exe"))
            {
              processInfo.TryGetValue("PageFileUsage", out memUse);
              if (memUse != string.Empty)
              {
            memoryUsed.Add(memUsagepList.deamon, memUse);
              }
            }
              }
              return memoryUsed;
        }
        /*
        public string getMemoryUsedByID(string processId)
        {
          Connection wmiConnection = new Connection();
          Win32_Process p = new Win32_Process(wmiConnection);
          IList<Dictionary<string,string>> mUsed = p.GetPropertyValues();
          //IDictionary<string, string> mUsed = p.GetPropertyValues();
          string memUse = string.Empty;
          foreach (Dictionary<string,string> processInfo in mUsed)
          {
        if (processInfo.ContainsValue(processId))
        {
          processInfo.TryGetValue("PageFileUsage", out memUse);
        }
        if (memUse != null && memUse != string.Empty)
          return memUse;
          }
          return null;

        }

        public string getMemoryUsedByName(string processName, string parentProcessName)
        {
          return null;
        }
        */
        public ProcessAndUsage getMemoryUsed(string mode)
        {
            ProcessAndUsage pau = new ProcessAndUsage();
              Connection wmiConnection;
              if (mode == "sa")
              {
            //get local machine memory usage information.
            wmiConnection = new Connection();
            memUsagepList.setType("server");
            Dictionary<string, string> memoryUsed = getProcessMemoryUsage(wmiConnection);
            string value = string.Empty;
            memoryUsed.TryGetValue(memUsagepList.derby, out value);
            pau.ServerDerby = value;
            memoryUsed.TryGetValue(memUsagepList.jetty, out value);
            pau.ServerJetty = value;
            memoryUsed.TryGetValue(memUsagepList.deamon, out value);
            pau.ServerDeamon = value;
              }
              else
              {
            //get local machine memory usage information.
            wmiConnection = new Connection();
            memUsagepList.setType("client");
            Dictionary<string, string> ClientMemoryUsed = getProcessMemoryUsage(wmiConnection);
            string value = string.Empty;
            ClientMemoryUsed.TryGetValue(memUsagepList.jetty, out value);
            pau.ClientJetty = value;
            ClientMemoryUsed.TryGetValue(memUsagepList.deamon, out value);
            pau.ClientDeamon = value;

            //get remote machine memory usage information.
            wmiConnection = new Connection("CsDataManager10", "CsDataManager!0", "cnshw76k3w1x", "cnshw76k3w1x");
            memUsagepList.setType("server");
            Dictionary<string, string> ServerMemoryUsed = getProcessMemoryUsage(wmiConnection);
            ServerMemoryUsed.TryGetValue(memUsagepList.derby, out value);
            pau.ServerDerby = value;
            ServerMemoryUsed.TryGetValue(memUsagepList.jetty, out value);
            pau.ServerJetty = value;
            ServerMemoryUsed.TryGetValue(memUsagepList.deamon, out value);
            pau.ServerDeamon = value;
              }
              //mUsage.Add(memoryUsed);
              return pau;
        }
 public Win32_Process(Connection WMIConnection)
 {
     this.WMIConnection = WMIConnection;
 }