protected void Page_Load(object sender, EventArgs e)
    {
        IConversationState convCircularDependenceTest_A     = (IConversationState)this.applicationContext.GetObject("convCircularDependenceTest_A");
        IConversationState convCircularDependenceTest_A_A_A = (IConversationState)this.applicationContext.GetObject("convCircularDependenceTest_A_A_A");
        StringBuilder      sbErrors = new StringBuilder();

        try
        {
            convCircularDependenceTest_A_A_A.InnerConversations.Add(convCircularDependenceTest_A);
            sbErrors.AppendLine("Circular was not detected. ");
        }
        catch (InvalidOperationException ioe)
        {
            LOG.Debug("SERVER SIDE ERROR", ioe);
            if (!ioe.Message.Contains("convCircularDependenceTest_A_A_A->convCircularDependenceTest_A->convCircularDependenceTest_A_A->convCircularDependenceTest_A_A_A"))
            {
                sbErrors.AppendLine(String.Format("Wrong CircularDependence message= '{0}'", ioe.Message));
            }
        }
        catch (Exception ex)
        {
            LOG.Error("SERVER SIDE ERROR", ex);
            sbErrors.AppendLine(String.Format("Unexpected Error: '{0}' \n {1}", ex.Message, ex.StackTrace));
        }

        Session["CircularDependenceTest"] = sbErrors.ToString();
    }
 private void CloseConversation(IConversationState conversation)
 {
     if (log.IsDebugEnabled)
     {
         log.Debug(String.Format("CloseConversation: Id='{0}'", conversation.Id));
     }
     if (conversation.RootSessionPerConversation != null)
     {
         ISession tmpSession = conversation.RootSessionPerConversation;
         if (conversation.Ended)
         {
             SessionFactoryUtils.CloseSession(tmpSession);
             conversation.RootSessionPerConversation = null;
         }
         else
         {
             if (tmpSession.IsConnected)
             {
                 tmpSession.Disconnect();
             }
         }
         RemoveSession(tmpSession);
     }
     if (log.IsDebugEnabled)
     {
         log.Debug("Closed LazySessionPerConversationHolder");
     }
 }
Exemple #3
0
            private void CloseConversation(IConversationState conversation)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug($"CloseConversation: Id='{conversation.Id}'");
                }

                if (conversation.RootSessionPerConversation != null)
                {
                    ISession tmpSession = conversation.RootSessionPerConversation;
                    if (conversation.Ended)
                    {
                        SessionFactoryUtils.CloseSession(tmpSession);
                        conversation.RootSessionPerConversation = null;
                    }
                    else
                    {
                        if (tmpSession.IsConnected)
                        {
                            IDbConnection conn = tmpSession.Disconnect();
                            if (conn != null && conn.State == ConnectionState.Open)
                            {
                                conn.Close();
                            }
                        }
                    }
                    RemoveSession(tmpSession);
                }
                if (log.IsDebugEnabled)
                {
                    log.Debug("Closed LazySessionPerConversationHolder");
                }
            }
 /// <summary>
 /// <see cref="IConversationManager"/>
 /// </summary>
 public void EndOnTimeOut()
 {
     try
     {
         if (LOG.IsDebugEnabled)
         {
             LOG.Debug("EndOnTimeOut");
         }
         this.MutexEditDic.WaitOne(5000);
         foreach (String keyItem in this.conversations.Keys)
         {
             IConversationState conversationItem = this.conversations[keyItem];
             if (conversationItem.TimeOut > 0)
             {
                 if (DateTime.Now.Subtract(conversationItem.LastAccess).TotalMilliseconds > conversationItem.TimeOut)
                 {
                     if (LOG.IsDebugEnabled)
                     {
                         LOG.Debug(String.Format("Timeout for conversation '{0}'", conversationItem.Id));
                     }
                     conversationItem.EndConversation();
                 }
             }
         }
     }
     finally
     {
         this.MutexEditDic.ReleaseMutex();
     }
 }
        /// <summary>
        /// <see cref="IConversationManager"/>
        /// </summary>
        /// <param name="conversation"></param>
        public void SetActiveConversation(IConversationState conversation)
        {
            if (LOG.IsDebugEnabled)
            {
                LOG.Debug(String.Format("SetActiveConversation('{0}')", conversation.Id));
            }

            //Close connection for the last conversation, if it is open.
            if (this.activeConversation != null && this.activeConversation != conversation)
            {
                this.Close(this.SessionFactory, this.conversations.Values);
            }
            this.Open(conversation, this.conversations.Values);

            this.activeConversation = conversation;

            //Ending the paused conversations.
            if (this.EndPaused)
            {
                foreach (IConversationState convItem in this.conversations.Values)
                {
                    if (convItem.IsPaused)
                    {
                        convItem.EndConversation();
                    }
                }
            }
        }
Exemple #6
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            screenRectangle = new Rectangle(0, 0, 1280, 720);

            graphics.PreferredBackBufferWidth  = ScreenRectangle.Width;
            graphics.PreferredBackBufferHeight = ScreenRectangle.Height;

            gameStateManager = new GameStateManager(this);
            Components.Add(gameStateManager);

            this.IsMouseVisible = true;

            titleIntroState   = new TitleIntroState(this);
            startMenuState    = new MainMenuState(this);
            gamePlayState     = new GamePlayState(this);
            conversationState = new ConversationState(this);
            battleState       = new BattleState(this);

            gameStateManager.ChangeState((TitleIntroState)titleIntroState, PlayerIndex.One);

            characterManager = CharacterManager.Instance;
        }
