Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/openmpp/main
Browse files Browse the repository at this point in the history
  • Loading branch information
esseff committed Apr 25, 2023
2 parents 76b95e4 + dfd9777 commit 0e8846a
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 112 deletions.
54 changes: 11 additions & 43 deletions props/model-ompp.4.build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -135,42 +135,6 @@
<BuildDependsOn>OmcCompile;$(BuildDependsOn)</BuildDependsOn>
</PropertyGroup>


<!--
StopOms
-->
<!-- Stop oms web-service if model.ompp_ui.tickle exist -->
<!-- otherwise omc compile will fail because model.sqlite is opened by oms.exe -->
<PropertyGroup>
<ABS_OM_ROOT Condition="'$(OM_ROOT)'!=''">$([System.IO.Path]::GetFullPath('$(OM_ROOT)'))</ABS_OM_ROOT>
<!-- bug: System.IO.Path::GetFullPath('../../..') return: C:\Program Files (x86)\Microsoft Visual Studio\2019 -->
<!-- bug: System.IO.Path::GetFullPath('../../..') return wrong value under VS 2022 -->
<ABS_OM_ROOT Condition="'$(OM_ROOT)'=='../../..'">$([System.IO.Path]::GetFullPath('$(ProjectDir)..\..\..'))</ABS_OM_ROOT>
<PUBLISH_DIR_REL_TO_OM_ROOT>$([MSBuild]::MakeRelative($(ABS_OM_ROOT), $(PUBLISH_DIR)))</PUBLISH_DIR_REL_TO_OM_ROOT>
<OMS_URL_TICKLE>$(PUBLISH_DIR)/$(MODEL_NAME).oms_url.tickle</OMS_URL_TICKLE>
<OMS_URL_TICKLE_REL>$(PUBLISH_DIR_REL_TO_OM_ROOT)/$(MODEL_NAME).oms_url.tickle</OMS_URL_TICKLE_REL>
<STOP_OMS_LOG>$(PUBLISH_DIR_REL_TO_OM_ROOT)/$(MODEL_NAME).stop_oms.log</STOP_OMS_LOG>
</PropertyGroup>

<Target Name="StopOms"
Condition="Exists('$(OMS_URL_TICKLE)')"
BeforeTargets="OmcCompile"
>

<Message Text="Using PowerShell to stop oms web-service:" />
<Message
Text="(set OMS_URL_TICKLE=$(OMS_URL_TICKLE_REL)) &amp; (set STOP_OMS_LOG=$(STOP_OMS_LOG)) &amp; powershell -NonInteractive -ExecutionPolicy Bypass -File props/stopOms.ps1"
/>
<Exec
WorkingDirectory="$(OM_ROOT)"
ContinueOnError="true"
Command="(set OMS_URL_TICKLE=$(OMS_URL_TICKLE_REL)) &amp; (set STOP_OMS_LOG=$(STOP_OMS_LOG)) &amp; powershell -NonInteractive -ExecutionPolicy Bypass -File props/stopOms.ps1"
/>
<Delete Files="$(OMS_URL_TICKLE)" />

</Target>


<!--
ModelPublish
-->
Expand Down Expand Up @@ -330,7 +294,6 @@
ContinueOnError="true"/>
</Target>


<!--
StartOmppUI
-->
Expand All @@ -342,26 +305,31 @@
Template files are located in OM_ROOT/etc directory
-->
<PropertyGroup>
<START_OMPP_UI_LOG>$(PUBLISH_DIR_REL_TO_OM_ROOT)/$(MODEL_NAME).start_ompp_ui.log</START_OMPP_UI_LOG>
<RUN_TEMPLATE Condition="'$(Configuration)'=='Debug' And '$(Platform)'=='Win32'">run.Debug.template.txt</RUN_TEMPLATE>
<RUN_TEMPLATE Condition="'$(Configuration)'=='Debug' And '$(Platform)'=='x64'">run.Debug.template.txt</RUN_TEMPLATE>
<RUN_TEMPLATE Condition="'$(OM_CFG_DEFAULT_RUN_TMPL)'!=''">$(OM_CFG_DEFAULT_RUN_TMPL)</RUN_TEMPLATE>
<RUN_TEMPLATE Condition="'$(Configuration)'=='Release' And '$(Platform)'=='Win32'"></RUN_TEMPLATE>
<RUN_TEMPLATE Condition="'$(Configuration)'=='Release' And '$(Platform)'=='x64'"></RUN_TEMPLATE>
<OMS_URL_TICKLE>$(PUBLISH_DIR)/$(MODEL_NAME).oms_url.tickle</OMS_URL_TICKLE>
<ABS_OM_ROOT Condition="'$(OM_ROOT)'!=''">$([System.IO.Path]::GetFullPath('$(OM_ROOT)'))</ABS_OM_ROOT>
<!-- bug: System.IO.Path::GetFullPath('../../..') return: C:\Program Files (x86)\Microsoft Visual Studio\2019 -->
<!-- bug: System.IO.Path::GetFullPath('../../..') return wrong value under VS 2022 -->
<ABS_OM_ROOT Condition="'$(OM_ROOT)'=='../../..'">$([System.IO.Path]::GetFullPath('$(ProjectDir)..\..\..'))</ABS_OM_ROOT>
<ABS_START_UI_BAT>&quot;$(ABS_OM_ROOT)\props\start-ui-at-build.bat&quot;</ABS_START_UI_BAT>
</PropertyGroup>

