// POST api/Control
        public dynamic Post(NmcConfigJson value)
        {
            if (!string.IsNullOrWhiteSpace(value.User)) Properties.Settings.Default.RpcUsername = value.User;
            if (!string.IsNullOrWhiteSpace(value.Pass)) Properties.Settings.Default.RpcPassword = value.Pass;
            if (!string.IsNullOrWhiteSpace(value.Port))
            {
                ushort port;
                if (ushort.TryParse(value.Port, out port))
                    Properties.Settings.Default.RpcPort = port;
            }
            if (!string.IsNullOrWhiteSpace(value.Logging))
            {
                bool logging;
                if (bool.TryParse(value.Logging, out logging))
                {
                    if (Program.LoggingEnabled != logging)
                    {
                        if (!logging)
                            Console.WriteLine("Logging disabled by Api command.");
                        Program.LoggingEnabled = logging;
                        if (logging)
                            Console.WriteLine("Logging enabled by Api command.");
                    }

                }
            }
            return new { status = "ok" };
        }
Exemplo n.º 2
0
        public async void SendConfig(NmcConfigJson config)
        {
            using (var client = new HttpClient())
            {
                client.Timeout = TimeSpan.FromMilliseconds(3000);
                var cts = new System.Threading.CancellationTokenSource();

                HttpResponseMessage response = null;
                try
                {
                    HttpRequestMessage request = new HttpRequestMessage();

                    string      json    = Newtonsoft.Json.JsonConvert.SerializeObject(config);
                    HttpContent content = new StringContent(json);
                    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    response = await client.PostAsync("http://localhost:" + Port + "/api/control", content, cts.Token);
                }
                catch { }
            }
        }
Exemplo n.º 3
0
 // POST api/Control
 public dynamic Post(NmcConfigJson value)
 {
     if (!string.IsNullOrWhiteSpace(value.User))
     {
         Properties.Settings.Default.RpcUsername = value.User;
     }
     if (!string.IsNullOrWhiteSpace(value.Pass))
     {
         Properties.Settings.Default.RpcPassword = value.Pass;
     }
     if (!string.IsNullOrWhiteSpace(value.Port))
     {
         ushort port;
         if (ushort.TryParse(value.Port, out port))
         {
             Properties.Settings.Default.RpcPort = port;
         }
     }
     if (!string.IsNullOrWhiteSpace(value.Logging))
     {
         bool logging;
         if (bool.TryParse(value.Logging, out logging))
         {
             if (Program.LoggingEnabled != logging)
             {
                 if (!logging)
                 {
                     Console.WriteLine("Logging disabled by Api command.");
                 }
                 Program.LoggingEnabled = logging;
                 if (logging)
                 {
                     Console.WriteLine("Logging enabled by Api command.");
                 }
             }
         }
     }
     return(new { status = "ok" });
 }
Exemplo n.º 4
0
 private void SendConfig(NmcConfigJson config)
 {
     apiClient.SendConfig(config);
 }