Deveel.Data.Session.Session C# (CSharp) Method

Session() public method

Constructs the session for the given user and transaction to the given database.
public Session ( ITransaction transaction, string userName ) : System
transaction ITransaction A transaction that handles the commands issued by /// the user during the session.
userName string
return System
        public Session(ITransaction transaction, string userName)
            : base(transaction as IEventSource)
        {
            if (transaction == null)
                throw new ArgumentNullException("transaction");

            if (String.IsNullOrEmpty(userName))
                throw new ArgumentNullException("userName");

            if (String.Equals(userName, User.SystemName, StringComparison.OrdinalIgnoreCase) ||
                String.Equals(userName, User.PublicName, StringComparison.OrdinalIgnoreCase))
                throw new ArgumentException(String.Format("Cannot open a session for user '{0}'.", userName));

            Transaction = transaction;
            Context = transaction.Context.CreateSessionContext();
            Context.RegisterInstance(this);

            Transaction.Context.Route<QueryEvent>(OnQueryCommand);

            Transaction.GetTableManager().AddInternalTables(new SessionTableContainer(this));

            access = new SessionAccess(this);

            if (!transaction.Database.Sessions.Add(this))
                throw new InvalidOperationException("The session was already in the database session list");

            User = new User(this, userName);
            startedOn = DateTimeOffset.UtcNow;

            this.OnEvent(new SessionEvent(SessionEventType.Begin));
        }