コード例 #1
0
        /// <summary>
        /// Preprocesses and runs Mike She
        /// Note that if the MzLauncher is used it uses the execution engine flags from the .she-file
        /// </summary>
        /// <param name="MsheFileName"></param>
        /// <param name="UseMZLauncher"></param>
        public static void PreprocessAndRun(string MsheFileName, bool UseMZLauncher)
        {
            Process Runner = new Process();

              string path;
              DHIRegistry key = new DHIRegistry(DHIProductAreas.COMMON_COMPONNETS, false);
              key.GetHomeDirectory(out path);

              if (UseMZLauncher)
              {
            Runner.StartInfo.FileName = Path.Combine(path,"Mzlaunch.exe");
            Runner.StartInfo.Arguments = Path.GetFullPath(MsheFileName) + " -exit";
              }

              else
              {
            Runner.StartInfo.FileName = Path.Combine(path,"Mshe_preprocessor.exe");
            Runner.StartInfo.Arguments = MsheFileName;
            Runner.Start();
            Runner.WaitForExit();
            Runner.StartInfo.FileName = Path.Combine(path,"Mshe_watermovement.exe");
              }
              Runner.Start();
              Runner.WaitForExit();
              Runner.Close();
        }
コード例 #2
0
ファイル: Model.cs プロジェクト: msruzy/hydronumerics
        /// <summary>
        /// Preprocesses and runs Mike She
        /// Note that if the MzLauncher is used it uses the execution engine flags from the .she-file
        /// </summary>
        /// <param name="MsheFileName"></param>
        /// <param name="UseMZLauncher"></param>
        private void PreprocessAndRun(bool Async, bool UseMZLauncher)
        {
            Console.WriteLine("Starting simulation: " + FileName);

//      if (Runner==null)
            Runner = new Process();
            string      path;
            DHIRegistry key = new DHIRegistry(DHIProductAreas.COMMON_COMPONNETS, false);

            key.GetHomeDirectory(out path);

            if (!File.Exists(Path.Combine(path, "Mshe_preprocessor.exe")))
            {
                path += "\\x64";
            }


            if (UseMZLauncher)
            {
                Runner.StartInfo.FileName  = Path.Combine(path, "Mzlaunch.exe");
                Runner.StartInfo.Arguments = Path.GetFullPath(FileName) + " -exit";
            }
            else
            {
                Runner.StartInfo.FileName  = Path.Combine(path, "Mshe_preprocessor.exe");
                Runner.StartInfo.Arguments = FileName;
                Runner.Start();
                Runner.WaitForExit();
                Runner.StartInfo.FileName = Path.Combine(path, "Mshe_watermovement.exe");
            }

            Runner.EnableRaisingEvents = true;
            Runner.Exited += new EventHandler(Runner_Exited);
            Runner.Start();

            if (!Async)
            {
                Runner.WaitForExit();
            }
        }
