コード例 #1
0
 /// <summary>
 /// 命令转为JSON
 /// </summary>
 /// <param name="rct"></param>
 /// <param name="rctna"></param>
 /// <returns></returns>
 public static string CmdToString(RunCmdType rct = null, RunCmdTypeNoArg rctna = null)
 {
     if (rct != null)
     {
         return(JsonConvert.SerializeObject(rct));
     }
     else if (rctna != null)
     {
         return(JsonConvert.SerializeObject(rctna));
     }
     return("");
 }
コード例 #2
0
        /// <summary>
        /// 获取所有服务的状态
        /// 只可使用与Windows
        /// </summary>
        /// <param name="rct"></param>
        /// <returns></returns>
        public static Dictionary <string, Dictionary <string, bool> > WindowsServicesStatusGet(RunCmdTypeNoArg rct = null)
        {
            try
            {
                // minion名称 <服务名称,状态>
                Dictionary <string, Dictionary <string, bool> > list = new Dictionary <string, Dictionary <string, bool> >();
                if (rct == null)
                {
                    rct = new RunCmdTypeNoArg();
                }
                rct.tgt       = "os:Windows";
                rct.expr_form = "grain";
                rct.client    = "local";
                rct.fun       = "service.get_enabled";
                var enableServiceList = JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(CmdRunString(RunCmdTypeNoArgToString(rct)));
                rct.fun = "service.get_disabled";
                var disableServiceList = JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(CmdRunString(RunCmdTypeNoArgToString(rct)));

                foreach (var minionName in enableServiceList)
                {
                    Dictionary <string, bool> temp = new Dictionary <string, bool>();
                    // 处于启用状态的服务
                    foreach (var item in minionName.Value)
                    {
                        temp.Add(item, true);
                    }
                    // 处于禁用状态的服务
                    foreach (var item in disableServiceList[minionName.Key])
                    {
                        temp.Add(item, false);
                    }

                    list.Add(minionName.Key, temp);
                }
                return(list);
            }
            catch
            {
                return(null);
            }
        }
コード例 #3
0
 /// <summary>
 /// 命令转为JSON
 /// </summary>
 /// <param name="rctna"></param>
 /// <returns></returns>
 public static string RunCmdTypeNoArgToString(RunCmdTypeNoArg rctna)
 {
     return(CmdToString(null, rctna));
 }