Exemple #7
0
        /// <summary>
        /// Open a new session or reconect the
        /// <see cref="IConversationState.RootSessionPerConversation"/> in <paramref name="activeConversation"/>.
        /// Participating in an existing session registed with <see cref="TransactionSynchronizationManager"/>
        /// is not alowed.
        /// </summary>
        /// <param name="activeConversation"></param>
        /// <param name="allManagedConversation"></param>
        /// <exception cref="InvalidOperationException">
        /// <list type="bullet">
        /// <item>If there is another conversation with a <see cref="ISession"/> with opened
        /// <see cref="IDbConnection"/>.</item>
        /// <item>If attempting to participate in an existing NHibernate <see cref="ISessionFactory"/>
        /// managed by <see cref="TransactionSynchronizationManager"/>.
        /// </item>
        /// </list>
        /// </exception>
        public void Open(IConversationState activeConversation, ICollection <IConversationState> allManagedConversation)
        {
            bool isDebugEnabled = log.IsDebugEnabled;

            if (IsOpen)
            {
                if (activeConversation.Id != OpenerConversationId)
                {
                    throw new InvalidOperationException("There is another conversation with a ISession with opened IDbConnection.");
                }
                else
                {
                    if (isDebugEnabled)
                    {
                        log.Debug($"SessionPerConversationScope is already open for this conversation: Id:'{activeConversation.Id}'.");
                    }
                }
            }
            else
            {
                if (activeConversation.SessionFactory != null)
                {
                    if (isDebugEnabled)
                    {
                        log.Debug($"activeConversation with 'session-per-conversation': Id:'{activeConversation.Id}'.");
                    }

                    // single session mode
                    if (TransactionSynchronizationManager.HasResource(activeConversation.SessionFactory))
                    {
                        // Do not modify the Session: just set the participate flag.
                        if (isDebugEnabled)
                        {
                            log.Debug("Participating in existing NHibernate SessionFactory IS NOT ALLOWED.");
                        }
                        throw new InvalidOperationException("Participating in existing NHibernate SessionFactory IS NOT ALLOWED.");
                    }
                    else
                    {
                        if (isDebugEnabled)
                        {
                            log.Debug("Opening single NHibernate Session in SessionPerConversationScope");
                        }

                        TransactionSynchronizationManager.BindResource(activeConversation.SessionFactory, new LazySessionPerConversationHolder(this, activeConversation, allManagedConversation));

                        SetOpen(true);
                        OpenerConversationId = activeConversation.Id;
                    }
                }
                else
                {
                    if (isDebugEnabled)
                    {
                        log.Debug($"activeConversation with NO 'session-per-conversation': Id:'{activeConversation.Id}'.");
                    }
                }
            }
        }
        private void DoOpenSession(IConversationState conversation)
        {
            lock (this)
            {
                ISession session = null;
                if (conversation.RootSessionPerConversation == null)
                {
                    //new session
                    session = (
                        (EntityInterceptor != null)
                                   ? conversation.SessionFactory.OpenSession(EntityInterceptor)
                                   : conversation.SessionFactory.OpenSession()
                        );
                    conversation.RootSessionPerConversation = session;
                }
                else
                {
                    //reconnect existing one.
                    if (conversation.DbProvider != null)
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug(String.Format("DoOpenSession: Conversation has a DbProvider: Id='{0}'", conversation.Id));
                        }
                        if (!conversation.RootSessionPerConversation.IsConnected)
                        {
                            if (log.IsDebugEnabled)
                            {
                                log.Debug(String.Format("DoOpenSession: Conversation is not Connected: Id='{0}'", conversation.Id));
                            }

                            IDbConnection connection = conversation.DbProvider.CreateConnection();
                            connection.Open();

                            conversation.RootSessionPerConversation.Reconnect(connection);
                        }
                        else
                        {
                            if (log.IsDebugEnabled)
                            {
                                log.Debug(String.Format("DoOpenSession: Conversation is already Connected: Id='{0}'", conversation.Id));
                            }
                        }
                    }
                    else
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug(String.Format("DoOpenSession: Conversation has NO DbProvider: Id='{0}'", conversation.Id));
                        }
                        conversation.RootSessionPerConversation.Reconnect();
                    }
                    session = conversation.RootSessionPerConversation;
                }
                session.FlushMode = DefaultFlushMode;
            }
        }
 /// <summary>
 /// Initialize a new instance.
 /// </summary>
 public LazySessionPerConversationHolder(SessionPerConversationScope owner, IConversationState activeConversation, ICollection <IConversationState> allManagedConversation)
 {
     if (log.IsDebugEnabled)
     {
         log.Debug("Created LazyReconnectableSessionHolder");
     }
     this.owner = owner;
     this.activeConversation     = activeConversation;
     this.allManagedConversation = allManagedConversation;
 }
        public void LoadActiveConversation()
        {
            //reset this.activeConversation
            this.activeConversation = null;

            if (LOG.IsDebugEnabled)
            {
                LOG.Debug("LoadActiveConversation");
            }

            HttpCookie activeConveCookie = HttpContext.Current.Request.Cookies[CONVERSATION_COOKIE_ID];

            if (activeConveCookie != null && !String.IsNullOrEmpty(activeConveCookie.Value))
            {
                if (LOG.IsDebugEnabled)
                {
                    LOG.Debug(String.Format("LoadActiveConversation: cooking found for current active conversation: [{0}]", activeConveCookie.ToString()));
                }
                if (this.conversations.ContainsKey(activeConveCookie.Value))
                {
                    if (LOG.IsDebugEnabled)
                    {
                        LOG.Debug(String.Format("LoadActiveConversation: active conversation found for id: '{0}'", activeConveCookie.Value));
                    }
                    IConversationState conversation = this.conversations[activeConveCookie.Value];
                    if (conversation != null)
                    {
                        if (LOG.IsDebugEnabled)
                        {
                            LOG.Debug(String.Format("LoadActiveConversation: conversation found: '{0}'", conversation.Id));
                        }
                        //find root conversation.
                        IConversationState rootConversation = conversation;
                        while (rootConversation.ParentConversation != null)
                        {
                            rootConversation = rootConversation.ParentConversation;
                        }
                        rootConversation.StartResumeConversation();
                        this.SetActiveConversation(rootConversation);
                    }
                }
                else
                {
                    if (LOG.IsDebugEnabled)
                    {
                        LOG.Debug(String.Format("LoadActiveConversation: conversation NOT found for id on the cookie: '{0}'", activeConveCookie.Value));
                    }
                    HttpContext.Current.Response.Cookies.Remove(CONVERSATION_COOKIE_ID);
                }
            }
        }
