Example #1
0
        public void SM006(StateScope scope)
        {
            // arrange
            var storedSessionState = new Dictionary <string, object>()
            {
                { "one", "value one" },
                { "two", 2 }
            };

            var sessionManagerMock = new Mock <ISessionManager>();

            sessionManagerMock.Setup(m => m.Load(scope))
            .Returns(storedSessionState);

            IDictionary <string, object> persistedState = null;

            sessionManagerMock.Setup(m => m.Save(scope, It.IsAny <IDictionary <string, object> >()))
            .Callback <StateScope, IDictionary <string, object> >((scope, state) => persistedState = state);

            var stateManager = new StateManager(sessionManagerMock.Object);

            // act
            stateManager.SetValue(scope, "One", "Value One");
            stateManager.Save();

            // assert
            sessionManagerMock.Verify(m => m.Save(scope, It.IsAny <IDictionary <string, object> >()), Times.Once);

            persistedState.Should().NotBeNull();
            persistedState.Should().ContainKey("One");
            persistedState["One"].Should().Be("Value One");
        }
Example #2
0
        public XnaComponent(
            bool enableDepthStencil,
            bool preferMultiSampling,
            bool preferAnisotropicFiltering,
            Int32Rect targetSize = default(Int32Rect),
            ExitRunScopeBehavior exitRunScopeBehavior = ExitRunScopeBehavior.Stop)
        {
            _exitRunScopeBehavior  = exitRunScopeBehavior;
            _graphicsOptions       = new XnaGraphicsOptions(enableDepthStencil, preferAnisotropicFiltering, preferMultiSampling);
            _deviceTransitionScope = new StateScope();
            _suppressDrawScope     = new StateScope();
            _services = new ServiceContainer();

            _maximumElapsedTime = TimeSpan.FromMilliseconds(500.0);
            _time                       = new XnaTime();
            _isFixedTimeStep            = false;
            _updatesSinceRunningSlowly1 = 0x7fffffff;
            _updatesSinceRunningSlowly2 = 0x7fffffff;

            _clock         = new XnaClock();
            _totalGameTime = TimeSpan.Zero;
            _accumulatedElapsedGameTime = TimeSpan.Zero;
            _lastFrameElapsedGameTime   = TimeSpan.Zero;
            _targetElapsedTime          = TimeSpan.FromTicks(166667);

            _timer = new XnaTimer();

            _targetSize = new Int32Rect(0, 0, Math.Max(1, targetSize.Width), Math.Max(1, targetSize.Height));

            _runScope = new StateScope(OnRunScopeIsWithinChanged);
        }
        static public StateCollection <T> Current(StateScope scope, string group)
        {
            StateCollection <T> collection = null;

            switch (scope)
            {
            case StateScope.Application:
                collection = (StateAccess.State.ContainsApplication(group)
                                                      ? (StateCollection <T>)StateAccess.State.GetApplication(group)
                                                      :  new StateCollection <T>(scope, group));
                break;

            case StateScope.Session:
                collection = (StateAccess.State.ContainsSession(group)
                                                      ? (StateCollection <T>)StateAccess.State.GetSession(group)
                                                      :  new StateCollection <T>(scope, group));
                break;

            case StateScope.Operation:
                collection = (StateAccess.State.ContainsOperation(group)
                                                      ? (StateCollection <T>)StateAccess.State.GetOperation(group)
                                                      :  new StateCollection <T>(scope, group));
                break;
            }
            return(collection);
        }
Example #4
0
        public override string[] GetKeys(StateScope scope)
        {
            List <string> keys = new List <string>();

            switch (scope)
            {
            case StateScope.Application:
                foreach (string key in ApplicationData.Keys)
                {
                    keys.Add(key);
                }
                break;

            case StateScope.Session:
                foreach (string key in SessionData.Keys)
                {
                    keys.Add(key);
                }
                break;

            case StateScope.Operation:
                foreach (string key in OperationData.Keys)
                {
                    keys.Add(key);
                }
                break;
            }

            return(keys.ToArray());
        }
Example #5
0
        public override string[] GetKeys(StateScope scope)
        {
            List <string> keys = new List <string>();

            switch (scope)
            {
            case StateScope.Application:
                foreach (string key in HttpContext.Current.Application.AllKeys)
                {
                    keys.Add(key);
                }
                break;

            case StateScope.Session:
                foreach (string key in HttpContext.Current.Session.Keys)
                {
                    keys.Add(key);
                }
                break;

            case StateScope.Operation:
                foreach (string key in HttpContext.Current.Items.Keys)
                {
                    keys.Add(key);
                }
                break;
            }

            return(keys.ToArray());
        }
