Esempio n. 1
0
        public IActionResult Add(Server model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            Repository.Add(model);
            var    sbServerIP = ShellHelper.GetServerIPV4();
            var    stServerId = model.Id;
            Action runCommand = () =>
            {
                var    client        = new SshClient(model.IP, "root", model.RootPassword);
                string installScript = System.IO.File.ReadAllText("InstallScripts/Server");
                installScript = string.Format(installScript, sbServerIP, stServerId);
                try
                {
                    client.Connect();
                    client.RunCommand(installScript);
                }
                finally
                {
                    client.Disconnect();
                    client.Dispose();
                }
            };

            ThreadPool.QueueUserWorkItem(x => runCommand());
            return(RedirectToAction(nameof(Details), new { id = model.Id }));
        }