Exemple #11
0
            public void CloseAll()
            {
                foreach (IConversationState conversation in allManagedConversation)
                {
                    CloseConversation(conversation);
                }
                owner = null;
                activeConversation     = null;
                allManagedConversation = null;

                if (log.IsDebugEnabled)
                {
                    log.Debug("CloseAll LazySessionPerConversationHolder");
                }
            }
 /// <summary>
 /// Remove conversation.
 /// </summary>
 /// <param name="conversation"></param>
 private void RemoveConversation(IConversationState conversation)
 {
     try
     {
         this.MutexEditDic.WaitOne(5000);
         if (!this.conversations.Remove(conversation.Id))
         {
             throw new InvalidOperationException(String.Format("Conversation '{0}' does not exist on this manager.", conversation.Id));
         }
     }
     finally
     {
         this.MutexEditDic.ReleaseMutex();
     }
 }
Exemple #13
0
    private void startResumeConversationIsEnded()
    {
        Regex msgErrorRx = new Regex(".*StartResumeConversation.*conversation.*is.*ended.*");
        IConversationState otherConversationState = null;

        //BEGIN: Raise error
        try
        {
            otherConversationState    = new WebConversationSpringState();
            otherConversationState.Id = "otherConversationState";
            // make not new
            otherConversationState.EndConversation();
            otherConversationState.StartResumeConversation();
            throw new Exception("NOT OK: No raise for 'otherConversationState.StartResumeConversation()'");
        }
        catch (InvalidOperationException ioe)
        {
            if (msgErrorRx.IsMatch(ioe.Message))
            {
                this.Session["testResult"] = "OK";
            }
            else
            {
                throw new Exception("NOT OK " + ioe.Message);
            }
        }
        finally
        {
            otherConversationState.EndConversation();
        }
        //END: Raise error

        //BEGIN: NO Raise error
        try
        {
            otherConversationState    = new WebConversationSpringState();
            otherConversationState.Id = "otherConversationState";
            // make not new
            otherConversationState.StartResumeConversation();
            otherConversationState.EndConversation();
            this.Session["testResult"] = "OK";
        }
        finally
        {
            otherConversationState.EndConversation();
        }
        //END: NO Raise error
    }
Exemple #14
0
    private void idIsDifferentFromSpringName()
    {
        Regex msgErrorRx = new Regex(".*Id.*is.*different.*from.*spring.*name.*");
        IConversationState otherConversationState = null;

        //BEGIN: Raise error
        try
        {
            otherConversationState    = new WebConversationSpringState();
            otherConversationState.Id = "otherConversationState";
            // different name
            ((IObjectNameAware)otherConversationState).ObjectName = "different_name";
            throw new Exception("NOT OK: No raise for '((IObjectNameAware)otherConversationState).ObjectName ='");
        }
        catch (InvalidOperationException ioe)
        {
            if (msgErrorRx.IsMatch(ioe.Message))
            {
                this.Session["testResult"] = "OK";
            }
            else
            {
                throw new Exception("NOT OK " + ioe.Message);
            }
        }
        finally
        {
            otherConversationState.EndConversation();
        }
        //END: Raise error

        //BEGIN: NO Raise error
        try
        {
            otherConversationState    = new WebConversationSpringState();
            otherConversationState.Id = "otherConversationState";
            // make not new
            // different name
            ((IObjectNameAware)otherConversationState).ObjectName = "otherConversationState";
            this.Session["testResult"] = "OK";
        }
        finally
        {
            otherConversationState.EndConversation();
        }
        //END: NO Raise error
    }
        /// <summary>
        /// <see cref="IConversationManager"/>
        /// </summary>
        public void FreeEnded()
        {
            try
            {
                if (LOG.IsDebugEnabled)
                {
                    LOG.Debug("EndOnTimeOut");
                }
                this.MutexEditDic.WaitOne(5000);
                List <IConversationState> removeList = new List <IConversationState>();
                foreach (String keyItem in this.conversations.Keys)
                {
                    IConversationState conversationItem = this.conversations[keyItem];
                    if (conversationItem.Ended)
                    {
                        if (LOG.IsDebugEnabled)
                        {
                            LOG.Debug(String.Format("FreeEnded: Release conversation '{0}'", conversationItem.Id));
                        }
                        removeList.Add(conversationItem);
                    }
                }

                if (removeList.Count > 0)
                {
                    this.Close(this.SessionFactory, removeList);
                }

                foreach (IConversationState conversationItem in removeList)
                {
                    if (LOG.IsDebugEnabled)
                    {
                        LOG.Debug(String.Format("FreeEnded: Remove conversation '{0}'", conversationItem.Id));
                    }
                    conversationItem.EndConversation();
                    this.RemoveConversation(conversationItem);
                }
            }
            finally
            {
                this.MutexEditDic.ReleaseMutex();
            }
        }
        /// <summary>
        /// <see cref="IConversationManager"/>
        /// </summary>
        /// <param name="conversation"></param>
        public void AddConversation(IConversationState conversation)
        {
            try
            {
                this.MutexEditDic.WaitOne(5000);
                this.conversations.Add(conversation.Id, conversation);
            }
            finally
            {
                this.MutexEditDic.ReleaseMutex();
            }

            if (conversation.ConversationManager != null && conversation.ConversationManager != this)
            {
                throw new InvalidOperationException(String.Format("Conversation already has another manager. conversation='{0}'", conversation.Id));
            }

            if (conversation.ConversationManager == null)
            {
                conversation.ConversationManager = this;
            }
        }
