private void RunEM2()
        {
            _process = new Process();
            _process.StartInfo.FileName       = EnvironmentInfo.GetEM2ExecutableFile();
            _process.StartInfo.Arguments     += EnvironmentInfo.EncloseByQuotes(_em2ConfigurationFile);
            _process.StartInfo.CreateNoWindow = true;

            //redirect the standard-output and standard-error of the process, to be asynchronously read by event handlers
            _process.StartInfo.UseShellExecute        = false;
            _process.StartInfo.RedirectStandardOutput = true;
            _process.StartInfo.RedirectStandardError  = true;
            _process.OutputDataReceived += new DataReceivedEventHandler(RunLogHandler);
            _process.ErrorDataReceived  += new DataReceivedEventHandler(ErrorLogHandler);

            //out-commented the following part and using a BackgroundWorker instead, as the callback function works from the processes thread
            //thus accessing the RunInfo-window fails
            //set event handler to recognise termination
            //_process.EnableRaisingEvents = true;
            //_process.Exited += new EventHandler(ExitedHandler);

            //start the process and start the asynchronous read of the output
            if (!_process.Start())
            {
                lock (_errorLogLock) { _errorLog.Add("Failed to start model run."); } //should not happen
                _runManager.HandleRunExited(this);
            }

            _process.BeginOutputReadLine();
            _process.BeginErrorReadLine();
            _processStatusAdditionalInfo = string.Format("{0:T}", _process.StartTime) + " - ";

            _process.WaitForExit();
        }
예제 #2
0
        private bool EM2_Run(SystemBackgroundWorker sbw)
        {
            sbw.process = new Process();
            sbw.process.StartInfo.FileName   = EnvironmentInfo.GetEM2ExecutableFile();
            sbw.process.StartInfo.Arguments += EnvironmentInfo.EncloseByQuotes(sbw.config.First().Key);

            sbw.process.StartInfo.CreateNoWindow        = true;
            sbw.process.StartInfo.UseShellExecute       = false;
            sbw.process.StartInfo.RedirectStandardError = true;
            sbw.process.ErrorDataReceived += (t1, t2) => { if (t2.Data != null && t2.Data != "")
                                                           {
                                                               sbw.em2_hasErrorFile = true;
                                                           }
            };

            sbw.process.Start();
            sbw.process.BeginErrorReadLine();
            sbw.process.WaitForExit();
            return(sbw.process.ExitCode == 1);
        }
