Пример #1
0
        //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;
        }
Пример #2
0
            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 InputFileTemplate AddTemplate()
 {
     InputFileTemplate newFile = new InputFileTemplate();
     AddTemplate(newFile);
     return newFile;
 }
 public InputFileTemplate AddTemplate(string path, InputFileTemplateType type)
 {
     InputFileTemplate newFile = new InputFileTemplate(path, type);
     AddTemplate(newFile);
     return newFile;
 }
 public void AddTemplate(InputFileTemplate file)
 {
     templateFiles.Add(file);
 }