Exemple #17
0
    private void alreadyHasAnotherManagerNotRaise()
    {
        IConversationManager otherConversationManager = new WebConversationManager();

        //Not raise error
        IConversationState otherConversationState = null;

        try
        {
            otherConversationState    = new WebConversationSpringState();
            otherConversationState.Id = "otherConversationState";
            otherConversationManager.AddConversation(otherConversationState);
            this.Session["testResult"] = "OK";
        }
        catch (InvalidOperationException ioe)
        {
            this.Session["testResult"] = "NOT OK " + ioe.ToString();
        }
        finally
        {
            otherConversationState.EndConversation();
        }
    }
Exemple #18
0
        public override void Update(GameTime gameTime)
        {
            Vector2 motion = Vector2.Zero;
            int     cp     = 8;

            if (Xin.KeyboardState.IsKeyDown(Keys.W) && Xin.KeyboardState.IsKeyDown(Keys.A))
            {
                motion.X = -1;
                motion.Y = -1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkLeft;
            }
            else if (Xin.KeyboardState.IsKeyDown(Keys.W) && Xin.KeyboardState.IsKeyDown(Keys.D))
            {
                motion.X = 1;
                motion.Y = -1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkRight;
            }
            else if (Xin.KeyboardState.IsKeyDown(Keys.S) && Xin.KeyboardState.IsKeyDown(Keys.A))
            {
                motion.X = -1;
                motion.Y = 1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkLeft;
            }
            else if (Xin.KeyboardState.IsKeyDown(Keys.S) && Xin.KeyboardState.IsKeyDown(Keys.D))
            {
                motion.X = 1;
                motion.Y = 1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkRight;
            }
            else if (Xin.KeyboardState.IsKeyDown(Keys.W))
            {
                motion.Y = -1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkUp;
            }
            else if (Xin.KeyboardState.IsKeyDown(Keys.S))
            {
                motion.Y = 1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkDown;
            }
            else if (Xin.KeyboardState.IsKeyDown(Keys.A))
            {
                motion.X = -1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkLeft;
            }
            else if (Xin.KeyboardState.IsKeyDown(Keys.D))
            {
                motion.X = 1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkRight;
            }
            if (motion != Vector2.Zero)
            {
                motion.Normalize();
                motion *= (player.Speed * (float)gameTime.ElapsedGameTime.TotalSeconds);

                Rectangle playerRect = new Rectangle(
                    (int)player.Sprite.Position.X + (int)motion.X + cp,
                    (int)player.Sprite.Position.Y + (int)motion.Y + cp,
                    Engine.TileWidth - cp,
                    Engine.TileHeight - cp);

                foreach (string characterName in world.CurrentMap.Characters.Keys)
                {
                    ICharacter character = GameRef.CharacterManager.GetCharacter(characterName);

                    Rectangle characterRect = new Rectangle(
                        (int)world.CurrentMap.Characters[characterName].X * Engine.TileWidth + cp,
                        (int)world.CurrentMap.Characters[characterName].Y * Engine.TileHeight + cp,
                        Engine.TileWidth - cp,
                        Engine.TileHeight - cp);

                    // if player collides with character, stop their movement
                    if (playerRect.Intersects(characterRect))
                    {
                        motion = Vector2.Zero;
                        break;
                    }
                }

                Vector2 newPosition = player.Sprite.Position + motion;
                player.Sprite.Position    = newPosition;
                player.Sprite.IsAnimating = true;
                player.Sprite.LockToMap(new Point(world.CurrentMap.WidthInPixels, world.CurrentMap.HeightInPixels));
            }
            else
            {
                player.Sprite.IsAnimating = false;
            }

            camera.LockToSprite(world.CurrentMap, player.Sprite, Game1.ScreenRectangle);
            player.Sprite.Update(gameTime);

            if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter))
            {
                foreach (string characterName in world.CurrentMap.Characters.Keys)
                {
                    ICharacter character = CharacterManager.Instance.GetCharacter(characterName);

                    float distance = Vector2.Distance(player.Sprite.Center, character.Sprite.Center);

                    // if player is close to character
                    if (Math.Abs(distance) < 72f)
                    {
                        // get the main game conversation state controller.   one per game
                        IConversationState conversationState = (IConversationState)GameRef.Services.GetService(typeof(IConversationState));

                        manager.PushState(
                            (ConversationState)conversationState,
                            PlayerIndexInControl);

                        conversationState.SetConversation(player, character);
                        conversationState.StartConversation();
                    }
                }
                foreach (Rectangle r in world.CurrentMap.PortalLayer.Portals.Keys)
                {
                    Portal p        = world.CurrentMap.PortalLayer.Portals[r];
                    float  distance = Vector2.Distance(
                        player.Sprite.Center,
                        new Vector2(
                            r.X * Engine.TileWidth + Engine.TileWidth / 2,
                            r.Y * Engine.TileHeight + Engine.TileHeight / 2));
                    if (Math.Abs(distance) < 64f)
                    {
                        world.ChangeMap(p.DestinationLevel, new Rectangle(p.DestinationTile.X, p.DestinationTile.Y, 32, 32));
                        player.Position = new Vector2(
                            p.DestinationTile.X * Engine.TileWidth,
                            p.DestinationTile.Y * Engine.TileHeight);
                        camera.LockToSprite(world.CurrentMap, player.Sprite, Game1.ScreenRectangle);
                        return;
                    }
                }
            }
            if (Xin.CheckKeyReleased(Keys.B))
            {
                foreach (string s in world.CurrentMap.Characters.Keys)
                {
                    ICharacter c        = CharacterManager.Instance.GetCharacter(s);
                    float      distance = Vector2.Distance(player.Sprite.Center, c.Sprite.Center);
                    if (Math.Abs(distance) < 72f && !c.Battled)
                    {
                        GameRef.BattleState.SetAvatars(player.CurrentAvatar, c.BattleAvatar);
                        manager.PushState(
                            (BattleState)GameRef.BattleState,
                            PlayerIndexInControl);
                        c.Battled = true;
                    }
                }
            }

            // TODO:  Save game data as json.  Create GameSave class that has all necessary objects and serialize it.
            // F1 = Save Game
            // Produces:
            // avatar.sav
            // level1Lance,teacherone,WalkDown.Water,Water,0,100,1,9,12,10,50,-3,Tackle,Block*Marissa,teachertwo,WalkDown,MarissaHello,0-Wind,Wind,0,100,1,10,10,12,50,50,Tackle,Block.Earth,Earth,0,100,1,10,10,9,60,60,Tackle,Block
            if (Xin.CheckKeyReleased(Keys.F1))
            {
                FileStream   stream = new FileStream("avatars.sav", FileMode.Create, FileAccess.Write);
                BinaryWriter writer = new BinaryWriter(stream);
                world.Save(writer);
                player.Save(writer);
                writer.Close();
                stream.Close();
            }
            base.Update(gameTime);
        }
        private void DoOpenSession(IConversationState conversation)
        {
            lock (this)
            {
                ISession session = null;
                if (conversation.RootSessionPerConversation == null)
                {
                    //new session
                    session = (
                                   (EntityInterceptor != null)
                                   ? conversation.SessionFactory.OpenSession(EntityInterceptor)
                                   : conversation.SessionFactory.OpenSession()
                               );
                    conversation.RootSessionPerConversation = session;
                }
                else
                {
                    //reconnect existing one.
                    if (conversation.DbProvider != null)
                    {
                        if (log.IsDebugEnabled) log.Debug(String.Format("DoOpenSession: Conversation has a DbProvider: Id='{0}'", conversation.Id));
                        if (!conversation.RootSessionPerConversation.IsConnected)
                        {
                            if (log.IsDebugEnabled) log.Debug(String.Format("DoOpenSession: Conversation is not Connected: Id='{0}'", conversation.Id));

                            IDbConnection connection = conversation.DbProvider.CreateConnection();
                            connection.Open();

                            conversation.RootSessionPerConversation.Reconnect(connection);
                        }
                        else
                        {
                            if (log.IsDebugEnabled) log.Debug(String.Format("DoOpenSession: Conversation is already Connected: Id='{0}'", conversation.Id));
                        }
                    }
                    else
                    {
                        if (log.IsDebugEnabled) log.Debug(String.Format("DoOpenSession: Conversation has NO DbProvider: Id='{0}'", conversation.Id));
                        conversation.RootSessionPerConversation.Reconnect();
                    }
                    session = conversation.RootSessionPerConversation;
                }
                session.FlushMode = DefaultFlushMode;
            }
        }