コード例 #3
0
        public ITimeSpaceComponent CreateInstance()
        {
            string newSheFileName = "";

            if (_copyModels)
            {
                throw new NotImplementedException("Copy model's not implemented yet. Check the MikeSheConfig txt file. ");
                // Copy Entire 'base' directory to a new one in the same root directory with instancenumber name
                DirectoryInfo sourceDirectory = Directory.GetParent(_msheFileName);
                DirectoryInfo targetDirectory = Directory.GetParent(Directory.GetParent(sourceDirectory.ToString()) + "\\" + _instanceCounter + "\\" + _instanceCounter);
                CopyDirectory(sourceDirectory, targetDirectory);

                newSheFileName = targetDirectory.ToString() + "\\" + Path.GetFileName(_msheFileName);
            }
            else if (!_copyModels)
            {
                if (_instanceCounter != -1)
                {
                    string parentPath = new DirectoryInfo(_msheFileName).Parent.Parent.Parent.FullName.ToString();
                    string filename   = Path.GetFileName(_msheFileName);
                    //newSheFileName = Path.Combine(parentPath, "Ensembles", _instanceCounter.ToString(), filename);
                    newSheFileName = Path.Combine(parentPath, "Ensembles\\", _instanceCounter.ToString(), filename);
                    if (!File.Exists(newSheFileName))
                    {
                        Console.WriteLine(" ****************\n ");
                        Console.WriteLine("In  ModelAccess.cs at InitializeModel \n");
                        Console.WriteLine("\n  Error in Model Instance --> {0}\n", _instanceCounter);
                        Console.WriteLine("\n  File Not Found --> {0}\n", _instanceCounter);
                        throw new Exception("Could not find the model .she file in ModelOpenMI2 :" + newSheFileName);
                    }
                }
                // Else If (_instanceCounter == _numEnsembles)
                // NOW initialize the MainModel
                else
                {
                    string parentPath = new DirectoryInfo(_msheFileName).Parent.Parent.Parent.FullName.ToString();
                    string filename   = Path.GetFileName(_msheFileName);
                    newSheFileName = Path.Combine(parentPath, "MainModel\\MainModel\\", filename);
                    if (!File.Exists(newSheFileName))
                    {
                        Console.WriteLine(" ****************\n ");
                        Console.WriteLine("In  ModelAccess.cs at InitializeModel \n");
                        Console.WriteLine("\n  Error in Model Instance --> {0}\n", _instanceCounter);
                        Console.WriteLine("\n  File Not Found --> {0}\n", _instanceCounter);
                        throw new Exception("Could not find the model .she file in ModelOpenMI2 :" + newSheFileName);
                    }
                }


                /*
                 * // Not Copying models
                 * DirectoryInfo sourceDirectory = Directory.GetParent(_msheFileName);
                 * DirectoryInfo targetDirectory = Directory.GetParent(Directory.GetParent(sourceDirectory.ToString()) + "\\" + _instanceCounter + "\\" + _instanceCounter);
                 * newSheFileName = targetDirectory.ToString() + "\\" + Path.GetFileName(_msheFileName);
                 */
            }
            else
            {
                throw new Exception("Copy models or not - unspecified.");
            }

            if (!File.Exists(newSheFileName))
            {
                throw new FileNotFoundException("Mike She file not found: ", newSheFileName);
            }

            // Preprocess mshe before initializing.
            string      path;
            DHIRegistry key = new DHIRegistry(DHIProductAreas.COMMON_COMPONNETS, false);

            key.GetHomeDirectory(out path);
            path = path + "x64";
            if (_runPreProcessor)
            {
                Process runner = new Process();
                runner.StartInfo.FileName = System.IO.Path.Combine(path, "MSHE_PreProcessor.exe");
                // Check if file exisits
                if (!System.IO.File.Exists(runner.StartInfo.FileName))
                {
                    Console.WriteLine("PreProcessor Executable not found:  {0}", runner.StartInfo.FileName);
                }

                runner.StartInfo.Arguments = newSheFileName;
                // Change the Working Directory necessary for the SVAT module in MikeSHE
                runner.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(newSheFileName);
                runner.StartInfo.UseShellExecute  = false;
                runner.Start();
                runner.WaitForExit();
            }

            _instanceCounter++;

            _mshe = new MikeSheOpenMITimespaceComponentExtensions();

            IList <IArgument> prop = _mshe.Arguments;

            prop.UpdateValue("SetupPath", Path.GetDirectoryName(newSheFileName));
            prop.UpdateValue("SetupFileName", Path.GetFileName(Path.GetFileName(newSheFileName)));
            prop.UpdateValue("ForceRemote", true);
            try
            {
                _mshe.Initialize();
            }
            catch (System.Exception excep)
            {
                Console.WriteLine("Problem with Model Initialization. \nFile:\n {0}\n\n ", newSheFileName);
                Console.WriteLine(excep.Message);
            }

            var outputItemsList = _mshe.EngineOutputItems.ToList();
            var inputtItemsList = _mshe.EngineInputItems.ToList();

            // For OpenMI 2.0 we need to add a consumer ( a dummy in this case ) for each Output
            // Exchange Item.
            Input         dummyInput2 = new Input("dummyIn");
            List <string> outToRemove = new List <string>();

            for (int i = 0; i < _mshe.EngineOutputItems.Count; i++)
            {
                if (_exchangeItems.Contains(_mshe.EngineOutputItems[i].Id))
                {
                    _mshe.EngineOutputItems[i].AddConsumer(dummyInput2);
                }
                else
                {
                    outToRemove.Add(_mshe.EngineOutputItems[i].Id);
                }
            }
            outToRemove = outToRemove.Distinct().ToList();
            while (_mshe.EngineOutputItems.Count != _exchangeItems.Count)
            {
                _mshe.EngineOutputItems.Remove(_mshe.EngineOutputItems.First(s => outToRemove.Contains(s.Id)));
            }

            // For OpenMI 2.0 we need to add a consumer ( a dummy in this case ) for each Output
            // Exchange Item.
            List <string> inToRemove = new List <string>();

            for (int i = 0; i < _mshe.EngineInputItems.Count; i++)
            {
                if (!_exchangeItems.Contains(_mshe.EngineInputItems[i].Id))
                {
                    inToRemove.Add(_mshe.EngineInputItems[i].Id);
                }
            }
            inToRemove = inToRemove.Distinct().ToList();
            while (_mshe.EngineInputItems.Count != _exchangeItems.Count)
            {
                _mshe.EngineInputItems.Remove(_mshe.EngineInputItems.First(s => inToRemove.Contains(s.Id)));
            }

            try
            {
                _mshe.Prepare();
            }
            catch (System.Exception excep)
            {
                string err = "Problem with Model Initialization/Prepare. Ensure \n\t(1) .she file exisits and is not being used by any other process or service (like licserv) \n\t(2) MIKE is licensed correctly & licserv is running correctly \n\t(3) The .she file and associated model files are not read only \n\t(4) The MikeShe file can run on it's own (no negative rainfall, incompatible options etc.). \n";
                Console.WriteLine(" ****************\n ");
                Console.WriteLine("In ModelAccess.cs at InitializeModel \n");
                Console.WriteLine("\n  Error in Model Instance --> {0}\n", _instanceCounter);
                Console.WriteLine(err);
                Console.WriteLine(excep.Message);
                Console.WriteLine(" ****************\n ");
                string exceptionString = "\n\n EXIT - problem with model initilizatoin. \n Error in Model Instance --> " + _instanceCounter.ToString() + "\n";
                throw new Exception(exceptionString);
            }

            _mshe.Update();

            //int startin = 60 - DateTime.Now.Second;
            //System.Threading.TimerCallback c;
            //ThreadCallBack = new System.Threading.Timer(o => Console.WriteLine("  ------> working: i=" + _instanceCounter.ToString() + " time: " + _mshe.CurrentTime.ToDateTime()), null, startin * 1000, 30000);

            return(_mshe);
        }