<Target Name="StartOmppUI"
Condition="'$(OPEN_MODEL_WEB_UI)'=='true'"
Outputs="$(OMS_URL_TICKLE)"
AfterTargets="ModelPublish"
AfterTargets="ModelPublish;RunModel"
>
<Message Text="Using PowerShell to start openM++ UI:" />
<Message Text="Using batch file to start openM++ UI:" />
<Message
Text="(set PUBLISH_DIR=$(PUBLISH_DIR_REL_TO_OM_ROOT)) &amp; (set OMS_URL_TICKLE=$(OMS_URL_TICKLE_REL)) &amp; (set OM_CFG_DEFAULT_RUN_TMPL=$(RUN_TEMPLATE)) &amp; (set START_OMPP_UI_LOG=$(START_OMPP_UI_LOG)) &amp; (set $(MODEL_ROOT_ENV)) &amp; powershell -NonInteractive -ExecutionPolicy Bypass -File props/startOmppUI.ps1"
Text="(set MODEL_NAME=$(MODEL_NAME)) &amp; (set OM_ROOT=$(ABS_OM_ROOT)) &amp; (set OM_CFG_DEFAULT_RUN_TMPL=$(RUN_TEMPLATE)) &amp; $(ABS_START_UI_BAT)"
/>
<Exec
WorkingDirectory="$(OM_ROOT)"
Command="(set PUBLISH_DIR=$(PUBLISH_DIR_REL_TO_OM_ROOT)) &amp; (set OMS_URL_TICKLE=$(OMS_URL_TICKLE_REL)) &amp; (set OM_CFG_DEFAULT_RUN_TMPL=$(RUN_TEMPLATE)) &amp; (set START_OMPP_UI_LOG=$(START_OMPP_UI_LOG)) &amp; (set $(MODEL_ROOT_ENV)) &amp; powershell -NonInteractive -ExecutionPolicy Bypass -File props/startOmppUI.ps1"
WorkingDirectory="$(PUBLISH_DIR)"
Command="(set MODEL_NAME=$(MODEL_NAME)) &amp; (set OM_ROOT=$(ABS_OM_ROOT)) &amp; (set OM_CFG_DEFAULT_RUN_TMPL=$(RUN_TEMPLATE)) &amp; $(ABS_START_UI_BAT)"
/>
</Target>

Expand Down
30 changes: 25 additions & 5 deletions props/start-ompp-ui.bat
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,26 @@ mkdir "%PUBLISH_DIR%\io\download"
mkdir "%PUBLISH_DIR%\io\upload"
cd .

REM start oms web-service and UI
REM delete oms URL file if exist

set OMS_URL_TICKLE=%MODEL_NAME%.oms_url.tickle

REM @echo OMS_URL_TICKLE = %OMS_URL_TICKLE%

if exist "%OMS_URL_TICKLE%" (

del /q %OMS_URL_TICKLE%
if ERRORLEVEL 1 (
@echo FAIL to delete: %OMS_URL_TICKLE%
EXIT 1
)
)
if exist "%OMS_URL_TICKLE%" (
@echo FAIL to delete: %OMS_URL_TICKLE%
EXIT 1
)

set OMS_URL_TICKLE=%PUBLISH_DIR%\%MODEL_NAME%.oms_url.tickle
rem set START_OMPP_UI_LOG=%PUBLISH_DIR%\%MODEL_NAME%.start_ompp_ui.log
REM start oms web-service and UI

set OM_CFG_INI_ALLOW=true
set OM_CFG_INI_ANY_KEY=true
Expand All @@ -135,10 +151,14 @@ timeout /T 2 /nobreak >nul

REM read oms url from file and open browser

