/// <summary>
        /// Clears all the serialized and compressed caches set
        /// by the 'Resolve' method for the cacheKey provided.
        /// The default ICacheClient registered in the AppHost will be used.
        /// </summary>
        /// <param name="requestContext">The request context.</param>
        /// <param name="cacheKeys">The cache keys.</param>
        public static void RemoveFromCache(
            this IRequestContext requestContext, params string[] cacheKeys)
        {
            var cacheClient = GetDefaultCacheClient();

            ContentCacheManager.Clear(cacheClient, cacheKeys);
        }
        public void Resolve_twice_with_no_CompressionType_does_not_cache_compressed_result()
        {
            var xmlResult = ContentCacheManager.Resolve(
                () => model,
                MimeTypes.Xml,
                null,
                cacheClient,
                CacheKey,
                null);

            Assert.That(xmlResult, Is.EqualTo(xmlModel));

            xmlResult = ContentCacheManager.Resolve(
                () => model,
                MimeTypes.Xml,
                null,
                cacheClient,
                CacheKey,
                null);

            Assert.That(xmlResult, Is.EqualTo(xmlModel));

            var cachedResult = cacheClient.Get <ModelWithIdAndName>(CacheKey);

            ModelWithIdAndName.AssertIsEqual(model, cachedResult);

            var serializedCacheKey     = ContentCacheManager.GetSerializedCacheKey(CacheKey, MimeTypes.Xml);
            var serializedCachedResult = cacheClient.Get <string>(serializedCacheKey);

            Assert.That(serializedCachedResult, Is.EqualTo(xmlModel));

            AssertNoCompressedResults(cacheClient, serializedCacheKey);
        }
 /// <summary>
 /// Overload for the <see cref="ContentCacheManager.Resolve"/> method returning the most
 /// optimized result based on the MimeType and CompressionType from the IRequestContext.
 /// </summary>
 public static object ToOptimizedResultUsingCache <T>(
     this IRequestContext requestContext, ICacheClient cacheClient, string cacheKey,
     Func <T> factoryFn)
     where T : class
 {
     return(ContentCacheManager.Resolve(
                factoryFn, requestContext, cacheClient, cacheKey, null));
 }
