public object Create(object parent, object configContext, XmlNode section) { XmlSerializer ser = new XmlSerializer(typeof(MinecraftConfig)); MinecraftConfig config = null; using (XmlNodeReader reader = new XmlNodeReader(section)) { config = ser.Deserialize(reader) as MinecraftConfig; reader.Close(); } return(config); }
protected override void OnStart(string[] args) { _log = LogManager.GetLogger(this.GetType()); _isStopping = false; try { _log.Info("Starting minecraft"); MinecraftConfig config = ConfigurationManager.GetSection( typeof(MinecraftConfig).Name) as MinecraftConfig; Process startCmd = new Process(); startCmd.StartInfo.FileName = config.JavaExecutable; startCmd.StartInfo.Arguments = string.Format("-Xmx{0}M -Xms{1}M -jar {2}\\minecraft_server.jar nogui", config.MaxHeapInMegabytes, config.InitialHeapInMegabytes, config.MinecraftJarDirectory); startCmd.StartInfo.WorkingDirectory = config.MinecraftJarDirectory; startCmd.StartInfo.UseShellExecute = false; startCmd.StartInfo.RedirectStandardInput = true; startCmd.StartInfo.RedirectStandardOutput = true; startCmd.StartInfo.RedirectStandardError = true; startCmd.EnableRaisingEvents = true; startCmd.OutputDataReceived += new DataReceivedEventHandler(startCmd_OutputDataReceived); startCmd.ErrorDataReceived += new DataReceivedEventHandler(startCmd_ErrorDataReceived); startCmd.Exited += new EventHandler(startCmd_Exited); _log.InfoFormat("Executing '{0} {1}'", startCmd.StartInfo.FileName, startCmd.StartInfo.Arguments); startCmd.Start(); startCmd.BeginOutputReadLine(); startCmd.BeginErrorReadLine(); _standardInput = startCmd.StandardInput; } catch (Exception ex) { _log.Fatal("Failed to start minecraft", ex); } }