public void SaveBooks(IEnumerable <Book> books)
        {
            if (ReferenceEquals(books, null))
            {
                throw new ArgumentNullException();
            }

            try
            {
                using (var writer = new BinaryWriter(File.Open(FilePath, FileMode.OpenOrCreate, FileAccess.Write)))
                {
                    foreach (var book in books)
                    {
                        writer.Write(book.Title);
                        writer.Write(book.Author);
                        writer.Write(book.ReleaseDate.ToString("d"));
                        writer.Write(book.Price);
                    }
                }
                logger.Trace($"Saved {books.Count()} books to {Environment.CurrentDirectory}'\'{FilePath}");
            }
            catch (IOException ex)
            {
                logger.Error($"error {ex.GetType()} in\n {ex.StackTrace}\n whith message {ex.Message}");
                throw new Exception("Can't save data", ex);
            }
        }
Ejemplo n.º 2
0
        public void Draw(IPlotOperation plotOperation)
        {
            var area       = viewport.RenderedArea;
            var insets     = viewport.RenderInsets;
            var renderType = viewport.RenderType;

            var screenOrigin = new MapCoordinate(0, 0);

            screenNavigator.NavigateTo(GridDirection.North, screenOrigin, out MapCoordinate northWest, insets.Top);
            screenNavigator.NavigateTo(GridDirection.West, northWest, out northWest, insets.Left);

            screenNavigator.NavigateTo(GridDirection.South, screenOrigin, out MapCoordinate southWest, insets.Bottom);
            screenNavigator.NavigateTo(GridDirection.West, southWest, out southWest, insets.Left);

            var valid     = true;
            var mapOrigin = viewport.CenterPointInMapCoordinates;

            valid &= mapAccessNavigator.NavigateTo(GridDirection.North, mapOrigin, out MapCoordinate mapRowStart, insets.Top);
            valid &= mapAccessNavigator.NavigateTo(GridDirection.West, mapRowStart, out mapRowStart, insets.Left);

            var rowStart = northWest;

            if (logger.IsTraceEnabled)
            {
                logger.Trace(
                    "Rendering frame lines from {0} -> {1} in area {2} (Insets: {3}, ScreenOrigin: {4}, MapOrigin: {5})",
                    northWest, southWest, area, insets, screenOrigin, mapOrigin);
            }

            plotOperation.StartDrawing();

            for (var y = 0; y < area.Height; y += 1)
            {
                if (renderType == RenderType.Grid)
                {
                    RenderLine(plotOperation, mapRowStart, rowStart, area.Width, valid, y);
                    screenNavigator.NavigateTo(GridDirection.South, rowStart, out rowStart);
                    valid = mapAccessNavigator.NavigateTo(GridDirection.South, mapRowStart, out mapRowStart);
                }
                else
                {
                    // In any of the two isometric modes the renderer cannot just move straight downwards.
                    // Rows are offset against each other, so the renderer has to alternate between the
                    // south-east and south-west direction.
                    //
                    // On the first line, the start and end position are outwards from the screen so
                    // the line is actually two elements longer.
                    RenderLine(plotOperation, mapRowStart, rowStart, area.Width, valid, y); // was area.Width
                    screenNavigator.NavigateTo(GridDirection.SouthEast, rowStart, out rowStart);
                    valid = mapAccessNavigator.NavigateTo(GridDirection.SouthEast, mapRowStart, out mapRowStart);
                    RenderLine(plotOperation, mapRowStart, rowStart, area.Width, valid, y); // was area.Width
                    screenNavigator.NavigateTo(GridDirection.SouthWest, rowStart, out rowStart);
                    valid = mapAccessNavigator.NavigateTo(GridDirection.SouthWest, mapRowStart, out mapRowStart);
                }
            }

            plotOperation.FinishedDrawing();
        }
Ejemplo n.º 3
0
        public IReadOnlyList <TRenderTile> Find(string tag)
        {
            if (tilesByName.TryGetValue(tag, out IReadOnlyList <TRenderTile> tile))
            {
                return(tile);
            }

            logger.Trace("Missing tile in registry for tag ({0})", tag);
            return(fallback);
        }
Ejemplo n.º 4
0
        public void SaveBooks(IEnumerable <Book> books)
        {
            if (ReferenceEquals(books, null))
            {
                throw new ArgumentNullException();
            }

            try
            {
                using (var fileStream = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    new XmlSerializer(typeof(List <Book>)).Serialize(fileStream, new List <Book>(books));
                }

                logger.Trace($"Saved {books.Count()} books to {Environment.CurrentDirectory}'\'{FilePath}");
            }

            catch (IOException ex)
            {
                logger.Error($"error {ex.GetType()} in\n {ex.StackTrace}\n whith message {ex.Message}");
                throw new Exception("Can't save data", ex);
            }
        }
Ejemplo n.º 5
0
        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            var newSize = Game.Window.ClientBounds.Size;

            if (currentSize != newSize)
            {
                if (logger.IsTraceEnabled)
                {
                    logger.Trace("Screen size change detected. Was {0}, now {1}", currentSize, newSize);
                }
                currentSize = newSize;
                WindowSizeChanged?.Invoke(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 6
0
 public static void EmitMissingTileWarning(string tag)
 {
     MissingTilesTracer.Trace("Missing tile in registry for tag ({0})", tag);
 }