public void GenerationTests() { var _args = new CmdArgs(); var _asmPath = GetCurrentAssemblyPath(); _args.InputFile = Path.Combine(_asmPath,"TypeScripter.Console.Tests.dll"); _args.OutputFolder = Path.Combine(_asmPath, "testout"); Directory.Delete(_args.OutputFolder,true); _args.InputNamespace = "TypeScripter.Console.Tests.TestModels"; var _generator = new TSGenerator(); var _types = _generator.GenerateTypeScript(_args); Assert.AreEqual(1, _types.Count); Assert.AreEqual("TypeScripter.Console.Tests.TestModels.Person", _types[0]); var _outputFile = Path.Combine(_args.OutputFolder, "TypeScripter.Console.Tests.TestModels.d.ts"); Assert.IsTrue(Directory.Exists(_args.OutputFolder)); Assert.IsTrue(File.Exists(_outputFile)); }
static void Main(string[] args) { Setup.StandartSetup(); CmdArgs cmdArgs = new CmdArgs(args); MyWaterTamega mwt = new MyWaterTamega(); mwt.Run(cmdArgs); }
public bool Run(FileName task_library, CmdArgs cmdArgs, string task_class) { Assembly compiledAssembly = Assembly.LoadFrom(task_library.FullPath); IMohidScript scriptInterface = (IMohidScript)FindScriptInterface("IMohidScript", compiledAssembly, task_class); if (scriptInterface == null) return false; return scriptInterface.Run(cmdArgs); }
public bool Run(FileName script, CmdArgs cmdArgs) { Assembly compiledAssembly = Compile(script); IMohidScript scriptInterface = (IMohidScript)FindScriptInterface("IMohidScript", compiledAssembly); if (scriptInterface == null) return false; return scriptInterface.Run(cmdArgs); }
public bool Run(CmdArgs args) { Init(); bool res = false; if (LoadConfig(args)) res = RunSimulation(); return res; }
public bool Run(CmdArgs args) { if (!LoadConfig()) return false; for (int i = 0; i < cfg.Root.ChildNodes.Count; i++) { ConfigNode cn = cfg.Root.ChildNodes[i]; Console.WriteLine("Block name: {0}", cn.Name); } return true; }
static void Main() { CmdArgs cmdArgs = new CmdArgs(Environment.GetCommandLineArgs()); if (cmdArgs.Options.Count <= 0 && cmdArgs.Parameters.Count <= 0 && cmdArgs.Arguments.Count <= 1) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); return; } AttachConsole(ATTACH_PARENT_PROCESS); if (cmdArgs.HasParameter("sc")) { ScriptCompiler script = new ScriptCompiler(); if (!script.Run(new FileName(cmdArgs.Parameter("s")), cmdArgs)) Console.WriteLine("The run failed."); else Console.WriteLine("The run was ok."); } else if (cmdArgs.HasParameter("sv")) { Console.WriteLine("Run VB.NET script is not implemented yet."); } else if (cmdArgs.HasParameter("l")) { Console.WriteLine("Run from DLL is not implemented yet."); } else { Console.WriteLine(""); Console.WriteLine("To launch visual interface: MohidToolBox"); Console.WriteLine("To use command line: MohidToolbox [[--sc][--sv] scriptfilename] [--l dllfilename]"); Console.WriteLine(""); Console.WriteLine(" --sc : Used to indicate a CSharp script file name"); Console.WriteLine(" --sv : Used to indicate a VB.NET script file name (not implemented)"); Console.WriteLine(" --l : Used to indicate a DLL script file name (not implemented)"); Console.WriteLine(""); Console.WriteLine("If no options are present, the visual interface will be launched."); Console.WriteLine("ATTENTION: Only ONE of the above options can be used at a time"); Console.WriteLine(""); Console.WriteLine("Press a key..."); } return; }
private void cmdWhenWillItStopRaining(IServerPlayer player, int groupId, CmdArgs args) { rainStopFunc(player, groupId); }
private void cmdWeatherClient(int groupId, CmdArgs args) { string text = getWeatherInfo <WeatherSystemClient>(capi.World.Player); capi.ShowChatMessage(text); }
protected IMohidSim LoadUserInterface(CmdArgs args) { try { FileName interfaceName; data.sim.PreProcessing = OnPreProcessing; if (args.HasParameter("script")) interfaceName = new FileName(args.Parameters["script"]); else return null; if (interfaceName.Extension.ToLower() == "dll") //it's a library { if (!args.HasParameter("class")) return null; string class_name = args.Parameter("class"); Assembly ass = Assembly.LoadFrom(interfaceName.FullPath); data.userInterface = (IMohidSim)Activator.CreateInstance(ass.GetType("Mohid." + class_name)); return data.userInterface; } else //it's a script { ScriptCompiler sc = new ScriptCompiler(); Assembly ass = sc.Compile(interfaceName); data.userInterface = (IMohidSim)sc.FindScriptInterface("IMohidSim", ass); return data.userInterface; } } catch (Exception ex) { throw new Exception("MohidRunEngine.LoadUserInterface", ex); } }
private void ReturnThingsCommand(IServerPlayer player, int groupId, CmdArgs args) { if (args.Length < 2) { player.SendMessage(ReturnThingsHelp); return; } IPlayer fromPlayer = api.World.AllPlayers.FirstOrDefault(p => p.PlayerName.ToLower() == args[0].ToLower()); if (fromPlayer == null) { player.SendMessage(Lang.Get("Player {0} not found", args[0])); return; } string localPath = "ModData/" + api.GetWorldId() + "/" + Mod.Info.ModID + "/" + fromPlayer.PlayerUID; string path = api.GetOrCreateDataPath(localPath); string[] files = Directory.GetFiles(path).OrderByDescending(f => new FileInfo(f).Name).ToArray(); if (args[1] == "list") { if (files.Length == 0) { player.SendMessage(Lang.Get("No data saved")); return; } StringBuilder str = new StringBuilder(); for (int i = 0; i < files.Length; i++) { str.AppendLine(i + ". " + Path.GetFileName(files[i])); } player.SendMessage(str.ToString()); return; } IPlayer toPlayer = api.World.AllPlayers.FirstOrDefault(p => p.PlayerName.ToLower() == args[1].ToLower()); if (toPlayer == null) { player.SendMessage(Lang.Get("Player {0} not found", args[1])); return; } if (!api.World.AllOnlinePlayers.Contains(toPlayer) || toPlayer.Entity == null) { player.SendMessage(Lang.Get("Player {0} is offline or not fully loaded.", args[1])); return; } int offset = args.Length > 2 ? args[2].ToInt(-1) : 0; if (offset == -1 || files.Length <= offset) { player.SendMessage(Lang.Get("Index {0} not found", args.Length > 2 ? args[2] : offset.ToString())); return; } var dcm = api.ModLoader.GetModSystem <DeathContentManager>(); InventoryGeneric inventory = dcm.LoadLastDeathContent(fromPlayer, offset); foreach (var slot in inventory) { if (slot.Empty) { continue; } if (!toPlayer.InventoryManager.TryGiveItemstack(slot.Itemstack)) { api.World.SpawnItemEntity(slot.Itemstack, toPlayer.Entity.ServerPos.XYZ.AddCopy(0, 1, 0)); } slot.Itemstack = null; slot.MarkDirty(); } player.SendMessage(Lang.Get("Returned things from {0} to {1} with index {2}", fromPlayer.PlayerName, toPlayer.PlayerName, offset)); }
static void Main(string[] args) { DateTime start, end; FilePath rootResultsPath; FileName hdfResultsFile; List<FilePath> timeseriesOutputPath = new List<FilePath>(); FileName exporterEXE; FilePath exporterWorkingPath; bool joinTimeseries = false; bool useDateOnTimeseriesName = true; string folderFormat, startFormat, endFormat; StringBuilder exporterCFGBase = new StringBuilder(); StringBuilder exporterCFG = new StringBuilder(); List<ConfigNode> nodes; double runLenght; bool verbose; List<FileInfo> tsFileInfoList = new List<FileInfo>(); Dictionary<string, TimeSeries> outTS = new Dictionary<string,TimeSeries>(); TimeSeries newTS = new TimeSeries(); TextFile txtFile, errors; int timeseriesSaveCounter = 1, saveCounter; int timeseriesNameCounter; errors = new TextFile("errors.log"); errors.OpenNewToWrite(); verbose = true; FilePath path; bool dateAndTimeInOutputFolder; string outputFolderFormat = "", outputFolderStartFormat = "", outputFolderEndFormat = "", outputPath, outputPath2; bool useCounter; try { CmdArgs cmdArgs = new CmdArgs(args); if (cmdArgs.HasOption("v")) verbose = true; else verbose = false; if (cmdArgs.HasParameter("cfg")) { if (verbose) Console.Write("Reading configuration file..."); Config conf = new Config(cmdArgs.Parameters["cfg"]); conf.Load(); if (verbose) Console.WriteLine("[OK]"); if (verbose) Console.Write("Looking for 'timeseries.to.extract' blocks..."); List<ConfigNode> tsList = conf.Root.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "timeseries.to.extract"; }); if (tsList == null || tsList.Count <= 0) throw new Exception("No 'timeseries.to.extract' block found in configuration file."); if (verbose) { Console.WriteLine("[OK]"); Console.WriteLine("{0} 'timeseries.to.extract' block(s) found.", tsList.Count); } dateAndTimeInOutputFolder = conf.Root["user.def.output.folder", false].AsBool(); if (dateAndTimeInOutputFolder) { outputFolderFormat = conf.Root["user.def.output.folder.format", "start-end"].AsString(); outputFolderStartFormat = conf.Root["user.def.output.start.format", "yyyyMMddHH"].AsString(); outputFolderEndFormat = conf.Root["user.def.output.end.format", "yyyyMMddHH"].AsString(); } int tscCount = 1; foreach (ConfigNode tsc in tsList) { timeseriesNameCounter = 1; if (verbose) Console.Write("Processing 'timeseries.to.extract' block {0}...", tscCount); start = tsc["start"].AsDateTime(); end = tsc["end"].AsDateTime(); rootResultsPath = tsc["root.results.path", @".\"].AsFilePath(); hdfResultsFile = tsc["hdf.results.file"].AsFileName(); if (tsc.Contains("backup_path")) { path = tsc["backup_path"].AsFilePath(); timeseriesOutputPath.Add(path); } if (tsc.Contains("storage_path")) { path = tsc["storage_path"].AsFilePath(); timeseriesOutputPath.Add(path); } if (tsc.Contains("publish_path")) { path = tsc["publish_path"].AsFilePath(); timeseriesOutputPath.Add(path); } if (timeseriesOutputPath.Count <= 0) { throw new Exception("An error was found in the configuration file. Missing keyword." + "At least ONE of the following keywords must be provided:" + "BACKUP_PATH, STORAGE_PATH, PUBLISH_PATH"); } exporterEXE = tsc["exporter.exe"].AsFileName(); exporterWorkingPath = tsc["exporter.working.path"].AsFilePath(); joinTimeseries = tsc["join.timeseries", true].AsBool(); if (joinTimeseries && dateAndTimeInOutputFolder) { throw new Exception("join.timeseries can't be used with user.def.output.folder"); } folderFormat = tsc["folder.format", "start-end"].AsString(); startFormat = tsc["start.format", "yyyyMMddHH"].AsString(); endFormat = tsc["end.format", "yyyyMMddHH"].AsString(); runLenght = tsc["run.lenght"].AsDouble(); useCounter = tsc["use.counter.on.names", false].AsBool(); if (joinTimeseries) { outTS = new Dictionary<string, TimeSeries>(); newTS = new TimeSeries(); timeseriesSaveCounter = tsc["save.counter"].AsInt(); } else { useDateOnTimeseriesName = tsc["use.date.on.timeseries.name", true].AsBool(); } exporterCFGBase.Append("EXPORT_TYPE : "); exporterCFGBase.AppendLine(tsc["export.type", 1].AsString()); exporterCFGBase.Append("COMPUTE_RESIDUAL : "); exporterCFGBase.AppendLine(tsc["compute.residual", 0].AsString()); exporterCFGBase.Append("VARIABLE_GRID : "); exporterCFGBase.AppendLine(tsc["variable.grid", 0].AsString()); exporterCFGBase.Append("WATERPOINTS_NAME : "); exporterCFGBase.AppendLine(tsc["points.name", "WaterPoints2D"].AsString()); exporterCFGBase.Append("GRID_FILENAME : "); exporterCFGBase.AppendLine(tsc["grid.file.name", "grid.dat"].AsString()); nodes = tsc.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "timeseries"; }); if (nodes == null || nodes.Count <= 0) throw new Exception("No 'timeseries' block found in configuration file."); foreach (ConfigNode param in nodes) { exporterCFGBase.AppendLine(); exporterCFGBase.AppendLine("<BeginTimeSerie>"); exporterCFGBase.Append(" NAME : "); exporterCFGBase.AppendLine(param["name"].AsString()); if (param.NodeData.ContainsKey("coord.y")) { exporterCFGBase.Append(" COORD_Y : "); exporterCFGBase.AppendLine(param["coord.y"].AsString()); } if (param.NodeData.ContainsKey("coord.x")) { exporterCFGBase.Append(" COORD_X : "); exporterCFGBase.AppendLine(param["coord.x"].AsString()); } if (param.NodeData.ContainsKey("depth.level")) { exporterCFGBase.Append(" DEPTH_LEVEL : "); exporterCFGBase.AppendLine(param["depth.level"].AsString()); } if (param.NodeData.ContainsKey("localization.i")) { exporterCFGBase.Append(" LOCALIZATION_I : "); exporterCFGBase.AppendLine(param["localization.i"].AsString()); } if (param.NodeData.ContainsKey("localization.j")) { exporterCFGBase.Append(" LOCALIZATION_J : "); exporterCFGBase.AppendLine(param["localization.j"].AsString()); } if (param.NodeData.ContainsKey("localization.k")) { exporterCFGBase.Append(" LOCALIZATION_K : "); exporterCFGBase.AppendLine(param["localization.k"].AsString()); } if (param.NodeData.ContainsKey("latitude")) { exporterCFGBase.Append(" LATITUDE : "); exporterCFGBase.AppendLine(param["latitude"].AsString()); } if (param.NodeData.ContainsKey("longitude")) { exporterCFGBase.Append(" LONGITUDE : "); exporterCFGBase.AppendLine(param["longitude"].AsString()); } exporterCFGBase.AppendLine("<EndTimeSerie>"); if (joinTimeseries) { outTS[param["name"].AsString()] = new TimeSeries(); } } nodes = tsc.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "parameter"; }); if (nodes == null || nodes.Count <= 0) throw new Exception("No 'parameter' block found in configuration file."); foreach (ConfigNode param in nodes) { exporterCFGBase.AppendLine(); exporterCFGBase.AppendLine("<BeginParameter>"); exporterCFGBase.Append(" HDF_GROUP : "); exporterCFGBase.AppendLine(param["hdf.group"].AsString()); exporterCFGBase.Append(" PROPERTY : "); exporterCFGBase.AppendLine(param["hdf.property"].AsString()); exporterCFGBase.AppendLine("<EndParameter>"); } txtFile = new TextFile(exporterWorkingPath.Path + "nomfich.dat"); txtFile.OpenNewToWrite(); txtFile.WriteLine("IN_MODEL : hdfexporter.dat"); txtFile.Close(); ExternalApp hdf5exporter = new ExternalApp(); hdf5exporter.CheckSuccessMethod = CheckSuccessMethod.DEFAULTOUTPUT; hdf5exporter.TextToCheck = "Program HDF5Exporter successfully terminated"; hdf5exporter.Wait = true; hdf5exporter.WorkingDirectory = exporterWorkingPath.Path; hdf5exporter.Executable = exporterEXE.FullPath; bool fail; DateTime actual = start; FilePath hdfResultsPath = new FilePath(); saveCounter = 1; while (actual.AddDays(runLenght) <= end) { fail = false; hdfResultsPath.Path = rootResultsPath.Path + (folderFormat.Replace("start", actual.ToString(startFormat)).Replace("end", actual.AddDays(runLenght).ToString(endFormat))); if (System.IO.Directory.Exists(hdfResultsPath.Path)) { exporterCFG.Clear(); exporterCFG.Append("START_TIME : "); exporterCFG.AppendLine(actual.ToString("yyyy M d H m s")); exporterCFG.Append("END_TIME : "); exporterCFG.AppendLine(actual.AddDays(runLenght).ToString("yyyy M d H m s")); exporterCFG.AppendLine(); exporterCFG.AppendLine("<BeginHDF5File>"); exporterCFG.Append(" NAME : "); exporterCFG.AppendLine(hdfResultsPath.Path + hdfResultsFile.FullName); exporterCFG.AppendLine("<EndHDF5File>"); txtFile.File.FullPath = exporterWorkingPath.Path + "hdfexporter.dat"; txtFile.OpenNewToWrite(); txtFile.Write(exporterCFGBase.ToString()); txtFile.Write(exporterCFG.ToString()); txtFile.Close(); try { bool res = hdf5exporter.Run(); if (!res) { throw new Exception("Unsuccessfull HDF5Exporter run"); } } catch (Exception e_run) { errors.WriteLine("[" + DateTime.Now.ToString() + "] HDF5Exporter Run Exception when processing '" + hdfResultsFile + "' on results folder '" + hdfResultsPath.Path + "'"); errors.WriteLine("[" + DateTime.Now.ToString() + "] The exception returned this message: " + e_run.Message); fail = true; } if (!fail) { FileTools.FindFiles(ref tsFileInfoList, exporterWorkingPath, "*.ets", true, "", System.IO.SearchOption.TopDirectoryOnly); if (joinTimeseries) { foreach (FileInfo file in tsFileInfoList) { if (outTS[file.FileName.Name].NumberOfInstants > 0) { saveCounter++; try { newTS.Load(file.FileName); outTS[file.FileName.Name].AddTimeSeries(newTS); } catch { errors.WriteLine("[" + DateTime.Now.ToString() + "] Was not possible to read timeseries '" + file.FileName.FullName + "' from HDF file '" + hdfResultsFile + "' on results folder '" + hdfResultsPath.Path + "'"); } System.IO.File.Delete(file.FileName.FullPath); if (saveCounter > timeseriesSaveCounter) { try { if (dateAndTimeInOutputFolder) { outputPath = timeseriesOutputPath[0].Path + (outputFolderFormat.Replace("start", actual.ToString(outputFolderStartFormat)).Replace("end", actual.AddDays(runLenght).ToString(outputFolderEndFormat))) + System.IO.Path.DirectorySeparatorChar; } else { outputPath = timeseriesOutputPath[0].Path; } if (!System.IO.Directory.Exists(outputPath)) System.IO.Directory.CreateDirectory(outputPath); outTS[file.FileName.Name].Save(new FileName(outputPath + file.FileName.FullName)); saveCounter = 1; if (timeseriesOutputPath.Count > 1) { for (int i = 1; i < timeseriesOutputPath.Count; i++) { outputPath2 = timeseriesOutputPath[i].Path + (outputFolderFormat.Replace("start", actual.ToString(outputFolderStartFormat)).Replace("end", actual.AddDays(runLenght).ToString(outputFolderEndFormat))) + System.IO.Path.DirectorySeparatorChar; if (!System.IO.Directory.Exists(outputPath2)) System.IO.Directory.CreateDirectory(outputPath2); FileTools.CopyFile(new FileName(outputPath + file.FileName.FullName), new FileName(outputPath2 + file.FileName.FullName), CopyOptions.OVERWRIGHT); } } } catch (Exception ex) { errors.WriteLine("[" + DateTime.Now.ToString() + "] Was not possible to save joined timeseries '" + file.FileName.FullName + "' from HDF file '" + hdfResultsFile + "' when processing results folder '" + hdfResultsPath.Path + "'"); errors.WriteLine("[" + DateTime.Now.ToString() + "] The exception returned this message: " + ex.Message); } } } else { outTS[file.FileName.Name].Load(file.FileName); System.IO.File.Delete(file.FileName.FullPath); } } } else { FileName timeseriesTarget = new FileName(); foreach (FileInfo file in tsFileInfoList) { if (dateAndTimeInOutputFolder) { outputPath = timeseriesOutputPath[0].Path + (outputFolderFormat.Replace("start", actual.ToString(outputFolderStartFormat)).Replace("end", actual.AddDays(runLenght).ToString(outputFolderEndFormat))) + System.IO.Path.DirectorySeparatorChar; } else { outputPath = timeseriesOutputPath[0].Path; } timeseriesTarget.Path = outputPath; if (!System.IO.Directory.Exists(outputPath)) System.IO.Directory.CreateDirectory(outputPath); if (useDateOnTimeseriesName) { timeseriesTarget.FullName = file.FileName.FullName.Insert(file.FileName.FullName.LastIndexOf('.'), actual.ToString(startFormat) + "_" + actual.AddDays(runLenght).ToString(endFormat)); } else if (useCounter) { timeseriesTarget.FullName = file.FileName.FullName.Insert(file.FileName.FullName.LastIndexOf('.'), timeseriesNameCounter.ToString()); timeseriesNameCounter++; } else { timeseriesTarget.FullName = file.FileName.FullName; } FileTools.CopyFile(file.FileName, timeseriesTarget, CopyOptions.OVERWRIGHT); if (timeseriesOutputPath.Count > 1) { for (int i = 1; i < timeseriesOutputPath.Count; i++) { outputPath2 = timeseriesOutputPath[i].Path + (outputFolderFormat.Replace("start", actual.ToString(outputFolderStartFormat)).Replace("end", actual.AddDays(runLenght).ToString(outputFolderEndFormat))) + System.IO.Path.DirectorySeparatorChar; if (!System.IO.Directory.Exists(outputPath2)) System.IO.Directory.CreateDirectory(outputPath2); FileTools.CopyFile(new FileName(outputPath + file.FileName.FullName), new FileName(outputPath2 + file.FileName.FullName), CopyOptions.OVERWRIGHT); } } } } } } actual = actual.AddDays(runLenght); } tscCount++; if (joinTimeseries) { foreach (KeyValuePair<string, TimeSeries> pair in outTS) { if (dateAndTimeInOutputFolder) { outputPath = timeseriesOutputPath[0].Path + (outputFolderFormat.Replace("start", actual.ToString(outputFolderStartFormat)).Replace("end", actual.AddDays(runLenght).ToString(outputFolderEndFormat))) + System.IO.Path.DirectorySeparatorChar; } else { outputPath = timeseriesOutputPath[0].Path; } if (!System.IO.Directory.Exists(outputPath)) System.IO.Directory.CreateDirectory(outputPath); pair.Value.Save(new FileName(outputPath + pair.Key + ".ets")); for (int i = 1; i < timeseriesOutputPath.Count; i++) { outputPath2 = timeseriesOutputPath[i].Path + (outputFolderFormat.Replace("start", actual.ToString(outputFolderStartFormat)).Replace("end", actual.AddDays(runLenght).ToString(outputFolderEndFormat))) + System.IO.Path.DirectorySeparatorChar; if (!System.IO.Directory.Exists(outputPath2)) System.IO.Directory.CreateDirectory(outputPath2); FileTools.CopyFile(new FileName(outputPath + pair.Key + ".ets"), new FileName(outputPath2 + pair.Key + ".ets"), CopyOptions.OVERWRIGHT); } } } } } Console.WriteLine("[OK]"); } catch(Exception ex) { if (verbose) { Console.WriteLine("[FAIL]"); Console.WriteLine(""); Console.WriteLine("An EXCEPTION was raised. The message returned was:"); Console.WriteLine(ex.Message); } } Console.WriteLine("GetTSFromModelResultsHDF finished."); errors.Close(); }
public bool Run(CmdArgs args, IMohidSim test = null) { bool sim_run = true; data.args = args; try { if (test != null) { data.userInterface = test; } else { if (Verbose) Console.Write("Loading User Interface..."); LoadUserInterface(args); if (Verbose) Console.WriteLine("[OK]"); } OnStart(); if (Verbose) Console.Write("Loading Configuration..."); LoadConfig(args); if (Verbose) Console.WriteLine("[OK]"); if (Verbose) Console.Write("Loading Log File..."); LoadLogFile(); if (Verbose) Console.WriteLine("[OK]"); } catch(Exception ex) { if (Verbose) { Console.WriteLine("[FAILED]"); Console.WriteLine(""); Console.WriteLine("An EXCEPTION was raised. The message returned was:"); Console.WriteLine(ex.Message); Console.WriteLine(""); } throw new Exception("MohidRunEngine.Run", ex); } try { AfterInit(); if (data.useEndOfSimulation) { useEndDate = true; simEnd = data.endOfSimulation; if (Verbose) Console.WriteLine("Using End from config file: {0}", simEnd.ToString("dd/MM/yyyy HH:mm:ss")); } else { useEndDate = false; //simEnd = data.sim.Start.AddDays(data.sim.SimLenght); //if (Verbose) Console.WriteLine("Using End from run: {0}", simEnd); } int count = 0; string end; if (data.maxIterations < 1 && !data.useEndOfSimulation) end = " of infinite simulations"; else if (data.maxIterations > 0 && data.useEndOfSimulation) end = " of " + data.maxIterations.ToString() + ", ending on " + data.endOfSimulation.ToString("yyyy-MM-dd"); else if (data.maxIterations > 0) end = " of " + data.maxIterations.ToString(); else end = ". Ending " + data.endOfSimulation.ToString("yyyy-MM-dd"); if (Verbose && data.maxIterations > 0) Console.WriteLine("Number of max iterations expected: {0}", data.maxIterations); while (data.maxIterations != 0 && (!useEndDate || data.sim.Start < simEnd)) { try { SetupRun(); OnSimStart(); count++; if (Verbose) { Console.WriteLine(""); Console.WriteLine("Simulation {0}{1}", count, end); Console.WriteLine("Start: {0} End: {1}", data.sim.Start.ToString("yyyy-MM-dd HH:mm:ss"), data.sim.End.ToString("yyyy-MM-dd HH:mm:ss")); Console.WriteLine(""); } if (!(sim_run = Run()) && !OnRunFail()) { AddNewEntryToLog(sim_run); break; } OnSimEnd(); AddNewEntryToLog(sim_run); NextSimSetup(); } catch (Exception ex) { Console.WriteLine(""); Console.WriteLine("An EXCEPTION was raised. The message returned was:"); Console.WriteLine(ex.Message); Console.WriteLine(""); OnException(); throw; } } OnEnd(); if (Verbose) { Console.WriteLine(""); Console.WriteLine("Finished."); } } catch (Exception ex) { Console.WriteLine("Exception: {0}", ex.Message); Console.WriteLine("Saving LOG..."); data.log.Save(); throw new Exception("MohidRunEngine.Run", ex); } Console.WriteLine("Saving LOG..."); data.log.Save(); return sim_run; }
// ***** Binary **** / /// <summary> Adds a binary command argument. </summary> /// <param name="argument"> The argument. </param> public void AddBinArgument(string argument) { _lazyArguments.Add(() => CmdArgs.Add(Escaping.Escape(argument))); }
/// <summary> Adds a binary command argument. </summary> /// <param name="argument"> The argument. </param> public void AddBinArgument(Double argument) { _lazyArguments.Add(() => CmdArgs.Add(CommunicationManager.BoardType == BoardType.Bit16 ? BinaryConverter.ToString((float)argument) : BinaryConverter.ToString(argument))); }
/// <summary> Adds a command argument. </summary> /// <param name="argument"> The argument. </param> public void AddArgument(UInt16 argument) { _lazyArguments.Add(() => CmdArgs.Add(argument.ToString(CultureInfo.InvariantCulture))); }
/// <summary> Adds a command argument. </summary> /// <param name="argument"> The argument. </param> public void AddArgument(UInt32 argument) { // Make sure the other side can read this: on a 16 processor, read as Long _lazyArguments.Add(() => CmdArgs.Add(argument.ToString(CultureInfo.InvariantCulture))); }
/// <summary> Adds a command argument. </summary> /// <param name="argument"> The argument. </param> public void AddArgument(float argument) { _lazyArguments.Add(() => CmdArgs.Add(argument.ToString("R", CultureInfo.InvariantCulture))); }
static void Main(string[] args) { Database db = null; string query; OdbcDataReader dbReader; int interval_seconds_guess; string dateFormat; string server = "http://www.meteoagri.com/"; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; try { db = new Database(); CmdArgs cmdArgs = new CmdArgs(args); List<DataToRead> list = new List<DataToRead>(); int defaultDaysToDownload; string user, pass; bool save_ts = cmdArgs.HasOption("save_ts"); bool save_db = cmdArgs.HasOption("save_db"); if (!cmdArgs.HasParameter("user")) throw new Exception("Must provide the user. Uses '--user user_name'."); if (!cmdArgs.HasParameter("pass")) throw new Exception("Must provide the pass. Uses '--pass password'."); user = cmdArgs.Parameters["user"]; pass = cmdArgs.Parameters["pass"]; if (cmdArgs.HasParameter("cfg")) { Config conf = new Config(cmdArgs.Parameters["cfg"]); conf.Load(); if (save_db) { ConfigNode dbConf = conf.Root.ChildNodes.Find(delegate(ConfigNode node) { return node.Name == "database.config"; }); if (dbConf == null) throw new Exception("No 'database.config' block was found."); if (db.Connect(dbConf["db.conn.string"].AsString()) != Result.TRUE) throw new Exception("Connection to database was not possible. The message returned was: " + db.RaisedException.Message); } server = conf.Root["server", "http://www.meteoagri.com/"].AsString(); defaultDaysToDownload = conf.Root["days.to.download", 14].AsInt(); dateFormat = conf.Root["date.format", "#yyyy-MM-dd HH:mm:ss#"].AsString(); interval_seconds_guess = conf.Root["interval.guess", 900].AsInt(); List<ConfigNode> nodeList = conf.Root.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "data.to.read"; }); if (nodeList == null) throw new Exception("No blocks 'nodes.to.read' were found."); DataToRead item; NodeData nd; int blockNumber = 1; foreach (ConfigNode node in nodeList) { item = new DataToRead(); list.Add(item); item.TimeSeriesFileName = node["time.series.file.name", ""].AsString(); item.TableName = node["table.name"].AsString(); item.DBDateColumn = node["db.date.column"].AsString(); List<ConfigNode> cfList = node.ChildNodes.FindAll(delegate(ConfigNode n) { return n.Name == "node"; }); if (cfList == null) throw new Exception("No blocks 'node' were found on block number " + blockNumber.ToString()); foreach (ConfigNode cn in cfList) { nd = new NodeData(); nd.DefaultValue = cn["default.value", ""].AsString(); nd.DBColumn = cn["column"].AsString(); nd.TSHeader = cn["ts.header", nd.DBColumn].AsString(); nd.NodeID = cn["node.id"].AsString(); item.NodesList.Add(nd); } if (save_db) { query = string.Format("SELECT {0} FROM {1} ORDER BY {0} DESC", item.DBDateColumn, item.TableName); dbReader = db.ExecuteQuerySingleRow(query); item.Start = DateTime.Now.AddDays(-defaultDaysToDownload); if (dbReader.HasRows) { while (dbReader.Read()) item.Start = dbReader.GetDateTime(dbReader.GetOrdinal(item.DBDateColumn)).AddDays(1); if (!dbReader.IsClosed) dbReader.Close(); } } else { item.Start = DateTime.Now.AddDays(-defaultDaysToDownload); } blockNumber++; } } else throw new Exception("No valid configuration file provided. use 'cfg' parameter."); MeteoAgriEngine maEng = new MeteoAgriEngine(server); maEng.TimeOut = 360; Console.Write("Connecting to MeteoAgri..."); if (maEng.Login(user, pass)) { Console.WriteLine("[OK]"); int count = 1; int nItems = 0; Console.WriteLine("DATA READ/WRITE in progress."); foreach (DataToRead dr in list) { TimeSeries ts = new TimeSeries(); ts.StartInstant = dr.Start; ts.TimeUnits = TimeUnits.SECONDS; foreach (NodeData nd in dr.NodesList) { Column col = new Column(typeof(string), 0, nd.TSHeader); col.DefaultValue = "0"; ts.AddColumn(col); } //First, find how many "slots" will be downloaded int slots = (int)(DateTime.Now - dr.Start).TotalSeconds / interval_seconds_guess; if (slots <= 0) { count++; continue; //throw new Exception("Start date for 'data.to.read' number " + count.ToString() + " (" + dr.Start.ToString("yyyy-MM-dd") + ") is same than today's date"); } nItems = 0; int column = -1; foreach (NodeData nd in dr.NodesList) { column++; Console.WriteLine("Reading from ARBVS server the node {0}, id = {1}...", nd.DBColumn, nd.NodeID); maEng.GetData(nd.NodeID, dr.Start, slots, ts, column, dateFormat); //if (nd.Data == null) //{ // Console.WriteLine("[NO DATA]"); // //throw new Exception(maEng.ExceptionMessage); //} //else if (nd.Data.Count < 1) //{ // Console.WriteLine("[NO DATA]"); // //throw new Exception("ARBVS server returned an empty node"); //} //else //{ // if (nItems < 1) // nItems = nd.Data[0].Data.Count; // else if (nItems != nd.Data[0].Data.Count) // { // Console.WriteLine("[ERROR]"); // throw new Exception("ARBVS server returned a different number of items than the previous node"); // } // Console.WriteLine("[OK]"); // //Console.WriteLine(""); // //Console.WriteLine("The data returned was:"); // //foreach (MeteoAgriNode node in nodes) // //{ // // Console.WriteLine("NODE : {0}", node.NodeId); // // foreach (MeteoAgriData data in node.Data) // // Console.WriteLine(string.Format(" type:'{0}' d:'{1}' s:'{2}' t:'{3}' value:'{4}'", // // data.Type, data.D, data.S, data.T, data.Value)); // // Console.WriteLine("------------"); // //} //} } string fields, data; //if (nItems > 0) //{ //DateTime start = DateTime.Now; //bool start_defined = false; if (save_db) { Console.Write("Writing info on database..."); for (int i = 0; i < ts.NumberOfInstants; i++) { fields = "Instant"; data = ts.InstantAsDateTime(i).ToString(dateFormat); //if (dr.NodesList[0].Data[0].Data[i].D == "-1") //{ // start = DateTime.ParseExact(dr.NodesList[0].Data[0].Data[i].T, "yyyyMMddTHH:mm:ss", null); // data = start.ToString(dateFormat); // start_defined = true; //} //else //{ // if (!start_defined) // throw new Exception("The start instant was not found in the imported data."); // start = start.AddSeconds(double.Parse(dr.NodesList[0].Data[0].Data[i].T)); // data = start.ToString(dateFormat); //} int column_index = -1; foreach (NodeData nd in dr.NodesList) { column_index++; fields += ", " + nd.DBColumn; data += ", " + (ts[column_index, i] as string); } query = string.Format("INSERT INTO {0} ({1}) VALUES ({2})", dr.TableName, fields, data); //if (db.ExecuteCommand(query) != 1) db.ExecuteCommand(query); } Console.WriteLine("[OK][{0} items inserted]", ts.NumberOfInstants.ToString()); //} } if (save_ts) { if (ts.NumberOfInstants > 1) ts.Save(new FileName(dr.TimeSeriesFileName)); else Console.WriteLine("No data was available for {0}", dr.TimeSeriesFileName); } count++; } Console.Write("Logging out..."); if (maEng.Logout()) Console.WriteLine("[OK]"); else { Console.WriteLine("[ERROR]"); Console.WriteLine("The message returned was:"); Console.WriteLine(maEng.ExceptionMessage); } } else { Console.WriteLine("[ERROR]"); Console.WriteLine("The message returned was:"); Console.WriteLine(maEng.ExceptionMessage); } db.Disconnect(); } catch (Exception ex) { if (db != null) db.Disconnect(); Console.WriteLine(""); Console.WriteLine("An exception has happened. The message returned was:"); Console.WriteLine(ex.Message); } //Console.WriteLine(""); //Console.WriteLine("Press any key..."); //Console.ReadKey(); }
static int Main(string[] args) { TextFile log = null; CmdArgs cmd_args = null; Engine eng = null; int result = 0; bool debug = false; try { cmd_args = new CmdArgs(args); } catch (Exception ex) { Console.WriteLine("Error when trying to parse the command line arguments."); Console.WriteLine("The message returned was:"); Console.WriteLine(ex.Message); result = -1; } if (result == 0) try { string log_file; if (cmd_args.HasParameter("log")) { log_file = cmd_args.Parameters["log"]; } else { if (cmd_args.HasParameter("logpath")) log_file = (new FilePath(cmd_args.Parameters["logpath"])).Path + "log_"; else log_file = "log_"; DateTime DateNow = DateTime.Now; log_file += DateNow.Year.ToString("D4") + DateNow.Month.ToString("D2") + DateNow.Day.ToString("D2") + "-" + DateNow.Hour.ToString("D2") + DateNow.Minute.ToString("D2") + DateNow.Second.ToString("D2") + ".dat"; //Console.WriteLine("WARNING: Missing 'log' parameter."); //Console.WriteLine("A log file will be created with the name:"); //Console.WriteLine(log_file); } log = new TextFile(log_file); } catch (Exception ex) { Console.WriteLine("Error when trying to create log file."); Console.WriteLine("The message returned was:"); Console.WriteLine(ex.Message); result = -2; } bool verbose = false; if (cmd_args.HasOption("verbose")) verbose = true; if (cmd_args.HasOption("debug")) debug = true; if (result == 0) try { DateTime d_and_t = DateTime.Now; if (!cmd_args.HasParameter("cfg")) throw new Exception("No configuration file was provided."); if (cmd_args.HasParameter("date")) d_and_t = DateTime.ParseExact(cmd_args.Parameters["date"], "yyyy mm dd", CultureInfo.InvariantCulture); if (verbose) Console.WriteLine("Starting sms engine."); eng = new Engine(); eng.Debug = debug; if (verbose) Console.WriteLine("Loading configuration."); if (!eng.LoadConfig(new Mohid.Files.FileName(cmd_args.Parameters["cfg"]))) throw new Exception("Error when loading the configuration file."); if (verbose) Console.WriteLine("Sending messages."); if (!eng.SendMessages(d_and_t)) throw new Exception("Error when trying to send the messages."); } catch (Exception ex) { Console.WriteLine("Error when trying to send messages."); Console.WriteLine("The exception returned was:"); Console.WriteLine(ex.Message); result = -3; } if (log != null) { if (eng.HasErrors) { log.OpenNewToWrite(); log.Write(eng.Errors); log.Close(); } } return result; }
static void Main(string[] args) { try { SMSEngine sms = new SMSEngine(); CmdArgs cmdArgs = new CmdArgs(args); string number, message; //PORT NUMBER if (cmdArgs.HasParameter("port")) { sms.Port.PortName = "COM" + cmdArgs.Parameters["port"]; } else throw new Exception("'port' parameter is missing."); //BAUDRATE if (cmdArgs.HasParameter("baudrate")) { sms.Baudrate = int.Parse(cmdArgs.Parameters["baudrate"]); } else throw new Exception("'baudrate' parameter is missing."); //SMS CENTER if (cmdArgs.HasParameter("sms.center")) { sms.SMSCenter = cmdArgs.Parameters["sms.center"]; } else throw new Exception("'sms.center' parameter is missing."); //PIN CODE if (cmdArgs.HasParameter("pin")) { sms.PinCode = cmdArgs.Parameters["pin"]; } else throw new Exception("'pin' parameter is missing."); //TIMEOUT if (cmdArgs.HasParameter("time.out")) { sms.TimeOut = int.Parse(cmdArgs.Parameters["time.out"]); } //WAIT TIME if (cmdArgs.HasParameter("wait.time")) { sms.WaitTime = int.Parse(cmdArgs.Parameters["wait.time"]); } //INTERVAL BETWEEN MESSAGES if (cmdArgs.HasParameter("interval.time")) { sms.IntervalBetweenMessages = int.Parse(cmdArgs.Parameters["interval.time"]); } //NUMBER if (cmdArgs.HasParameter("number") && cmdArgs.HasParameter("message")) { number = cmdArgs.Parameters["number"]; message = cmdArgs.Parameters["message"]; sms.SendSMS(number, message); } else throw new Exception("No NUMBER or MESSAGE parameter found"); } catch (Exception ex) { Console.WriteLine("An EXCEPTION was raised. The message returned was:"); Console.WriteLine(ex.Message); } }
/// <summary> Adds a binary command argument. </summary> /// <param name="argument"> The argument. </param> public void AddBinArgument(UInt32 argument) { _lazyArguments.Add(() => CmdArgs.Add(BinaryConverter.ToString(argument))); }
public override bool OnWorldEditCommand(WorldEdit worldEdit, CmdArgs args) { switch (args.PopWord()) { case "magic": { MagicSelect = (bool)args.PopBool(false); worldEdit.Good("Magic select now " + (MagicSelect ? "on" : "off")); return(true); } case "edgeblocks": { string arg = args.PopWord("list"); switch (arg) { case "list": worldEdit.Good("Edge blocks: " + string.Join(", ", EdgeBlocks)); break; case "add": string blockcode = args.PopAll(); if (matchesAnyBlock(worldEdit.sapi, blockcode)) { EdgeBlocks = EdgeBlocks.Append(args.PopAll()); worldEdit.Good("Ok, edge block '" + blockcode + "' added."); SetEdgeBlocks(worldEdit.sapi.World, EdgeBlocks); } else { worldEdit.Good("Error, block code/wildcard '" + blockcode + "' does not match any known blocks."); } break; case "remove": List <string> elems = new List <string>(EdgeBlocks); if (elems.Remove(args.PopAll())) { worldEdit.Good("Ok, edge block removed."); SetEdgeBlocks(worldEdit.sapi.World, elems.ToArray()); } else { worldEdit.Good("No such edge block in list."); } break; default: worldEdit.Bad("Invalid arg. Syntax: /we edgeblocks or /we edgeblocks [list|add|remove] [blockcode]"); break; } } return(true); } return(false); }
/// <summary> /// Returns all remaining arguments as single merged string, concatenated with spaces. /// </summary> /// <param name="args">The CmdArgs instance that called this extension method.</param> /// <param name="defaultValue">The default value to use, if nothing remains within the argument buffer.</param> public static string PopAll(this CmdArgs args, string defaultValue) { var retVal = args.PopAll(); return(string.IsNullOrWhiteSpace(retVal) ? defaultValue : retVal); }
protected void LoadConfig(CmdArgs args) { try { data.cfg = new Config(); Config cfg = data.cfg; string configFile; if (args.HasParameter("simcfg")) configFile = args.Parameter("simcfg"); else configFile = "sim.cfg"; if (args.HasParameter("max.iter")) data.maxIterations = int.Parse(args.Parameter("max.iter")); else data.maxIterations = -1; cfg.ConfigFile.FullPath = configFile; if (!cfg.Load()) throw new Exception("Was not possible to load the configuration file '" + configFile + "'. " + cfg.ExceptionMessage); ConfigNode root = cfg.Root; data.sim.SimDirectory = root["sim.folder", "sim"].AsFilePath(); data.logFileName = root["log.file", data.sim.SimDirectory.Path + "sim.log"].AsFileName(); data.RestartFailedRun = root["restart.failed.run", true].AsBool(); data.sim.Start = root["sim.start"].AsDateTime(data.dateFormat); data.sim.SimLenght = root["sim.lenght", 14].AsDouble(); data.simID = 1; data.sim.CheckRun = root["check.run", true].AsBool(); data.sim.Verbose = root["verbose", true].AsBool(); data.sim.Wait = root["wait", true].AsBool(); data.sim.SuccessString = root["check.this", "successfully terminated"].AsString(); data.sim.SetupRunPeriod = root["setup.run.period", false].AsBool(); if (data.sim.SetupRunPeriod) { data.sim.EndTAG = root["sim.end.tag", "<<end>>"].AsString(); data.sim.StartTAG = root["sim.start.tag", "<<start>>"].AsString(); } data.sim.DataDirectory = root["data.folder", data.sim.SimDirectory.Path + "data"].AsFilePath(); data.sim.WorkingDirectory = root["working.folder", data.sim.SimDirectory.Path + "exe"].AsFilePath(); data.resFolder = root["results.folder", data.sim.SimDirectory.Path + "res"].AsFilePath(); data.storeFolder = root["store.folder", data.sim.SimDirectory.Path + "store"].AsFilePath(); data.oldFolder = root["old.folder", data.sim.SimDirectory.Path + "old"].AsFilePath(); data.sim.SaveOutput = root["save.output", true].AsBool(); if (data.sim.SaveOutput) { data.sim.OutputFile = new FileName(data.resFolder.Path + root["output.file", "result.txt"].AsString()); } data.sim.Executable = root["mohid.executable", "mohid.exe"].AsFileName(); data.sim.CreateInputFiles = root["use.templates", false].AsBool(); if (root.NodeData.ContainsKey("sim.end")) { data.useEndOfSimulation = true; data.endOfSimulation = root["sim.end"].AsDateTime(data.dateFormat); } else data.useEndOfSimulation = false; if (!data.useEndOfSimulation && data.maxIterations < 1 && !root["infinite.run", false].AsBool()) throw new Exception("'sim.end' keyword and 'max.iter' parameter are missing and 'infinit.run' keyword is missing or set to False."); if (data.sim.SetupRunPeriod && !data.sim.CreateInputFiles) throw new Exception("If 'setup.run.period' is set to True, 'use.templates' also must be set to True."); if (data.sim.CreateInputFiles) { InputFileTemplate newTemplate; List<ConfigNode> itfList = root.ChildNodes.FindAll(FindFirstTemplateInfoBlocks); foreach (ConfigNode ticn in itfList) { newTemplate = new InputFileTemplate(ticn["file"].AsFileName().FullPath, (InputFileTemplateType)Enum.Parse(typeof(InputFileTemplateType), ticn["type", "data"].AsString(), true)); data.templatesStart.Add(newTemplate); } data.sim.TemplateFilesList = data.templatesStart; data.changeTemplates = root["change.templates", true].AsBool(); if (data.changeTemplates) { itfList = root.ChildNodes.FindAll(FindNextTemplateInfoBlocks); foreach (ConfigNode ticn in itfList) { newTemplate = new InputFileTemplate(ticn["file"].AsFileName().FullPath, (InputFileTemplateType)Enum.Parse(typeof(InputFileTemplateType), ticn["type", "data"].AsString(), true)); data.templatesContinuation.Add(newTemplate); } } } } catch (Exception ex) { throw new Exception("MohidRunEngine.LoadConfig", ex); } }
public void CmdLightUtil(int groupId, CmdArgs args) { string arg = args.PopWord(); switch (arg) { case "lightlevel": bool?cnd = args.PopBool(); if (cnd != null) { config.LightLevels = (bool)cnd; } else { config.LightLevels = !config.LightLevels; } break; case "type": int?type = args.PopInt(); if (type != null) { config.LightLevelType = (EnumLightLevelType)type; } capi.ShowChatMessage("Light Util Type Set To " + Enum.GetName(typeof(EnumLightLevelType), config.LightLevelType)); break; case "radius": int?rad = args.PopInt(); if (rad != null) { config.LightRadius = (int)rad; } capi.ShowChatMessage("Light Util Radius Set To " + config.LightRadius); break; case "alpha": float?alpha = args.PopFloat(); config.LightLevelAlpha = alpha != null ? (float)alpha : config.LightLevelAlpha; capi.ShowChatMessage("Light Util Opacity Set To " + config.LightLevelAlpha); break; case "red": int?red = args.PopInt(); if (red != null) { config.LightLevelRed = (int)red; } capi.ShowChatMessage("Red Level Set To " + config.LightLevelRed); break; case "above": bool?ab = args.PopBool(); if (ab != null) { config.LightLevels = (bool)ab; } else { config.LUShowAbove = !config.LUShowAbove; } capi.ShowChatMessage("Show Above Set To " + config.LUShowAbove); break; default: capi.ShowChatMessage("Syntax: .lightutil [lightlevel|type|radius|alpha|red|above]"); break; } configLoader.SaveConfig(); }
//protected bool FindTemplatesSpecialSetup(ConfigNode toMatch) //{ // if (toMatch.Name == "template.special.setup") // return true; // return false; //} protected bool LoadConfig(CmdArgs args) { Config cfg = new Config(); string configFile; if (args.HasParameter("cfg")) configFile = args.Parameter("cfg"); else configFile = "sim.cfg"; if (args.HasParameter("max.iter")) maxIterations = int.Parse(args.Parameter("max.iter")); else maxIterations = -1; cfg.ConfigFile.FullPath = configFile; if (!cfg.Load()) return false; ConfigNode root = cfg.Root; try { sim.SimDirectory = root["sim.folder", "sim"].AsFilePath(); if (!log.Load(root["log.file", sim.SimDirectory.Path + "sim.log"].AsFileName())) return false; RestartFailedRun = root["restart.failed.run", true].AsBool(); if (log.Count > 0) { ConfigNode lastEntry = log[log.Count - 1]; if (!lastEntry["run.status"].AsBool()) { if (RestartFailedRun) { sim.Start = lastEntry["sim.start"].AsDateTime(dateFormat); sim.SimLenght = lastEntry["sim.lenght"].AsDouble(); simID = lastEntry["sim.id"].AsInt(); } else return false; } else { sim.Start = lastEntry["sim.end"].AsDateTime(dateFormat); sim.SimLenght = root["sim.lenght", 14].AsDouble(); simID = lastEntry["sim.id"].AsInt() + 1; } } else { sim.Start = root["sim.start"].AsDateTime(dateFormat); sim.SimLenght = root["sim.lenght", 14].AsDouble(); simID = 1; } sim.WorkingDirectory = root["working.folder", "."].AsFilePath(); sim.CheckRun = root["check.run", true].AsBool(); sim.Verbose = root["verbose", true].AsBool(); sim.Wait = root["wait", true].AsBool(); sim.SuccessString = root["check.this", "successfully terminated"].AsString(); sim.DataDirectory = root["data.folder", sim.SimDirectory.Path + "data"].AsFilePath(); sim.SetupRunPeriod = root["setup.run.period", false].AsBool(); if (sim.SetupRunPeriod) { sim.EndTAG = root["sim.end.tag", "<<end>>"].AsString(); sim.StartTAG = root["sim.start.tag", "<<start>>"].AsString(); } sim.SetupRunPeriod = root["wait", false].AsBool(); sim.SaveOutput = true; sim.OutputFile = new FileName(sim.SimDirectory.Path + "res" + System.IO.Path.DirectorySeparatorChar + root["output.file", "result.txt"].AsString()); sim.Executable = new FileName(sim.SimDirectory.Path + "exe" + System.IO.Path.DirectorySeparatorChar + root["mohid.executable", "mohid.exe"].AsString()); sim.CreateInputFiles = root["use.templates", false].AsBool(); endOfSimulation = root["sim.end"].AsDateTime(dateFormat); resFolder = root["results.folder", sim.SimDirectory.Path + "res"].AsFilePath(); storeFolder = root["store.folder", sim.SimDirectory.Path + "store"].AsFilePath(); oldFolder = root["old.folder", sim.SimDirectory.Path + "old"].AsFilePath(); if (sim.SetupRunPeriod && !sim.CreateInputFiles) return false; if (sim.CreateInputFiles) { InputFileTemplate newTemplate; List<ConfigNode> itfList = root.ChildNodes.FindAll(FindFirstTemplateInfoBlocks); foreach (ConfigNode ticn in itfList) { newTemplate = new InputFileTemplate(ticn["file"].AsFileName().FullPath, (InputFileTemplateType)Enum.Parse(typeof(InputFileTemplateType), ticn["type", "data"].AsString(), true)); first.Add(newTemplate); } changeTemplates = root["change.templates", true].AsBool(); if (changeTemplates) { itfList = root.ChildNodes.FindAll(FindNextTemplateInfoBlocks); foreach (ConfigNode ticn in itfList) { newTemplate = new InputFileTemplate(ticn["file"].AsFileName().FullPath, (InputFileTemplateType)Enum.Parse(typeof(InputFileTemplateType), ticn["type", "data"].AsString(), true)); next.Add(newTemplate); } } //itfList = root.ChildNodes.FindAll(FindTemplatesSpecialSetup); //if (itfList.Count > 0) //{ // templatesSpecialSetup = true; //} //else // templatesSpecialSetup = false; } } catch { return false; } return true; }
static void Main(string[] args) { Database db = null; string query; OdbcDataReader dbReader; string dateFormat; string server = "http://www.meteoagri.com/"; try { db = new Database(); CmdArgs cmdArgs = new CmdArgs(args); List<DataToRead> list = new List<DataToRead>(); int defaultDaysToDownload; if (cmdArgs.HasParameter("cfg")) { Config conf = new Config(cmdArgs.Parameters["cfg"]); conf.Load(); ConfigNode dbConf = conf.Root.ChildNodes.Find(delegate(ConfigNode node) { return node.Name == "database.config"; }); if (dbConf == null) throw new Exception("No 'database.config' block was found."); if (db.Connect(dbConf["db.conn.string"].AsString()) != Result.TRUE) throw new Exception("Connection to database was not possible. The message returned was: " + db.RaisedException.Message); server = conf.Root["server", "http://www.meteoagri.com/"].AsString(); defaultDaysToDownload = conf.Root["days.to.download", 14].AsInt(); dateFormat = conf.Root["date.format", "#yyyy-MM-dd#"].AsString(); List<ConfigNode> nodeList = conf.Root.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "data.to.read"; }); if (nodeList == null) throw new Exception("No blocks 'nodes.to.read' were found."); DataToRead item; NodeData nd; int blockNumber = 1; foreach (ConfigNode node in nodeList) { item = new DataToRead(); list.Add(item); item.TableName = node["table.name"].AsString(); item.DBDateColumn = node["db.date.column"].AsString(); List<ConfigNode> cfList = node.ChildNodes.FindAll(delegate(ConfigNode n) { return n.Name == "node"; }); if (cfList == null) throw new Exception("No blocks 'node' were found on block number " + blockNumber.ToString()); foreach (ConfigNode cn in cfList) { nd = new NodeData(); nd.DBColumn = cn["column"].AsString(); nd.NodeID = cn["node.id"].AsString(); item.NodesList.Add(nd); } query = string.Format("SELECT {0} FROM {1} ORDER BY {0} DESC", item.DBDateColumn, item.TableName); dbReader = db.ExecuteQuerySingleRow(query); item.Start = DateTime.Now.AddDays(-defaultDaysToDownload); if (dbReader.HasRows) { while (dbReader.Read()) item.Start = dbReader.GetDateTime(dbReader.GetOrdinal(item.DBDateColumn)).AddDays(1); if (!dbReader.IsClosed) dbReader.Close(); } blockNumber++; } } else throw new Exception("No valid configuration file provided. use 'cfg' parameter."); MeteoAgriEngine maEng = new MeteoAgriEngine(server); maEng.TimeOut = 360; Console.Write("Connecting to MeteoAgri..."); if (maEng.Login("arbvs", "arbvs")) { Console.WriteLine("[OK]"); int count = 1; int nItems = 0; Console.WriteLine("DATA READ/WRITE in progress."); foreach (DataToRead dr in list) { //First, find how many "slots" will be downloaded int slots = (DateTime.Now - dr.Start).Days; if (slots <= 0) { count++; continue; //throw new Exception("Start date for 'data.to.read' number " + count.ToString() + " (" + dr.Start.ToString("yyyy-MM-dd") + ") is same than today's date"); } nItems = 0; foreach (NodeData nd in dr.NodesList) { Console.Write("Reading from ARBVS server the node {0}, id = {1}...", nd.DBColumn, nd.NodeID); nd.Data = maEng.GetData(nd.NodeID, dr.Start, slots); if (nd.Data == null) { Console.WriteLine("[NO DATA]"); //throw new Exception(maEng.ExceptionMessage); } else if (nd.Data.Count < 1) { Console.WriteLine("[NO DATA]"); //throw new Exception("ARBVS server returned an empty node"); } else { if (nItems < 1) nItems = nd.Data[0].Data.Count; else if (nItems != nd.Data[0].Data.Count) { Console.WriteLine("[ERROR]"); throw new Exception("ARBVS server returned a different number of items than the previous node"); } Console.WriteLine("[OK]"); //Console.WriteLine(""); //Console.WriteLine("The data returned was:"); //foreach (MeteoAgriNode node in nodes) //{ // Console.WriteLine("NODE : {0}", node.NodeId); // foreach (MeteoAgriData data in node.Data) // Console.WriteLine(string.Format(" type:'{0}' d:'{1}' s:'{2}' t:'{3}' value:'{4}'", // data.Type, data.D, data.S, data.T, data.Value)); // Console.WriteLine("------------"); //} } } string fields, data; if (nItems > 0) { Console.Write("Writing info on database..."); for (int i = 0; i < nItems; i++) { fields = "Instant"; data = dr.Start.AddDays(i).ToString(dateFormat); foreach (NodeData nd in dr.NodesList) { fields += ", " + nd.DBColumn; data += ", " + nd.Data[0].Data[i].Value; } query = string.Format("INSERT INTO {0} ({1}) VALUES ({2})", dr.TableName, fields, data); //if (db.ExecuteCommand(query) != 1) db.ExecuteCommand(query); } Console.WriteLine("[OK][{0} items inserted]", nItems); } count++; } Console.Write("Logging out..."); if (maEng.Logout()) Console.WriteLine("[OK]"); else { Console.WriteLine("[ERROR]"); Console.WriteLine("The message returned was:"); Console.WriteLine(maEng.ExceptionMessage); } } else { Console.WriteLine("[ERROR]"); Console.WriteLine("The message returned was:"); Console.WriteLine(maEng.ExceptionMessage); } db.Disconnect(); } catch (Exception ex) { if (db != null) db.Disconnect(); Console.WriteLine(""); Console.WriteLine("An exception has happened. The message returned was:"); Console.WriteLine(ex.Message); } //Console.WriteLine(""); //Console.WriteLine("Press any key..."); //Console.ReadKey(); }
public void CmdShape(int groupId, CmdArgs args) { BlockPos pos = capi.World.Player.CurrentBlockSelection?.Position ?? capi.World.Player.Entity.Pos.AsBlockPos; string arg = args.PopWord(); int radius = (int)args.PopInt(4); int thickness = (int)args.PopInt(1); int attach = (bool)args.PopBool(false) ? radius + 1 : 0; switch (arg) { case "sphere": for (int x = -radius; x <= radius; x++) { for (int y = -radius; y <= radius; y++) { for (int z = -radius; z <= radius; z++) { BlockPos iPos = new BlockPos(pos.X + x, pos.Y + y + attach, pos.Z + z); int r = x * x + y * y + z * z; if (r <= (radius * radius) && r > (radius - thickness) * (radius - thickness) && iPos.Y > 0) { highlighted.Add(iPos); } } } } MakeHighlights(highlighted); break; case "dome": for (int x = -radius; x <= radius; x++) { for (int y = -radius; y <= radius; y++) { for (int z = -radius; z <= radius; z++) { if (y < 0) { continue; } BlockPos iPos = new BlockPos(pos.X + x, pos.Y + y + attach, pos.Z + z); int r = x * x + y * y + z * z; if (r <= (radius * radius) && r > (radius - thickness) * (radius - thickness) && iPos.Y > 0) { highlighted.Add(iPos); } } } } MakeHighlights(highlighted); break; case "cube": for (int x = -radius; x <= radius; x++) { for (int y = -radius; y <= radius; y++) { for (int z = -radius; z <= radius; z++) { int r = thickness; if (x < r && y < r && z < r && x > -r && y > -r && z > -r) { continue; } BlockPos iPos = new BlockPos(pos.X + x, pos.Y + y + attach - 1, pos.Z + z); if (iPos.Y > 0) { highlighted.Add(iPos); } } } } MakeHighlights(highlighted); break; case "path": WaypointUtilSystem wUtil = capi.ModLoader.GetModSystem <WaypointUtilSystem>(); if (radius > wUtil.Waypoints.Count || thickness > wUtil.Waypoints.Count) { break; } BlockPos wp1Pos = wUtil.Waypoints[radius]?.Position?.AsBlockPos, wp2Pos = wUtil.Waypoints[thickness]?.Position?.AsBlockPos; if (wp1Pos != null && wp2Pos != null) { highlighted = new HashSet <BlockPos>(highlighted.Concat(PlotLine3d(wp1Pos, wp2Pos))); } MakeHighlights(highlighted); break; case "circle": for (int x = -radius; x <= radius; x++) { for (int z = -radius; z <= radius; z++) { BlockPos iPos = new BlockPos(pos.X + x, pos.Y, pos.Z + z); int r = x * x + z * z; if (r <= (radius * radius) && r > (radius - thickness) * (radius - thickness) && iPos.Y > 0) { highlighted.Add(iPos); } } } MakeHighlights(highlighted); break; case "extrude": var tmp = new HashSet <BlockPos>(); var dir = thickness == 0 ? new Vec3i(0, 1, 0) : thickness == 1 ? new Vec3i(1, 0, 0) : thickness == 2 ? new Vec3i(0, 0, 1) : thickness == 3 ? new Vec3i(1, 1, 1) : new Vec3i(0, 0, 0); foreach (var val in highlighted) { for (int i = 0; i < radius; i++) { tmp.Add(val.AddCopy(dir * i)); } } highlighted = new HashSet <BlockPos>(highlighted.Concat(tmp).ToList()); MakeHighlights(highlighted); break; case "toflatten": HashSet <BlockPos> temp = new HashSet <BlockPos>(highlighted); foreach (var val in highlighted) { if (capi.World.BlockAccessor.GetBlock(val).Id == 0) { temp.Remove(val); } } highlighted = temp; MakeHighlights(highlighted); break; case "save": using (TextWriter tw = new StreamWriter("shape" + radius + ".json")) { tw.Write(JsonConvert.SerializeObject(highlighted, Formatting.None)); tw.Close(); } break; case "load": using (TextReader tr = new StreamReader("shape" + radius + ".json")) { highlighted = JsonConvert.DeserializeObject <HashSet <BlockPos> >(tr.ReadToEnd()); tr.Close(); } MakeHighlights(highlighted); break; case "clear": capi.World.HighlightBlocks(capi.World.Player, 514, new List <BlockPos>(), EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Cubes); highlighted.Clear(); break; default: break; } }
private void cmdSnowAccum(IServerPlayer player, int groupId, CmdArgs args) { WeatherSystemServer wsys = api.ModLoader.GetModSystem <WeatherSystemServer>(); string cmd = args.PopWord(); if (cmd == "on") { wsys.snowSimSnowAccu.ProcessChunks = true; player.SendMessage(groupId, "Snow accum process chunks on", EnumChatType.CommandSuccess); return; } if (cmd == "off") { wsys.snowSimSnowAccu.ProcessChunks = false; player.SendMessage(groupId, "Snow accum process chunks off", EnumChatType.CommandSuccess); return; } if (cmd == "processhere") { BlockPos plrPos = player.Entity.Pos.AsBlockPos; int chunksize = api.World.BlockAccessor.ChunkSize; Vec2i chunkPos = new Vec2i(plrPos.X / chunksize, plrPos.Z / chunksize); wsys.snowSimSnowAccu.AddToCheckQueue(chunkPos); player.SendMessage(groupId, "Ok, added to check queue", EnumChatType.CommandSuccess); return; } if (cmd == "info") { BlockPos plrPos = player.Entity.Pos.AsBlockPos; int chunksize = api.World.BlockAccessor.ChunkSize; Vec2i chunkPos = new Vec2i(plrPos.X / chunksize, plrPos.Z / chunksize); IServerMapChunk mc = sapi.WorldManager.GetMapChunk(chunkPos.X, chunkPos.Y); byte[] data = mc.GetData("lastSnowAccumUpdateTotalHours"); double lastSnowAccumUpdateTotalHours = data == null ? 0 : SerializerUtil.Deserialize <double>(data); player.SendMessage(groupId, "lastSnowAccumUpdateTotalHours: " + lastSnowAccumUpdateTotalHours, EnumChatType.CommandSuccess); int regionX = (int)player.Entity.Pos.X / sapi.World.BlockAccessor.RegionSize; int regionZ = (int)player.Entity.Pos.Z / sapi.World.BlockAccessor.RegionSize; WeatherSystemServer wsysServer = sapi.ModLoader.GetModSystem <WeatherSystemServer>(); long index2d = wsysServer.MapRegionIndex2D(regionX, regionZ); WeatherSimulationRegion simregion; wsysServer.weatherSimByMapRegion.TryGetValue(index2d, out simregion); int reso = WeatherSimulationRegion.snowAccumResolution; SnowAccumSnapshot sumsnapshot = new SnowAccumSnapshot() { //SumTemperatureByRegionCorner = new API.FloatDataMap3D(reso, reso, reso), SnowAccumulationByRegionCorner = new API.FloatDataMap3D(reso, reso, reso) }; float[] sumdata = sumsnapshot.SnowAccumulationByRegionCorner.Data; // Can't grow bigger than one full snow block float max = 3 + 0.5f; int len = simregion.SnowAccumSnapshots.Length; int i = simregion.SnowAccumSnapshots.Start; // This code here causes wacky snow patterns // The lerp itself is fine!!! while (len-- > 0) { SnowAccumSnapshot hoursnapshot = simregion.SnowAccumSnapshots[i]; i = (i + 1) % simregion.SnowAccumSnapshots.Length; float[] snowaccumdata = hoursnapshot.SnowAccumulationByRegionCorner.Data; for (int j = 0; j < snowaccumdata.Length; j++) { sumdata[j] = GameMath.Clamp(sumdata[j] + snowaccumdata[j], -max, max); } lastSnowAccumUpdateTotalHours = Math.Max(lastSnowAccumUpdateTotalHours, hoursnapshot.TotalHours); } for (int j = 0; j < sumdata.Length; j++) { player.SendMessage(groupId, j + ": " + sumdata[j], EnumChatType.CommandSuccess); } return; } if (cmd == "here") { float amount = (float)args.PopFloat(0); BlockPos plrPos = player.Entity.Pos.AsBlockPos; int chunksize = api.World.BlockAccessor.ChunkSize; Vec2i chunkPos = new Vec2i(plrPos.X / chunksize, plrPos.Z / chunksize); IServerMapChunk mc = sapi.WorldManager.GetMapChunk(chunkPos.X, chunkPos.Y); int reso = WeatherSimulationRegion.snowAccumResolution; SnowAccumSnapshot sumsnapshot = new SnowAccumSnapshot() { SumTemperatureByRegionCorner = new API.FloatDataMap3D(reso, reso, reso), SnowAccumulationByRegionCorner = new API.FloatDataMap3D(reso, reso, reso) }; sumsnapshot.SnowAccumulationByRegionCorner.Data.Fill(amount); var updatepacket = wsys.snowSimSnowAccu.UpdateSnowLayer(sumsnapshot, true, mc, chunkPos); wsys.snowSimSnowAccu.accum = 1f; var ba = sapi.World.GetBlockAccessorBulkMinimalUpdate(true, false); ba.UpdateSnowAccumMap = false; wsys.snowSimSnowAccu.processBlockUpdates(chunkPos, updatepacket, ba); ba.Commit(); player.SendMessage(groupId, "Ok, test snow accum gen complete", EnumChatType.CommandSuccess); return; } }
/// <summary> Adds a binary command argument. </summary> /// <param name="argument"> The argument. </param> public void AddBinArgument(bool argument) { _lazyArguments.Add(() => CmdArgs.Add(BinaryConverter.ToString(argument ? (byte)1 : (byte)0))); }
static int Main(string[] args) { CmdArgs cmdArgs = null; Exception last_exception = null; string task_block; try { Setup.StandartSetup(); cmdArgs = new CmdArgs(args); //====================================================================================== //Load configuration //====================================================================================== Config cfg = new Config(cmdArgs.Parameter("cfg")); if (!cfg.Load()) { Console.WriteLine("[{0}] Was not possible to load the configuration file '{1}'", DateTime.Now, cmdArgs.Parameter("cfg")); return -1; } //====================================================================================== //Check to see if there are a specific name for the task block //====================================================================================== if (cmdArgs.HasParameter("task")) task_block = cmdArgs.Parameter("task"); else task_block = "task.config"; //====================================================================================== //Execute task //====================================================================================== ConfigNode task_cfg = cfg.Root.ChildNodes.Find(delegate(ConfigNode node) { return node.Name == task_block; }); if (task_cfg != null) { TaskEngine te = new TaskEngine(); if (!te.LoadConfig(task_cfg)) { if ((last_exception = te.LastException) == null) last_exception = new Exception("Unknow error during process of task configuration."); } if (!te.CreateNewHDF()) { if ((last_exception = te.LastException) == null) last_exception = new Exception("Unknow error during process of task execution."); } te.End(); } else { last_exception = new Exception("No task.config block found in configuration."); } if (cmdArgs.HasOption("verbose")) { if (last_exception != null) Console.WriteLine("MohidHDF5Processor FAILED to complete the process."); else Console.WriteLine("MohidHDF5Processor SUCCESSFULLY completed the process."); } //====================================================================================== //Send STATUS e-mail if mail.config block exists //====================================================================================== ConfigNode mail_cfg = cfg.Root.ChildNodes.Find(delegate(ConfigNode node) { return node.Name == "mail.config"; }); if (mail_cfg != null) { MailEngine mail_engine = new MailEngine(); if (!mail_engine.SendMail(mail_cfg, last_exception)) { Console.WriteLine("[{0}] Was not possible to send the status e-mail.", DateTime.Now); if ((last_exception = mail_engine.LastException) != null) Console.WriteLine("The message returned was: {0}", last_exception); return -1; } } else if (last_exception != null) { throw last_exception; } } catch(Exception ex) { Console.WriteLine("[{0}] An unexpected exception happened. The message returned was: {1}", DateTime.Now, ex.Message); return -1; } return 0; // HDFEngine engine = new HDFEngine(); // Exception last_ex = null; // Console.WriteLine("Starting..."); // if (!engine.InitializeLibrary()) // { // Console.WriteLine("Library start failed."); // if ((last_ex = engine.LastException) != null) // Console.WriteLine("Message: {0}", last_ex.Message); // } // if (!engine.OpenHDF(new FileName(@"E:\Development\Tests\HDF5\basin.evtp.hdf5"))) // { // Console.WriteLine("File Open failed."); // if ((last_ex = engine.LastException) != null) // Console.WriteLine("Message: {0}", last_ex.Message); // } // Console.WriteLine("ROOT: '/'"); // List<HDFObjectInfo> list = engine.GetTree(null, engine.FileID, "/"); // PrintList(list, 0); // Console.WriteLine(""); // Console.WriteLine("ROOT: '/Grid/'"); // list.Clear(); // list = engine.GetTree(null, engine.FileID, "/Grid/"); // PrintList(list, 1); // if (!engine.CloseHDF()) // { // Console.WriteLine("File Close failed."); // if ((last_ex = engine.LastException) != null) // Console.WriteLine("Message: {0}", last_ex.Message); // } // if (!engine.CloseLibrary()) // { // Console.WriteLine("Library close failed."); // if ((last_ex = engine.LastException) != null) // Console.WriteLine("Message: {0}", last_ex.Message); // } // Console.WriteLine("End. Press any key."); // Console.ReadKey(); //} //public static void PrintList(List<HDFObjectInfo> list, int level) //{ // foreach (HDFObjectInfo oi in list) // { // Console.WriteLine("{0}: {1}", level, oi.Name); // if (oi.Children != null) // PrintList(oi.Children, level + 1); // } }
/// <summary> /// Delegate for /treasure command. Places a treasure chest 2 blocks in front of the player /// </summary> private void PlaceTreasureChestInFrontOfPlayer(IServerPlayer player, int groupId, CmdArgs args) { PlaceTreasureChest(_api.World.BlockAccessor, player.Entity.Pos.HorizontalAheadCopy(2).AsBlockPos); }
public static bool Prefix(IServerPlayer player, int groupId, CmdArgs args) { player.SendMessage(groupId, Lang.Get("Waypoints have been disabled by LostInTheWild"), EnumChatType.CommandSuccess); return(false); // skip original method }
private void OnCmdNpc(IServerPlayer player, int groupId, CmdArgs args) { long entityid = 0; currentEntityIdByPlayerUid.TryGetValue(player.PlayerUID, out entityid); if (entityid == 0) { player.SendMessage(groupId, "Select a npc first", EnumChatType.Notification); return; } Entity entity; sapi.World.LoadedEntities.TryGetValue(entityid, out entity); EntityAnimalBot entityNpc = entity as EntityAnimalBot; if (entityNpc == null) { player.SendMessage(groupId, "No such npc with this id found", EnumChatType.Notification); return; } string cmd = args.PopWord(); switch (cmd) { case "start": entityNpc.StartExecuteCommands(); player.SendMessage(groupId, "Started command execution", EnumChatType.Notification); break; case "stop": entityNpc.StopExecuteCommands(); player.SendMessage(groupId, "Stopped command execution", EnumChatType.Notification); break; case "loop": entityNpc.LoopCommands = (bool)args.PopBool(); player.SendMessage(groupId, "Command list set to looping", EnumChatType.Notification); break; case "clear": entityNpc.Commands.Clear(); if (entityNpc.ExecutingCommands.Count > 0) { entityNpc.ExecutingCommands.Peek().Stop(); } entityNpc.ExecutingCommands.Clear(); player.SendMessage(groupId, "Command list cleared", EnumChatType.Notification); break; case "remove": int index = (int)args.PopInt(); if (index >= 0 && index < entityNpc.Commands.Count) { entityNpc.Commands.RemoveAt(index); player.SendMessage(groupId, "Ok, removed given command", EnumChatType.Notification); } else { player.SendMessage(groupId, "Index out of range or command list empty", EnumChatType.Notification); } break; case "list": StringBuilder sb = new StringBuilder(); int i = 0; foreach (var val in entityNpc.Commands) { sb.AppendLine(i + ": " + val.ToString()); i++; } player.SendMessage(groupId, sb.ToString(), EnumChatType.Notification); break; case "upd": { int?idx = args.PopInt(null); if (idx == null) { player.SendMessage(groupId, "No index supplied", EnumChatType.Notification); return; } if (idx < 0 || idx > entityNpc.Commands.Count) { player.SendMessage(groupId, "Index out of range", EnumChatType.Notification); return; } entityNpc.Commands[(int)idx].Update(player, sapi, args); return; } case "exec": { string subcmd = args.PopWord(); if (subcmd == null) { player.SendMessage(groupId, "Syntax: /npc enq [tp|goto|upd|playanim]", EnumChatType.Notification); return; } Vec3d target = null; if (subcmd == "tp" || subcmd == "goto") { Vec3d spawnpos = sapi.World.DefaultSpawnPosition.XYZ; spawnpos.Y = 0; target = args.PopFlexiblePos(player.Entity.Pos.XYZ, spawnpos); } if (subcmd == "goto") { if (args.Length <= 2) { player.SendMessage(groupId, "Syntax: /npc exec goto x y z animcode speed [animspeed]", EnumChatType.Notification); return; } entityNpc.ExecutingCommands.Enqueue(new NpcGotoCommand(entityNpc, target, args.PopWord(), (float)args.PopFloat(0.02f), (float)args.PopFloat(1))); } if (subcmd == "lookat") { entityNpc.ExecutingCommands.Enqueue(new NpcLookatCommand(entityNpc, (float)args.PopFloat(0))); } if (subcmd == "tp") { entityNpc.ExecutingCommands.Enqueue(new NpcTeleportCommand(entityNpc, target)); } if (subcmd == "playanim") { if (args.Length < 1) { player.SendMessage(groupId, "Syntax: /npc exec animcode [animspeed]", EnumChatType.Notification); return; } entityNpc.ExecutingCommands.Enqueue(new NpcPlayAnimationCommand(entityNpc, args.PopWord(), (float)args.PopFloat(1))); } entityNpc.StartExecuteCommands(false); player.SendMessage(groupId, "Started executing. " + entityNpc.ExecutingCommands.Count + " commands in queue", EnumChatType.Notification); } break; case "enq": case "enqueue": { string subcmd = args.PopWord(); if (subcmd == null) { player.SendMessage(groupId, "Syntax: /npc enq [tp|goto|upd|playanim]", EnumChatType.Notification); return; } Vec3d target = null; if (subcmd == "tp" || subcmd == "goto") { Vec3d spawnpos = sapi.World.DefaultSpawnPosition.XYZ; spawnpos.Y = 0; target = args.PopFlexiblePos(player.Entity.Pos.XYZ, spawnpos); } if (subcmd == "goto") { if (args.Length <= 2) { player.SendMessage(groupId, "Syntax: /npc enq goto x y z animcode speed [animspeed]", EnumChatType.Notification); return; } entityNpc.Commands.Add(new NpcGotoCommand(entityNpc, target, args.PopWord(), (float)args.PopFloat(0.02f), (float)args.PopFloat(1))); player.SendMessage(groupId, "Command enqueued", EnumChatType.Notification); return; } if (subcmd == "lookat") { entityNpc.Commands.Add(new NpcLookatCommand(entityNpc, (float)args.PopFloat(0))); player.SendMessage(groupId, "Command enqueued", EnumChatType.Notification); } if (subcmd == "tp") { entityNpc.Commands.Add(new NpcTeleportCommand(entityNpc, target)); player.SendMessage(groupId, "Command enqueued", EnumChatType.Notification); return; } if (subcmd == "playanim") { if (args.Length < 1) { player.SendMessage(groupId, "Syntax: /npc enq animcode [animspeed]", EnumChatType.Notification); return; } entityNpc.Commands.Add(new NpcPlayAnimationCommand(entityNpc, args.PopWord(), (float)args.PopFloat(1))); player.SendMessage(groupId, "Command enqueued", EnumChatType.Notification); return; } player.SendMessage(groupId, "Unknown command", EnumChatType.Notification); break; } default: player.SendMessage(groupId, "Syntax: /npc [list|enqueue or enq|start|stop|clear|remove|loop]", EnumChatType.Notification); break; } }
public override bool OnWorldEditCommand(WorldEdit worldEdit, CmdArgs args) { switch (args[0]) { case "tm": EnumBrushMode brushMode = EnumBrushMode.Fill; if (args.Length > 1) { int index; int.TryParse(args[1], out index); if (Enum.IsDefined(typeof(EnumBrushMode), index)) { brushMode = (EnumBrushMode)index; } } BrushMode = brushMode; worldEdit.Good(workspace.ToolName + " mode " + brushMode + " set."); workspace.ResendBlockHighlights(worldEdit); return(true); case "tdl": EnumDepthLimit depthLimit = EnumDepthLimit.NoLimit; if (args.Length > 1) { int index; int.TryParse(args[1], out index); if (Enum.IsDefined(typeof(EnumDepthLimit), index)) { depthLimit = (EnumDepthLimit)index; } } DepthLimit = depthLimit; worldEdit.Good(workspace.ToolName + " depth limit set to " + depthLimit); workspace.ResendBlockHighlights(worldEdit); return(true); case "ts": EnumBrushShape shape = EnumBrushShape.Ball; if (args.Length > 1) { int index; int.TryParse(args[1], out index); if (Enum.IsDefined(typeof(EnumBrushShape), index)) { shape = (EnumBrushShape)index; } } BrushShape = shape; worldEdit.Good(workspace.ToolName + " shape " + BrushShape + " set."); GenBrush(); workspace.ResendBlockHighlights(worldEdit); return(true); case "tsx": case "tsy": case "tsz": { float size = 0; if (args.Length > 1) { float.TryParse(args[1], out size); } if (args[0] == "tsx") { BrushDim1 = size; } if (args[0] == "tsy") { BrushDim2 = size; } if (args[0] == "tsz") { BrushDim3 = size; } string text = dimensionNames[(int)BrushShape][0] + "=" + BrushDim1; text += ", " + dimensionNames[(int)BrushShape][1] + "=" + BrushDim2; text += ", " + dimensionNames[(int)BrushShape][2] + "=" + BrushDim3; worldEdit.Good(workspace.ToolName + " dimensions " + text + " set."); GenBrush(); workspace.ResendBlockHighlights(worldEdit); return(true); } case "tr": { BrushDim1 = 0; float size; if (args.Length > 1 && float.TryParse(args[1], out size)) { BrushDim1 = size; } if (args.Length > 2 && float.TryParse(args[2], out size)) { BrushDim2 = size; } else { BrushDim2 = BrushDim1; } if (args.Length > 3 && float.TryParse(args[3], out size)) { BrushDim3 = size; } else { BrushDim3 = BrushDim2; } string text = dimensionNames[(int)BrushShape][0] + "=" + BrushDim1; text += ", " + dimensionNames[(int)BrushShape][1] + "=" + BrushDim2; text += ", " + dimensionNames[(int)BrushShape][2] + "=" + BrushDim3; worldEdit.Good(workspace.ToolName + " dimensions " + text + " set."); GenBrush(); workspace.ResendBlockHighlights(worldEdit); } return(true); case "tcx": case "tcy": case "tcz": { float size = 0; if (args.Length > 1) { float.TryParse(args[1], out size); } if (args[0] == "tcx") { CutoutDim1 = size; } if (args[0] == "tcy") { CutoutDim2 = size; } if (args[0] == "tcz") { CutoutDim3 = size; } string text = dimensionNames[(int)BrushShape][0] + "=" + CutoutDim1; text += ", " + dimensionNames[(int)BrushShape][1] + "=" + CutoutDim2; text += ", " + dimensionNames[(int)BrushShape][2] + "=" + CutoutDim3; worldEdit.Good(workspace.ToolName + " cutout dimensions " + text + " set."); GenBrush(); workspace.ResendBlockHighlights(worldEdit); return(true); } case "tcr": { CutoutDim1 = 0; float size; if (args.Length > 1 && float.TryParse(args[1], out size)) { CutoutDim1 = size; } if (args.Length > 2 && float.TryParse(args[2], out size)) { CutoutDim2 = size; } else { CutoutDim2 = CutoutDim1; } if (args.Length > 3 && float.TryParse(args[3], out size)) { CutoutDim3 = size; } else { CutoutDim3 = CutoutDim2; } string text = dimensionNames[(int)BrushShape][0] + "=" + CutoutDim1; text += ", " + dimensionNames[(int)BrushShape][1] + "=" + CutoutDim2; text += ", " + dimensionNames[(int)BrushShape][2] + "=" + CutoutDim3; worldEdit.Good("Cutout " + workspace.ToolName + " dimensions " + text + " set."); GenBrush(); workspace.ResendBlockHighlights(worldEdit); } return(true); case "tgr": { BrushDim1++; BrushDim2++; BrushDim3++; string text = dimensionNames[(int)BrushShape][0] + "=" + BrushDim1; text += ", " + dimensionNames[(int)BrushShape][1] + "=" + BrushDim2; text += ", " + dimensionNames[(int)BrushShape][2] + "=" + BrushDim3; worldEdit.Good(workspace.ToolName + " dimensions " + text + " set."); GenBrush(); workspace.ResendBlockHighlights(worldEdit); } return(true); case "tsr": { BrushDim1 = Math.Max(0, BrushDim1 - 1); BrushDim2 = Math.Max(0, BrushDim2 - 1); BrushDim3 = Math.Max(0, BrushDim3 - 1); string text = dimensionNames[(int)BrushShape][0] + "=" + BrushDim1; text += ", " + dimensionNames[(int)BrushShape][1] + "=" + BrushDim2; text += ", " + dimensionNames[(int)BrushShape][2] + "=" + BrushDim3; worldEdit.Good(workspace.ToolName + " dimensions " + text + " set."); GenBrush(); workspace.ResendBlockHighlights(worldEdit); } return(true); } return(false); }
private void CmdEdit(IServerPlayer player, int groupId, CmdArgs args) { this.player = player; this.groupId = groupId; BlockPos centerPos = player.Entity.Pos.AsBlockPos; if (args.Length == 0) { Bad("Invalid arguments"); return; } switch (args[0]) { case "mex": if (startMarker == null || endMarker == null) { Bad("Please mark start and end position"); break; } if (args.Length < 2) { Bad("Please provide a filename"); break; } ExportArea(args[1], startMarker, endMarker); break; case "imp": if (startMarker == null) { Bad("Please mark a start position"); break; } if (args.Length < 2) { Bad("Please provide a filename"); break; } EnumOrigin origin = EnumOrigin.StartPos; if (args.Length > 2) { try { origin = (EnumOrigin)Enum.Parse(typeof(EnumOrigin), args[2]); } catch (Exception) { } } ImportArea(args[1], startMarker, origin); break; case "blu": BlockLineup(centerPos); Good("Block lineup created"); break; // Mark start case "ms": startMarker = centerPos; Good("Start position " + startMarker + " marked"); break; // Mark end case "me": endMarker = centerPos; Good("End position " + endMarker + " marked"); break; // Mark clear case "mc": startMarker = null; endMarker = null; Good("Marked positions cleared"); break; // Fill marked case "fillm": if (startMarker == null || endMarker == null) { Bad("Start marker or end marker not set"); return; } IPlayerInventoryManager plrInv = player.InventoryManager; IItemStack stack = plrInv.ActiveHotbarSlot.Itemstack; if (stack == null || stack.Class == EnumItemClass.Item) { Bad("Please put the desired block in your active hotbar slot"); return; } int filled = FillArea((ushort)stack.Id, startMarker, endMarker); Good(filled + " marked blocks placed"); break; // Clear marked case "clm": { if (startMarker == null || endMarker == null) { Bad("Start marker or end marker not set"); return; } int cleared = FillArea(0, startMarker, endMarker); Good(cleared + " marked blocks cleared"); } break; // Clear area case "cla": { if (args.Length < 2) { Bad("Missing size param"); return; } int size = 0; if (!int.TryParse(args[1], out size)) { Bad("Invalide size param"); return; } int height = 20; if (args.Length > 2) { int.TryParse(args[2], out height); } int cleared = FillArea(0, centerPos.AddCopy(-size, 0, -size), centerPos.AddCopy(size, height, size)); Good(cleared + " Blocks cleared"); } break; default: Bad("No such function " + args[0]); break; } }
public void CmdLightUtil(int groupId, CmdArgs args) { string arg = args.PopWord(); switch (arg) { case "lightlevel": bool?cnd = args.PopBool(); if (cnd != null) { config.LightLevels = (bool)cnd; } else { config.LightLevels = !config.LightLevels; } break; case "type": int?type = args.PopInt(); if (type != null) { config.LightLevelType = (EnumLightLevelType)type; } capi.ShowChatMessage("Light Util Type Set To " + Enum.GetName(typeof(EnumLightLevelType), config.LightLevelType)); break; case "radius": int?rad = args.PopInt(); if (rad != null) { config.LightRadius = (int)rad; } capi.ShowChatMessage("Light Util Radius Set To " + config.LightRadius); break; case "alpha": float?alpha = args.PopFloat(); config.LightLevelAlpha = alpha != null ? (float)alpha : config.LightLevelAlpha; capi.ShowChatMessage("Light Util Opacity Set To " + config.LightLevelAlpha); break; case "red": int?red = args.PopInt(); if (red != null) { config.LightLevelRed = (int)red; } capi.ShowChatMessage("Red Level Set To " + config.LightLevelRed); break; case "above": bool?ab = args.PopBool(); if (ab != null) { config.LightLevels = (bool)ab; } else { config.LUShowAbove = !config.LUShowAbove; } capi.ShowChatMessage("Show Above Set To " + config.LUShowAbove); break; case "nutrients": bool?ac = args.PopBool(); config.Nutrients = ac ?? !config.Nutrients; capi.ShowChatMessage("Show Farmland Nutrient Set To " + config.Nutrients); break; case "mxnutrients": bool?ad = args.PopBool(); config.MXNutrients = ad ?? !config.MXNutrients; capi.ShowChatMessage(string.Format("Farmland Nutrient Display Set To {0}.", config.MXNutrients ? "Max" : "Min")); break; default: capi.ShowChatMessage("Syntax: .lightutil [lightlevel|type|radius|alpha|red|above|nutrients(enable farmland nutrient display)|mxnutrients(toggle whether to show the min or max nutrient)]"); break; } configLoader.SaveConfig(); }
private void cmdPrecTestServer(IServerPlayer player, int groupId, CmdArgs args) { WeatherSystemServer wsys = api.ModLoader.GetModSystem <WeatherSystemServer>(); EntityPos pos = player.Entity.Pos; int wdt = 400; float hourStep = 4f; float days = 1f; float posStep = 2f; double totaldays = api.World.Calendar.TotalDays; string subarg = args.PopWord(); bool climateTest = subarg == "climate"; if (subarg == "pos") { float precip = wsys.GetPrecipitation(pos.X, pos.Y, pos.Z, totaldays); player.SendMessage(groupId, "Prec here: " + precip, EnumChatType.CommandSuccess); return; } ClimateCondition conds = api.World.BlockAccessor.GetClimateAt(new BlockPos((int)pos.X, (int)pos.Y, (int)pos.Z), EnumGetClimateMode.WorldGenValues, totaldays); int offset = wdt / 2; Bitmap bmp; int[] pixels; if (subarg == "here") { wdt = 400; bmp = new Bitmap(wdt, wdt, PixelFormat.Format32bppArgb); pixels = new int[wdt * wdt]; posStep = 3f; offset = wdt / 2; for (int dx = 0; dx < wdt; dx++) { for (int dz = 0; dz < wdt; dz++) { float x = dx * posStep - offset; float z = dz * posStep - offset; if ((int)x == 0 && (int)z == 0) { pixels[dz * wdt + dx] = ColorUtil.ColorFromRgba(255, 0, 0, 255); continue; } float precip = wsys.GetPrecipitation(pos.X + x, pos.Y, pos.Z + z, totaldays); int precipi = (int)GameMath.Clamp(255 * precip, 0, 254); pixels[dz * wdt + dx] = ColorUtil.ColorFromRgba(precipi, precipi, precipi, 255); } } bmp.SetPixels(pixels); bmp.Save("preciphere.png"); player.SendMessage(groupId, "Ok exported", EnumChatType.CommandSuccess); return; } bmp = new Bitmap(wdt, wdt, PixelFormat.Format32bppArgb); pixels = new int[wdt * wdt]; using (var gif = AnimatedGif.AnimatedGif.Create("precip.gif", 100, -1)) { for (int i = 0; i < days * 24f; i++) { if (climateTest) { for (int dx = 0; dx < wdt; dx++) { for (int dz = 0; dz < wdt; dz++) { conds.Rainfall = (float)i / (days * 24f); float precip = wsys.GetRainCloudness(conds, pos.X + dx * posStep - offset, pos.Z + dz * posStep - offset, api.World.Calendar.TotalDays); int precipi = (int)GameMath.Clamp(255 * precip, 0, 254); pixels[dz * wdt + dx] = ColorUtil.ColorFromRgba(precipi, precipi, precipi, 255); } } } else { for (int dx = 0; dx < wdt; dx++) { for (int dz = 0; dz < wdt; dz++) { float precip = wsys.GetPrecipitation(pos.X + dx * posStep - offset, pos.Y, pos.Z + dz * posStep - offset, totaldays); int precipi = (int)GameMath.Clamp(255 * precip, 0, 254); pixels[dz * wdt + dx] = ColorUtil.ColorFromRgba(precipi, precipi, precipi, 255); } } } totaldays += hourStep / 24f; bmp.SetPixels(pixels); gif.AddFrame(bmp, 100, GifQuality.Grayscale); } } player.SendMessage(groupId, "Ok exported", EnumChatType.CommandSuccess); }
public override bool OnWorldEditCommand(WorldEdit worldEdit, CmdArgs args) { switch (args[0]) { case "imc": if (workspace.clipboardBlockData != null) { this.blockDatas = new BlockSchematic[] { workspace.clipboardBlockData }; worldEdit.Good("Ok, using copied blockdata"); nextRnd = 0; workspace.ResendBlockHighlights(worldEdit); } else { worldEdit.Good("No copied block data available"); } return(true); case "ims": string exportFolderPath = worldEdit.sapi.GetOrCreateDataPath("WorldEdit"); List <string> filenames = new List <string>(); for (int i = 1; i < args.Length; i++) { string filename = Path.GetFileName(args[i]); string filepath = Path.Combine(exportFolderPath, args[i]); if (!filename.EndsWith("*") && !filename.EndsWith("/") && !filename.EndsWith(".json")) { filename += ".json"; } try { string[] foundFilePaths = Directory.GetFiles(Path.GetDirectoryName(filepath), filename); for (int j = 0; j < foundFilePaths.Length; j++) { filenames.Add(foundFilePaths[j].Substring(exportFolderPath.Length + 1)); } } catch (Exception) { worldEdit.Bad("Unable to read files from this source"); return(true); } } if (filenames.Count > 0) { BlockDataFilenames = string.Join(",", filenames); LoadBlockdatas(worldEdit.sapi, worldEdit); worldEdit.Good("Ok, found " + filenames.Count + " block data source files"); } else { BlockDataFilenames = null; this.blockDatas = new BlockSchematic[0]; worldEdit.Good("No source files under this name/wildcard found"); } nextRnd = rand.Next(blockDatas.Length); workspace.ResendBlockHighlights(worldEdit); return(true); case "imo": Origin = EnumOrigin.BottomCenter; if (args.Length > 1) { int origin; int.TryParse(args[1], out origin); if (Enum.IsDefined(typeof(EnumOrigin), origin)) { Origin = (EnumOrigin)origin; } } worldEdit.Good("Paste origin " + Origin + " set."); workspace.ResendBlockHighlights(worldEdit); return(true); case "tm": ReplaceMode = EnumReplaceMode.Replaceable; if (args.Length > 1) { int replaceable = 0; int.TryParse(args[1], out replaceable); if (Enum.IsDefined(typeof(EnumReplaceMode), replaceable)) { ReplaceMode = (EnumReplaceMode)replaceable; } } worldEdit.Good("Replace mode " + ReplaceMode + " set."); workspace.ResendBlockHighlights(worldEdit); return(true); case "imrrand": RandomRotate = args.Length > 1 && (args[1] == "1" || args[1] == "true" || args[1] == "on"); worldEdit.Good("Random rotation now " + (RandomRotate ? "on" : "off")); SetRandomAngle(worldEdit.sapi.World); workspace.ResendBlockHighlights(worldEdit); return(true); case "imn": nextRnd = rand.Next(blockDatas.Length); workspace.ResendBlockHighlights(worldEdit); break; case "imr": if (blockDatas == null || blockDatas.Length == 0) { worldEdit.Bad("Please define a block data source first."); return(true); } int angle = 90; if (args.Length > 1) { if (!int.TryParse(args[1], out angle)) { worldEdit.Bad("Invalid Angle (not a number)"); return(true); } } if (angle < 0) { angle += 360; } if (angle != 0 && angle != 90 && angle != 180 && angle != 270) { worldEdit.Bad("Invalid Angle, allowed values are -270, -180, -90, 0, 90, 180 and 270"); return(true); } for (int i = 0; i < blockDatas.Length; i++) { blockDatas[i].TransformWhilePacked(worldEdit.sapi.World, EnumOrigin.BottomCenter, angle, null); } workspace.ResendBlockHighlights(worldEdit); worldEdit.Good("Ok, all schematics rotated by " + angle + " degrees"); return(true); case "imflip": if (blockDatas == null || blockDatas.Length == 0) { worldEdit.Bad("Please define a block data source first."); return(true); } for (int i = 0; i < blockDatas.Length; i++) { blockDatas[i].TransformWhilePacked(worldEdit.sapi.World, EnumOrigin.BottomCenter, 0, EnumAxis.Y); } workspace.ResendBlockHighlights(worldEdit); worldEdit.Good("Ok, imported sources flipped"); return(true); case "immirror": if (blockDatas == null || blockDatas.Length == 0) { worldEdit.Bad("Please define a block data source first."); return(true); } EnumAxis axis = EnumAxis.X; if (args.PopWord().ToLowerInvariant() == "z") { axis = EnumAxis.Z; } for (int i = 0; i < blockDatas.Length; i++) { blockDatas[i].TransformWhilePacked(worldEdit.sapi.World, EnumOrigin.BottomCenter, 0, axis); } workspace.ResendBlockHighlights(worldEdit); worldEdit.Good("Ok, imported sources mirrored around " + axis + " axis"); return(true); } return(false); }
private void cmdWeatherServer(IServerPlayer player, int groupId, CmdArgs args) { WeatherSystemServer wsysServer = sapi.ModLoader.GetModSystem <WeatherSystemServer>(); int regionX = (int)player.Entity.Pos.X / sapi.World.BlockAccessor.RegionSize; int regionZ = (int)player.Entity.Pos.Z / sapi.World.BlockAccessor.RegionSize; string arg = args.PopWord(); if (arg == "setprecip") { if (args.Length == 0) { if (wsysServer.OverridePrecipitation == null) { player.SendMessage(groupId, "Currently no precipitation override active.", EnumChatType.CommandSuccess); } else { player.SendMessage(groupId, string.Format("Override precipitation value is currently at {0}.", wsysServer.OverridePrecipitation), EnumChatType.CommandSuccess); } return; } string val = args.PopWord(); if (val == "auto") { wsysServer.OverridePrecipitation = null; player.SendMessage(groupId, "Ok auto precipitation on", EnumChatType.CommandSuccess); } else { float level = val.ToFloat(0); wsysServer.OverridePrecipitation = level; player.SendMessage(groupId, string.Format("Ok precipitation set to {0}", level), EnumChatType.CommandSuccess); } wsysServer.serverChannel.BroadcastPacket(new WeatherConfigPacket() { OverridePrecipitation = wsysServer.OverridePrecipitation, RainCloudDaysOffset = wsysServer.RainCloudDaysOffset }); return; } if (arg == "stoprain") { rainStopFunc(player, groupId, true); wsysServer.broadCastConfigUpdate(); return; } if (arg == "acp") { wsysServer.autoChangePatterns = !wsysServer.autoChangePatterns; player.SendMessage(groupId, "Ok autochange weather patterns now " + (wsysServer.autoChangePatterns ? "on" : "off"), EnumChatType.CommandSuccess); return; } if (arg == "lp") { string patterns = string.Join(", ", wsysServer.WeatherConfigs.Select(c => c.Code)); player.SendMessage(groupId, "Patterns: " + patterns, EnumChatType.CommandSuccess); return; } if (arg == "t") { foreach (var val in wsysServer.weatherSimByMapRegion) { val.Value.TriggerTransition(); } player.SendMessage(groupId, "Ok transitioning to another weather pattern", EnumChatType.CommandSuccess); return; } if (arg == "c") { foreach (var val in wsysServer.weatherSimByMapRegion) { val.Value.TriggerTransition(1f); } player.SendMessage(groupId, "Ok selected another weather pattern", EnumChatType.CommandSuccess); return; } if (arg == "setw") { wsysServer.ReloadConfigs(); string code = args.PopWord(); bool ok = true; foreach (var val in wsysServer.weatherSimByMapRegion) { val.Value.ReloadPatterns(api.World.Seed); ok &= val.Value.SetWindPattern(code, true); if (ok) { val.Value.TickEvery25ms(0.025f); } } if (!ok) { player.SendMessage(groupId, "No such wind pattern found", EnumChatType.CommandError); } else { player.SendMessage(groupId, "Ok wind pattern set", EnumChatType.CommandSuccess); } return; } if (arg == "setev" || arg == "setevr") { wsysServer.ReloadConfigs(); string code = args.PopWord(); WeatherSimulationRegion weatherSim; if (arg == "setevr") { long index2d = wsysServer.MapRegionIndex2D(regionX, regionZ); wsysServer.weatherSimByMapRegion.TryGetValue(index2d, out weatherSim); if (weatherSim == null) { player.SendMessage(groupId, "Weather sim not loaded (yet) for this region", EnumChatType.CommandError); return; } if (weatherSim.SetWeatherEvent(code, true)) { weatherSim.TickEvery25ms(0.025f); player.SendMessage(groupId, "Ok weather event for this region set", EnumChatType.CommandSuccess); } else { player.SendMessage(groupId, "No such weather event found", EnumChatType.CommandError); } } else { bool ok = true; foreach (var val in wsysServer.weatherSimByMapRegion) { ok &= val.Value.SetWeatherEvent(code, true); if (ok) { val.Value.TickEvery25ms(0.025f); } } if (!ok) { player.SendMessage(groupId, "No such weather event found", EnumChatType.CommandError); } else { player.SendMessage(groupId, "Ok weather event set for all loaded regions", EnumChatType.CommandSuccess); } } return; } if (arg == "set" || arg == "seti") { wsysServer.ReloadConfigs(); string code = args.PopWord(); bool ok = true; foreach (var val in wsysServer.weatherSimByMapRegion) { ok &= val.Value.SetWeatherPattern(code, true); if (ok) { val.Value.TickEvery25ms(0.025f); } } if (!ok) { player.SendMessage(groupId, "No such weather pattern found", EnumChatType.CommandError); } else { player.SendMessage(groupId, "Ok weather pattern set for all loaded regions", EnumChatType.CommandSuccess); } return; } if (arg == "setirandom") { wsysServer.ReloadConfigs(); bool ok = true; foreach (var val in wsysServer.weatherSimByMapRegion) { ok &= val.Value.SetWeatherPattern(val.Value.RandomWeatherPattern().config.Code, true); if (ok) { val.Value.TickEvery25ms(0.025f); } } if (!ok) { player.SendMessage(groupId, "No such weather pattern found", EnumChatType.CommandError); } else { player.SendMessage(groupId, "Ok random weather pattern set", EnumChatType.CommandSuccess); } return; } if (arg == "setir") { wsysServer.ReloadConfigs(); string code = args.PopWord(); WeatherSimulationRegion weatherSim; long index2d = wsysServer.MapRegionIndex2D(regionX, regionZ); wsysServer.weatherSimByMapRegion.TryGetValue(index2d, out weatherSim); if (weatherSim == null) { player.SendMessage(groupId, "Weather sim not loaded (yet) for this region", EnumChatType.CommandError); return; } if (weatherSim.SetWeatherPattern(code, true)) { weatherSim.TickEvery25ms(0.025f); player.SendMessage(groupId, "Ok weather pattern set for current region", EnumChatType.CommandSuccess); } else { player.SendMessage(groupId, "No such weather pattern found", EnumChatType.CommandError); } return; } string text = getWeatherInfo <WeatherSystemServer>(player); player.SendMessage(groupId, text, EnumChatType.CommandSuccess); }
private void CmdEditClient(int groupId, CmdArgs args) { TriggerWorldEditDialog(); }
static void Main(string[] args) { CmdArgs cmdArgs = new CmdArgs(args); Dictionary<String, String> replace_list = new Dictionary<string, string>(); DateTime end, actual_start, actual_end; if (!cmdArgs.HasParameter("cfg")) { Console.WriteLine("Configuration file was not provided. Use --cfg [file] to provide one."); Console.WriteLine("Operation Aborted."); return; } Config cfg = new Config(cmdArgs.Parameter("cfg")); if (!cfg.Load()) { Console.WriteLine("Was not possible to load '" + cmdArgs.Parameter("cfg") + "'."); if (!string.IsNullOrWhiteSpace(cfg.ExceptionMessage)) { Console.WriteLine("The message returned was:"); Console.WriteLine(cfg.ExceptionMessage); Console.WriteLine("Operation Aborted."); return; } } ConfigNode root = cfg.Root; int id = root["start.id", 1].AsInt(); string template = root["template", "FillMatrix.template"].AsString(); string dateFormat = root["dateFormat.format", "yyyy-MM-dd HH:mm:ss"].AsString(); actual_start = root["start"].AsDateTime(dateFormat); end = root["end"].AsDateTime(dateFormat); int interval; if (root.NodeData.ContainsKey("interval.days")) { interval = root["interval.days"].AsInt(); actual_end = actual_start.AddDays(interval); } else { interval = 10; actual_end = end; } string interpolation = root["interpolation.method", "2"].AsString(); replace_list.Add("<<start>>", actual_start.ToString("yyyy M d H m s")); replace_list.Add("<<end>>", actual_end.ToString("yyyy M d H m s")); replace_list.Add("<<id>>", id.ToString()); replace_list.Add("<<interpolation>>", interpolation); ExternalApp fillmatrix = new ExternalApp(); while (actual_end <= end) { TextFile.Replace(template, "FillMatrix.dat", ref replace_list); fillmatrix.CheckSuccessMethod = CheckSuccessMethod.DONOTCHECK; fillmatrix.Wait = true; fillmatrix.WorkingDirectory = @".\"; fillmatrix.Executable = @".\fillmatrix.exe"; try { fillmatrix.Run(); } catch (Exception ex) { Console.WriteLine("Erro detectado. Mensagem de erro:"); Console.WriteLine(ex.Message); Console.WriteLine("ID : {0}", id.ToString()); Console.WriteLine("Start : {0}", actual_start.ToString()); Console.WriteLine("End : {0}", actual_end.ToString()); Console.WriteLine(""); } id++; actual_start = actual_end; actual_end = actual_start.AddDays(14); if (actual_start < end && actual_end > end) actual_end = end; replace_list["<<start>>"] = actual_start.ToString("yyyy M d H m s"); replace_list["<<end>>"] = actual_end.ToString("yyyy M d H m s"); replace_list["<<id>>"] = id.ToString(); } }
static void LoadConfig(CmdArgs args, MohidRunEngineData data) { data.cfg = new Config(); Config cfg = data.cfg; string configFile; if (args.HasParameter("simcfg")) configFile = args.Parameter("simcfg"); else configFile = "sim.cfg"; cfg.ConfigFile.FullPath = configFile; if (!cfg.Load()) throw new Exception("Was not possible to load the configuration file '" + configFile + "'. " + cfg.ExceptionMessage); }
public override bool OnWorldEditCommand(WorldEdit worldEdit, CmdArgs args) { switch (args[0]) { case "tr": Radius = 0; if (args.Length > 1) { float size; float.TryParse(args[1], out size); Radius = size; } worldEdit.Good("Raise/Lower radius " + Radius + " set."); return(true); case "tgr": Radius++; worldEdit.Good("Raise/Lower radius " + Radius + " set"); return(true); case "tsr": Radius = Math.Max(0, Radius - 1); worldEdit.Good("Raise/Lower radius " + Radius + " set"); return(true); case "tdepth": Depth = 0; if (args.Length > 1) { float size; float.TryParse(args[1], out size); Depth = size; } worldEdit.Good("Raise/Lower depth " + Depth + " set."); return(true); case "tm": Mode = EnumHeightToolMode.Uniform; if (args.Length > 1) { int mode; int.TryParse(args[1], out mode); try { Mode = (EnumHeightToolMode)mode; } catch (Exception) { } } worldEdit.Good("Raise/Lower mode " + Mode + " set."); return(true); } return(false); }
static void Main(string[] args) { OPTamegaScript script = new OPTamegaScript(); CmdArgs cmdArgs = null; Exception e = null; bool sendMail = false; bool sendSMS = false; bool verbose = false; try { Setup.StandartSetup(); cmdArgs = new CmdArgs(args); if (cmdArgs.HasParameter("mailcfg")) sendMail = true; if (cmdArgs.HasParameter("smscfg")) sendSMS = true; if (cmdArgs.HasOption("verbose")) verbose = true; } catch (Exception ex) { Console.WriteLine("Exception raised during initialization: {0}", ex.Message); return; } try { if (Run(cmdArgs, verbose)) throw new Exception("Run failed."); } catch (Exception ex) { e = ex; } if (sendMail) { try { Config cfg = new Config(cmdArgs.Parameter("mailcfg")); if (!cfg.Load()) { Console.WriteLine("[{0}] Was not possible to load the mail configuration file '{1}'", DateTime.Now, cmdArgs.Parameter("mailcfg")); } else { MailSender ms = new MailSender(); string sendTo, header, message; if (e != null) { header = "[ERROR] " + cfg.Root["header", "MohidRun Report"].AsString(); sendTo = "sendto.onerror"; message = cfg.Root["message", "Mohid Run Report"].AsString() + Environment.NewLine; message += "Exception raised: " + Environment.NewLine; message += e.Message; } else { header = "[SUCCESS] " + cfg.Root["header", "MohidRun Report"].AsString(); sendTo = "sendto.onsuccess"; message = cfg.Root["message", "Mohid Run Report"].AsString(); } ms.SetFrom(cfg.Root["from"].AsString(), cfg.Root["display", cfg.Root["from"].AsString()].AsString()); ms.User = cfg.Root["user", "*****@*****.**"].AsString(); ms.Password = cfg.Root["pass", "MohidOperationalISTMARETEC2011"].AsString(); ms.SetMessage(message, header); ms.Host = cfg.Root["host", "smtp.gmail.com"].AsString(); ms.Port = cfg.Root["port", 587].AsInt(); ms.EnableSSL = cfg.Root["enable.ssl", true].AsBool(); foreach (ConfigNode n in cfg.Root.ChildNodes.FindAll(delegate(ConfigNode node) { return (node.Name == sendTo || node.Name == "sendto"); })) { if (!(n["bcc", ""].AsString() == "")) ms.AddBCC(n["bcc"].AsString(), n["display", n["bcc"].AsString()].AsString()); else if (!(n["cc", ""].AsString() == "")) ms.AddCC(n["cc"].AsString(), n["display", n["cc"].AsString()].AsString()); else ms.AddTo(n["to"].AsString(), n["display", n["to"].AsString()].AsString()); } ms.SendMail(); } } catch (Exception ex) { Console.WriteLine("[{0}] Was not possible to send the mail. An EXCEPTION happened. The message returned was:", DateTime.Now); Console.WriteLine("{0}", ex.Message); } } if (sendSMS) { } }
static void Main(string[] args) { CmdArgs cmdArgs = null; Exception last_exception = null; try { Setup.StandardSetup(); cmdArgs = new CmdArgs(args); //====================================================================================== //Load configuration //====================================================================================== Config cfg = new Config(cmdArgs.Parameter("cfg")); if (!cfg.Load()) { Console.WriteLine("[{0}] Was not possible to load the configuration file '{1}'", DateTime.Now, cmdArgs.Parameter("cfg")); return; } //====================================================================================== //Execute tasks //====================================================================================== List<ConfigNode> task_list = cfg.Root.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "task.config"; }); if (task_list != null && task_list.Count > 0) { Tasks t_engine = new Tasks(task_list); if (!t_engine.RunTasks()) { if (t_engine.SuccessfullTasks == 0) Console.WriteLine("All tasks failed"); else if(t_engine.SuccessfullTasks == 1) Console.WriteLine("Only 1 task from a total of " + t_engine.NumberOfTasks + " were successfull"); else Console.WriteLine("Only " + t_engine.SuccessfullTasks + " tasks from a total of " + t_engine.NumberOfTasks + " were successfull"); last_exception = t_engine.LastException; } } else { last_exception = new Exception("No task.config block found in configuration."); } //====================================================================================== //Send STATUS e-mail if mail.config block exists //====================================================================================== ConfigNode mail_cfg = cfg.Root.ChildNodes.Find(delegate(ConfigNode node) { return node.Name == "mail.config"; }); if (mail_cfg != null) { MailEngine mail_engine = new MailEngine(); if (!mail_engine.SendMail(mail_cfg, last_exception)) { Console.WriteLine("[{0}] Was not possible to send the status e-mail.", DateTime.Now); if ((last_exception = mail_engine.LastException) != null) Console.WriteLine("The message returned was: {0}", last_exception); return; } } else if (last_exception != null) { throw last_exception; } } catch (Exception ex) { Console.WriteLine("[{0}] An unexpected exception happened. The message returned was: {1}", DateTime.Now, ex.Message); return; } }
static bool Run(CmdArgs args, bool Verbose) { bool sim_run = true; MohidRunEngineData data = new MohidRunEngineData(); data.args = args; OPTamegaScript op = new OPTamegaScript(); try { if (Verbose) Console.Write("Loading Configuration..."); LoadConfig(args, data); if (Verbose) Console.WriteLine("[OK]"); if (Verbose) Console.Write("Running..."); op.OnSimStart(data); if (Verbose) Console.WriteLine("[OK]"); } catch (Exception ex) { if (Verbose) { Console.WriteLine("[FAILED]"); Console.WriteLine(""); Console.WriteLine("An EXCEPTION was raised. The message returned was:"); Console.WriteLine(ex.Message); Console.WriteLine(""); } } return sim_run; }
static int Main(string[] args) { CmdArgs cmdArgs = null; Exception e = null; bool sendMail = false; bool sendSMS = false; bool verbose = true; IMohidSim stdScript = null; int return_value = 0; try { Setup.StandardSetup(); cmdArgs = new CmdArgs(args); if (cmdArgs.HasOption("v")) verbose = true; else verbose = false; if (cmdArgs.HasParameter("m")) sendMail = true; if (cmdArgs.HasParameter("s")) sendSMS = true; if (cmdArgs.HasOption("i")) stdScript = (IMohidSim)new StandardScript(); } catch (Exception ex) { if (verbose) Console.WriteLine("[{0}] Model Runner: Exception raised during initialization: {0}", DateTime.Now, ex.Message); return -1; } try { MohidRunEngine mre = new MohidRunEngine(); mre.Verbose = verbose; mre.Run(cmdArgs, stdScript); } catch (Exception ex) { e = ex; return_value = -1; } if (sendMail) { try { Config cfg = new Config(cmdArgs.Parameter("m")); if (!cfg.Load()) { if (verbose) Console.WriteLine("[{0}] Model Runner: Was not possible to load the mail configuration file '{1}'", DateTime.Now, cmdArgs.Parameter("mailcfg")); } else { MailSender ms = new MailSender(); string sendTo, header, message; if (e != null) { header = "[ERROR] " + cfg.Root["header", "MohidRun Report"].AsString(); sendTo = "sendto.onerror"; message = cfg.Root["message", "Mohid Run Report"].AsString() + Environment.NewLine; message += "An exception happened" + e.Message + Environment.NewLine; while (e != null) { message += " => " + e.Message + Environment.NewLine; e = e.InnerException; } } else { header = "[SUCCESS] " + cfg.Root["header", "MohidRun Report"].AsString(); sendTo = "sendto.onsuccess"; message = cfg.Root["message", "Mohid Run Report"].AsString(); } ms.SetFrom(cfg.Root["from"].AsString(), cfg.Root["display", cfg.Root["from"].AsString()].AsString()); ms.User = cfg.Root["user", "*****@*****.**"].AsString(); ms.Password = cfg.Root["pass", "MohidOperationalISTMARETEC2011"].AsString(); ms.SetMessage(message, header); ms.Host = cfg.Root["host", "smtp.gmail.com"].AsString(); ms.Port = cfg.Root["port", 587].AsInt(); ms.EnableSSL = cfg.Root["enable.ssl", true].AsBool(); foreach (ConfigNode n in cfg.Root.ChildNodes.FindAll(delegate(ConfigNode node) { return (node.Name == sendTo || node.Name == "sendto"); })) { if (!(n["bcc", ""].AsString() == "")) ms.AddBCC(n["bcc"].AsString(), n["display", n["bcc"].AsString()].AsString()); else if (!(n["cc", ""].AsString() == "")) ms.AddCC(n["cc"].AsString(), n["display", n["cc"].AsString()].AsString()); else ms.AddTo(n["to"].AsString(), n["display", n["to"].AsString()].AsString()); } ms.SendMail(); } } catch (Exception ex) { if (verbose) { Console.WriteLine("[{0}] Model Runner: Was not possible to send the mail. An EXCEPTION happened. The message returned was:", DateTime.Now); Console.WriteLine("{0}", ex.Message); } return_value -= 2; } } if (sendSMS) { } return return_value; }
public override void OnNoOption(string option, CmdArgs args) { AddTraderWaypoint(false); }
static void Main(string[] args) { string stepMessage = ""; FileName outputFileName; try { stepMessage = "command line arguments loading."; CmdArgs cmdArgs = new CmdArgs(args); if (cmdArgs.HasParameter("cfg")) { stepMessage = "configuration file loading."; Config conf = new Config(cmdArgs.Parameters["cfg"]); conf.Load(); stepMessage = "configuration file parsing."; ConfigNode nodeList = conf.Root.ChildNodes.Find(delegate(ConfigNode node){ return node.Name == "timeseries.to.join"; }); if (nodeList == null) throw new Exception("Block 'timeseries.to.join' is missing."); outputFileName = conf.Root["output.file.name", "output.tsr"].AsFileName(); TimeUnits timeUnits = (TimeUnits) Enum.Parse(typeof(TimeUnits), conf.Root["time.units", "seconds"].AsString(), true); List<FileName> list = new List<FileName>(); foreach (KeyValuePair<string, KeywordData> item in nodeList.NodeData) list.Add(item.Value.AsFileName()); if (list.Count <= 1) throw new Exception("Block 'timeseries.to.join' must contain at least 2 entries"); stepMessage = "loading timeseries."; List<TimeSeries> timeSeries = new List<TimeSeries>(); foreach(FileName ts in list) { TimeSeries newTS = new TimeSeries(); newTS.Load(ts); timeSeries.Add(newTS); } DateTime start = timeSeries[0].StartInstant; for (int i = 1; i < timeSeries.Count; i++) { if (timeSeries[i].StartInstant < start) start = timeSeries[i].StartInstant; } stepMessage = "creating output timeseries."; TimeSeries outTS = new TimeSeries(); outTS.StartInstant = start; outTS.TimeUnits = timeUnits; foreach (Column col in timeSeries[0].Columns) { Column newCol = new Column(col.ColumnType); newCol.Header = col.Header; outTS.AddColumn(newCol); } foreach (TimeSeries toJoin in timeSeries) outTS.AddTimeSeries(toJoin); stepMessage = "saving output timeseries."; outTS.Save(outputFileName); Console.WriteLine("Process complete with success."); } else { Console.WriteLine("Parameter --cfg is missing."); Console.WriteLine("Execution aborted."); return; } } catch (Exception ex) { Console.WriteLine("An exception was raised while {0}", stepMessage); Console.WriteLine("Exception message: {0}", ex.Message); } }
private void OnPinnedOption(string option, CmdArgs args) { AddTraderWaypoint(true); }
public override void CallHandler(IPlayer player, int groupId, CmdArgs args) { }
public void CmdMeasuringTape(int groupId, CmdArgs args) { WaypointUtilSystem wUtil = capi.ModLoader.GetModSystem <WaypointUtilSystem>(); string arg = args.PopWord(); switch (arg) { case "start": if (capi.World.Player.CurrentBlockSelection != null) { start = capi.World.Player.CurrentBlockSelection.Position; //capi.ShowChatMessage("Okay, start set to: " + start); MakeHighlights(); } else { capi.ShowChatMessage("Please look at a block."); } break; case "end": if (capi.World.Player.CurrentBlockSelection != null) { end = capi.World.Player.CurrentBlockSelection.Position; //capi.ShowChatMessage("Okay, end set to: " + end); MakeHighlights(); } else { capi.ShowChatMessage("Please look at a block."); } break; case "startwp": int?swpID = args.PopInt(); if (swpID != null) { start = wUtil.Waypoints[(int)swpID].Position.AsBlockPos; MakeHighlights(); } else { capi.ShowChatMessage("Please enter a waypoint id."); } break; case "endwp": int?ewpID = args.PopInt(); if (ewpID != null) { end = wUtil.Waypoints[(int)ewpID].Position.AsBlockPos; MakeHighlights(); } else { capi.ShowChatMessage("Please enter a waypoint id."); } break; case "calc": string type = args.PopWord(); switch (type) { case "block": capi.ShowChatMessage("Block Distance: " + Math.Round(start.DistanceTo(end) + 1)); break; case "euclidian": capi.ShowChatMessage("Euclidian Distance: " + start.DistanceTo(end)); break; case "manhattan": capi.ShowChatMessage("Manhattan Distance: " + start.ManhattenDistance(end)); break; case "horizontal": capi.ShowChatMessage("Horizontal Distance: " + Math.Sqrt(start.HorDistanceSqTo(end.X, end.Z))); break; case "horizontalmanhattan": capi.ShowChatMessage("Horizontal Manhattan Distance: " + start.HorizontalManhattenDistance(end)); break; default: capi.ShowChatMessage("Syntax: .measure calc [block|euclidian|manhattan|horizontal|horizontalmanhattan]"); break; } break; default: capi.ShowChatMessage("Syntax: .measure [start|end|calc]"); break; } }
static void Main(string[] args) { string stepMessage = ""; List<ConfigNode> timeseries, parameters; List<string> cfg = new List<string>(); List<string> blocks = new List<string>(); DateTime start, end, actual; FilePath root; bool hasFolders; TextFile config, errors; string hdfTag; FileName hdf5EXE = new FileName(); FilePath workingFolder = new FilePath(); FilePath tsPath; Dictionary<string, TimeSeries> outTS = new Dictionary<string, TimeSeries>(); TimeSeries newTS = new TimeSeries(); List<string> failedPeriods = new List<string>(); int count_to_save; bool use_year_on_path; bool join_time_series; string startFormat, endFormat, folderFormat; errors = new TextFile("errors.log"); errors.OpenNewToWrite(); count_to_save = 0; try { stepMessage = "command line arguments loading."; CmdArgs cmdArgs = new CmdArgs(args); if (cmdArgs.HasParameter("cfg")) { stepMessage = "configuration file loading."; Config conf = new Config(cmdArgs.Parameters["cfg"]); conf.Load(); stepMessage = "configuration file parsing."; ConfigNode tsc = conf.Root.ChildNodes.Find(delegate(ConfigNode node) { return node.Name == "timeseries.to.extract"; }); if (tsc == null) throw new Exception("block 'timeseries.to.extract' is missing."); start = tsc["start.date"].AsDateTime(); end = tsc["end.date"].AsDateTime(); hdfTag = tsc["hdf.tag"].AsString(); hdf5EXE = tsc["exporter.exe"].AsFileName(); workingFolder = tsc["exporter.working"].AsFilePath(); tsPath = tsc["timeseries.output.path"].AsFilePath(); //root = tsc["root", ".\\"].AsFilePath(); hasFolders = tsc["has.folders", true].AsBool(); use_year_on_path = tsc["use.year.on.path", true].AsBool(); join_time_series = tsc["join.timeseries", true].AsBool(); folderFormat = tsc["folder.format", "{start}_{end}"].AsString(); startFormat = tsc["start.format", "yyyyMMddHH"].AsString(); endFormat = tsc["end.format", "yyyyMMddHH"].AsString(); blocks.Add("EXPORT_TYPE : " + tsc["export.type", 1].AsString()); blocks.Add("COMPUTE_RESIDUAL : " + tsc["compute.residual", 0].AsString()); blocks.Add("VARIABLE_GRID : " + tsc["variable.grid", 0].AsString()); blocks.Add("WATERPOINTS_NAME : " + tsc["points.name", "WaterPoints2D"].AsString()); blocks.Add("GRID_FILENAME : " + tsc["grid.name", "grid.dat"].AsString()); blocks.Add(""); timeseries = tsc.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "timeseries"; }); if (timeseries.Count < 1) throw new Exception("Block 'timeseries' is missing. There must be at least one."); //Creates the blocks of timeseries foreach (ConfigNode n in timeseries) { blocks.Add("<BeginTimeSerie>"); blocks.Add(" NAME : " + n["name"].AsString()); blocks.Add(" COORD_Y : " + n["y"].AsString()); blocks.Add(" COORD_X : " + n["x"].AsString()); blocks.Add("<EndTimeSerie>"); blocks.Add(""); outTS[n["name"].AsString()] = new TimeSeries(); if (System.IO.File.Exists(tsPath.Path + n["name"].AsString() + ".ets")) { outTS[n["name"].AsString()].Load(new FileName(tsPath.Path + n["name"].AsString() + ".ets")); } } parameters = tsc.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "parameters"; }); if (parameters.Count < 1) throw new Exception("Block 'parameters' is missing. There must be at least one."); //Creates the blocks of parameters foreach (ConfigNode n in parameters) { blocks.Add("<BeginParameter>"); blocks.Add(" HDF_GROUP : " + n["group"].AsString()); blocks.Add(" PROPERTY : " + n["property"].AsString()); blocks.Add("<EndParameter>"); blocks.Add(""); } config = new TextFile(); config.File.FullPath = workingFolder.Path + "HDF5Exporter.dat"; bool quit = false; actual = start; FilePath yearFolder = new FilePath(); ExternalApp hdf5exporter = new ExternalApp(); hdf5exporter.CheckSuccessMethod = CheckSuccessMethod.DEFAULTOUTPUT; hdf5exporter.TextToCheck = "Program HDF5Exporter successfully terminated"; hdf5exporter.Wait = true; hdf5exporter.WorkingDirectory = workingFolder.Path; hdf5exporter.Executable = hdf5EXE.FullPath; FilePath wp = workingFolder; List<FileInfo> tsList = new List<FileInfo>(); bool failed, res; do { failed = false; if (use_year_on_path) yearFolder.Path = root.Path + actual.Year.ToString(); else yearFolder.Path = root.Path; if (FileTools.FolderExists(yearFolder)) { if (System.IO.File.Exists(yearFolder.Path + hdfTag + actual.ToString("yyyyMMddHH") + "_" + actual.AddHours(5).ToString("yyyyMMddHH") + ".hdf5")) { config.OpenNewToWrite(); cfg.Clear(); cfg.Add(""); cfg.Add("START_TIME : " + actual.ToString("yyyy M d H m s")); cfg.Add("END_TIME : " + actual.AddHours(5).ToString("yyyy M d H m s")); cfg.Add(""); cfg.Add("<BeginHDF5File>"); cfg.Add(" NAME : " + yearFolder.Path + hdfTag + actual.ToString("yyyyMMddHH") + "_" + actual.AddHours(5).ToString("yyyyMMddHH") + ".hdf5"); cfg.Add("<EndHDF5File>"); cfg.Add(""); config.WriteLines(cfg); config.WriteLines(blocks); config.Close(); //executes HDF5Exporter try { Console.Write("Running HDF5Exporter to file " + hdfTag + actual.ToString("yyyyMMddHH") + "_" + actual.AddHours(5).ToString("yyyyMMddHH") + ".hdf5 ..."); res = hdf5exporter.Run(); if (!res) { errors.WriteLine("Unsuccessfull HDF5Exporter run on file '" + hdfTag + actual.ToString("yyyyMMddHH") + "_" + actual.AddHours(5).ToString("yyyyMMddHH") + ".hdf5'"); failed = true; Console.WriteLine("[Failed]"); } else { Console.WriteLine("[OK]"); } } catch(Exception e_run) { errors.WriteLine("HDF5Exporter Run Exception on file '" + hdfTag + actual.ToString("yyyyMMddHH") + "_" + actual.AddHours(5).ToString("yyyyMMddHH") + ".hdf5'"); errors.WriteLine("Exception returned this message: " + e_run.Message); failed = true; Console.WriteLine("[Exception]"); } if (!failed) { FileTools.FindFiles(ref tsList, wp, "*.ets", true, "", System.IO.SearchOption.TopDirectoryOnly); foreach (FileInfo file in tsList) { if (outTS[file.FileName.Name].NumberOfInstants > 0) { try { newTS.Load(file.FileName); //outTS.Load(new FileName(tsPath.Path + file.FileName.FullName)); outTS[file.FileName.Name].AddTimeSeries(newTS); } catch { errors.WriteLine("Was not possible to read timeseries '" + file.FileName + "' from HDF file '" + hdfTag + actual.ToString("yyyyMMddHH") + "_" + actual.AddHours(5).ToString("yyyyMMddHH") + ".hdf5'"); } //outTS.Save(new FileName(tsPath.Path + file.FileName.FullName)); System.IO.File.Delete(file.FileName.FullPath); } else { //FileTools.CopyFile(file.FileName, new FileName(tsPath.Path + file.FileName.FullName), CopyOptions.OVERWRIGHT); //outTS[file.FileName.Name].Load(new FileName(tsPath.Path + file.FileName.FullName)); outTS[file.FileName.Name].Load(file.FileName); System.IO.File.Delete(file.FileName.FullPath); } } count_to_save++; if (count_to_save >= 60) { count_to_save = 0; foreach (FileInfo file in tsList) { Console.Write("Saving Timeseries '" + file.FileName.Name + "' ..."); try { outTS[file.FileName.Name].Save(new FileName(tsPath.Path + file.FileName.Name + ".ets")); Console.WriteLine("[OK]"); FileTools.CopyFile(new FileName(tsPath.Path + file.FileName.Name + ".ets"), new FileName((new FilePath(tsPath.Path + "bkp")).Path + file.FileName.Name + ".ets"), CopyOptions.OVERWRIGHT); } catch(Exception e_run) { Console.WriteLine("[FAILED]"); errors.WriteLine("Was not possible to save timeseries '" + file.FileName.Name + ".ets'"); errors.WriteLine("Exception returned this message: " + e_run.Message); } } } } } } actual = actual.AddHours(6); if (actual >= end) quit = true; } while (!quit); foreach (KeyValuePair<string, TimeSeries> pair in outTS) { pair.Value.Save(new FileName(tsPath.Path + pair.Key + ".ets")); } //TimeUnits timeUnits = (TimeUnits)Enum.Parse(typeof(TimeUnits), conf.Root["time.units", "seconds"].AsString(), true); // List<FileName> list = new List<FileName>(); // foreach (KeyValuePair<string, KeywordData> item in nodeList.NodeData) // list.Add(item.Value.AsFileName()); // if (list.Count <= 1) // throw new Exception("Block 'timeseries.to.join' must contain at least 2 entries"); // stepMessage = "loading timeseries."; // List<TimeSeries> timeSeries = new List<TimeSeries>(); // foreach (FileName ts in list) // { // TimeSeries newTS = new TimeSeries(); // newTS.Load(ts); // timeSeries.Add(newTS); // } // start = timeSeries[0].StartInstant; // for (int i = 1; i < timeSeries.Count; i++) // { // if (timeSeries[i].StartInstant < start) // start = timeSeries[i].StartInstant; // } // stepMessage = "creating output timeseries."; // TimeSeries outTS = new TimeSeries(); // outTS.StartInstant = start; // outTS.TimeUnits = timeUnits; // foreach (Column col in timeSeries[0].Columns) // { // Column newCol = new Column(col.ColumnType); // newCol.Header = col.Header; // outTS.AddColumn(newCol); // } // foreach (TimeSeries toJoin in timeSeries) // outTS.AddTimeSeries(toJoin); // stepMessage = "saving output timeseries."; // outTS.Save(outputFileName); // Console.WriteLine("Process complete with success."); //} //else //{ // Console.WriteLine("Parameter --cfg is missing."); // Console.WriteLine("Execution aborted."); // return; //} } } catch (Exception ex) { Console.WriteLine("An exception was raised while {0}", stepMessage); Console.WriteLine("Exception message: {0}", ex.Message); } errors.Close(); }
static void Main(string[] args) { bool verbose = false; try { CmdArgs cmdArgs = new CmdArgs(args); if (cmdArgs.HasOption("v")) verbose = true; else verbose = false; if (cmdArgs.HasParameter("cfg")) { if (verbose) { Console.WriteLine(""); Console.Write("Reading configuration file..."); } Config conf = new Config(cmdArgs.Parameters["cfg"]); conf.Load(); if (verbose) Console.WriteLine("[OK]"); if (verbose) Console.Write("Looking for 'xyz.to.process' blocks..."); List<ConfigNode> bkList = conf.Root.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "xyz.to.process"; }); if (bkList == null || bkList.Count <= 0) throw new Exception("No 'xyz.to.process' block found in configuration file."); if (verbose) { Console.WriteLine("[OK]"); Console.WriteLine("{0} 'xyz.to.process' block(s) found.", bkList.Count); } int bkCount = 1; foreach (ConfigNode bk in bkList) { if (verbose) Console.Write("Processing 'xyz.to.process' block #{0}...", bkCount); FileName input = bk["input.file"].AsFileName(); FileName output = bk["output.file"].AsFileName(); bool eraseNoData = bk["erase.no.data", true].AsBool(); double noData = -99.0; if (eraseNoData) noData = bk["no.data.value", -99.0].AsDouble(); bool applyScaleFator = bk["apply.scale.fator", true].AsBool(); double scaleFactor = 1.0; if (applyScaleFator) scaleFactor = bk["scale.factor", 1.0].AsDouble(); Dictionary<string, string> lookupTable = new Dictionary<string, string>(); List<ConfigNode> lookupTables = bk.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "lookup.table"; }); foreach (ConfigNode lt in lookupTables) { foreach (KeyValuePair<string, KeywordData> kp in lt.NodeData) lookupTable[kp.Key] = kp.Value.AsString(); } //Start processing XYZ TextFile file_i = new TextFile(input); file_i.OpenToRead(); TextFile file_o = new TextFile(output); file_o.OpenNewToWrite(); string line_i = null; string line_o = null; string [] tokens; string [] sep = {" "}; double res; while ((line_i = file_i.ReadLine()) != null) { tokens = line_i.Split(sep, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 3) { foreach (KeyValuePair<string, string> kp in lookupTable) if (double.Parse(tokens[2]) == double.Parse(kp.Key)) { tokens[2] = kp.Value; break; } res = double.Parse(tokens[2]); if (eraseNoData && res == noData) continue; if (applyScaleFator) res *= scaleFactor; line_o = string.Format("{0} {1} {2} ", tokens[0], tokens[1], res); } else line_o = line_i; file_o.WriteLine(line_o); } file_i.Close(); file_o.Close(); bkCount++; if (verbose) Console.WriteLine("[OK]"); } } } catch (Exception ex) { if (verbose) { Console.WriteLine("[FAIL]"); Console.WriteLine(""); Console.WriteLine("An EXCEPTION was raised. The message returned was:"); Console.WriteLine(ex.Message); } } if (verbose) { Console.WriteLine("Process finished."); Console.WriteLine(""); } }