예제 #1
0
        static public Hashtable DiscoverCachesViaWMI()
        {
            ServiceController sc = new ServiceController("Winmgmt");

            runningcaches = new Hashtable();
            if (sc.Status == ServiceControllerStatus.Running)
            {
                try
                {
                    foreach (Process process in processes)
                    {
                        string   cmdLine = GetCommandLine(process);
                        string[] tmp     = cmdLine.Split(' ');
                        if (tmp != null && tmp.Length > 0)
                        {
                            object param = new CacheHostParam();
                            SeperateHostArgumentParser.CommandLineParser(ref param, tmp);
                            CacheHostParam cParam    = (CacheHostParam)param;
                            CacheHostInfo  cacheInfo = null;
                            if (!runningcaches.ContainsKey(cParam.CacheName.ToLower()))
                            {
                                cacheInfo                = new CacheHostInfo();
                                cacheInfo.ProcessId      = process.Id;
                                cacheInfo.ManagementPort = cParam.ManagementPort;
                                runningcaches.Add(cParam.CacheName.ToLower(), cacheInfo);
                            }
                            else
                            {
                                cacheInfo                = runningcaches[cParam.CacheName.ToLower()] as CacheHostInfo;
                                cacheInfo.ProcessId      = process.Id;
                                cacheInfo.ManagementPort = cParam.ManagementPort;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(runningcaches);
                }
                return(runningcaches);
            }
            else
            {
                return(runningcaches);
            }
        }
예제 #2
0
        public static Hashtable DiscoverCachesViaPGrep()
        {
            runningcaches = new Hashtable();
#if NETCORE
            string result = "pgrep -af dotnet.*Alachisoft.NCache.CacheHost.dll".Bash();
            foreach (string line in result.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None))
            {
                if (!String.IsNullOrEmpty(line))
                {
                    string[] tokens    = Regex.Split(line, "\\s+");
                    string   cachename = "";
                    int      cacheport = 0;
                    int      pid       = 0;
                    if (int.TryParse(tokens[0], out pid))
                    {
                        for (int i = 0; i < 6; i++)
                        {
                            if (tokens[i] == "/i")
                            {
                                cachename = tokens[i + 1];
                            }
                            else if (tokens[i] == "/p")
                            {
                                int.TryParse(tokens[i + 1], out cacheport);
                            }
                        }

                        CacheHostInfo info = new CacheHostInfo();
                        info.ProcessId      = pid;
                        info.ManagementPort = cacheport;
                        runningcaches.Add(cachename, info);
                        if (runningcaches.Count == processes.Length)
                        {
                            break;
                        }
                    }
                }
            }
#endif
            return(runningcaches);
        }