Ejemplo n.º 1
0
        private static List <Service> LoadServices(ServiceInfo serviceInfo)
        {
            var retVal = new List <Service>();

            foreach ((string name, Dictionary <string, string> parms)s in serviceInfo.LocalServices)
            {
                string  serviceName = s.name.Split('.')[0];
                Service aux         = retVal.SingleOrDefault(x => x.Name == serviceName);
                if (aux == null)
                {
                    aux         = new Service();
                    aux.Actions = new Dictionary <string, Service.Action>();
                    aux.Name    = serviceName;
                    retVal.Add(aux);
                    aux.Settings = new object();
                    aux.Metadata = new object();
                }
                Service.Action action = new Service.Action();
                action.Name              = s.name;
                action.Cache             = false;
                action.Metric            = new Service.Action.Metrics();
                action.Params            = s.parms;
                aux.Actions[action.Name] = action;
            }
            return(retVal);
        }
Ejemplo n.º 2
0
        public static InfoMessage Parse(byte[] data)
        {
            JObject     obj    = JObject.Parse(Encoding.Default.GetString(data));
            InfoMessage retVal = new InfoMessage();
            JObject     client = (JObject)obj["client"];

            retVal.Client = new Dictionary <string, string>();
            foreach (var x in client.Properties())
            {
                retVal.Client[x.Name] = (string)x.Value;
            }
            retVal.HostName = (string)obj["hostname"];
            retVal.IPList   = new IPAddress[obj["ipList"].Count()];
            for (int x = 0; x < retVal.IPList.Length; x++)
            {
                retVal.IPList[x] = IPAddress.Parse((string)obj["ipList"][x]);
            }
            retVal.Sender   = (string)obj["sender"];
            retVal.Services = new List <Service>();
            foreach (JObject serviceElement in obj["services"])
            {
                Service serv = new Service();
                serv.Actions = new Dictionary <string, Service.Action>();
                foreach (var actionElement in ((JObject)serviceElement["actions"]).Properties())
                {
                    Service.Action act = new Service.Action();
                    act.Cache         = (bool)actionElement.Value["cache"];
                    act.Metric        = new Service.Action.Metrics();
                    act.Metric.Meta   = (bool)actionElement.Value["metrics"]["meta"];
                    act.Metric.Params = (bool)actionElement.Value["metrics"]["params"];
                    act.Name          = actionElement.Name;
                    act.Params        = new Dictionary <string, string>();
                    if (actionElement.Value["params"] != null)
                    {
                        foreach (var paramElement in ((JObject)actionElement.Value["params"]).Properties())
                        {
                            act.Params[paramElement.Name] = paramElement.Value.HasValues ? (string)paramElement.Value["type"] : (string)paramElement.Value;
                        }
                    }

                    serv.Actions[actionElement.Name] = act;
                }
                serv.Metadata = null;
                serv.Name     = (string)serviceElement["name"];
                serv.Settings = null;
                retVal.Services.Add(serv);
            }
            retVal.Ver = (string)obj["ver"];

            return(retVal);
        }