示例#1
0
        /// <summary>
        /// Sets the application level parameters to those specified at the command line.
        /// </summary>
        /// <param name="args">array of command line parameters</param>


        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        static public void Run(string[] args)
        {
            object param = new ListCachesParam();

            CommandLineArgumentParser.CommandLineParser(ref param, args);
            cParam = (ListCachesParam)param;
            AssemblyUsage.PrintLogo(cParam.IsLogo);



            if (cParam.IsUsage)
            {
                AssemblyUsage.PrintUsage();
                return;
            }

            if (!cParam.Detail && string.IsNullOrEmpty(cParam.Server) && args.Length != 0 && cParam.Port == -1 && cParam.IsUsage)
            {
                AssemblyUsage.PrintUsage();
                return;
            }


            if (cParam.Port != -1)
            {
                NCache.Port = cParam.Port;
            }
            if (cParam.Server != null && !cParam.Server.Equals(""))
            {
                NCache.ServerName = cParam.Server;
            }

            string getBindIp = string.Empty;



            try
            {
                ICacheServer m = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                getBindIp = m.GetBindIP();
                Console.WriteLine("Listing registered caches on server {0}:{1}\n", getBindIp, NCache.Port);

                if (m != null)
                {
                    Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo[] caches = m.GetAllConfiguredCaches();
                    Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo[] partitionedReplicaCaches = m.GetConfiguredPartitionedReplicaCaches();// PartitionedReplicaCaches;

                    if (caches.Length > 0 || partitionedReplicaCaches.Length > 0)
                    {
                        if (!cParam.Detail)
                        {
                            Console.WriteLine("{0,-20} {1,-15} {2,-30} {3,-5}", "Cache-ID", "Partition Id", "Scheme", "Status");
                            Console.WriteLine("{0,-20} {1,-15} {2,-30} {3,-5}", "--------", "------------", "------", "------");
                        }

                        if (caches.Length > 0)
                        {
                            for (int i = 0; i < caches.Length; i++)
                            {
                                Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo cacheInfo = caches[i];
                                if (!cParam.Detail)
                                {
                                    PrintCacheInfo(m.GetCacheStatistics2(cacheInfo.CacheId), "N/A", cacheInfo.CacheId, cacheInfo.IsRunning);
                                }
                                else
                                {
                                    PrintDetailedCacheInfo(m.GetCacheStatistics2(cacheInfo.CacheId), null, cParam.PrintConf, cParam.XmlSyntax, cacheInfo.IsRunning, cacheInfo.CacheId, cacheInfo.CachePropString);
                                }
                            }
                        }

                        if (partitionedReplicaCaches.Length > 0)
                        {
                            IEnumerator ide = partitionedReplicaCaches.GetEnumerator();
                            while (ide.MoveNext())
                            {
                                Hashtable cacheTbl = ide.Current as Hashtable;
                                if (cacheTbl != null)
                                {
                                    IDictionaryEnumerator e = cacheTbl.GetEnumerator();
                                    while (e.MoveNext())
                                    {
                                        string partId = e.Key as string;
                                        Cache  cache  = (Cache)e.Value;
                                        if (!detailed)
                                        {
                                            PrintCacheInfo(cache, partId);
                                        }
                                        else
                                        {
                                            PrintDetailedCacheInfo(cache, partId, printConf, xmlSyntax);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("There are no registered caches on {0}", NCache.ServerName);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: {0}", e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
            }
            finally
            {
                NCache.Dispose();
            }
        }
示例#2
0
        /// <summary>
        /// Sets the application level parameters to those specified at the command line.
        /// </summary>
        /// <param name="args">array of command line parameters</param>


        /// <summary>
        /// The main entry point for the tool.
        /// </summary>
        static public void Run(string[] args)
        {
            object param = new ListCachesParam();

            CommandLineArgumentParser.CommandLineParser(ref param, args);
            cParam = (ListCachesParam)param;
            AssemblyUsage.PrintLogo(cParam.IsLogo);



            if (cParam.IsUsage)
            {
                AssemblyUsage.PrintUsage();
                return;
            }

            if (!cParam.Detail && string.IsNullOrEmpty(cParam.Server) && args.Length != 0 && cParam.Port == -1 && cParam.IsUsage)
            {
                AssemblyUsage.PrintUsage();
                return;
            }


            if (cParam.Port != -1)
            {
                NCache.Port = cParam.Port;
            }
            if (cParam.Server != null && !cParam.Server.Equals(""))
            {
                NCache.ServerName = cParam.Server;
            }

            string getBindIp = string.Empty;



            try
            {
                ICacheServer m = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                getBindIp = m.GetBindIP();
                Console.WriteLine("Listing registered caches on server {0}:{1}\n", getBindIp, NCache.Port);

                if (m != null)
                {
                    Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo[] caches = m.GetAllConfiguredCaches();

                    if (caches.Length > 0)
                    {
                        if (!cParam.Detail)
                        {
                            Console.WriteLine("{0,-25} {1,-35} {2,-15}", "Cache-Name", "Scheme", "Status");
                            Console.WriteLine("{0,-25} {1,-35} {2,-15}", "----------", "------", "------");
                        }

                        if (caches.Length > 0)
                        {
                            for (int i = 0; i < caches.Length; i++)
                            {
                                Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo cacheInfo = caches[i];
                                if (!cParam.Detail)
                                {
                                    PrintCacheInfo(cacheInfo.Topology.ToString(), cacheInfo.CacheId, cacheInfo.IsRunning, cacheInfo.ProcessID);
                                }
                                else
                                {
                                    PrintDetailedCacheInfo(m.GetCacheStatistics2(cacheInfo.CacheId), cacheInfo.Topology.ToString(), null, cacheInfo.IsRunning, cacheInfo.CacheId, cacheInfo.CachePropString, cacheInfo.ProcessID.ToString());
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("There are no registered caches on {0}", NCache.ServerName);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: {0}", e.Message);
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
            }
            finally
            {
                NCache.Dispose();
            }
        }