コード例 #4
0
ファイル: Model.cs プロジェクト: XiBeichuan/hydronumerics
    /// <summary>
    /// Preprocesses and runs Mike She
    /// Note that if the MzLauncher is used it uses the execution engine flags from the .she-file
    /// </summary>
    /// <param name="MsheFileName"></param>
    /// <param name="UseMZLauncher"></param>
    private void PreprocessAndRun(bool Async, bool UseMZLauncher)
    {
      Console.WriteLine("Starting simulation: " + FileName);

//      if (Runner==null)
        Runner = new Process();
      string path;
      DHIRegistry key = new DHIRegistry(DHIProductAreas.COMMON_COMPONNETS, false);
      key.GetHomeDirectory(out path);

      if (!File.Exists(Path.Combine(path, "Mshe_preprocessor.exe")))
        path += "\\x64";


      if (UseMZLauncher)
      {
        Runner.StartInfo.FileName = Path.Combine(path, "Mzlaunch.exe");
        Runner.StartInfo.Arguments = Path.GetFullPath(FileName) + " -exit";
      }
      else
      {
        Runner.StartInfo.FileName = Path.Combine(path, "Mshe_preprocessor.exe");
        Runner.StartInfo.Arguments = FileName;
        Runner.Start();
        Runner.WaitForExit();
        Runner.StartInfo.FileName = Path.Combine(path, "Mshe_watermovement.exe");
      }

      Runner.EnableRaisingEvents = true;
      Runner.Exited += new EventHandler(Runner_Exited);
      Runner.Start();
      
      if (!Async)
      {
        Runner.WaitForExit();
      }
    }