static int Main(string[] raw) { ArgumentList args = new ArgumentList(raw); List <string> input = new List <string>(args.Unnamed); if (args.Contains("nologo") == false) { Console.WriteLine("StampCopyright.exe"); Console.WriteLine("Copyright 2009-{0:yyyy} by Roger Knapp, Licensed under the Apache License, Version 2.0", DateTime.Now); Console.WriteLine(""); } if ((args.Count == 0 && args.Unnamed.Count == 0) || args.Contains("?") || args.Contains("help")) { return(DoHelp()); } try { args.TryGetValue("svn", out _subversion); Log.ConsoleLevel = System.Diagnostics.TraceLevel.Warning; _changes = 0; _copyText = File.ReadAllText(input[0]).Trim(); _copyText = _copyText.Replace("YEAR", DateTime.Now.Year.ToString()); _copyText = _copyText.Replace("yyyy", DateTime.Now.Year.ToString()); input.RemoveAt(0); ProjectVisitor visitor = new ProjectVisitor(false, input.ToArray()); visitor.VisitProjectItems(VisitProjectItem); } catch (ApplicationException ae) { Log.Error(ae); Console.Error.WriteLine(); Console.Error.WriteLine(ae.Message); Environment.ExitCode = -1; } catch (Exception e) { Log.Error(e); Console.Error.WriteLine(); Console.Error.WriteLine(e.ToString()); Environment.ExitCode = -1; } if (args.Contains("wait")) { Console.WriteLine(); Console.WriteLine("Press [Enter] to continue..."); Console.ReadLine(); } return(Environment.ExitCode); }
static int Main(string[] raw) { ArgumentList args = new ArgumentList(raw); List<string> input = new List<string>(args.Unnamed); if (args.Contains("nologo") == false) { Console.WriteLine("StampCopyright.exe"); Console.WriteLine("Copyright 2009-{0:yyyy} by Roger Knapp, Licensed under the Apache License, Version 2.0", DateTime.Now); Console.WriteLine(""); } if ((args.Count == 0 && args.Unnamed.Count == 0) || args.Contains("?") || args.Contains("help")) return DoHelp(); try { args.TryGetValue("svn", out _subversion); Log.ConsoleLevel = System.Diagnostics.TraceLevel.Warning; _changes = 0; _copyText = File.ReadAllText(input[0]).Trim(); _copyText = _copyText.Replace("YEAR", DateTime.Now.Year.ToString()); _copyText = _copyText.Replace("yyyy", DateTime.Now.Year.ToString()); input.RemoveAt(0); ProjectVisitor visitor = new ProjectVisitor(false, input.ToArray()); visitor.VisitProjectItems(VisitProjectItem); } catch (ApplicationException ae) { Log.Error(ae); Console.Error.WriteLine(); Console.Error.WriteLine(ae.Message); Environment.ExitCode = -1; } catch (Exception e) { Log.Error(e); Console.Error.WriteLine(); Console.Error.WriteLine(e.ToString()); Environment.ExitCode = -1; } if (args.Contains("wait")) { Console.WriteLine(); Console.WriteLine("Press [Enter] to continue..."); Console.ReadLine(); } return Environment.ExitCode; }
public void autoSave() { bool firstrun = true; DateTime lastsave = new DateTime(); ISender console = new ConsoleSender(); List <string> empty = new List <string>(); ArgumentList arguments = new ArgumentList(); while (isEnabled) { if (autosaveenabled) { if (!firstrun && (DateTime.UtcNow > lastsave.AddMinutes(autosaveinterval))) { if (!arguments.Contains("automap")) { arguments.Add("automap"); } MapCommand(console, arguments); lastsave = DateTime.UtcNow; } if (firstrun) { firstrun = false; lastsave = DateTime.UtcNow; } } Thread.Sleep(1000); } }
public virtual void Run(ICommandInterpreter interpreter, string[] arguments) { ArgumentList args = new ArgumentList(arguments); if (args.Count == 1 && args.Contains("?")) { Help(); return; } //translate ordinal referenced names Argument last = null; for (int i = 0; i < _arguments.Length && args.Unnamed.Count > 0; i++) { if (_arguments[i].Type == typeof (ICommandInterpreter)) break; last = _arguments[i]; args.Add(last.DisplayName, args.Unnamed[0]); args.Unnamed.RemoveAt(0); } if (last != null && args.Unnamed.Count > 0 && last.Type.IsArray) { for (int i = 0; i < _arguments.Length && args.Unnamed.Count > 0; i++) { args.Add(last.DisplayName, args.Unnamed[0]); args.Unnamed.RemoveAt(0); } } List<object> invokeArgs = new List<object>(); foreach (Argument arg in _arguments) { object argValue = arg.GetArgumentValue(interpreter, args, arguments); invokeArgs.Add(argValue); } //make sure we actually used all arguments. List<string> names = new List<string>(args.Keys); InterpreterException.Assert(names.Count == 0, "Unknown argument(s): {0}", String.Join(", ", names.ToArray())); InterpreterException.Assert(args.Unnamed.Count == 0, "Too many arguments supplied."); Invoke(Method, Target, invokeArgs.ToArray()); }
public void TestUnnamed() { ArgumentList args = new ArgumentList("some", "/thing", "else"); Assert.AreEqual(2, args.Unnamed.Count); Assert.AreEqual(1, args.Count); Assert.IsTrue(args.Contains("thing")); Assert.AreEqual("some", args.Unnamed[0]); Assert.AreEqual("else", args.Unnamed[1]); args.Unnamed.RemoveAt(0); Assert.AreEqual(1, args.Unnamed.Count); Assert.AreEqual("else", args.Unnamed[0]); args.Clear(); Assert.AreEqual(0, args.Count); Assert.AreEqual(1, args.Unnamed.Count); args.Unnamed.Clear(); Assert.AreEqual(0, args.Unnamed.Count); }
static int Main(string[] raw) { ArgumentList args = new ArgumentList(raw); using (DisposingList dispose = new DisposingList()) using (Log.AppStart(Environment.CommandLine)) { if (args.Contains("nologo") == false) { Console.WriteLine("XhtmlValidate.exe"); Console.WriteLine("Copyright 2010 by Roger Knapp, Licensed under the Apache License, Version 2.0"); Console.WriteLine(""); } if ((args.Unnamed.Count == 0) || args.Contains("?") || args.Contains("help")) return DoHelp(); try { FileList files = new FileList(); files.RecurseFolders = true; foreach (string spec in args.Unnamed) { Uri uri; if (Uri.TryCreate(spec, UriKind.Absolute, out uri) && !(uri.IsFile || uri.IsUnc)) { using(WebClient wc = new WebClient()) { TempFile tfile = new TempFile(); dispose.Add(tfile); wc.DownloadFile(uri, tfile.TempPath); files.Add(tfile.Info); } } else files.Add(spec); } if( files.Count == 0 ) return 1 + DoHelp(); XhtmlValidation validator = new XhtmlValidation(XhtmlDTDSpecification.Any); foreach (FileInfo f in files) validator.Validate(f.FullName); } catch (ApplicationException ae) { Log.Error(ae); Console.Error.WriteLine(); Console.Error.WriteLine(ae.Message); Environment.ExitCode = -1; } catch (Exception e) { Log.Error(e); Console.Error.WriteLine(); Console.Error.WriteLine(e.ToString()); Environment.ExitCode = -1; } } if (args.Contains("wait")) { Console.WriteLine(); Console.WriteLine("Press [Enter] to continue..."); Console.ReadLine(); } return Environment.ExitCode; }
static int Main(string[] raw) { ArgumentList args = new ArgumentList(raw); using (Log.AppStart(Environment.CommandLine)) { if (args.Contains("nologo") == false) { Console.WriteLine("StampVersion.exe"); Console.WriteLine("Copyright 2009 by Roger Knapp, Licensed under the Apache License, Version 2.0"); Console.WriteLine(""); } if ((args.Unnamed.Count == 0 && args.Count == 0) || args.Contains("?") || args.Contains("help")) return DoHelp(); try { string major = null, minor = null, build = null, revision = null; string version; if(args.TryGetValue("version", out version)) { string[] dotted = version.Split('.'); major = dotted[0]; minor = dotted.Length >= 1 ? dotted[1] : null; build = dotted.Length >= 2 ? dotted[2] : null; revision = dotted.Length >= 3 ? dotted[3] : null; } major = GetNumber("Major", args, major); minor = GetNumber("Minor", args, minor); build = GetNumber("Build", args, build); revision = GetNumber("Revision", args, revision); if (major == null && minor == null && build == null && revision == null) return DoHelp(); string fileversion = args.SafeGet("fileversion"); FileList files = new FileList(@"AssemblyInfo.cs"); Regex versionPattern = new Regex(@"[^a-z,A-Z,0-9](?<Type>AssemblyVersion|AssemblyFileVersion)\s*\(\s*\" + '\"' + @"(?<Version>[0-2]?[0-9]{1,9}\.[0-2]?[0-9]{1,9}(?:(?:\.[0-2]?[0-9]{1,9}(?:(?:\.[0-2]?[0-9]{1,9})|(?:\.\*))?)|(?:\.\*))?)\" + '\"' + @"\s*\)"); foreach (FileInfo file in files.ToArray()) { StringBuilder content = new StringBuilder(); int lastpos = 0; string text = File.ReadAllText(file.FullName); foreach (Match match in versionPattern.Matches(text)) { Group verMatch = match.Groups["Version"]; content.Append(text, lastpos, verMatch.Index - lastpos); lastpos = verMatch.Index + verMatch.Length; string[] parts = verMatch.Value.Split('.'); if( parts.Length < 2 )//regex should prevent us getting here throw new ApplicationException(String.Format("Bad version string: {0} on line {1}", verMatch.Value, content.ToString().Split('\n').Length)); if (parts.Length < 3) parts = new string[] { parts[0], parts[1], "0" }; else if( parts.Length == 3 && parts[2] == "*" ) parts = new string[] { parts[0], parts[1], "0", "*" }; if (parts.Length == 3 && revision != null) parts = new string[] { parts[0], parts[1], parts[2], "0" }; if( build != null && build == "*" ) parts = new string[] { parts[0], parts[1], "*" }; if (major != null && parts.Length > 0) parts[0] = major; if (minor != null && parts.Length > 1) parts[1] = minor; if (build != null && parts.Length > 2) parts[2] = build; if (revision != null && parts.Length > 3) parts[3] = revision; //AssemblyFileVersion doesn't use '*', so trim off the build and/or revision if (match.Groups["Type"].Value == "AssemblyFileVersion") { if (parts.Length >= 4 && parts[3] == "*") parts = new string[] { parts[0], parts[1], parts[2] }; if (parts.Length >= 3 && parts[2] == "*") parts = new string[] { parts[0], parts[1] }; if (!String.IsNullOrEmpty(fileversion)) { parts = fileversion.Split('.'); } } string newVersion = String.Join(".", parts); //Console.WriteLine("Changed '{0}' to '{1}'", verMatch.Value, newVersion); content.Append(newVersion); } content.Append(text, lastpos, text.Length - lastpos); if ((file.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) file.Attributes = file.Attributes & ~FileAttributes.ReadOnly; File.WriteAllText(file.FullName, content.ToString()); } } catch (ApplicationException ae) { Log.Error(ae); Console.Error.WriteLine(); Console.Error.WriteLine(ae.Message); Environment.ExitCode = -1; } catch (Exception e) { Log.Error(e); Console.Error.WriteLine(); Console.Error.WriteLine(e.ToString()); Environment.ExitCode = -1; } } if (args.Contains("wait")) { Console.WriteLine(); Console.WriteLine("Press [Enter] to continue..."); Console.ReadLine(); } return Environment.ExitCode; }
void MapCommand(ISender sender, ArgumentList argz) { bool autosave = false; if (argz.Contains("automap")) { autosave = true; argz.Remove("automap"); } try { if (isMapping) { throw new CommandError("Still currently mapping."); } p = mapoutputpath; filename = "world-now.png"; var timestamp = false; var reload = false; var highlight = false; string nameOrID = ""; var savefromcommand = false; string cs = colorscheme; var autosaveedit = false; var options = new OptionSet() { { "t|timestamp", v => timestamp = true }, { "n|name=", v => filename = v }, { "L|reload", v => reload = true }, { "s|save", v => savefromcommand = true }, { "p|path=", v => p = v }, { "h|highlight=", v => { nameOrID = v; highlight = true; } }, { "c|colorscheme=", v => cs = v }, { "a|autosave", v => autosaveedit = true }, }; var args = options.Parse(argz); if (autosaveedit) { if (autosaveenabled) { properties.setValue("autosave-enabled", "False"); sender.sendMessage("autosave disabled."); } else { properties.setValue("autosave-enabled", "True"); sender.sendMessage("autosave enabled."); } if (highlight) { if (highlightsearch(sender as Player, nameOrID)) { properties.setValue("autosave-highlight", "True"); properties.setValue("autosave-highlightID", nameOrID); sender.sendMessage("autosave highlight settings updated."); } } if (timestamp) { if (autosavetimestamp) { properties.setValue("autosave-timestamp", "False"); sender.sendMessage("autosave now using regular name."); } else { properties.setValue("autosave-timestamp", "True"); sender.sendMessage("autosave now using timestamp."); } } if (filename != "world-now.png") { properties.setValue("autosave-filename", filename); } properties.Save(); return; } if (reload || autosave) { sender.sendMessage("map: Reloaded settings database, entries: " + properties.Count); properties.Load(); var msg = string.Concat( "Settings: mapoutputpath=", p, ", ", "colorscheme=", cs); if (!(Directory.Exists(p))) { msg = string.Concat(msg, " (DOESNT EXIST)"); ProgramLog.Error.Log("<map> ERROR: Loaded Directory does not exist."); } if (!autosave) { ProgramLog.Admin.Log("<map> " + msg); } //sender.sendMessage ("map: " + msg); if (!(cs == "MoreTerra" || cs == "Terrafirma")) { ProgramLog.Error.Log("<map> ERROR: please change colorscheme"); } } if (autosave) { p = autosavepath; filename = autosavename; timestamp = autosavetimestamp; if (autosavehighlight) { nameOrID = autosavehightlightID; } } if (timestamp) { DateTime value = DateTime.Now; string time = value.ToString("yyyy-MM-dd_HH-mm-ss"); filename = string.Concat("terraria-", time, ".png"); } if (savefromcommand) { properties.setValue("color-scheme", cs); properties.setValue("mapoutput-path", p); properties.Save(); } // chests are not an item so i draw them from the chest array if (highlight && nameOrID.ToLower() != "chest") { highlightsearch(sender as Player, nameOrID); hlchests = false; } else { if (nameOrID.ToLower() == "chest") //double checking { hlchests = true; } } if (args.Count == 0 && isEnabled) { if (!reload && Directory.Exists(p)) { if (cs == "Terrafirma") { isMapping = true; //for now highlighting is only in terrafirma color scheme MapPlugin.highlight = highlight; Thread imagethread; imagethread = new Thread(mapWorld2); imagethread.Name = "Mapper"; imagethread.Start(); while (!imagethread.IsAlive) { ; } // the thread terminates itself since there is no while loop in mapWorld2 } else if (cs == "MoreTerra") { isMapping = true; Thread imagethread; imagethread = new Thread(mapWorld); imagethread.Name = "Mapper"; imagethread.Start(); while (!imagethread.IsAlive) { ; } // the thread terminates itself since there is no while loop in mapWorld } else { ProgramLog.Error.Log("Save ERROR: check colorscheme"); } if (!(Directory.Exists(p))) { sender.sendMessage("map: " + p + " does not exist."); ProgramLog.Error.Log("<map> ERROR: Loaded Directory does not exist."); } } } else { throw new CommandError(""); } } catch (OptionException) { throw new CommandError(""); } }
static int Main(string[] argsRaw) { int errors = 0; ArgumentList arguments = new ArgumentList(argsRaw); if (!arguments.Contains("nologo")) { Console.WriteLine("{0}", typeof(Program).Assembly); foreach (System.Reflection.AssemblyCopyrightAttribute a in typeof(Program).Assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyCopyrightAttribute), false)) { Console.WriteLine("{0}", a.Copyright); } Console.WriteLine(".NET Runtime Version={0}", System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion()); } if (arguments.Contains("?") || arguments.Contains("help")) { return(ShowHelp(Console.Out)); } Log.Open(TextWriter.Null); Log.ConsoleLevel = arguments.Contains("verbose") ? TraceLevel.Verbose : TraceLevel.Warning; try { CSBuildConfig config = null; if (arguments.Contains("config")) { using (System.Xml.XmlReader rdr = new System.Xml.XmlTextReader(arguments["config"])) config = Config.ReadXml(Config.SCHEMA_NAME, rdr); } else { config = Config.ReadConfig("CSBuildConfig"); } if (config == null) { throw new ApplicationException("Unable to locate configuration section 'CSBuildConfig', and no /config= option was given."); } string logfile = config.Options.LogPath(new Dictionary <string, string>()); if (arguments.Contains("log")) { logfile = Path.GetFullPath(arguments["log"]); } if (logfile != null) { Directory.CreateDirectory(Path.GetDirectoryName(logfile)); Log.Open(TextWriter.Synchronized(new StreamWriter(File.Open(logfile, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Delete)))); if (config.Options.ConsoleEnabled) { Log.ConsoleLevel = arguments.Contains("verbose") ? TraceLevel.Verbose : !arguments.Contains("quiet") ? TraceLevel.Info : TraceLevel.Warning; } } List <string> propertySets = new List <string>(); foreach (BuildProperty p in config.Options.GlobalProperties) { propertySets.Add(String.Format("{0}={1}", p.Name, p.Value)); } if (config.Options.ImportOptionsFile != null) { try { string fpath = config.Options.ImportOptionsFile.AbsolutePath(new Dictionary <string, string>()); propertySets.AddRange(File.ReadAllLines(fpath)); } catch (FileNotFoundException e) { throw new ApplicationException("Unable to locate options file: " + e.FileName, e); } } propertySets.AddRange(arguments.SafeGet("p").Values); propertySets.AddRange(arguments.SafeGet("property").Values); using (Log.AppStart(Environment.CommandLine)) using (Log.Start("Build started {0}", DateTime.Now)) { LoggerVerbosity?verbosity = config.Options.ConsoleLevel; if (arguments.Contains("quiet")) { verbosity = LoggerVerbosity.Quiet; } else if (arguments.Contains("verbose")) { verbosity = LoggerVerbosity.Normal; } else if (arguments.Contains("verbosity")) { verbosity = (LoggerVerbosity)Enum.Parse(typeof(LoggerVerbosity), arguments["verbosity"], true); } string[] targetNames = new List <string>(arguments.Unnamed).ToArray(); using (CmdLineBuilder b = new CmdLineBuilder(config, verbosity, arguments.SafeGet("group"), targetNames, propertySets.ToArray())) { b.Start(); errors += b.Complete(TimeSpan.FromHours(config.Options.TimeoutHours)); } } } catch (ApplicationException ae) { Log.Verbose(ae.ToString()); Log.Error("\r\n{0}", ae.Message); errors += 1; } catch (System.Configuration.ConfigurationException ce) { Log.Verbose(ce.ToString()); Log.Error("\r\nConfiguration Exception: {0}", ce.Message); errors += 1; } catch (Exception e) { Log.Error(e); errors += 1; } if (arguments.Contains("wait")) { Console.WriteLine(); Console.WriteLine("Press [Enter] to continue..."); Console.ReadLine(); } return(errors); }
/// <summary> /// Sets OP status to a given Player. /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> public void OpPlayer(ISender sender, ArgumentList args) { var playerName = args.GetString(0); if (Storage.IsAvailable) { var existing = Authentication.GetPlayer(playerName); if (existing == null && (args.Contains("-c") || args.Contains("-create"))) { var password = args.GetString(1); existing = Authentication.CreatePlayer(playerName, password, true); Utils.NotifyAllOps("Opping " + playerName + " [" + sender.SenderName + "]", true); var player = Tools.GetPlayerByName(playerName); if (player != null) { player.SendMessage("You are now a server operator.", Color.Green); player.SetOp(true); player.SetAuthentication(player.name, "tdsm"); } sender.Message("Op success", Color.DarkGreen); } else if (existing != null) { if (existing.Operator) { throw new CommandError("Player is already an operator"); } if (Authentication.UpdatePlayer(playerName, null, op: true)) { Utils.NotifyAllOps("Opping " + playerName + " [" + sender.SenderName + "]", true); var player = Tools.GetPlayerByName(playerName); if (player != null) { player.SendMessage("You are now a server operator.", Color.Green); player.SetOp(true); player.SetAuthentication(player.name, "tdsm"); } sender.Message("Op success", Color.DarkGreen); } else { sender.Message("Failed to op player", Color.DarkRed); } } else { sender.Message("No user found by " + playerName, Color.DarkRed); sender.Message("Please use the `user` command or add the -create switch", Color.DarkRed); } } else { var password = args.GetString(1); Utils.NotifyAllOps("Opping " + playerName + " [" + sender.SenderName + "]", true); Core.Ops.Add(playerName, password); var player = Tools.GetPlayerByName(playerName); if (player != null) { player.SendMessage("You are now a server operator.", Color.Green); player.SetOp(true); player.SetAuthentication(player.name, "tdsm"); } if (!Core.Ops.Save()) { Utils.NotifyAllOps("Failed to save op list [" + sender.SenderName + "]", true); return; } } }
void MapCommand( ISender sender, ArgumentList argz) { bool autosave = false; if (argz.Contains("automap")) { autosave = true; argz.Remove("automap"); } try { if (isMapping) { throw new CommandError("Still currently mapping."); } p = mapoutputpath; filename = "world-now.png"; var timestamp = false; var reload = false; var highlight = false; string nameOrID = ""; var savefromcommand = false; string cs = colorscheme; var autosaveedit = false; var options = new OptionSet () { { "t|timestamp", v => timestamp = true }, { "n|name=", v => filename = v }, { "L|reload", v => reload = true }, { "s|save", v => savefromcommand = true }, { "p|path=", v => p = v }, { "h|highlight=", v => { nameOrID = v; highlight = true; } }, { "c|colorscheme=", v => cs = v }, { "a|autosave", v => autosaveedit = true }, }; var args = options.Parse (argz); if (autosaveedit) { if (autosaveenabled) { properties.setValue("autosave-enabled", "False"); sender.sendMessage("autosave disabled."); } else { properties.setValue("autosave-enabled", "True"); sender.sendMessage("autosave enabled."); } if (highlight) { if (highlightsearch(sender as Player, nameOrID)) { properties.setValue("autosave-highlight", "True"); properties.setValue("autosave-highlightID", nameOrID); sender.sendMessage("autosave highlight settings updated."); } } if (timestamp) { if (autosavetimestamp) { properties.setValue("autosave-timestamp", "False"); sender.sendMessage("autosave now using regular name."); } else { properties.setValue("autosave-timestamp", "True"); sender.sendMessage("autosave now using timestamp."); } } if (filename != "world-now.png") { properties.setValue("autosave-filename", filename); } properties.Save(); return; } if (reload || autosave) { sender.sendMessage ("map: Reloaded settings database, entries: " + properties.Count); properties.Load (); var msg = string.Concat ( "Settings: mapoutputpath=", p, ", ", "colorscheme=", cs); if ( !(Directory.Exists(p)) ){ msg = string.Concat ( msg , " (DOESNT EXIST)" ); ProgramLog.Error.Log ("<map> ERROR: Loaded Directory does not exist."); } if (!autosave) { ProgramLog.Admin.Log("<map> " + msg); } //sender.sendMessage ("map: " + msg); if ( !(cs=="MoreTerra" || cs=="Terrafirma") ){ ProgramLog.Error.Log ("<map> ERROR: please change colorscheme"); } } if (autosave) { p = autosavepath; filename = autosavename; timestamp = autosavetimestamp; if (autosavehighlight) { nameOrID = autosavehightlightID; } } if (timestamp) { DateTime value = DateTime.Now; string time = value.ToString("yyyy-MM-dd_HH-mm-ss"); filename = string.Concat("terraria-", time, ".png"); } if(savefromcommand){ properties.setValue ("color-scheme", cs); properties.setValue ("mapoutput-path", p); properties.Save(); } // chests are not an item so i draw them from the chest array if (highlight && nameOrID.ToLower() != "chest") { highlightsearch(sender as Player, nameOrID); hlchests = false; } else { if(nameOrID.ToLower() == "chest") //double checking hlchests = true; } if (args.Count == 0 && isEnabled) { if(!reload && Directory.Exists(p)){ if(cs=="Terrafirma"){ isMapping = true; //for now highlighting is only in terrafirma color scheme MapPlugin.highlight = highlight; Thread imagethread; imagethread = new Thread(mapWorld2); imagethread.Name = "Mapper"; imagethread.Start(); while (!imagethread.IsAlive); // the thread terminates itself since there is no while loop in mapWorld2 } else if(cs=="MoreTerra"){ isMapping = true; Thread imagethread; imagethread = new Thread(mapWorld); imagethread.Name = "Mapper"; imagethread.Start(); while (!imagethread.IsAlive); // the thread terminates itself since there is no while loop in mapWorld } else{ ProgramLog.Error.Log ("Save ERROR: check colorscheme"); } if( !(Directory.Exists(p)) ){ sender.sendMessage ("map: "+p+" does not exist."); ProgramLog.Error.Log ("<map> ERROR: Loaded Directory does not exist."); } } } else { throw new CommandError (""); } } catch (OptionException) { throw new CommandError (""); } }
/// <summary> /// Sets OP status to a given Player. /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> public void OpPlayer(ISender sender, ArgumentList args) { var playerName = args.GetString(0); if (Storage.IsAvailable) { var existing = Authentication.GetPlayer(playerName); if (existing == null && (args.Contains("-c") || args.Contains("-create"))) { var password = args.GetString(1); existing = Authentication.CreatePlayer(playerName, password, true); Utils.NotifyAllOps("Opping " + playerName + " [" + sender.SenderName + "]", true); var player = Tools.GetPlayerByName(playerName); if (player != null) { player.SendMessage("You are now a server operator.", Color.Green); player.SetOp(true); player.SetAuthentication(player.name, "tdsm"); } sender.Message("Op success", Color.DarkGreen); } else if (existing != null) { if (existing.Operator) throw new CommandError("Player is already an operator"); if (Authentication.UpdatePlayer(playerName, null, op: true)) { Utils.NotifyAllOps("Opping " + playerName + " [" + sender.SenderName + "]", true); var player = Tools.GetPlayerByName(playerName); if (player != null) { player.SendMessage("You are now a server operator.", Color.Green); player.SetOp(true); player.SetAuthentication(player.name, "tdsm"); } sender.Message("Op success", Color.DarkGreen); } else { sender.Message("Failed to op player", Color.DarkRed); } } else { sender.Message("No user found by " + playerName, Color.DarkRed); sender.Message("Please use the `user` command or add the -create switch", Color.DarkRed); } } else { var password = args.GetString(1); Utils.NotifyAllOps("Opping " + playerName + " [" + sender.SenderName + "]", true); Core.Ops.Add(playerName, password); var player = Tools.GetPlayerByName(playerName); if (player != null) { player.SendMessage("You are now a server operator.", Color.Green); player.SetOp(true); player.SetAuthentication(player.name, "tdsm"); } if (!Core.Ops.Save()) { Utils.NotifyAllOps("Failed to save op list [" + sender.SenderName + "]", true); return; } } }
static int Main(string[] raw) { ArgumentList args = new ArgumentList(raw); using (Log.AppStart(Environment.CommandLine)) { if (args.Count == 0 || args.Unnamed.Count == 0 || args.Contains("?")) { return(DoHelp()); } if (args.Contains("nologo") == false) { Console.WriteLine("CSharpTest.Net.CoverageReport.exe"); Console.WriteLine("Copyright 2009 by Roger Knapp, Licensed under the Apache License, Version 2.0"); Console.WriteLine(""); } try { List <string> filesFound = new List <string>(); FileList files = new FileList(); files.RecurseFolders = args.Contains("s"); files.Add(new List <string>(args.Unnamed).ToArray()); XmlParser parser = new XmlParser(args.SafeGet("exclude").Values); foreach (System.IO.FileInfo file in files) { filesFound.Add(file.FullName); using (Log.Start("parsing file: {0}", file.FullName)) parser.Parse(file.FullName); } parser.Complete(); if (args.Contains("module")) { using (Log.Start("Creating module report.")) using (XmlReport rpt = new XmlReport(OpenText(args["module"]), parser, "Module Summary", filesFound.ToArray())) new MetricReport(parser.ByModule).Write(rpt); } if (args.Contains("namespace")) { using (Log.Start("Creating namespace report.")) using (XmlReport rpt = new XmlReport(OpenText(args["namespace"]), parser, "Namespace Summary", filesFound.ToArray())) new MetricReport(parser.ByNamespace).Write(rpt); } if (args.Contains("class")) { using (Log.Start("Creating class report.")) using (XmlReport rpt = new XmlReport(OpenText(args["class"]), parser, "Module Class Summary", filesFound.ToArray())) new MetricReport(parser.ByModule, parser.ByNamespace, parser.ByClass).Write(rpt); } if (args.Contains("unused")) { using (Log.Start("Creating unused statement report.")) using (UnusedReport rpt = new UnusedReport(OpenText(args["unused"]), parser)) new MetricReport(parser.ByModule, parser.ByMethod).Write(rpt); } if (args.Contains("combine")) { using (Log.Start("Creating combined coverage file.")) using (XmlCoverageWriter wtr = new XmlCoverageWriter(OpenText(args["combine"]), parser)) new MetricReport(parser.ByModule, parser.ByMethod).Write(wtr); } //foreach (ModuleInfo mi in parser) // Console.WriteLine("{0} hit {1} of {2} for {3}", mi.Name, mi.VisitedPoints, mi.SequencePoints, mi.CoveragePercent); } catch (Exception e) { Log.Error(e); Console.Error.WriteLine(); Console.Error.WriteLine("Exception: {0}", e.Message); Console.Error.WriteLine(); Environment.ExitCode = -1; } } if (args.Contains("wait")) { Console.WriteLine("Press [Enter] to continue..."); Console.ReadLine(); } return(Environment.ExitCode); }
static int Main(string[] argsRaw) { int errors = 0; ArgumentList arguments = new ArgumentList(argsRaw); if (!arguments.Contains("nologo")) { Console.WriteLine("{0}", typeof (Program).Assembly); foreach (System.Reflection.AssemblyCopyrightAttribute a in typeof(Program).Assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyCopyrightAttribute), false)) Console.WriteLine("{0}", a.Copyright); Console.WriteLine(".NET Runtime Version={0}", System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion()); } if (arguments.Contains("?") || arguments.Contains("help")) return ShowHelp(Console.Out); Log.Open(TextWriter.Null); Log.ConsoleLevel = arguments.Contains("verbose") ? TraceLevel.Verbose : TraceLevel.Warning; try { CSBuildConfig config = null; if (arguments.Contains("config")) { using (System.Xml.XmlReader rdr = new System.Xml.XmlTextReader(arguments["config"])) config = Config.ReadXml(Config.SCHEMA_NAME, rdr); } else config = Config.ReadConfig("CSBuildConfig"); if (config == null) throw new ApplicationException("Unable to locate configuration section 'CSBuildConfig', and no /config= option was given."); string logfile = config.Options.LogPath(new Dictionary<string, string>()); if (arguments.Contains("log")) logfile = Path.GetFullPath(arguments["log"]); if (logfile != null) { Directory.CreateDirectory(Path.GetDirectoryName(logfile)); Log.Open(TextWriter.Synchronized(new StreamWriter(File.Open(logfile, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Delete)))); if(config.Options.ConsoleEnabled) Log.ConsoleLevel = arguments.Contains("verbose") ? TraceLevel.Verbose : !arguments.Contains("quiet") ? TraceLevel.Info : TraceLevel.Warning; } List<string> propertySets = new List<string>(); foreach (BuildProperty p in config.Options.GlobalProperties) propertySets.Add(String.Format("{0}={1}",p.Name, p.Value)); if (config.Options.ImportOptionsFile != null) { try { string fpath = config.Options.ImportOptionsFile.AbsolutePath(new Dictionary<string, string>()); propertySets.AddRange(File.ReadAllLines(fpath)); } catch(FileNotFoundException e) { throw new ApplicationException("Unable to locate options file: " + e.FileName, e); } } propertySets.AddRange(arguments.SafeGet("p").Values); propertySets.AddRange(arguments.SafeGet("property").Values); using (Log.AppStart(Environment.CommandLine)) using (Log.Start("Build started {0}", DateTime.Now)) { LoggerVerbosity? verbosity = config.Options.ConsoleLevel; if (arguments.Contains("quiet")) verbosity = LoggerVerbosity.Quiet; else if (arguments.Contains("verbose")) verbosity = LoggerVerbosity.Normal; else if (arguments.Contains("verbosity")) verbosity = (LoggerVerbosity)Enum.Parse(typeof(LoggerVerbosity), arguments["verbosity"], true); string[] targetNames = new List<string>(arguments.Unnamed).ToArray(); using (CmdLineBuilder b = new CmdLineBuilder(config, verbosity, arguments.SafeGet("group"), targetNames, propertySets.ToArray())) { b.Start(); errors += b.Complete(TimeSpan.FromHours(config.Options.TimeoutHours)); } } } catch (ApplicationException ae) { Log.Verbose(ae.ToString()); Log.Error("\r\n{0}", ae.Message); errors += 1; } catch (System.Configuration.ConfigurationException ce) { Log.Verbose(ce.ToString()); Log.Error("\r\nConfiguration Exception: {0}", ce.Message); errors += 1; } catch (Exception e) { Log.Error(e); errors += 1; } if (arguments.Contains("wait")) { Console.WriteLine(); Console.WriteLine("Press [Enter] to continue..."); Console.ReadLine(); } return errors; }
/// <summary> /// Checks the state of a slot. /// </summary> /// <param name="server">Current Server instance</param> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> public static void Slots(Server server, ISender sender, ArgumentList args) { bool dinfo = args.Contains("-d") || args.Contains("-dp") || args.Contains("-pd"); bool pinfo = args.Contains("-p") || args.Contains("-dp") || args.Contains("-pd"); int k = 0; for (int i = 0; i < 255; i++) { var slot = Netplay.slots[i]; var player = Main.players[i]; if (slot.state != SlotState.VACANT) { k += 1; var name = ""; if (player != null) { name = string.Concat(", ", player.Op ? "Op. " : "", "\"", (player.Name ?? "<null>"), "\""); if (player.AuthenticatedAs != null) { if (player.Name == player.AuthenticatedAs) name = name + " (auth'd)"; else name = name + " (auth'd as " + player.AuthenticatedAs + ")"; } } var addr = "<secret>"; if (!(sender is Player && player.Op)) addr = slot.remoteAddress; var msg = string.Format("slot {0}: {1}, {2}{3}", i, slot.state, addr, name); if (pinfo && player != null) { msg += string.Format(", {0}/{1}hp", player.statLife, player.statLifeMax); } if (dinfo) { msg += string.Format(", {0}{1}{2}, tx:{3:0.0}K, rx:{4:0.0}K, q:{5}", slot.conn.kicking ? "+" : "-", slot.conn.sending ? "+" : "-", slot.conn.receiving ? "+" : "-", slot.conn.BytesSent / 1024.0, slot.conn.BytesReceived / 1024.0, slot.conn.QueueLength); } sender.sendMessage(msg); } } sender.sendMessage(string.Format("{0}/{1} slots occupied.", k, Main.maxNetplayers)); }
static int Main(string[] raw) { ArgumentList args = new ArgumentList(raw); using (Log.AppStart(Environment.CommandLine)) { if (args.Count == 0 || args.Unnamed.Count == 0 || args.Contains("?")) return DoHelp(); if (args.Contains("nologo") == false) { Console.WriteLine("CSharpTest.Net.CoverageReport.exe"); Console.WriteLine("Copyright 2009 by Roger Knapp, Licensed under the Apache License, Version 2.0"); Console.WriteLine(""); } try { List<string> filesFound = new List<string>(); FileList files = new FileList(); files.RecurseFolders = args.Contains("s"); files.Add(new List<string>(args.Unnamed).ToArray()); XmlParser parser = new XmlParser( args.SafeGet("exclude").Values ); foreach (System.IO.FileInfo file in files) { filesFound.Add(file.FullName); using(Log.Start("parsing file: {0}", file.FullName)) parser.Parse(file.FullName); } parser.Complete(); if (args.Contains("module")) { using (Log.Start("Creating module report.")) using (XmlReport rpt = new XmlReport(OpenText(args["module"]), parser, "Module Summary", filesFound.ToArray())) new MetricReport(parser.ByModule).Write(rpt); } if (args.Contains("namespace")) { using (Log.Start("Creating namespace report.")) using (XmlReport rpt = new XmlReport(OpenText(args["namespace"]), parser, "Namespace Summary", filesFound.ToArray())) new MetricReport(parser.ByNamespace).Write(rpt); } if (args.Contains("class")) { using (Log.Start("Creating class report.")) using (XmlReport rpt = new XmlReport(OpenText(args["class"]), parser, "Module Class Summary", filesFound.ToArray())) new MetricReport(parser.ByModule, parser.ByNamespace, parser.ByClass).Write(rpt); } if (args.Contains("unused")) { using (Log.Start("Creating unused statement report.")) using (UnusedReport rpt = new UnusedReport(OpenText(args["unused"]), parser)) new MetricReport(parser.ByModule, parser.ByMethod).Write(rpt); } if (args.Contains("combine")) { using (Log.Start("Creating combined coverage file.")) using (XmlCoverageWriter wtr = new XmlCoverageWriter(OpenText(args["combine"]), parser)) new MetricReport(parser.ByModule, parser.ByMethod).Write(wtr); } //foreach (ModuleInfo mi in parser) // Console.WriteLine("{0} hit {1} of {2} for {3}", mi.Name, mi.VisitedPoints, mi.SequencePoints, mi.CoveragePercent); } catch (Exception e) { Log.Error(e); Console.Error.WriteLine(); Console.Error.WriteLine("Exception: {0}", e.Message); Console.Error.WriteLine(); Environment.ExitCode = -1; } } if (args.Contains("wait")) { Console.WriteLine("Press [Enter] to continue..."); Console.ReadLine(); } return Environment.ExitCode; }
static int Main(string[] raw) { ArgumentList args = new ArgumentList(raw); using (Log.AppStart(Environment.CommandLine)) { if (args.Contains("nologo") == false) { Console.WriteLine("StampVersion.exe"); Console.WriteLine("Copyright 2009 by Roger Knapp, Licensed under the Apache License, Version 2.0"); Console.WriteLine(""); } if ((args.Unnamed.Count == 0 && args.Count == 0) || args.Contains("?") || args.Contains("help")) { return(DoHelp()); } try { string major = null, minor = null, build = null, revision = null; string version; if (args.TryGetValue("version", out version)) { string[] dotted = version.Split('.'); major = dotted[0]; minor = dotted.Length >= 1 ? dotted[1] : null; build = dotted.Length >= 2 ? dotted[2] : null; revision = dotted.Length >= 3 ? dotted[3] : null; } major = GetNumber("Major", args, major); minor = GetNumber("Minor", args, minor); build = GetNumber("Build", args, build); revision = GetNumber("Revision", args, revision); if (major == null && minor == null && build == null && revision == null) { return(DoHelp()); } FileList files = new FileList(@"AssemblyInfo.cs"); Regex versionPattern = new Regex(@"[^a-z,A-Z,0-9](?<Type>AssemblyVersion|AssemblyFileVersion)\s*\(\s*\" + '\"' + @"(?<Version>[0-2]?[0-9]{1,9}\.[0-2]?[0-9]{1,9}(?:(?:\.[0-2]?[0-9]{1,9}(?:(?:\.[0-2]?[0-9]{1,9})|(?:\.\*))?)|(?:\.\*))?)\" + '\"' + @"\s*\)"); foreach (FileInfo file in files.ToArray()) { StringBuilder content = new StringBuilder(); int lastpos = 0; string text = File.ReadAllText(file.FullName); foreach (Match match in versionPattern.Matches(text)) { Group verMatch = match.Groups["Version"]; content.Append(text, lastpos, verMatch.Index - lastpos); lastpos = verMatch.Index + verMatch.Length; string[] parts = verMatch.Value.Split('.'); if (parts.Length < 2) //regex should prevent us getting here { throw new ApplicationException(String.Format("Bad version string: {0} on line {1}", verMatch.Value, content.ToString().Split('\n').Length)); } if (parts.Length < 3) { parts = new string[] { parts[0], parts[1], "0" } } ; else if (parts.Length == 3 && parts[2] == "*") { parts = new string[] { parts[0], parts[1], "0", "*" } } ; if (parts.Length == 3 && revision != null) { parts = new string[] { parts[0], parts[1], parts[2], "0" } } ; if (build != null && build == "*") { parts = new string[] { parts[0], parts[1], "*" } } ; if (major != null && parts.Length > 0) { parts[0] = major; } if (minor != null && parts.Length > 1) { parts[1] = minor; } if (build != null && parts.Length > 2) { parts[2] = build; } if (revision != null && parts.Length > 3) { parts[3] = revision; } //AssemblyFileVersion doesn't use '*', so trim off the build and/or revision if (match.Groups["Type"].Value == "AssemblyFileVersion") { if (parts.Length >= 4 && parts[3] == "*") { parts = new string[] { parts[0], parts[1], parts[2] } } ; if (parts.Length >= 3 && parts[2] == "*") { parts = new string[] { parts[0], parts[1] } } ; } string newVersion = String.Join(".", parts); //Console.WriteLine("Changed '{0}' to '{1}'", verMatch.Value, newVersion); content.Append(newVersion); } content.Append(text, lastpos, text.Length - lastpos); File.WriteAllText(file.FullName, content.ToString()); } } catch (ApplicationException ae) { Log.Error(ae); Console.Error.WriteLine(); Console.Error.WriteLine(ae.Message); Environment.ExitCode = -1; } catch (Exception e) { Log.Error(e); Console.Error.WriteLine(); Console.Error.WriteLine(e.ToString()); Environment.ExitCode = -1; } } if (args.Contains("wait")) { Console.WriteLine(); Console.WriteLine("Press [Enter] to continue..."); Console.ReadLine(); } return(Environment.ExitCode); }
public void MapCommand(ISender sender, ArgumentList argz) { bool autosave = false; api_call = false; if (argz.Contains("automap")) { autosave = true; argz.Remove("automap"); } if (argz.Contains("api-call")) { api_call = true; //flag so we don't save png file later... we only need the bitmap object. argz.Remove("api-call"); } try { if (isMapping) { throw new CommandError("Still currently mapping."); } p = mapoutputpath; filename = "world-now.png"; var timestamp = false; var reload = false; var highlight = false; highlightID = 0; hlchests = false; string nameOrID = ""; var savefromcommand = false; string cs = colorscheme; var autosaveedit = false; string x1 = ""; string x2 = ""; string y1 = ""; string y2 = ""; crop = false; generate_tiles = false; var options = new OptionSet() { { "t|timestamp", v => timestamp = true }, { "n|name=", v => filename = v }, { "L|reload", v => reload = true }, { "s|save", v => savefromcommand = true }, { "p|path=", v => p = v }, { "h|highlight=", v => { nameOrID = v; highlight = true; } }, { "c|colorscheme=", v => cs = v }, { "a|autosave", v => autosaveedit = true }, { "x1|xA=", v => { x1 = v; crop = true; } }, { "x2|xB=", v => { x2 = v; crop = true; } }, { "y1|yA=", v => { y1 = v; crop = true; } }, { "y2|yB=", v => { y2 = v; crop = true; } }, { "w|web", v => generate_tiles = true }, }; var args = options.Parse(argz); Player player = sender as Player; if (crop) { if (x1.Equals("") || x2.Equals("") || y1.Equals("") || y2.Equals("")) { //we need both coordinates throw new CommandError("If cropping, please specify x1, y1, x2, and y2."); } else { //we need x1,y1 to be the top left corner //and x2,y2 to the bottom right corner bool cornererror = false; int x1num; int x2num; int y1num; int y2num; try { x1num = Convert.ToInt32(x1); x2num = Convert.ToInt32(x2); y1num = Convert.ToInt32(y1); y2num = Convert.ToInt32(y2); //enforce bitmap boundaries if (x1num < 0) { x1num = 0; } if (y1num < 0) { y1num = 0; } if (x2num > Main.maxTilesX) { x2num = Main.maxTilesX; } if (y2num > Main.maxTilesY) { y2num = Main.maxTilesY; } if ((x1num >= x2num) || (y1num >= y2num)) { cornererror = true; } if (!cornererror) { //update numbers, for use with the mapping threads this.x1 = x1num; this.x2 = x2num; this.y1 = y1num; this.y2 = y2num; } } catch { throw new CommandError("x1, y1, x2, and y2 must be integers."); } if (cornererror) { throw new CommandError("(" + x1num + "," + y1num + ")(" + x2num + "," + y2num + ") (x1,y1) must be the top left corner."); } } } if (autosaveedit) { if (autosaveenabled) { properties.SetValue("autosave-enabled", "False"); sender.SendMessage("autosave disabled."); } else { properties.SetValue("autosave-enabled", "True"); sender.SendMessage("autosave enabled."); } if (highlight) { if (highlightsearch(sender as Player, nameOrID)) { properties.SetValue("autosave-highlight", "True"); properties.SetValue("autosave-highlightID", nameOrID); sender.SendMessage("autosave highlight settings updated."); } } if (timestamp) { if (autosavetimestamp) { properties.SetValue("autosave-timestamp", "False"); sender.SendMessage("autosave now using regular name."); } else { properties.SetValue("autosave-timestamp", "True"); sender.SendMessage("autosave now using timestamp."); } } if (filename != "world-now.png") { properties.SetValue("autosave-filename", filename); } properties.Save(); return; } if (reload || autosave || api_call) { if (reload) { sender.SendMessage("map: Reloaded settings database, entries: " + properties.Count); } if (autosave) { ProgramLog.BareLog(ProgramLog.Plugin, "<map> Reloaded settings database, entries: " + properties.Count); } properties.Load(); var msg = string.Concat( "Settings: mapoutputpath=", p, ", ", "colorscheme=", cs); if (!(Directory.Exists(p))) { msg = string.Concat(msg, " (DOESNT EXIST)"); ProgramLog.Error.Log("<map> ERROR: Loaded Directory does not exist."); } if (!autosave && !api_call) { ProgramLog.Admin.Log("<map> " + msg); } //sender.sendMessage ("map: " + msg); if (!(cs == "MoreTerra" || cs == "Terrafirma")) { ProgramLog.Error.Log("<map> ERROR: please change colorscheme"); } } if (autosave) { p = autosavepath; filename = autosavename; timestamp = autosavetimestamp; if (autosavehighlight) { nameOrID = autosavehightlightID; } highlight = autosavehighlight; } if (timestamp) { DateTime value = DateTime.Now; string time = value.ToString("yyyy-MM-dd_HH-mm-ss"); filename = string.Concat("terraria-", time, ".png"); } if (savefromcommand) { properties.SetValue("color-scheme", cs); properties.SetValue("mapoutput-path", p); properties.Save(); } // chests are not an item so i draw them from the chest array if (highlight && nameOrID.ToLower() != "chest") { highlightsearch(sender as Player, nameOrID); hlchests = false; } else { if (nameOrID.ToLower() == "chest") //double checking { hlchests = true; } } if (args.Count == 0 && isEnabled) { if (!reload && Directory.Exists(p)) { if (cs == "Terrafirma") { isMapping = true; //for now highlighting is only in terrafirma color scheme MapPlugin.highlight = highlight; Thread imagethread; imagethread = new Thread(mapWorld2); imagethread.Name = "Mapper"; imagethread.Start(); while (!imagethread.IsAlive) { ; } // the thread terminates itself since there is no while loop in mapWorld2 } else if (cs == "MoreTerra") { isMapping = true; Thread imagethread; imagethread = new Thread(mapWorld); imagethread.Name = "Mapper"; imagethread.Start(); while (!imagethread.IsAlive) { ; } // the thread terminates itself since there is no while loop in mapWorld } else { ProgramLog.Error.Log("Save ERROR: check colorscheme"); } if (!(Directory.Exists(p))) { sender.SendMessage("map: " + p + " does not exist."); ProgramLog.Error.Log("<map> ERROR: Loaded Directory does not exist."); } } } else { throw new CommandError(""); } } catch (OptionException) { throw new CommandError(""); } }
static int Main(string[] raw) { ArgumentList args = new ArgumentList(raw); using (DisposingList dispose = new DisposingList()) using (Log.AppStart(Environment.CommandLine)) { if (args.Contains("nologo") == false) { Console.WriteLine("XhtmlValidate.exe"); Console.WriteLine("Copyright 2010 by Roger Knapp, Licensed under the Apache License, Version 2.0"); Console.WriteLine(""); } if ((args.Unnamed.Count == 0) || args.Contains("?") || args.Contains("help")) { return(DoHelp()); } try { FileList files = new FileList(); files.RecurseFolders = true; foreach (string spec in args.Unnamed) { Uri uri; if (Uri.TryCreate(spec, UriKind.Absolute, out uri) && !(uri.IsFile || uri.IsUnc)) { using (WebClient wc = new WebClient()) { TempFile tfile = new TempFile(); dispose.Add(tfile); wc.DownloadFile(uri, tfile.TempPath); files.Add(tfile.Info); } } else { files.Add(spec); } } if (files.Count == 0) { return(1 + DoHelp()); } XhtmlValidation validator = new XhtmlValidation(XhtmlDTDSpecification.Any); foreach (FileInfo f in files) { validator.Validate(f.FullName); } } catch (ApplicationException ae) { Log.Error(ae); Console.Error.WriteLine(); Console.Error.WriteLine(ae.Message); Environment.ExitCode = -1; } catch (Exception e) { Log.Error(e); Console.Error.WriteLine(); Console.Error.WriteLine(e.ToString()); Environment.ExitCode = -1; } } if (args.Contains("wait")) { Console.WriteLine(); Console.WriteLine("Press [Enter] to continue..."); Console.ReadLine(); } return(Environment.ExitCode); }
public void autoSave() { bool firstrun = true; DateTime lastsave = new DateTime(); ISender console = new ConsoleSender(); List<string> empty = new List<string>(); ArgumentList arguments = new ArgumentList(); while (isEnabled) { if (autosaveenabled) { if (!firstrun && (DateTime.UtcNow > lastsave.AddMinutes(autosaveinterval))) { if (!arguments.Contains("automap")) { arguments.Add("automap"); } MapCommand(console, arguments); lastsave = DateTime.UtcNow; } if (firstrun) { firstrun = false; lastsave = DateTime.UtcNow; } } Thread.Sleep(1000); } }