private void btnCreateSite_Click(object sender, RoutedEventArgs e) { ErrorMessage.Visibility = Visibility.Hidden; try { if (String.IsNullOrEmpty(this.txtSiteName.Text)) { throw new Exception("Site Name must Not be empty"); } if (String.IsNullOrEmpty(this.txtWebLocation.Text)) { throw new Exception("Location must Not be empty"); } if (String.IsNullOrEmpty(this.txtPort.Text) || ((Int32.Parse(this.txtPort.Text) > 65535))) { throw new Exception("Port number is not valid it should be in range 0-65535"); } List <string> commandStringList = new List <string>(); CommandParser cmdParser = new CommandParser(Environment.CurrentDirectory + "\\commands.json"); Dictionary <string, string[]> CommandsForExecution = new Dictionary <string, string[]>(); CommandsForExecution.Add("NPMInit", new string[] { }); CommandsForExecution.Add("NPMInstallPackage", new string[] { "--save express" }); CommandsForExecution.Add("CmdCreateDirectory", new string[] { "public" }); foreach (var pair in CommandsForExecution) { var com = cmdParser.GetCommand(pair.Key).Generate(pair.Value); commandStringList.Add(com); } System.IO.Directory.CreateDirectory(System.IO.Path.Combine(this.txtWebLocation.Text, this.txtSiteName.Text)); CommandLineManager mgr = new CommandLineManager(System.IO.Path.Combine(this.txtWebLocation.Text, this.txtSiteName.Text)); mgr.Commands = commandStringList; mgr.Run(); //Create QuickStart Scripts var moduleDir = System.IO.Path.Combine(this.txtWebLocation.Text, this.txtSiteName.Text, "nsm-server-config"); Directory.CreateDirectory(moduleDir); var packConfigContent = @"{ ""name"":""nsm-server-config"", ""description"":""Server Configuration NSM"", ""version"":""1.0.0"", ""main"":""index.js"" }"; System.IO.File.WriteAllText(System.IO.Path.Combine(moduleDir, "index.js"), String.Format("module.exports.portNumber = {0}", this.txtPort.Text)); System.IO.File.WriteAllText(System.IO.Path.Combine(moduleDir, "package.json"), packConfigContent); if (this.cmbWebServer.Text.ToLower() == "express") { File.Copy(System.IO.Path.Combine(Environment.CurrentDirectory, "QuickStartScripts\\Express.js"), System.IO.Path.Combine(this.txtWebLocation.Text, this.txtSiteName.Text, "server.js")); } App.siteManager.CreateSite(new Site { SiteId = Guid.NewGuid().ToString(), SiteName = this.txtSiteName.Text, SiteLocation = txtWebLocation.Text, SitePort = Int32.Parse(txtPort.Text), Extensions = new List <string>() }); App.siteManager.Save(); ((MainWindow)System.Windows.Application.Current.MainWindow).NavigationFrame.Navigate(new Home()); OnSitesUpdated(new EventArgs()); } catch (Exception ex) { ErrorMessage.Visibility = Visibility.Visible; ErrorMessage.Content = ex.Message; } }