public async Task HelloWorld_From_Sheet()
        {
            SheetCache sheetCache = new SheetCache(_spreadsheetRepository);
            var        csvString  = await sheetCache.GetCSVStringAsync("Test!A1");

            csvString.Should().Be("Hello World!");
        }
Beispiel #2
0
        public async Task HelloWorld_From_Cache()
        {
            SheetCache sheetCache = new SheetCache(_mockedCachedDataRepository);
            await sheetCache.GetCSVStringAsync("Test!A1");

            await sheetCache.GetCSVStringAsync("Test!A1");

            _mockRepository.CountCall.Should().Be(1);
        }
        public async Task MapObject_From_SheetCache()
        {
            SheetCache sheetCache = new SheetCache(_cachedDataRepository);
            var        user1      = await sheetCache.Get <User>();

            var users2 = await sheetCache.Get <User>();

            users2.Single().Should().BeEquivalentTo(user1.Single());
        }
        public async Task Cache_Should_Expire()
        {
            SheetCache sheetCache = new SheetCache(_cachedMockedDataRepository);
            await sheetCache.GetCSVStringAsync("Test!A1");

            Thread.Sleep(TimeSpan.FromSeconds(1.1));
            await sheetCache.GetCSVStringAsync("Test!A1");

            _mockRepository.CountCall.Should().Be(2);
        }
Beispiel #5
0
        public async Task MapObject_From_Sheet()
        {
            SheetCache sheetCache = new SheetCache(_cachedDataRepository);
            var        users      = await sheetCache.Get <User>();

            users.Single().Should().BeEquivalentTo(new User
            {
                Age      = 38,
                Username = "******"
            });
        }
        public async Task MapDictionary_From_Sheet()
        {
            SheetCache sheetCache = new SheetCache(_spreadsheetRepository);
            Dictionary <string, string> dictionary = await sheetCache.GetDictionary("Dictionary");

            dictionary.Should().BeEquivalentTo(new Dictionary <string, string>()
            {
                { "fizz", "buzz" },
                { "foo", "bar" }
            });
        }
Beispiel #7
0
        public ModuleModel()
        {
            //TODO: inject logger!
            //DI is for Dependency injection!
            sheets       = new SheetCache();
            destinations = new DestinationStorage();
            //TODO:Конфигурация!
            sorter = new GroupsSorter <Sheet>("Формат");
            PropertiesExractor propertiesExractor = new PropertiesExractor();

            sheetExtractor        = new SheetsExtractor(propertiesExractor, new SheetCreator(new BoundsCalculator()));
            destinationsExtractor = new DestinationsExtractor(propertiesExractor, new DestinationCreator());
        }
Beispiel #8
0
        public static Sprite GetImage(string collectionName, string imageName)
        {
            if (imageName == "harktitle")
            {
            }
            if (string.IsNullOrEmpty(collectionName))
            {
                return(null);
            }

            // Cached sprite
            Dictionary <string, Sprite> cachedCollection;
            Sprite sprite;

            if (collectionName == "dropdown")
            {
            }
            if (cachedSprites.TryGetValue(collectionName, out cachedCollection) && cachedCollection.TryGetValue(imageName, out sprite))
            {
                return(sprite);                //нашли в кешах, возвращаем Sprite
            }
            Collection collection;

            if (!collections.TryGetValue(collectionName, out collection))
            {
                Log.Write("debug", "Could not find collection '{0}'", collectionName);
                return(null);
            }

            MappedImage mi;

            if (!collection.Regions.TryGetValue(imageName, out mi))
            {
                return(null);
            }
            if (World == null)
            {
            }
            else
            {
                seqprov = World.Map.Rules.Sequences;
            }
            // по идее, можно написать в chrome.yaml разные ресурсы игры cps и т.п. , они будут загружаться , только при обращении в этот метод.
            // при обращении за cps , переменная wolrd уже будет заполнена.
            bool switch2Seq = false;

            if (seqprov != null)
            {
                if (seqprov.HasSequence(mi.Src))
                {
                    switch2Seq = true;
                }
            }
            Sprite     image = null, image2 = null;
            SheetCache sheet2d;

            if (switch2Seq)
            {
                if (cachedSheets2d.ContainsKey(mi.Src))                 //mi.Src это имя png файла.
                {
                    sheet2d = cachedSheets2d[mi.Src];
                }
                else
                {
                    sheet2d       = new SheetCache();
                    sheet2d.sheet = seqprov.GetSequence(mi.Src, "idle").GetSprite(0).Sheet2D;
                    cachedSheets2d.Add(mi.Src, sheet2d);
                }
                image2 = seqprov.GetSequence(mi.Src, "idle").GetSprite(0);
                int2 offset = new int2(image2.Bounds.Location.X, image2.Bounds.Location.Y);                                                                      //основная часть текстуры
                image = new Sprite(sheet2d.sheet, new Rectangle(mi.rect.X + offset.X, mi.rect.Y + offset.Y, mi.rect.Width, mi.rect.Height), TextureChannel.Red); //смещение в основной части текстуры

                if (mi.Rotate > 0)
                {
                    // передаем данные о повороте, если больше 0
                    image.Rotate = mi.Rotate;
                }
                if (mi.Stretched)
                {
                    image.Stretched = true;
                }
                image.SpriteType = 3;                 // для Utils.FastCreateQuad для алгоритма Fill rect with

                if (cachedCollection == null)
                {
                    cachedCollection = new Dictionary <string, Sprite>();
                    cachedSprites.Add(collectionName, cachedCollection);
                }
                cachedCollection.Add(imageName, image);
                return(image);
            }

            if (!switch2Seq)
            {
                // Cached sheet
                if (cachedCollection == null)
                {
                    cachedCollection = new Dictionary <string, Sprite>();
                    cachedSprites.Add(collectionName, cachedCollection);
                }


                if (cachedSheets2d.ContainsKey(mi.Src))                 //mi.Src это имя png файла. Каждый png будет в своем индексе у 2д текстуры
                {
                    sheet2d = cachedSheets2d[mi.Src];
                }
                else
                {
                    using (var stream = fileSystem.Open(mi.Src))
                    {
                        //currentPngSprite = seqprov.SpriteCache.SheetBuilder2D.Add(new Png(stream));
                        currentPngSprite = Game.SheetBuilder2D.Add(new Png(stream));
                        //sheet2d = new Sheet2D(SheetType.BGRA, stream);
                    }

                    sheet2d         = new SheetCache();
                    sheet2d.sheet   = Game.SheetBuilder2D.Current;
                    sheet2d.OffsetX = currentPngSprite.Bounds.Location.X;                     //так как теперь png внутри большой текстуры, то теперь нужно запоминать ее смещение и прибавлять к коориданатам в chrome.yaml
                    sheet2d.OffsetY = currentPngSprite.Bounds.Location.Y;
                    cachedSheets2d.Add(mi.Src, sheet2d);
                }
                //collection.OffsetLeft = sheet2d.OffsetX;
                //collection.OffsetTop = sheet2d.OffsetY;
                // Cache the sprite

                mi.OffsetTop  = sheet2d.OffsetY;
                mi.OffsetLeft = sheet2d.OffsetX;
                image         = mi.GetImage(sheet2d.sheet);
                cachedCollection.Add(imageName, image);
            }
            return(image);
        }