Example #6
0
 public IDictionary <string, object> Load(StateScope scope)
 {
     if (scope == StateScope.Session)
     {
         return(_sessionStorage.Load(_sessionKey));
     }
     return(_sessionStorage.Load(UserKey));
 }
Example #7
0
        public T GetValue <T>(StateScope scope, string key, T defaultValue = default)
        {
            var state = scope == StateScope.Session ? _sessionState : _userState;

            if (state.ContainsKey(key))
            {
                return((T)state[key]);
            }
            return(defaultValue);
        }
Example #8
0
 public void Save(StateScope scope, IDictionary <string, object> state)
 {
     if (scope == StateScope.Session)
     {
         _sessionStorage.Save(_sessionKey, state);
     }
     else
     {
         _sessionStorage.Save(UserKey, state);
     }
 }
Example #9
0
        public void SetValue <T>(StateScope scope, string key, T value)
        {
            var state = scope == StateScope.Session ? _sessionState : _userState;

            if (state.ContainsKey(key))
            {
                state[key] = value;
            }
            else
            {
                state.Add(key, value);
            }
        }
Example #10
0
        public void SM001(StateScope scope)
        {
            // arrange
            var sessionManagerMock = new Mock <ISessionManager>();

            sessionManagerMock.Setup(m => m.Load(scope))
            .Returns(new Dictionary <string, object>());

            var stateManager = new StateManager(sessionManagerMock.Object);

            // act
            var value = stateManager.GetValue(scope, "test", 42);

            // assert
            value.Should().Be(42);
        }
        public void StateScopeEntranceTest()
        {
            var scope = new StateScope();

            Assert.AreEqual(false, scope.IsWithin);
            using (scope.Enter())
            {
                Assert.AreEqual(true, scope.IsWithin);
                using (scope.Enter())
                {
                    Assert.AreEqual(true, scope.IsWithin);
                }
                Assert.AreEqual(true, scope.IsWithin);
            }
            Assert.AreEqual(false, scope.IsWithin);
        }
Example #12
0
        public void SM003(StateScope scope)
        {
            // arrange
            var sessionManagerMock = new Mock <ISessionManager>();

            sessionManagerMock.Setup(m => m.Load(scope))
            .Returns(new Dictionary <string, object>());

            var stateManager = new StateManager(sessionManagerMock.Object);

            // act
            var result = stateManager.HasValueFor(scope, "test");

            // assert
            result.Should().BeFalse();
        }
        public void StateScopeEntranceTriggersCallback()
        {
            var    eventsRaised = 0;
            Action callback     = () => eventsRaised++;

            var scope = new StateScope(callback);

            Assert.AreEqual(0, eventsRaised);
            using (scope.Enter())
            {
                // Went from false to true - so it should have raised
                Assert.AreEqual(1, eventsRaised);
                using (scope.Enter())
                {
                    // Already in - no raise
                    Assert.AreEqual(1, eventsRaised);
                }
                // Still in - no raise
                Assert.AreEqual(1, eventsRaised);
            }
            // Left - raise
            Assert.AreEqual(2, eventsRaised);
        }
Example #14
0
        public void SM005(StateScope scope)
        {
            // arrange
            var storedSessionState = new Dictionary <string, object>()
            {
                { "one", "value one" },
                { "two", 2 }
            };

            var sessionManagerMock = new Mock <ISessionManager>();

            sessionManagerMock.Setup(m => m.Load(scope))
            .Returns(storedSessionState);

            // act
            var stateManager = new StateManager(sessionManagerMock.Object);


            // assert
            sessionManagerMock.Verify(m => m.Load(scope), Times.Once);
            stateManager.GetValue <string>(scope, "one").Should().Be("value one");
            stateManager.GetValue <int>(scope, "two").Should().Be(2);
        }
Example #15
0
 /// <summary>
 /// Sets the scope and group key used by this collection.
 /// </summary>
 /// <param name="scope"></param>
 /// <param name="groupKey"></param>
 public StateNameValueCollection(StateScope scope, string groupKey)
 {
     Scope    = scope;
     GroupKey = groupKey;
 }
Example #16
0
 /// <summary>
 /// Sets the scope and group key used by this collection.
 /// </summary>
 /// <param name="scope"></param>
 /// <param name="groupKey"></param>
 public StateStack(StateScope scope, string groupKey) : base(scope, groupKey)
 {
 }
Example #17
0
 /// <summary>
 /// Creates a new AutoGrid instance.
 /// </summary>
 public AutoGrid()
 {
     _childData   = new Dictionary <UIElement, ChildLayoutInfo>();
     _layoutScope = new StateScope();
 }
