MAPIServices class
MAPIServices is the entry point to connect MAPI windows services.
MAPI is a service base concept.
That means that you must start by requesting a service.
MAPIServices.instance singleton allows perform such request on the localhost.
And most of your python code must start MAPIServices.instance.get_service("SERVICE_NAME")
If you need to connect a remote PC, you can create a new MAPIServices object.
Standard MAPI service names are:
- MorpheeProcessControl
- MorpheeResults
- UserApplicationMonitoring
- UserApplicationControl
- UserApplicationMonitoring_1
- UserApplicationControl_1
- UserApplicationMonitoring_2
- UserApplicationControl_2
- ...
Note that for xMOD, MAPI services are:
- Authority
- MorpheeProcessControl
- MorpheeResults
- SimulationControl
- ...
Services that end with _XX are related to MORPHEE instance XX.
Bases: MAPIService
MAPI services service is the main entry point of MAPI.
A singleton attribute instance can be used to request other MAPI services (e.g. MAPIServices.instance.get_service("MorpheeProcessControl"))
Source code in restmapi\restmapi\services.py
| class MAPIServices(MAPIService):
"""MAPI services service is the main entry point of MAPI.
A singleton attribute instance can be used to request other MAPI services (e.g. MAPIServices.instance.get_service("MorpheeProcessControl"))
"""
instance = None
def __init__(self, url=None):
"""Constructs a MAPI services. Usually you do not need to create a MAPIServices, we prefer using MAPIServices.instance.
Note that if you need to connect a distant computer you should create your own MAPIServices object.
Parameters
----------
url : string, optional
Base url from the service (without api/Services), by default the url is construct using MAPI registry parameters or "http://localhost:80" if the registry is not found.
"""
super().__init__(url)
self._mapi_base_url = f"{self._mapi_base_url}/api/Services/"
def get_available_rest_services(self):
"""List of available MAPI services
Note that the list change at runtime, if MORPHEE is started some new services are added to the list.
Returns
-------
List of string
Available service names.
"""
return self.invoke_web_get_request("List")
def get_service(self, name):
"""Query the MAPI service object proxy from its name
Parameters
----------
name : string
MAPI service name (can be retrieved from get_available_rest_services() list)
Returns
-------
object
Proxy object that map every REST request of the service
"""
serviceDesc = self.invoke_web_get_request(f"Service/{name}")
objType = serviceDesc["DefaultProxyType"].replace("FEV.Morphee.MAPI.Service.xMODRESTServices.", "")
objType = objType.replace("FEV.Morphee.MAPI.Internal.","")
objType = objType.replace("FEV.Morphee.MAPI.","")
objType = objType.split(",")[0]
return eval(objType)(serviceDesc["URL"])
def get_version(self):
"""Current version of MAPI
Returns
-------
string
MAPI version
"""
return self.invoke_web_get_request("Version")
def register_rest_service(self, name, contract, defaultProxyType, url, processId):
"""Allow to register new MAPI service (internal usage only)
Parameters
----------
name : string
New service name
contract : string
C# interface type of the contract
defaultProxyType : string
C# default proxy type class
url : string
Complete url of the new MAPI service
processId : int
Process id that manages the new MAPI service. If the process is killed, MAPI will remove automatically the registered service
"""
self.invoke_web_post_request(f"RegisterService?name={name}&contract={contract}&defaultProxyType={defaultProxyType}&url={url}&processId={processId}")
def unregister_rest_service(self, name):
"""Unregister a MAPI service previously registered with register_rest_service
Parameters
----------
name : string
MAPI service name
"""
self.invoke_web_post_request(f"UnregisterService?name={name}")
|
__init__(url=None)
Constructs a MAPI services. Usually you do not need to create a MAPIServices, we prefer using MAPIServices.instance.
Note that if you need to connect a distant computer you should create your own MAPIServices object.
Parameters:
-
url
(string, default:
None
)
–
Base url from the service (without api/Services), by default the url is construct using MAPI registry parameters or "http://localhost:80" if the registry is not found.
Source code in restmapi\restmapi\services.py
| def __init__(self, url=None):
"""Constructs a MAPI services. Usually you do not need to create a MAPIServices, we prefer using MAPIServices.instance.
Note that if you need to connect a distant computer you should create your own MAPIServices object.
Parameters
----------
url : string, optional
Base url from the service (without api/Services), by default the url is construct using MAPI registry parameters or "http://localhost:80" if the registry is not found.
"""
super().__init__(url)
self._mapi_base_url = f"{self._mapi_base_url}/api/Services/"
|
get_available_rest_services()
List of available MAPI services
Note that the list change at runtime, if MORPHEE is started some new services are added to the list.
Returns:
Source code in restmapi\restmapi\services.py
| def get_available_rest_services(self):
"""List of available MAPI services
Note that the list change at runtime, if MORPHEE is started some new services are added to the list.
Returns
-------
List of string
Available service names.
"""
return self.invoke_web_get_request("List")
|
get_service(name)
Query the MAPI service object proxy from its name
Parameters
name : string
MAPI service name (can be retrieved from get_available_rest_services() list)
Returns:
-
object
–
Proxy object that map every REST request of the service
Source code in restmapi\restmapi\services.py
| def get_service(self, name):
"""Query the MAPI service object proxy from its name
Parameters
----------
name : string
MAPI service name (can be retrieved from get_available_rest_services() list)
Returns
-------
object
Proxy object that map every REST request of the service
"""
serviceDesc = self.invoke_web_get_request(f"Service/{name}")
objType = serviceDesc["DefaultProxyType"].replace("FEV.Morphee.MAPI.Service.xMODRESTServices.", "")
objType = objType.replace("FEV.Morphee.MAPI.Internal.","")
objType = objType.replace("FEV.Morphee.MAPI.","")
objType = objType.split(",")[0]
return eval(objType)(serviceDesc["URL"])
|
get_version()
Current version of MAPI
Returns:
Source code in restmapi\restmapi\services.py
| def get_version(self):
"""Current version of MAPI
Returns
-------
string
MAPI version
"""
return self.invoke_web_get_request("Version")
|
register_rest_service(name, contract, defaultProxyType, url, processId)
Allow to register new MAPI service (internal usage only)
Parameters:
-
name
(string)
–
-
contract
(string)
–
C# interface type of the contract
-
defaultProxyType
(string)
–
C# default proxy type class
-
url
(string)
–
Complete url of the new MAPI service
-
processId
(int)
–
Process id that manages the new MAPI service. If the process is killed, MAPI will remove automatically the registered service
Source code in restmapi\restmapi\services.py
| def register_rest_service(self, name, contract, defaultProxyType, url, processId):
"""Allow to register new MAPI service (internal usage only)
Parameters
----------
name : string
New service name
contract : string
C# interface type of the contract
defaultProxyType : string
C# default proxy type class
url : string
Complete url of the new MAPI service
processId : int
Process id that manages the new MAPI service. If the process is killed, MAPI will remove automatically the registered service
"""
self.invoke_web_post_request(f"RegisterService?name={name}&contract={contract}&defaultProxyType={defaultProxyType}&url={url}&processId={processId}")
|
unregister_rest_service(name)
Unregister a MAPI service previously registered with register_rest_service
Parameters:
Source code in restmapi\restmapi\services.py
| def unregister_rest_service(self, name):
"""Unregister a MAPI service previously registered with register_rest_service
Parameters
----------
name : string
MAPI service name
"""
self.invoke_web_post_request(f"UnregisterService?name={name}")
|