Пример #1
0
        public void AddToResourceLibrary(ResourceLibrary resourceLibrary, TileManagerViewState viewState)
        {
            var movePath = String.Empty;
            ObservableCollection<Tile> collection = null; ;

            switch (viewState)
            {
                case TileManagerViewState.AddNewFloorTiles:
                    movePath = Constants.RESOURCE_LIBRARY_MANAGED_FLOOR_TILES;
                    collection = resourceLibrary.FloorTiles;
                    break;
                case TileManagerViewState.AddNewWallTiles:
                    movePath = Constants.RESOURCE_LIBRARY_MANAGED_WALL_TILES;
                    collection = resourceLibrary.WallTiles;
                    break;
                case TileManagerViewState.AddNewDecorTiles:
                    movePath = Constants.RESOURCE_LIBRARY_MANAGED_DECOR_TILES;
                    collection = resourceLibrary.DecorTiles;
                    break;
                default:
                    break;
            }

            //Step 1 - move source to managed raw assets
            var newFileLocation = Path.Combine(movePath, Path.GetFileName(_fileLocation));
            for (var fileNumber = 2; File.Exists(newFileLocation); fileNumber++)
            {
                var newFileName = Path.GetFileNameWithoutExtension(_fileLocation) + fileNumber.ToString() + Path.GetExtension(_fileLocation);
                newFileLocation = Path.Combine(movePath, newFileName);
            }
            File.Move(_fileLocation, newFileLocation);

            //Step 2 - add the resources
            foreach (Tile tile in Tiles)
            {
                collection.Add(tile);
            }

            //Step 3 - save the resourceLibrary
            resourceLibrary.Save();
        }