Exemple #20
0
    private void setParentConversationIsNotNew()
    {
        Regex msgErrorRx = new Regex(".*Conversation.*not.*new.*Conversation.Id.*Parent.*Tried.*");
        IConversationState otherConversationState = null;

        //BEGIN: Raise error
        try
        {
            otherConversationState    = new WebConversationSpringState();
            otherConversationState.Id = "otherConversationState";
            // make not new
            otherConversationState.StartResumeConversation();
            //try first by 'InnerConversations.Add'
            this.ConversationA.InnerConversations.Add(otherConversationState);
            throw new Exception("NOT OK: No raise for 'this.ConversationA.InnerConversations.Add(otherConversationState)'");
        }
        catch (InvalidOperationException ioe)
        {
            if (msgErrorRx.IsMatch(ioe.Message))
            {
                this.Session["testResult"] = "OK";
            }
            else
            {
                throw new Exception("NOT OK " + ioe.Message);
            }
        }
        finally
        {
            otherConversationState.EndConversation();
        }

        try
        {
            otherConversationState    = new WebConversationSpringState();
            otherConversationState.Id = "otherConversationState";
            // make not new
            otherConversationState.StartResumeConversation();
            //try second by 'ParentConversation = '
            otherConversationState.ParentConversation = this.ConversationA;
            throw new Exception("NOT OK: No raise for 'this.ConversationAA.ParentConversation = otherConversationState'");
        }
        catch (InvalidOperationException ioe)
        {
            if (msgErrorRx.IsMatch(ioe.Message))
            {
                this.Session["testResult"] = "OK";
            }
            else
            {
                throw new Exception("NOT OK, 'ex.Message' not match :" + ioe.Message);
            }
        }
        finally
        {
            otherConversationState.EndConversation();
        }
        //END: Raise error

        //BEGIN: NO Raise error
        try
        {
            otherConversationState    = new WebConversationSpringState();
            otherConversationState.Id = "otherConversationState";
            // leave new
            //try first by 'InnerConversations.Add'
            this.ConversationA.InnerConversations.Add(otherConversationState);
            this.Session["testResult"] = "OK";
        }
        finally
        {
            otherConversationState.EndConversation();
        }

        try
        {
            otherConversationState    = new WebConversationSpringState();
            otherConversationState.Id = "otherConversationState";
            // leave new
            //try second by 'ParentConversation = '
            otherConversationState.ParentConversation = this.ConversationA;
            this.Session["testResult"] = "OK";
        }
        finally
        {
            otherConversationState.EndConversation();
        }
        //END: NO Raise error
    }
        public void LoadActiveConversation()
        {
            //reset this.activeConversation
            this.activeConversation = null;

            if (LOG.IsDebugEnabled) LOG.Debug("LoadActiveConversation");

            HttpCookie activeConveCookie = HttpContext.Current.Request.Cookies[CONVERSATION_COOKIE_ID];
            if (activeConveCookie != null && !String.IsNullOrEmpty(activeConveCookie.Value))
            {
                if (LOG.IsDebugEnabled) LOG.Debug(String.Format("LoadActiveConversation: cooking found for current active conversation: [{0}]", activeConveCookie.ToString()));
                if (this.conversations.ContainsKey(activeConveCookie.Value))
                {
                    if (LOG.IsDebugEnabled) LOG.Debug(String.Format("LoadActiveConversation: active conversation found for id: '{0}'", activeConveCookie.Value));
                    IConversationState conversation = this.conversations[activeConveCookie.Value];
                    if (conversation != null)
                    {
                        if (LOG.IsDebugEnabled) LOG.Debug(String.Format("LoadActiveConversation: conversation found: '{0}'", conversation.Id));
                        //find root conversation.
                        IConversationState rootConversation = conversation;
                        while (rootConversation.ParentConversation != null)
                        {
                            rootConversation = rootConversation.ParentConversation;
                        }
                        rootConversation.StartResumeConversation();
                        this.SetActiveConversation(rootConversation);
                    }
                }
                else
                {
                    if (LOG.IsDebugEnabled) LOG.Debug(String.Format("LoadActiveConversation: conversation NOT found for id on the cookie: '{0}'", activeConveCookie.Value));
                    HttpContext.Current.Response.Cookies.Remove(CONVERSATION_COOKIE_ID);
                }
            }
        }