for /F "usebackq tokens=* delims=" %%i in ("%OMS_URL_TICKLE%") do (
if not exist "%OMS_URL_TICKLE%" (
@echo ERROR: oms start failed, URL file not found: %OMS_URL_TICKLE%
EXIT 1
)

for /F "usebackq tokens=* delims=" %%i in (%OMS_URL_TICKLE%) do (
set OMS_URL=%%i
)
@echo Starting openM++ UI at: %OMS_URL%

START %OMS_URL%

127 changes: 127 additions & 0 deletions props/start-ui-at-build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
@echo off

REM Windows: start openM++ UI from model/ompp/bin directory
REM
REM Environment:
REM
REM MODEL_NAME: model name, default: current directory name
REM
REM OM_ROOT: openM++ root folder, default: ..\..
REM
REM OM_CFG_DEFAULT_RUN_TMPL: if defined then UI configured to use this model run template, by default
REM if Release model.exe not exist and Debug modelD.exe exist then: run.Debug.template.txt
REM

setlocal enabledelayedexpansion

REM check MODEL_NAME and OM_ROOT environment

IF "%MODEL_NAME%" == "" (
@echo ERROR: empty MODEL_NAME environment variable
EXIT 1
)
@echo MODEL_NAME = %MODEL_NAME%

IF "%OM_ROOT%" == "" (
@echo ERROR: empty OM_ROOT environment variable
EXIT 1
)
@echo OM_ROOT = %OM_ROOT%

if not exist "%OM_ROOT%\html" (
@echo ERROR: missing UI html directory: %OM_ROOT%\html
EXIT 1
)
if not exist "%OM_ROOT%\bin\oms.exe" (
@echo ERROR: missing openM++ web-service: %OM_ROOT%\bin\oms.exe
EXIT 1
)
if not exist "%OM_ROOT%\bin\dbcopy.exe" (
@echo ERROR: missing openM++ dbcopy utility: %OM_ROOT%\bin\dbcopy.exe
EXIT 1
)

REM check if model.exe exist and model.sqlite exist
REM if only Debug modelD.exe exist then set model run template to run.Debug.template.txt

if exist "%MODEL_NAME%.exe" (
set model_exe_name=%MODEL_NAME%.exe
)
if not defined model_exe_name (
if exist "%MODEL_NAME%D.exe" (

set model_exe_name=%MODEL_NAME%D.exe

if not defined OM_CFG_DEFAULT_RUN_TMPL (
set OM_CFG_DEFAULT_RUN_TMPL=run.Debug.template.txt
)
)
)
if not defined model_exe_name (
@echo ERROR: %MODEL_NAME% exe not found
EXIT 1
)

if not exist "%MODEL_NAME%.sqlite" (
@echo ERROR: model SQLite database not found: %MODEL_NAME%.sqlite
EXIT 1
)

REM create directories for download and upload from UI, errors are not critical and can be ignored

mkdir "io\download"
mkdir "io\upload"
cd .

REM delete oms URL file if exist

set OMS_URL_TICKLE=%MODEL_NAME%.oms_url.tickle

REM @echo OMS_URL_TICKLE = %OMS_URL_TICKLE%

if exist "%OMS_URL_TICKLE%" (

del /q %OMS_URL_TICKLE%
if ERRORLEVEL 1 (
@echo FAIL to delete: %OMS_URL_TICKLE%
EXIT 1
)
)
if exist "%OMS_URL_TICKLE%" (
@echo FAIL to delete: %OMS_URL_TICKLE%
EXIT 1
)

REM start oms web-service and UI

set OM_CFG_INI_ALLOW=true
set OM_CFG_INI_ANY_KEY=true

REM set OM_ModelName=/path/to/model/dir

set model_root_name=OM_%MODEL_NAME%
set %model_root_name%="%CD%"

REM @echo %model_root_name% = %CD%

START "oms" "%OM_ROOT%"\bin\oms.exe -l localhost:0 -oms.ModelDir ..\bin -oms.ModelLogDir ..\bin -oms.UrlSaveTo %OMS_URL_TICKLE% -oms.HtmlDir "%OM_ROOT%\html" -oms.EtcDir "%OM_ROOT%\etc" -oms.HomeDir ..\bin -oms.AllowDownload -oms.AllowUpload -oms.AllowMicrodata -oms.LogRequest -OpenM.LogToFile
if ERRORLEVEL 1 (
@echo FAILED to start %OM_ROOT%\bin\oms.exe
EXIT 1
)

START /wait timeout /T 2 /nobreak >nul

REM read oms url from file and open browser

if not exist "%OMS_URL_TICKLE%" (
@echo ERROR: oms start failed, URL file not found: %OMS_URL_TICKLE%
EXIT 1
)

for /F "usebackq tokens=* delims=" %%i in (%OMS_URL_TICKLE%) do (
set OMS_URL=%%i
)
@echo Starting openM++ UI at: %OMS_URL%

START %OMS_URL%
37 changes: 0 additions & 37 deletions props/startOmppUI.ps1

This file was deleted.

27 changes: 0 additions & 27 deletions props/stopOms.ps1

This file was deleted.

0 comments on commit 0e8846a

Please sign in to comment.