LogonInfo

This topic explains what the LogonInfo object is and how to create- and use it in the Integration Framework. Every method in the Integration Framework requires a LogonInfo to be sent as the first parameter. This object contains the required information to create a connection with the service.

Creating the LogonInfo

The following example shows the recommended method for creating a new LogonInfo object.


	private LogonInfo CreateLogonInfo(IConnectionManager entry)
	{
		byte[] result;
		long tick = DateTime.UtcNow.Ticks;
		using (HMACSHA256 hmac = new HMACSHA256(GetBytes(PrivateHashKey)))
		{
			result = hmac.ComputeHash(GetBytes(PassCode + tick));
		}
					
		DateTime serverUTCDate = server.GetServerUTCDate();

		if (serverUTCDate > DateTime.UtcNow.AddMinutes(2) || serverUTCDate < DateTime.UtcNow.AddMinutes(2))
		{
			throw new Exception(Resources.ClientTimeNotSynchronized);
		}
		
		LogonInfo logonInfo = new LogonInfo
		{
			UserID = entry.CurrentUser.ID,
			storeId = (string) entry.CurrentStoreID,
			StaffID = entry.CurrentStaffID == RecordIdentifier.Empty ? "" : (string) entry.CurrentStaffID,
			terminalId = entry.CurrentTerminalID == RecordIdentifier.Empty ? "" : (string) entry.CurrentTerminalID,
			Settings = ((User)entry.CurrentUser).Profile.Settings,
			ClientID =  ClientID,
			Hash = result,
			Ticks = tick
		};

		return logonInfo;
	}
			
	private byte[] GetBytes(string str)
	{
		byte[] bytes = new byte[str.Length * sizeof(char)];
		System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
		return bytes;
	}		
	

For the method to work you will need to set two constants, namely PrivateHashKey and PassCode, and a generate a GUID as the ClientID.

The PrivateHashKey can be found and set in the configuration file. The PassCode is a password used to validate the credentials in a cloud environment.

Creating the IConnectionManager

If you do not have access to an IConnectionManager object, you can create one following this example.


	using LSOne.DataLayer.GenericConnector;
					
	private IConnectionManager dataModel;
	
	void LoadConnection()
	{
		dataModel = ConnectionManagerFactory.CreateConnectionManager();                    
		LoginResult result = dataModel.Login(
			Server,
			WindowsAuthentication,
			ServerLogin,
			ServerPassword,
			DatabaseName,
			LSOneLogin,
			LSOnePassword,
			ConnectionType,
			ConnectionUsageType.UsageNormalClient,
			"LSR");	
		
		if(result == LoginResult.Success)
			//Created connection manager		
	}
			

The parameters used for the login are described in the configuration file.