Exemple #22
0
    private void conversationAlreadyDifferentParent()
    {
        Regex msgErrorRx = new Regex(".*conversation.*already.*different.*parent.*");
        //BEGIN: Raise error
        IConversationState otherConversationState = null;

        try
        {
            otherConversationState    = new WebConversationSpringState();
            otherConversationState.Id = "otherConversationState";
            //try first by 'InnerConversations.Add'
            otherConversationState.InnerConversations.Add(this.ConversationAA);
            throw new Exception("NOT OK: No raise for 'InnerConversations.Add(this.ConversationAA)'");
        }
        catch (InvalidOperationException ioe)
        {
            if (msgErrorRx.IsMatch(ioe.Message))
            {
                this.Session["testResult"] = "OK";
            }
            else
            {
                throw new Exception("NOT OK " + ioe.Message);
            }
        }
        finally
        {
            otherConversationState.EndConversation();
        }

        try
        {
            otherConversationState    = new WebConversationSpringState();
            otherConversationState.Id = "otherConversationState";
            //try second by 'ParentConversation = '
            this.ConversationAA.ParentConversation = otherConversationState;
            throw new Exception("NOT OK: No raise for 'this.ConversationAA.ParentConversation = otherConversationState'");
        }
        catch (InvalidOperationException ioe)
        {
            if (msgErrorRx.IsMatch(ioe.Message))
            {
                this.Session["testResult"] = "OK";
            }
            else
            {
                throw new Exception("NOT OK, 'ex.Message' not match :" + ioe.Message);
            }
        }
        finally
        {
            otherConversationState.EndConversation();
        }
        //END: Raise error

        //BEGIN: NO Raise error
        otherConversationState = null;
        try
        {
            otherConversationState    = new WebConversationSpringState();
            otherConversationState.Id = "otherConversationState";
            //try first by 'InnerConversations.Add'
            this.ConversationAA.InnerConversations.Add(otherConversationState);
            this.Session["testResult"] = "OK";
        }
        finally
        {
            otherConversationState.EndConversation();
        }

        try
        {
            otherConversationState    = new WebConversationSpringState();
            otherConversationState.Id = "otherConversationState";
            //try second by 'ParentConversation = '
            otherConversationState.ParentConversation = this.ConversationA;
            this.Session["testResult"] = "OK";
        }
        finally
        {
            otherConversationState.EndConversation();
        }
        //END: NO Raise error
    }
 private void CloseConversation(IConversationState conversation)
 {
     if (log.IsDebugEnabled) log.Debug(String.Format("CloseConversation: Id='{0}'", conversation.Id));
     if (conversation.RootSessionPerConversation != null)
     {
         ISession tmpSession = conversation.RootSessionPerConversation;
         if (conversation.Ended)
         {
             SessionFactoryUtils.CloseSession(tmpSession);
             conversation.RootSessionPerConversation = null;
         }
         else
         {
             if (tmpSession.IsConnected)
             {
                 IDbConnection conn = tmpSession.Disconnect();
                 if (conn != null && conn.State == ConnectionState.Open)
                     conn.Close();
             }
         }
         RemoveSession(tmpSession);
     }
     if (log.IsDebugEnabled) log.Debug("Closed LazySessionPerConversationHolder");
 }
            public void CloseAll()
            {
                foreach (IConversationState conversation in this.allManagedConversation)
                {
                    this.CloseConversation(conversation);
                }
                owner = null;
                this.activeConversation = null;
                this.allManagedConversation = null;

                if (log.IsDebugEnabled) log.Debug("CloseAll LazySessionPerConversationHolder");
            }
        /// <summary>
        /// <see cref="IConversationManager"/>
        /// </summary>
        /// <param name="conversation"></param>
        public void SetActiveConversation(IConversationState conversation)
        {
            if (LOG.IsDebugEnabled) LOG.Debug(String.Format("SetActiveConversation('{0}')", conversation.Id));

            //Close connection for the last conversation, if it is open.
            if (this.activeConversation != null && this.activeConversation != conversation)
            {
                this.Close(this.SessionFactory, this.conversations.Values);
            }
            this.Open(conversation, this.conversations.Values);

            this.activeConversation = conversation;

            //Ending the paused conversations.
            if (this.EndPaused)
            {
                foreach (IConversationState convItem in this.conversations.Values)
                {
                    if (convItem.IsPaused)
                    {
                        convItem.EndConversation();
                    }
                }
            }
        }