Example #18
0
        public ClientWindow(
            [NotNull] IClientApplication app,
            [NotNull] IAppContext appContext,
            [NotNull] IAudioEngine audioEngine,
            [NotNull] IMusicPlayer musicPlayer,
            [NotNull] ISoundPlayer soundPlayer,
            [NotNull] IEventAggregator eventAggregator,
            [NotNull] INavigationCommandsProxy navigationCommands)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (appContext == null)
            {
                throw new ArgumentNullException("appContext");
            }
            if (audioEngine == null)
            {
                throw new ArgumentNullException("audioEngine");
            }
            if (musicPlayer == null)
            {
                throw new ArgumentNullException("musicPlayer");
            }
            if (soundPlayer == null)
            {
                throw new ArgumentNullException("soundPlayer");
            }
            if (eventAggregator == null)
            {
                throw new ArgumentNullException("eventAggregator");
            }
            if (navigationCommands == null)
            {
                throw new ArgumentNullException("navigationCommands");
            }

            _app                 = app;
            _appContext          = appContext;
            _audioEngine         = audioEngine;
            _musicPlayer         = musicPlayer;
            _soundPlayer         = soundPlayer;
            _eventAggregator     = eventAggregator;
            _navigationCommands  = navigationCommands;
            _waitCursorLock      = new object();
            _settingsChangeScope = new StateScope();

            _defaultCursor = new Cursor(
                Path.Combine(
                    Environment.CurrentDirectory,
                    @"Resources\Cursors\cursor.cur"));

            InitializeComponent();

            /*
             * Officially, we only support video resolutions of 1024x768 and up.  However, considering
             * 1280x720 is one of the standard High Definition resolutions, we will adjust our minimum
             * size constraints to accomodate it.
             */
            // ReSharper disable CompareOfFloatsByEqualityOperator
            if (SystemParameters.PrimaryScreenWidth != 1280d ||
                (SystemParameters.PrimaryScreenHeight != 720d))
            {
                MinHeight = 720;
                Height    = 720;
            }
            // ReSharper restore CompareOfFloatsByEqualityOperator

            Cursor = _defaultCursor;

            Loaded      += OnLoaded;
            SizeChanged += OnSizeChanged;

            _eventAggregator.GetEvent <TurnStartedEvent>().Subscribe(OnTurnStarted, ThreadOption.UIThread);
            _eventAggregator.GetEvent <GameStartedEvent>().Subscribe(OnGameStarted, ThreadOption.UIThread);
            _eventAggregator.GetEvent <GameEndedEvent>().Subscribe(OnGameEnded, ThreadOption.UIThread);
            _eventAggregator.GetEvent <GameEndingEvent>().Subscribe(OnGameEnding, ThreadOption.UIThread);
            _eventAggregator.GetEvent <ClientDisconnectedEvent>().Subscribe(OnClientDisconnected, ThreadOption.UIThread);
            _eventAggregator.GetEvent <GameEndedEvent>().Subscribe(OnGameEnded, ThreadOption.UIThread);
            _eventAggregator.GetEvent <AllTurnEndedEvent>().Subscribe(OnAllTurnEnded, ThreadOption.UIThread);
            _eventAggregator.GetEvent <ChatMessageReceivedEvent>().Subscribe(OnChatMessageReceived, ThreadOption.UIThread);

            ModelessDialogsRegion.SelectionChanged += OnModelessDialogsRegionSelectionChanged;
            ModalDialogsRegion.SelectionChanged    += OnModalDialogsRegionSelectionChanged;

            ClientSettings.Current.EnableAntiAliasingChanged += OnEnableAntiAliasingSettingsChanged;

            ApplyAntiAliasingSettings();

            InputBindings.Add(
                new KeyBinding(
                    CollectGarbageCommand,
                    new KeyGesture(Key.G, ModifierKeys.Control | ModifierKeys.Shift)));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.EscapeCommand,
                    new KeyGesture(Key.Escape, ModifierKeys.None)));

            InputBindings.Add(
                new KeyBinding(
                    _navigationCommands.ActivateScreen,
                    new KeyGesture(Key.F1, ModifierKeys.None))
            {
                CommandParameter = StandardGameScreens.GalaxyScreen
            });

            InputBindings.Add(
                new KeyBinding(
                    _navigationCommands.ActivateScreen,
                    new KeyGesture(Key.F2, ModifierKeys.None))
            {
                CommandParameter = StandardGameScreens.ColonyScreen
            });

            InputBindings.Add(
                new KeyBinding(
                    _navigationCommands.ActivateScreen,
                    new KeyGesture(Key.F3, ModifierKeys.None))
            {
                CommandParameter = StandardGameScreens.DiplomacyScreen
            });

            InputBindings.Add(
                new KeyBinding(
                    _navigationCommands.ActivateScreen,
                    new KeyGesture(Key.F4, ModifierKeys.None))
            {
                CommandParameter = StandardGameScreens.ScienceScreen
            });

            InputBindings.Add(
                new KeyBinding(
                    _navigationCommands.ActivateScreen,
                    new KeyGesture(Key.F5, ModifierKeys.None))
            {
                CommandParameter = StandardGameScreens.IntelScreen
            });

            InputBindings.Add(
                new KeyBinding(
                    ToggleFullScreenModeCommand,
                    Key.Enter,
                    ModifierKeys.Alt));

            CommandBindings.Add(
                new CommandBinding(
                    ClientCommands.EscapeCommand,
                    ExecuteEscapeCommand));

            CommandBindings.Add(
                new CommandBinding(
                    ToggleFullScreenModeCommand,
                    (s, e) => ToggleFullScreenMode()));

            CommandBindings.Add(
                new CommandBinding(
                    CollectGarbageCommand,
                    (s, e) =>
            {
                var process    = Process.GetCurrentProcess();
                var workingSet = process.WorkingSet64;
                var heapSize   = GC.GetTotalMemory(false);

                GameLog.Client.General.Info("Forcing garbage collection...");

                GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                GC.WaitForPendingFinalizers();

                process.Refresh();

                GameLog.Client.General.InfoFormat(
                    "[working set [{0:#,#,} K -> {1:#,#,} K], managed heap [{2:#,#,} K -> {3:#,#,} K]]",
                    workingSet,
                    process.WorkingSet64,
                    heapSize,
                    GC.GetTotalMemory(false));

                GameLog.Client.GameData.DebugFormat(
                    "[working set [{0:#,#,} K -> {1:#,#,} K], managed heap [{2:#,#,} K -> {3:#,#,} K]]",
                    workingSet,
                    process.WorkingSet64,
                    heapSize,
                    GC.GetTotalMemory(false));
            }));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.AutoTurnCommand,
                    Key.A,
                    ModifierKeys.Alt));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.ColonyInfoScreen,
                    Key.F8,
                    ModifierKeys.None));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.ColorInfoScreen,
                    Key.F6,
                    ModifierKeys.Alt));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.ErrorTxtCommand,
                    Key.E,
                    ModifierKeys.Control));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.LogTxtCommand,
                    Key.L,
                    ModifierKeys.Control));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.OptionsCommand,
                    Key.O,
                    ModifierKeys.Control));

            // CRTL+S makes saved file "_manual_save"
            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.SaveGame,
                    Key.S,
                    ModifierKeys.Control));

            InputBindings.Add(
                new KeyBinding(
                    ClientCommands.EndTurn,
                    Key.T,
                    ModifierKeys.Control));

            CommandBindings.Add(
                new CommandBinding(
                    ClientCommands.AutoTurnCommand,
                    (s, e) =>
            {
                var service      = ServiceLocator.Current.GetInstance <IPlayerOrderService>();
                service.AutoTurn = !service.AutoTurn;
                if (service.AutoTurn)
                {
                    ClientCommands.EndTurn.Execute(null);
                }
            }));

            var settings = ClientSettings.Current;

            Width  = settings.ClientWindowWidth;
            Height = settings.ClientWindowHeight;

            CheckFullScreenSettings();
        }
Example #19
0
        public bool HasValueFor(StateScope scope, string key)
        {
            var state = scope == StateScope.Session ? _sessionState : _userState;

            return(state.ContainsKey(key));
        }
 public abstract string[] GetKeys(StateScope scope);
Example #21
0
        public PlayerSlotView()
        {
            _updateScope = new StateScope();

            InitializeComponent();
        }
Example #22
0
 /// <summary>
 /// Sets the scope used by this collection.
 /// </summary>
 /// <param name="scope"></param>
 public StateNameValueCollection(StateScope scope)
 {
     Scope = scope;
 }
        public override string[] GetKeys(StateScope scope)
        {
            List<string> keys = new List<string>();

            switch (scope)
            {
                case StateScope.Application:
                    foreach (string key in HttpContext.Current.Application.AllKeys)
                        keys.Add(key);
                    break;
                case StateScope.Session:
                    foreach (string key in HttpContext.Current.Session.Keys)
                        keys.Add(key);
                    break;
                case StateScope.Operation:
                    foreach (string key in HttpContext.Current.Items.Keys)
                        keys.Add(key);
                    break;
            }

            return keys.ToArray();
        }
 public abstract string[] GetKeys(StateScope scope);