コード例 #1
0
ファイル: Main.cs プロジェクト: rvrn22/NCache
        /// <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,-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(m.GetCacheStatistics2(cacheInfo.CacheId), 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
        public void ListCaches()
        {
            ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
            OutputProvider.WriteLine("Licensed to use FREE of cost. Use As-is without support.\n");
            if (Port != -1)
            {
                NCache.Port = Port;
            }
            if (Server != null && !Server.Equals(""))
            {
                NCache.ServerName = Server;
            }

            string getBindIp = string.Empty;


            try
            {
                ICacheServer cacheServer = null;
                try
                {
                    cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                }
                catch (Exception e)
                {
                    OutputProvider.WriteErrorLine("Error: NCache service could not be contacted on server.");
                    return;
                }
                getBindIp = cacheServer.GetBindIP();
                OutputProvider.WriteLine("Listing registered caches on server {0}:{1}\n", getBindIp, NCache.Port);
                if (cacheServer != null)
                {
                    Alachisoft.NCache.Common.Monitoring.ConfiguredCacheInfo[] caches = cacheServer.GetAllConfiguredCaches();


                    if (caches.Length > 0)
                    {
                        if (!Detail)
                        {
                            OutputProvider.WriteLine("{0,-25} {1,-35} {2,-15}", "Cache-Name", "Topology", "Status(PID)");
                            OutputProvider.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 (!Detail)
                                {
                                    PrintCacheInfo(cacheInfo.Topology.ToString(), cacheInfo.CacheId, cacheInfo.IsRunning, cacheInfo.ProcessID);
                                }
                                else
                                {
                                    try
                                    {
                                        PrintDetailedCacheInfo(cacheServer.GetCacheStatistics2(cacheInfo.CacheId), cacheInfo.Topology.ToString(), null, cacheInfo.IsRunning, cacheInfo.CacheId, cacheInfo.CachePropString, cacheInfo.ProcessID.ToString());
                                    }
                                    catch (Exception e)
                                    {
                                        if (e.Message != null && e.Message.Contains("No connection could be made because the target machine actively refused it"))
                                        {
                                            PrintDetailedCacheInfo(null, cacheInfo.Topology.ToString(), null, false, cacheInfo.CacheId, cacheInfo.CachePropString, "0");
                                        }
                                        else
                                        {
                                            OutputProvider.WriteErrorLine("Error: {0}", e.Message);
                                            OutputProvider.WriteErrorLine(e.ToString());
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        OutputProvider.WriteLine("There are no registered caches on {0}", NCache.ServerName);
                    }
                }
            }
            catch (Exception e)
            {
                OutputProvider.WriteErrorLine("Error: {0}", e.Message);
                OutputProvider.WriteErrorLine(e.ToString());
            }
            finally
            {
                NCache.Dispose();
            }
            OutputProvider.WriteLine((Detail)?"": Environment.NewLine);
        }
コード例 #3
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();
            }
        }