Exemplo n.º 1
0
        /// <summary>
        /// Sets the state of the session to started
        /// </summary>
        /// <remarks>Cannot be used again prior to SessionEnd()</remarks>
        /// <returns>Returns the Session ID of the current session</returns>
        public virtual long SessionStart()
        {
            //Is there an existing session open?
            if (CurrentSessionID != -1)
            {
                //throw new Exception("An active session is already open.  Please use SessionEnd prior to begining a new session.");
                return(CurrentSessionID);
            }
            else
            {
                var     dateNow = DateTime.Now;
                Session session = new Session()
                {
                    ID            = Util.GenerateHashKey(Guid.NewGuid().ToString()),
                    Rnetwork_ID   = CurrentNetworkID,
                    DateTimeStart = dateNow,
                    DateTimeStop  = dateNow,
                    Hidden        = true,
                    SessionScore  = Int32.MinValue,
                };

                CurrentSessionID = session.ID;
                SessionCount     = MemoryManager.Sessions.Count;

                if (MemoryManager.Sessions.TryAdd(session.ID, session))
                {
                    //save session to db
                    if (PersistData)
                    {
                        MemoryManager.AddSessionToCreateToQueue(CurrentSessionID, session);
                    }

                    // reset input momentums
                    foreach (var item in InputMomentums)
                    {
                        item.Value.Reset();
                    }
                }
                else
                {
                    throw new Exception("The session already exists");
                }

                return(session.ID);
            }
        }