private void InitializeArtists()
        {
            Action <uint, IArtist> entityLoaded = (id, entity) => artistCache.Add(id, entity);

            Action <uint, ILink, uint> linkLoaded = (id, link, entityId) =>
            {
                var entity = artistCache.GetEntity(entityId);
                if (entity != null)
                {
                    entity.AddLink(link);
                    artistCache.Add(id, entity, link);
                }
            };

            Action <uint, ITag, uint> tagLoaded = (id, tag, entityId) =>
            {
                var entity = artistCache.GetEntity(entityId);
                if (entity != null)
                {
                    entity.AddTag(tag);
                    artistCache.Add(id, entity, tag);
                }
            };

            artistStore.Initialize(entityLoaded, linkLoaded, tagLoaded);
        }
        private void InitializeWorks()
        {
            Action <uint, IWork> entityLoaded = (id, entity) => workCache.Add(id, entity);

            Action <uint, ILink, uint> linkLoaded = (id, link, entityId) =>
            {
                var entity = workCache.GetEntity(entityId);
                if (entity != null)
                {
                    entity.AddLink(link);
                    workCache.Add(id, entity, link);
                }
            };

            Action <uint, ITag, uint> tagLoaded = (id, tag, entityId) =>
            {
                var entity = workCache.GetEntity(entityId);
                if (entity != null)
                {
                    entity.AddTag(tag);
                    workCache.Add(id, entity, tag);
                }
            };

            workStore.Initialize(entityLoaded, linkLoaded, tagLoaded);
        }
Esempio n. 3
0
        private void SaveLink(T entity, ILink link)
        {
            if (entity == null || link == null)
            {
                return;
            }

            var entityId = cache.GetId(entity);

            if (entityId == 0)
            {
                return;
            }

            var id = cache.GetId(link);

            if (id > 0)
            {
                database.SaveLink(this, id, link, entityId);
            }
            else
            {
                id = database.CreateLink(this, link, entityId);
                cache.Add(id, entity, link);
            }
        }
Esempio n. 4
0
        private List <T> ReNewCacheFromBase()
        {
            ClearCache();
            List <T> result = base.FindAll();

            if (result != null)
            {
                _cache.Add(result);
            }
            _isCacheValid = true;
            return(result);
        }
Esempio n. 5
0
        public ServiceResult ListStock(Guid id, string asxCode, string name, Date listingDate, bool trust, AssetCategory category)
        {
            // Check that id is unique
            var stock = _StockRepository.Get(id);

            if (stock != null)
            {
                return(ServiceResult.Error("A stock with id {0} already exists", id));
            }

            // Check if stock already exists with this code
            var effectivePeriod = new DateRange(listingDate, Date.MaxValue);

            if (_StockQuery.Find(effectivePeriod, y => y.AsxCode == asxCode).Any())
            {
                return(ServiceResult.Error("A stock already exists with the code {0} on {1}", asxCode, listingDate.ToShortDateString()));
            }

            stock = new Stock(id);
            stock.List(asxCode, name, listingDate, trust, category);
            _StockRepository.Add(stock);
            _StockCache.Add(stock);

            var stockPriceHistory = new StockPriceHistory(id);

            _StockPriceHistoryRepository.Add(stockPriceHistory);
            _StockPriceHistoryCache.Add(stockPriceHistory);

            stock.SetPriceHistory(stockPriceHistory);

            return(ServiceResult.Ok());
        }
Esempio n. 6
0
        public StockQueryTests()
        {
            _StockCache = new EntityCache <Stock>();

            _Stock1 = new Stock(Guid.NewGuid());
            _Stock1.List("ABC", "ABC Pty Ltd", new Date(2000, 01, 01), false, AssetCategory.AustralianStocks);
            _Stock1.DeList(new Date(2010, 01, 01));
            _StockCache.Add(_Stock1);

            _Stock2 = new Stock(Guid.NewGuid());
            _Stock2.List("XYZ", "XYZ Pty Ltd", new Date(2000, 01, 01), false, AssetCategory.AustralianStocks);
            _Stock2.ChangeProperties(new Date(2005, 01, 01), "XYZ2", "XYZ 2 Pty Ltd", AssetCategory.AustralianStocks);
            _StockCache.Add(_Stock2);

            _Stock3 = new Stock(Guid.NewGuid());
            _Stock3.List("DEF", "DEF Pty Ltd", new Date(2002, 01, 01), false, AssetCategory.AustralianProperty);
            _Stock3.ChangeProperties(new Date(2005, 01, 01), "XYZ", "XYZ Pty Ltd", AssetCategory.AustralianProperty);
            _StockCache.Add(_Stock3);
        }
Esempio n. 7
0
        public static IEntityCache <T> PopulateCache <T>(this IEntityCache <T> entityCache, IRepository <T> repository)
            where T : ITrackedEntity
        {
            entityCache.Clear();

            foreach (var entity in repository.All())
            {
                entityCache.Add(entity);
            }

            return(entityCache);
        }