예제 #1
0
 private void ParseListeners()
 {
     if (!(_root["listeners"] is JObject listenerNodes))
     {
         return;
     }
     foreach (var listenerNode in listenerNodes)
     {
         var definition = new ListenerDefinition();
         definition = ParseDefinition(definition, listenerNode.Value);
         _configuration.Listeners.Add(definition.Id, definition);
     }
 }
 public IHttpActionResult Delete([FromBody] ListenerDefinition definition)
 {
     try
     {
         var listener = Management.Server.Listeners.FirstOrDefault(x => x.Endpoint.Equals(definition.Endpoint, StringComparison.InvariantCultureIgnoreCase));
         if (listener == null)
         {
             return(BadRequest("Endpoint not found"));
         }
         Management.Server.RemoveListener(listener);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
 public IHttpActionResult Post([FromBody] ListenerDefinition definition)
 {
     try
     {
         if (Management.Server.Listeners.Any(x => x.Endpoint.Equals(definition.Endpoint, StringComparison.InvariantCultureIgnoreCase)))
         {
             return(BadRequest("Endpoint in use yet"));
         }
         var extension = ExtensionHelper.GetListener(definition.Type);
         if (extension == null)
         {
             return(BadRequest("Listener type not found"));
         }
         var listener = extension.Create();
         listener.Endpoint = definition.Endpoint;
         Management.Server.AddListener(listener);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
예제 #4
0
        private LogDefinition ParseLogDefinition(JObject logNode)
        {
            var definition = new LogDefinition();

            definition = ParseDefinition(definition, logNode, "", "formatter", "listeners", "sinks");

            var formatterNode = logNode["formatter"];

            if (formatterNode != null)
            {
                if (formatterNode.Type == JTokenType.String)
                {
                    definition.FormatterName = formatterNode.Value <string>();
                }
                else
                {
                    var    formatterDefinition = new FormatterDefinition();
                    string name = definition.Id + "_formatter";
                    formatterDefinition = ParseDefinition(formatterDefinition, formatterNode, name);

                    _configuration.Formatters.Add(name, formatterDefinition);
                    definition.FormatterName = name;
                }
            }

            var listenerNodes = logNode["listeners"];

            if (listenerNodes != null)
            {
                foreach (var listenerNode in listenerNodes)
                {
                    if (listenerNode.Type == JTokenType.String)
                    {
                        definition.ListenerNames.Add(formatterNode.Value <string>());
                    }
                    else
                    {
                        var name = definition.Id + "_listener" + DateTime.Now.Ticks;
                        var listenerDefinition = new ListenerDefinition();
                        listenerDefinition = ParseDefinition(listenerDefinition, listenerNode, name);

                        _configuration.Listeners.Add(name, listenerDefinition);
                        definition.ListenerNames.Add(name);
                    }
                }
            }

            var sinkNodes = logNode["sinks"];

            if (sinkNodes != null)
            {
                foreach (var sinkNode in sinkNodes)
                {
                    if (sinkNode.Type == JTokenType.String)
                    {
                    }
                    else
                    {
                        var name           = definition.Id + "_sink" + DateTime.Now.Ticks;
                        var sinkDefinition = new SinkDefinition();
                        sinkDefinition = ParseDefinition(sinkDefinition, sinkNode, name);

                        _configuration.Sinks.Add(name, sinkDefinition);
                        definition.SinkNames.Add(name);
                    }
                }
            }

            return(definition);
        }