Ejemplo n.º 1
0
        public void StopService(string serviceTypeName)
        {
            Console.Write("   关闭服务" + serviceTypeName + "..........");
            object obj = this.ServiceTable[serviceTypeName];

            if (obj != null)
            {
                ServiceHost serviceHost = (ServiceHost)obj;
                try
                {
                    serviceHost.Close();
                }
                catch (Exception value)
                {
                    Console.WriteLine(value);
                    return;
                }
                this.ServiceTable.Remove(serviceTypeName);
                CommandColor.SetGreen();
                Console.WriteLine("完成");
                CommandColor.SetWhite();
            }
            else
            {
                CommandColor.SetRed();
                Console.WriteLine("服务不存在");
                CommandColor.SetWhite();
            }
        }
Ejemplo n.º 2
0
 public void StartService(string serviceTypeName)
 {
     Console.Write("   启动服务" + serviceTypeName + "..........");
     if (this.GetServiceState(serviceTypeName))
     {
         CommandColor.SetYellow();
         Console.WriteLine("服务运行中");
         CommandColor.SetWhite();
     }
     else
     {
         int num = serviceTypeName.IndexOf('.', 4);
         if (num == -1)
         {
             CommandColor.SetRed();
             Console.WriteLine("失败");
             Console.WriteLine("服务名称格式错误");
             CommandColor.SetWhite();
         }
         else
         {
             string   str      = serviceTypeName.Substring(0, num);
             Assembly assembly = (Assembly)this.asstable[str + ".dll"];
             if (assembly == null)
             {
                 CommandColor.SetRed();
                 Console.WriteLine("失败");
                 Console.WriteLine("服务程序集不存在");
                 CommandColor.SetWhite();
             }
             else
             {
                 ServiceHost value = null;
                 Type        type  = assembly.GetType(serviceTypeName, true);
                 if (type == null)
                 {
                     CommandColor.SetRed();
                     Console.WriteLine("失败");
                     Console.WriteLine("服务类型不存在");
                     CommandColor.SetWhite();
                 }
                 else
                 {
                     try
                     {
                         value = this.starthostaddvalidation(type);
                     }
                     catch (Exception ex)
                     {
                         CommandColor.SetRed();
                         Console.Write("失败");
                         Console.WriteLine(ex.Message);
                         Console.WriteLine(ex.StackTrace);
                         CommandColor.SetWhite();
                         return;
                     }
                     this.ServiceTable.Add(serviceTypeName, value);
                     CommandColor.SetGreen();
                     Console.WriteLine("完成");
                     CommandColor.SetWhite();
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
        public void LoopCommand()
        {
            Console.WriteLine("查看命令帮助 help ");
            Console.Write("WCF>");
            bool flag = true;

            while (flag)
            {
                string[] strArray = Console.ReadLine().Split(' ');
                switch (strArray[0])
                {
                case "exit":
                    this.wcfmanage.StopAllService();
                    flag = false;
                    break;

                case "help":
                    CommandHelp.showhelp();
                    break;

                case "la":
                    this.ShowAllAss();
                    break;

                case "lapp":
                    this.ListAssService();
                    break;

                case "los":
                    this.ListOpenService();
                    break;

                case "startall":
                    this.wcfmanage.StartAllService();
                    break;

                case "stopall":
                    this.wcfmanage.StopAllService();
                    break;

                case "restart":
                    this.wcfmanage.StopAllService();
                    this.wcfmanage.RefreshApp();
                    this.wcfmanage.StartAllService();
                    break;

                case "rapp":
                    this.wcfmanage.RefreshApp();
                    break;

                case "start":
                    if (strArray.Length == 2)
                    {
                        this.wcfmanage.StartService(strArray[1]);
                        break;
                    }
                    CommandColor.SetRed();
                    Console.WriteLine("必须有参数 ,服务的名称!傻瓜^_^");
                    CommandColor.SetWhite();
                    break;

                case "stop":
                    if (strArray.Length == 2)
                    {
                        this.wcfmanage.StopService(strArray[1]);
                        break;
                    }
                    CommandColor.SetRed();
                    Console.WriteLine("必须有参数 ,服务的名称!傻瓜^_^");
                    CommandColor.SetWhite();
                    break;

                case "cacheinfo":
                    Console.WriteLine("当前缓存个数为" + Service.GetCacheHelp().GetCurrentCount().ToString());
                    break;

                default:
                    Console.WriteLine("命令打错了,笨蛋!^_^");
                    break;
                }
                Console.Write("\n");
                Console.Write("WCF>");
            }
        }