Exemple #4
0
        public Editor()
        {
            InitializeComponent();

            ux_OpenProjectDialog.FileOk += (sender, args) => ReadProject(ux_OpenProjectDialog.FileName);

            ux_LayerList.ItemCheck += (sender, args) =>
            {
                var name = (string)ux_LayerList.Items[args.Index];
                if (name == "Collision")
                {
                    ux_LevelEditor.Level.CollisionLayer.Alpha = args.NewValue == CheckState.Checked ? 255f : 0f;
                }
                else
                {
                    ux_LevelEditor.Level.MapLayers.First(ml => ml.Name == name).Alpha = args.NewValue == CheckState.Checked ? 255f : 0f;
                }
            };
            ux_LayerList.SelectedIndexChanged += (sender, args) =>
            {
                var item = ux_LayerList.SelectedItem;
            };

            ux_LevelEntityList.ItemCheck += (sender, args) =>
            {
                var entity = (GameObject)ux_LevelEntityList.SelectedItem;

                if (entity != null)
                {
                    entity.IsAlive = args.NewValue == CheckState.Checked;
                }
            };

            ux_LevelEntityList.DoubleClick += UxLevelEntityListOnDoubleClick;

            ux_LevelEditor.MouseDown += UxLevelEditorOnMouseDown;
            ux_LevelEditor.MouseMove += UxLevelEditorOnMouseMove;
            ux_LevelEditor.KeyDown   += UxLevelEditorOnKeyDown;

            KeyDown += UxLevelEditorOnKeyDown;

            Project.OnCompleteLoadContentDirectory += (sender, args) =>
            {
                var project = (Project)sender;
                project.ContentDirectories.ForEach(ContentCacheManager.AddContentDirectory);

                // TODO: disk op... show progress bar?
                ContentCacheManager.LoadContent(new ContentManager(ServiceLocator.Apply()));
            };

            ux_LevelEditor.MouseWheel += UxLevelEditorOnMouseWheel;

            // setup status bar controls
            AddZoomControlsToStatusBar(ux_StatusBar);

            ux_ShowGrid.Enabled = false;
        }
 /// <summary>
 /// Overload for the <see cref="ContentCacheManager.Resolve"/> method returning the most
 /// optimized result based on the MimeType and CompressionType from the IRequestContext.
 /// <param name="expireCacheIn">How long to cache for, null is no expiration</param>
 /// </summary>
 public static object ToOptimizedResultUsingCache <T>(
     this IRequestContext requestContext, ICacheClient cacheClient, string cacheKey,
     TimeSpan?expireCacheIn, Func <T> factoryFn)
     where T : class
 {
     return(ContentCacheManager.Resolve(
                factoryFn, requestContext.MimeType, requestContext.CompressionType,
                cacheClient, cacheKey, expireCacheIn));
 }
        /// <summary>
        /// Overload for the <see cref="ContentCacheManager.Resolve"/> method returning the most
        /// optimized result based on the MimeType and CompressionType from the IRequestContext.
        /// The default ICacheClient registered in the AppHost will be used.
        /// </summary>
        public static object ToOptimizedResultUsingCache <T>(this IRequestContext requestContext,
                                                             string cacheKey, Func <T> factoryFn)
            where T : class
        {
            var cacheClient = GetDefaultCacheClient();

            return(ContentCacheManager.Resolve(
                       factoryFn, requestContext.MimeType, requestContext.CompressionType,
                       cacheClient, cacheKey, null));
        }
        private static void AssertNoSerializedResults(
            ICacheClient cacheClient, string cacheKey)
        {
            foreach (var mimeType in ContentCacheManager.AllCachedMimeTypes)
            {
                var serializedCacheKey = ContentCacheManager.GetSerializedCacheKey(
                    cacheKey, mimeType);

                var serializedResult = cacheClient.Get <string>(serializedCacheKey);
                Assert.That(serializedResult, Is.Null);
            }
        }
        private static void AssertNoCompressedResults(
            ICacheClient cacheClient, string serializedCacheKey)
        {
            foreach (var compressionType in CompressionTypes.AllCompressionTypes)
            {
                var compressedCacheKey = ContentCacheManager.GetCompressedCacheKey(
                    serializedCacheKey, compressionType);

                var compressedCachedResult = cacheClient.Get <byte[]>(compressedCacheKey);
                Assert.That(compressedCachedResult, Is.Null);
            }
        }
        public void Clear_after_Resolve_with_MimeType_clears_all_cached_results()
        {
            ContentCacheManager.Resolve(
                () => model,
                serializationContext,
                cacheClient,
                CacheKey,
                null);

            ContentCacheManager.Clear(cacheClient, CacheKey);

            AssertEmptyCache(cacheClient, CacheKey);
        }
        public void Clear_after_Resolve_with_MimeType_and_CompressionType_clears_all_cached_results()
        {
            ContentCacheManager.Resolve(
                () => model,
                MimeTypes.Xml,
                CompressionTypes.Deflate,
                cacheClient,
                CacheKey,
                null);

            ContentCacheManager.Clear(cacheClient, CacheKey);

            AssertEmptyCache(cacheClient, CacheKey);
        }
Exemple #11
0
        public override void LoadContent()
        {
            Initialize();

            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(ScreenManager.GraphicsDevice);


            if (_hud != null)
            {
                _gameFont = ContentCacheManager.GetFont(@"Fonts\GameFont");
                _hud.Font = _gameFont;
            }


            base.LoadContent();
        }
        public void Clear_after_Resolve_with_MimeType_and_CompressionType_clears_all_cached_results()
        {
            var serializationContext = new SerializationContext(MimeTypes.Xml)
            {
                CompressionType = CompressionTypes.Deflate
            };

            ContentCacheManager.Resolve(
                () => model,
                serializationContext,
                cacheClient,
                CacheKey,
                null);

            ContentCacheManager.Clear(cacheClient, CacheKey);

            AssertEmptyCache(cacheClient, CacheKey);
        }
Exemple #13
0
        private void ProjectOnOnChange(object sender, ProjectChangeEventArgs eventArgs)
        {
            Project = (Project)sender;
            if (eventArgs.PropertyName == "ContentDirectories")
            {
                // total hack, create a level editor control
                // so that a valid GraphicsDevice object is created
                new LevelEditorControl {
                    Height = 100, Width = 100
                }.CreateControl();

                Project.ContentDirectories.ForEach(ContentCacheManager.AddContentDirectory);

                // TODO: disk op... show progress bar?
                ContentCacheManager.LoadContent(new ContentManager(ServiceLocator.Apply()));
            }

            UpdateUserInterface();
        }
        //[EnableCompression]
        public virtual ActionResult Index(IRebelRenderModel model)
        {
            if (model.CurrentNode == null)
            {
                return(new HttpNotFoundResult());
            }

            var contentCacheManager = new ContentCacheManager(RoutableRequestContext.Application, this);
            var content             = contentCacheManager.RenderContent(model);

            if (string.IsNullOrEmpty(content.Key))
            {
                return(View(
                           EmbeddedViewPath.Create("Rebel.Cms.Web.EmbeddedViews.Views.TemplateNotFound.cshtml,Rebel.Cms.Web"),
                           model.CurrentNode));
            }

            return(Content(content.Value, content.Key));
        }
