Skip to content

MAPIServiceWithSignalR base class

Bases: MAPIService

Manage signalR hub from MAPI services

Source code in restmapi\restmapi\services.py
class MAPIServiceWithSignalR(MAPIService):
	"""Manage signalR hub from MAPI services
	"""
	def __init__(self, url, hubName):
		"""Construct a MAPIServiceWithSignalR from its base url and hub name.

		Parameters
		----------
		url : string
			Base url from the service, by default the url is construct using MAPI registry parameters or "http://localhost:80" if the registry is not found. 
		hubName : string
			The signalR hub of the MAPI service.
		"""
		super().__init__(url)
		self.connection = None
		self.hub = None	
		self.session = None		
		self.disposed = False
		self.hubName = hubName

	def __enter__(self):
		return self	

	def __exit__(self, exception_type, exception_value, traceback):
		if self.connection != None:			
			self.disposed = True			
			self.thread.join(1)

	def init_signalr(self):
		"""Call init_signalr if you intend to use the signalr hub.
		Used with keyword on the MAPIServiceWithSignalR to be sure that the communication is closed at the end
		"""
		if self.session == None:	
			#self.connection.start()		
			self.thread = Thread(target=self.handle_signalr, args=[], daemon=True)	
			self.thread.start()
			while self.hub == None and self.thread.is_alive():
				time.sleep(0.1)								

	def handle_signalr(self):
		"""Internal thread method that manages the signalr communication
		"""
		self.session = Session()
		with self.session:				
			self.connection = Connection(self.get_signalr_hub_url(), self.session)
			self.hub = self.connection.register_hub(self.hubName)		
			with self.connection:					
				while not self.disposed:
					self.connection.wait(0.1)					

	def get_signalr_hub_url(self):
		"""Returns the signalr path of the MAPI service

		Returns
		-------
		string
			Signalr path
		"""
		return self.invoke_web_get_request("SignalRHubUrl")	        

__init__(url, hubName)

Construct a MAPIServiceWithSignalR from its base url and hub name.

Parameters:

  • url (string) –
    Base url from the service, by default the url is construct using MAPI registry parameters or "http://localhost:80" if the registry is not found.
    
  • hubName (string) –
    The signalR hub of the MAPI service.
    
Source code in restmapi\restmapi\services.py
def __init__(self, url, hubName):
	"""Construct a MAPIServiceWithSignalR from its base url and hub name.

	Parameters
	----------
	url : string
		Base url from the service, by default the url is construct using MAPI registry parameters or "http://localhost:80" if the registry is not found. 
	hubName : string
		The signalR hub of the MAPI service.
	"""
	super().__init__(url)
	self.connection = None
	self.hub = None	
	self.session = None		
	self.disposed = False
	self.hubName = hubName

get_signalr_hub_url()

Returns the signalr path of the MAPI service

Returns:

  • string

    Signalr path

Source code in restmapi\restmapi\services.py
def get_signalr_hub_url(self):
	"""Returns the signalr path of the MAPI service

	Returns
	-------
	string
		Signalr path
	"""
	return self.invoke_web_get_request("SignalRHubUrl")	        

handle_signalr()

Internal thread method that manages the signalr communication

Source code in restmapi\restmapi\services.py
def handle_signalr(self):
	"""Internal thread method that manages the signalr communication
	"""
	self.session = Session()
	with self.session:				
		self.connection = Connection(self.get_signalr_hub_url(), self.session)
		self.hub = self.connection.register_hub(self.hubName)		
		with self.connection:					
			while not self.disposed:
				self.connection.wait(0.1)					

init_signalr()

Call init_signalr if you intend to use the signalr hub. Used with keyword on the MAPIServiceWithSignalR to be sure that the communication is closed at the end

Source code in restmapi\restmapi\services.py
def init_signalr(self):
	"""Call init_signalr if you intend to use the signalr hub.
	Used with keyword on the MAPIServiceWithSignalR to be sure that the communication is closed at the end
	"""
	if self.session == None:	
		#self.connection.start()		
		self.thread = Thread(target=self.handle_signalr, args=[], daemon=True)	
		self.thread.start()
		while self.hub == None and self.thread.is_alive():
			time.sleep(0.1)