예제 #3
0
        private Dictionary <string, string> EM2_CreateConfig(string countryShortName, string outputPath, DataConfig.DataBaseRow dbr, CountryConfig.SystemRow sr, bool useTempCountry = true)
        {
            Dictionary <string, string> contentEMConfig = new Dictionary <string, string>();

            string emVersion = EM_AppContext.Instance.GetProjectName();

            if (emVersion.Trim() == string.Empty)
            {
                UserInfoHandler.ShowError($"{DefGeneral.BRAND_TITLE} version is not defined. Please define it via the menu 'Configuration'.");
                return(null);
            }
            //fill EMConfig-entry-list
            string dateTimePrefix = string.Format("{0:yyyyMMddHHmm}", DateTime.Now);

            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_ERRLOG_FILE, outputPath + dateTimePrefix + EM_XmlHandler.TAGS.EM2CONFIG_errLogFileName);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_LOG_WARNINGS, DefPar.Value.YES);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_EMVERSION, emVersion);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_UIVERSION, DefGeneral.UI_VERSION);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_PARAMPATH, useTempCountry ? EMPath.AddSlash(EMPath.Folder_Temp(EM_AppContext.FolderEuromodFiles)) : EMPath.AddSlash(Path.Combine(EMPath.Folder_Countries(EM_AppContext.FolderEuromodFiles), countryShortName)));
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_CONFIGPATH, EMPath.Folder_Config(EM_AppContext.FolderEuromodFiles));
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_OUTPUTPATH, outputPath);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_DATAPATH, EM_AppContext.FolderInput);
            string executablePath = EnvironmentInfo.GetEM2ExecutableFile();

            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_EMCONTENTPATH, EM_AppContext.FolderEuromodFiles);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_HEADER_DATE, dateTimePrefix);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_OUTFILE_DATE, "-");
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_LOG_RUNTIME, DefPar.Value.NO);
            if (EM_AppContext.Instance.IsPublicVersion())
            {
                contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_ISPUBLICVERSION, DefPar.Value.YES);
            }
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_DECSIGN_PARAM, EM_Helpers.uiDecimalSeparator);
            string startHH = EM_XmlHandler.TAGS.EM2CONFIG_defaultHHID;
            string lastHH  = EM_XmlHandler.TAGS.EM2CONFIG_defaultHHID;

            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_STARTHH, startHH);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_LASTHH, lastHH);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_COUNTRY_FILE, CountryAdministrator.GetCountryFileName(countryShortName));
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_DATACONFIG_FILE, CountryAdministrator.GetDataFileName(countryShortName));
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_DATASET_ID, dbr.ID);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_SYSTEM_ID, sr.ID);

            //generate for each (available) switchable policy a POLICY_SWITCH-entry
            Dictionary <string, string> extIDAndPattern = new Dictionary <string, string>();

            foreach (GlobLocExtensionRow e in ExtensionAndGroupManager.GetExtensions(countryShortName))
            {
                extIDAndPattern.Add(e.ID, e.ShortName);
            }

            List <string> policySwitchEntries = new List <string>();

            foreach (var e in extIDAndPattern)
            {
                string extID = e.Key, extShortName = e.Value;
                string policySwitchValue = string.Empty;
                if (dbr.GetDBSystemConfigRows().Count(x => x.SystemID == sr.ID) > 0)
                {
                    policySwitchValue = ExtensionAndGroupManager.GetExtensionDefaultSwitch(dbr.GetDBSystemConfigRows().First(x => x.SystemID == sr.ID), extID);
                }

                //generate the POLICY_SWITCH-entry
                //taking into account that there is no need to generate it if the switch is set to n/a (i.e. the switchable policy is not switchable for this db-system-combination or does not even exist)
                if (policySwitchValue != string.Empty && policySwitchValue != DefPar.Value.NA)
                {
                    string policySwitchEntry =                            //the executable needs three pieces of information to overwrite the default value of the policy switch:
                                               extShortName               //which switchable policy (e.g. BTA_??)
                                               + "=" + sr.ID              //which system
                                               + "=" + policySwitchValue; //and the respective value (on or off)
                    policySwitchEntries.Add(policySwitchEntry);
                }
            }

            //for each (available) switchable policy add a POLICY_SWITCH-entry
            foreach (string policySwitchEntry in policySwitchEntries)
            {
                contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_POLICY_SWITCH + Guid.NewGuid().ToString(), policySwitchEntry);
            }


            //now actually write the EMConfigXXX.xml files and hand them over to the run-manager
            string configurationFileNameAndPath = EMPath.Folder_Temp(EM_AppContext.FolderEuromodFiles) + EM_XmlHandler.TAGS.EM2CONFIG_labelEMConfig + Guid.NewGuid().ToString() + ".xml";

            using (XmlTextWriter configurationFileWriter = new XmlTextWriter(configurationFileNameAndPath, null))
            {
                configurationFileWriter.Formatting = System.Xml.Formatting.Indented;
                configurationFileWriter.WriteStartDocument(true);
                configurationFileWriter.WriteStartElement(EM_XmlHandler.TAGS.EM2CONFIG_labelEMConfig);

                string runFormInfoText = string.Empty;
                foreach (string key in contentEMConfig.Keys)
                {
                    if (key.StartsWith(EM_XmlHandler.TAGS.EM2CONFIG_SYSTEM_ID)) //remove Guid, see above
                    {
                        configurationFileWriter.WriteElementString(EM_XmlHandler.TAGS.EM2CONFIG_SYSTEM_ID, contentEMConfig[key]);
                    }
                    else if (key.StartsWith(EM_XmlHandler.TAGS.EM2CONFIG_POLICY_SWITCH)) //remove Guid, see above
                    {
                        configurationFileWriter.WriteElementString(EM_XmlHandler.TAGS.EM2CONFIG_POLICY_SWITCH, contentEMConfig[key]);
                    }
                    else
                    {
                        configurationFileWriter.WriteElementString(key, contentEMConfig[key]);
                    }
                }

                configurationFileWriter.WriteElementString(EM_XmlHandler.TAGS.EM2CONFIG_LAST_RUN, DefPar.Value.NO);
                configurationFileWriter.WriteEndElement();
                configurationFileWriter.WriteEndDocument();
            }
            // EM3 returns the config-dictionary, therefore (mis)use this structure to just store the file-path as the first entry (to avoid extra variables for EM2)
            return(new Dictionary <string, string>()
            {
                { configurationFileNameAndPath, null }
            });
        }