Exemple #15
0
        public void DrawMap(SpriteBatch spriteBatch)
        {
            if (_tileSetTextureIsDirty)
            {
                TileSetTexture = ContentCacheManager.GetTexture(TileSetTexturePath);

                TileSheet = new AnimationSheet(TileSetTexture, TileSize, TileSize);

                // add the animations
                for (int frame = 0; frame < TileSheet.TotalFrames; frame++)
                {
                    TileSheet.Add(frame, 1f, false, frame);
                }
            }

            if (TileSetTexture != null)
            {
                MapData.EachCell((cell, tile) =>
                {
                    // adjust the vector position according to the tilesize
                    cell *= TileSize;

                    // only draw tiles that have data
                    if (tile > -1)
                    {
                        TileSheet[tile].Draw(spriteBatch, cell, Color.White * Opacity);
                    }

                    if (DrawGrid)
                    {
                        var frame = new Rectangle((int)cell.X, (int)cell.Y, TileSize, TileSize);

                        var whiteTexture = new Texture2D(spriteBatch.GraphicsDevice, 1, 1);
                        whiteTexture.SetData(new Color[] { Color.White });

                        spriteBatch.Draw(whiteTexture, new Rectangle(frame.Left, frame.Top, frame.Width, 1), Color.White);
                        spriteBatch.Draw(whiteTexture, new Rectangle(frame.Left, frame.Bottom, frame.Width, 1), Color.White);
                        spriteBatch.Draw(whiteTexture, new Rectangle(frame.Left, frame.Top, 1, frame.Height), Color.White);
                        spriteBatch.Draw(whiteTexture, new Rectangle(frame.Right, frame.Top, 1, frame.Height + 1), Color.White);
                    }
                });
            }
        }
        public void Can_cache_null_result()
        {
            var xmlResult = ContentCacheManager.Resolve <ModelWithIdAndName>(
                () => null,
                serializationContext,
                cacheClient,
                CacheKey,
                null);

            Assert.That(xmlResult, Is.Null);

            var cachedResult = cacheClient.Get <ModelWithIdAndName>(CacheKey);

            Assert.That(cachedResult, Is.Null);

            var serializedCacheKey     = ContentCacheManager.GetSerializedCacheKey(CacheKey, MimeTypes.Xml);
            var serializedCachedResult = cacheClient.Get <string>(serializedCacheKey);

            Assert.That(serializedCachedResult, Is.Null);

            AssertNoCompressedResults(cacheClient, serializedCacheKey);
        }
        /// <summary>
        /// Load your graphics content.
        /// </summary>
        protected override void LoadContent()
        {
            // Load content belonging to the screen manager.
            _spriteBatch  = new SpriteBatch(GraphicsDevice);
            _font         = ContentCacheManager.GetFont("Fonts/MenuFont");
            _blankTexture = ContentCacheManager.GetTexture("FragEngine.Resources.blank.png");

            // Tell each of the screens to load their content.
            foreach (GameScreenBase screen in screens)
            {
                screen.LoadContent();
            }

            // update the title-safe area
            _titleSafeArea = new Rectangle(
                (int)Math.Floor(GraphicsDevice.Viewport.X +
                                GraphicsDevice.Viewport.Width * 0.05f),
                (int)Math.Floor(GraphicsDevice.Viewport.Y +
                                GraphicsDevice.Viewport.Height * 0.05f),
                (int)Math.Floor(GraphicsDevice.Viewport.Width * 0.9f),
                (int)Math.Floor(GraphicsDevice.Viewport.Height * 0.9f));
        }
Exemple #18
0
 public AnimationSheet(string texturePath, int frameWidth, int frameHeight)
     : this(frameWidth, frameHeight)
 {
     _texturePath = texturePath;
     SpriteSheet  = ContentCacheManager.GetTexture(texturePath);
 }
 /// <summary>
 /// Clears all the serialized and compressed caches set
 /// by the 'Resolve' method for the cacheKey provided
 /// </summary>
 /// <param name="requestContext"></param>
 /// <param name="cacheClient"></param>
 /// <param name="cacheKeys"></param>
 public static void RemoveFromCache(
     this IRequestContext requestContext, ICacheClient cacheClient, params string[] cacheKeys)
 {
     ContentCacheManager.Clear(cacheClient, cacheKeys);
 }
        public override void Initialize()
        {
            _collisionTiles = ContentCacheManager.GetTextureFromResource(TileSetTexturePath);

            base.Initialize();
        }
Exemple #21
0
        public override void LoadContent()
        {
            _logoTexture = ContentCacheManager.GetTexture(_texturePath);

            base.LoadContent();
        }