Exemple #26
0
        public override void Update(GameTime gameTime)
        {
            Vector2 motion = Vector2.Zero;
            int     cp     = 8;

            if (Xin.KeyboardState.IsKeyDown(Keys.W) && Xin.KeyboardState.IsKeyDown(Keys.A))
            {
                motion.X = -1;
                motion.Y = -1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkLeft;
            }
            else if (Xin.KeyboardState.IsKeyDown(Keys.W) && Xin.KeyboardState.IsKeyDown(Keys.D))
            {
                motion.X = 1;
                motion.Y = -1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkRight;
            }
            else if (Xin.KeyboardState.IsKeyDown(Keys.S) && Xin.KeyboardState.IsKeyDown(Keys.A))
            {
                motion.X = -1;
                motion.Y = 1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkLeft;
            }
            else if (Xin.KeyboardState.IsKeyDown(Keys.S) && Xin.KeyboardState.IsKeyDown(Keys.D))
            {
                motion.X = 1;
                motion.Y = 1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkRight;
            }
            else if (Xin.KeyboardState.IsKeyDown(Keys.W))
            {
                motion.Y = -1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkUp;
            }
            else if (Xin.KeyboardState.IsKeyDown(Keys.S))
            {
                motion.Y = 1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkDown;
            }
            else if (Xin.KeyboardState.IsKeyDown(Keys.A))
            {
                motion.X = -1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkLeft;
            }
            else if (Xin.KeyboardState.IsKeyDown(Keys.D))
            {
                motion.X = 1;
                player.Sprite.CurrentAnimation = AnimationKey.WalkRight;
            }
            if (motion != Vector2.Zero)
            {
                motion.Normalize();
                motion *= (player.Speed * (float)gameTime.ElapsedGameTime.TotalSeconds);
                Rectangle pRect = new Rectangle(
                    (int)player.Sprite.Position.X + (int)motion.X + cp,
                    (int)player.Sprite.Position.Y + (int)motion.Y + cp,
                    Engine.TileWidth - cp,
                    Engine.TileHeight - cp);
                foreach (string s in map.Characters.Keys)
                {
                    ICharacter c = GameRef.CharacterManager.GetCharacter(s);
                    Rectangle  r = new Rectangle(
                        (int)map.Characters[s].X * Engine.TileWidth + cp,
                        (int)map.Characters[s].Y * Engine.TileHeight + cp,
                        Engine.TileWidth - cp,
                        Engine.TileHeight - cp);
                    if (pRect.Intersects(r))
                    {
                        motion = Vector2.Zero;
                        break;
                    }
                }
                Vector2 newPosition = player.Sprite.Position + motion;
                player.Sprite.Position    = newPosition;
                player.Sprite.IsAnimating = true;
                player.Sprite.LockToMap(new Point(map.WidthInPixels, map.HeightInPixels));
            }
            else
            {
                player.Sprite.IsAnimating = false;
            }
            camera.LockToSprite(map, player.Sprite, Game1.ScreenRectangle);
            player.Sprite.Update(gameTime);
            if (Xin.CheckKeyReleased(Keys.Space) || Xin.CheckKeyReleased(Keys.Enter))
            {
                foreach (string s in map.Characters.Keys)
                {
                    ICharacter c        = CharacterManager.Instance.GetCharacter(s);
                    float      distance = Vector2.Distance(player.Sprite.Center, c.Sprite.Center);
                    if (Math.Abs(distance) < 72f)
                    {
                        IConversationState conversationState =
                            (IConversationState)GameRef.Services.GetService(typeof(IConversationState));
                        manager.PushState(
                            (ConversationState)conversationState,
                            PlayerIndexInControl);
                        conversationState.SetConversation(player, c);
                        conversationState.StartConversation();
                    }
                }
            }
            if (Xin.CheckKeyReleased(Keys.B))
            {
                foreach (string s in map.Characters.Keys)
                {
                    ICharacter c        = CharacterManager.Instance.GetCharacter(s);
                    float      distance = Vector2.Distance(player.Sprite.Center, c.Sprite.Center);
                    if (Math.Abs(distance) < 72f)
                    {
                        GameRef.BattleState.SetAvatars(player.CurrentAvatar, c.BattleAvatar);
                        manager.PushState(
                            (BattleState)GameRef.BattleState,
                            PlayerIndexInControl);
                    }
                }
            }
            base.Update(gameTime);
        }
        /// <summary>
        /// <see cref="IConversationManager"/>
        /// </summary>
        /// <param name="conversation"></param>
        public void AddConversation(IConversationState conversation)
        {
            try
            {
                this.MutexEditDic.WaitOne(5000);
                this.conversations.Add(conversation.Id, conversation);
            }
            finally
            {
                this.MutexEditDic.ReleaseMutex();
            }

            if (conversation.ConversationManager != null && conversation.ConversationManager != this)
            {
                throw new InvalidOperationException(String.Format("Conversation already has another manager. conversation='{0}'", conversation.Id));
            }

            if (conversation.ConversationManager == null)
            {
                conversation.ConversationManager = this;
            }
        }
 /// <summary>
 /// Initialize a new instance.
 /// </summary>
 public LazySessionPerConversationHolder(SessionPerConversationScope owner, IConversationState activeConversation, ICollection<IConversationState> allManagedConversation)
 {
     if (log.IsDebugEnabled) log.Debug("Created LazyReconnectableSessionHolder");
     this.owner = owner;
     this.activeConversation = activeConversation;
     this.allManagedConversation = allManagedConversation;
 }
 /// <summary>
 /// Remove conversation.
 /// </summary>
 /// <param name="conversation"></param>
 private void RemoveConversation(IConversationState conversation)
 {
     try
     {
         this.MutexEditDic.WaitOne(5000);
         if (!this.conversations.Remove(conversation.Id))
         {
             throw new InvalidOperationException(String.Format("Conversation '{0}' does not exist on this manager.", conversation.Id));
         }
     }
     finally
     {
         this.MutexEditDic.ReleaseMutex();
     }
 }
        /// <summary>
        /// Open a new session or reconect the
        /// <see cref="IConversationState.RootSessionPerConversation"/> in <paramref name="activeConversation"/>.
        /// Participating in an existing session registed with <see cref="TransactionSynchronizationManager"/>
        /// is not alowed.
        /// </summary>
        /// <param name="activeConversation"></param>
        /// <param name="allManagedConversation"></param>
        /// <exception cref="InvalidOperationException">
        /// <list type="bullet">
        /// <item>If there is another conversation with a <see cref="ISession"/> with opened 
        /// <see cref="IDbConnection"/>.</item>
        /// <item>If attempting to participate in an existing NHibernate <see cref="ISessionFactory"/>
        /// managed by <see cref="TransactionSynchronizationManager"/>.
        /// </item>
        /// </list>
        /// </exception>
        public void Open(IConversationState activeConversation, ICollection<IConversationState> allManagedConversation)
        {
            bool isDebugEnabled = log.IsDebugEnabled;

            if (IsOpen)
            {
                if (activeConversation.Id != this.OpenerConversationId)
                {
                    throw new InvalidOperationException("There is another conversation with a ISession with opened IDbConnection.");
                }
                else
                {
                    if (isDebugEnabled) log.Debug(String.Format("SessionPerConversationScope is already open for this conversation: Id:'{0}'.", activeConversation.Id));
                }
            }
            else
            {
                if (activeConversation.SessionFactory != null)
                {
                    if (isDebugEnabled) log.Debug(String.Format("activeConversation with 'session-per-conversation': Id:'{0}'.", activeConversation.Id));

                    // single session mode
                    if (TransactionSynchronizationManager.HasResource(activeConversation.SessionFactory))
                    {
                        // Do not modify the Session: just set the participate flag.
                        if (isDebugEnabled) log.Debug("Participating in existing NHibernate SessionFactory IS NOT ALLOWED.");
                        throw new InvalidOperationException("Participating in existing NHibernate SessionFactory IS NOT ALLOWED.");
                    }
                    else
                    {
                        if (isDebugEnabled) log.Debug("Opening single NHibernate Session in SessionPerConversationScope");
                        TransactionSynchronizationManager.BindResource(activeConversation.SessionFactory, new LazySessionPerConversationHolder(this, activeConversation, allManagedConversation));

                        SetOpen(true);
                        this.OpenerConversationId = activeConversation.Id;
                    }
                }
                else
                {
                    if (isDebugEnabled) log.Debug(String.Format("activeConversation with NO 'session-per-conversation': Id:'{0}'.", activeConversation.Id));
                }
            }
        }