Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapEditViewModel"/> class.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="sessionId">The session identifier.</param>
        public MapEditViewModel(Map map, Guid sessionId)
        {
            // Trace
            Tracer.Debug(string.Format("MapEditViewModel :: Calling new MapEditViewModel() with map id '{0}'", map.Id));

            try
            {
                // initialize
                this.callback                    = new MapEditorCallback();
                this.callback.NameUpdated       += this.NameUpdated;
                this.callback.IsPlayableUpdated += this.IsPlayableUpdated;
                this.callback.WindowAdded       += this.WindowAdded;
                this.callback.WindowRemoved     += this.WindowRemoved;
                this.callback.HoleAdded         += this.HoleAdded;
                this.callback.HoleRemoved       += this.HoleRemoved;
                this.proxy = new MapEditorServiceClient(this.callback, sessionId);

                // set map properties
                this.map        = map;
                this.IsPlayable = map.IsPlayable;
                this.MapName    = map.Name;

                // register the callback
                this.proxy.RegisterCallback(map.Id);

                // get the maps config and display it
                var config  = this.proxy.GetMapConfiguration();
                var windows = new GameWindow[config.WindowRows][];
                this.gridSize     = GameWindowSize / config.HoleGrid;
                this.HoleDiameter = GameWindowSize / config.HoleGrid;

                for (var row = 0; row < windows.Length; row++)
                {
                    windows[row] = new GameWindow[config.WindowCols];
                    for (var col = 0; col < windows[row].Length; col++)
                    {
                        var mapWindow = this.map.Windows != null
                            ? this.map.Windows.FirstOrDefault(item => item.X == col && item.Y == row)
                            : null;

                        windows[row][col] = new GameWindow(col, row, mapWindow, this.HoleDiameter);
                    }
                }

                this.GameWindows = windows;
            }
            catch (FaultException <CallbackNotValidException> )
            {
                this.HandleInvalidCallback();
            }
            catch (ServerUnavailableException ex)
            {
                this.HandleServerException(ex);
            }
        }
Exemple #2
0
        public void GetMapsTest()
        {
            // arrange
            var authenticatioProxy = new AuthenticationServiceClient();
            var sessionId          = authenticatioProxy.Login("editor", "editor", Role.Editor);
            var mapEditorProxy     = new MapEditorServiceClient(sessionId);

            // act
            var maps = mapEditorProxy.GetMaps().ToList();

            // asset
            Assert.IsTrue(maps.Count > 1);
            Assert.IsTrue(maps.First().Windows.Count == 1);
            Assert.IsTrue(maps.First().Windows.First().Holes.Count == 3);
        }
 /// <summary>
 /// Initializes this map.
 /// </summary>
 private async void Initialize()
 {
     this.proxy = new MapEditorServiceClient(this.sessionId);
     this.Maps  = new ObservableCollection <Map>();
     await this.LoadMaps();
 }