Esempio n. 1
0
 internal DefaultJsonSerializer(IEntityCache cache)
 {
     _serializer = new JsonSerializer {
         NullValueHandling = NullValueHandling.Ignore
     };
     _serializer.Converters.Insert(0, new CypherResultSetConverterFactoryJsonConverter(cache));
 }
Esempio n. 2
0
 internal CypherSession(string uri, IWebClient webClient)
 {
     _uri           = uri;
     _webClient     = webClient;
     _entityCache   = new DictionaryEntityCache();
     _webSerializer = new DefaultJsonSerializer(_entityCache);
 }
Esempio n. 3
0
 public CypherClientFactory(string baseUri, IWebClient webClient, IWebSerializer serializer, IEntityCache entityCache)
 {
     this._baseUri = baseUri;
     this._webClient = webClient;
     this._serializer = serializer;
     this._entityCache = entityCache;
 }
        public EntityRepository(ILogger logger, IEntityCache <IArtist> artistCache, IEntityStore <IArtist> artistStore, IEntityCache <IWork> workCache, IEntityStore <IWork> workStore)
        {
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (artistCache == null)
            {
                throw new ArgumentNullException("artistCache");
            }
            if (artistStore == null)
            {
                throw new ArgumentNullException("artistStore");
            }
            if (workCache == null)
            {
                throw new ArgumentNullException("workCache");
            }
            if (workStore == null)
            {
                throw new ArgumentNullException("workStore");
            }

            this.logger      = logger;
            this.artistCache = artistCache;
            this.artistStore = artistStore;
            this.workCache   = workCache;
            this.workStore   = workStore;
        }
Esempio n. 5
0
        private async Task AutoClearLoopAsync <TKey, TEntity>(IEntityCache <TKey, TEntity> cache, string optionsName, IBatchingStore store,
                                                              CancellationToken cancellationToken = default) where TEntity : IEntity <TKey>
        {
            CachingOptions options = _cachingOptions.Get(optionsName);

            if (options.Lifetime < TimeSpan.Zero)
            {
                _log.LogDebug("{ServiceName} cache lifetime set to 0 or lower, cache purges disabled", cache.GetType().Name);
                return;
            }

            _log.LogDebug("{ServiceName} starting cache auto-clear loop with rate of {ClearRate}", cache.GetType().Name, options.Lifetime);
            while (!cancellationToken.IsCancellationRequested)
            {
                await Task.Delay(options.Lifetime, cancellationToken).ConfigureAwait(false);

                // flush batch to prevent data loss
                store?.FlushBatch();
                // find and remove entities from cache
                IEnumerable <TEntity> expired = cache.Find(e => e.IsExpired(options.Lifetime));
                foreach (TEntity entity in expired)
                {
                    cache.Remove(entity.ID);
                }
                _log.LogDebug("{RemovedCount} expired {ServiceName} entities removed from cache", expired.Count(), cache.GetType().Name);
            }
        }
Esempio n. 6
0
 internal CypherSession(ConnectionProperties connectionProperties, IWebClient webClient)
 {
     _uri           = connectionProperties.Url;
     _webClient     = webClient;
     _entityCache   = new DictionaryEntityCache();
     _webSerializer = new DefaultJsonSerializer(_entityCache);
 }
 public CypherClientFactory(string baseUri, IWebClient webClient, IWebSerializer serializer, IEntityCache entityCache)
 {
     this._baseUri     = baseUri;
     this._webClient   = webClient;
     this._serializer  = serializer;
     this._entityCache = entityCache;
 }
        protected void InitializeCaches()
        {
            if (!_cachesInitialized)
            {
                using (var dbContext = _dbContextFactory.Create())
                {
                    _programmeDictionaryCache = new ProgrammeDictionaryCache(dbContext, trackingChanges: false);
                    _programmeDictionaryCache.Load();

                    _programmeCategoryCache = new ProgrammeCategoryCache(dbContext, trackingChanges: false);
                    _programmeCategoryCache.Load();

                    _scheduleCache =
                        new SqlServerEntityCache <int, ScheduleEntity>(dbContext, x => x.ScheduleUniqueKey, trackingChanges: false);
                    _scheduleCache.Load();

                    _salesAreaCache = new SqlServerEntityCache <string, SalesArea>(dbContext, x => x.Name, trackingChanges: false);
                    _salesAreaCache.Load();

                    _categoryHierarchyNames = new HashSet <string>(dbContext.Query <ProgrammeCategoryHierarchy>().Select(x => x.Name)
                                                                   .AsEnumerable());
                }

                _cachesInitialized = true;
            }
        }
Esempio n. 9
0
 internal TransactionalCypherClient(string baseUri, IWebClient webClient, IWebSerializer serializer, IEntityCache entityCache)
 {
     this._transactionUri = UriHelper.Combine(baseUri, "transaction/");
     this._webClient      = webClient;
     this._serializer     = serializer;
     this._entityCache    = entityCache;
 }
Esempio n. 10
0
 public StockService(IStockQuery stockQuery, IEntityCache <Stock> stockCache, IRepository <Stock> stockRepository, IEntityCache <StockPriceHistory> stockPriceHistoryCache, IRepository <StockPriceHistory> stockPriceHistoryRepository)
 {
     _StockQuery                  = stockQuery;
     _StockCache                  = stockCache;
     _StockRepository             = stockRepository;
     _StockPriceHistoryCache      = stockPriceHistoryCache;
     _StockPriceHistoryRepository = stockPriceHistoryRepository;
 }
Esempio n. 11
0
        public EntityManager(IEntityCache entityCache, IEntityBucket <T> bucket)
        {
            _allManagers.Add(this);
            _entityCache = entityCache;
            _bucket      = bucket;

            _bucket.BucketsUpdated += _bucket_BucketUpdated;
        }
Esempio n. 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InteractionTransaction"/> class.
        /// </summary>
        /// <param name="channelTypeMediumValue">The channel medium type value.</param>
        /// <param name="channelEntity">The channel entity.</param>
        /// <param name="componentEntity">The component entity.</param>
        /// <param name="info">
        /// The information about the <see cref="Interaction"/> object graph to be logged.
        /// In the case of conflicting values (i.e. channelEntity.Id vs info.ChannelEntityId), any values explicitly set on the <paramref name="info"/> parameter will take precedence.
        /// </param>
        public InteractionTransaction(DefinedValueCache channelTypeMediumValue, IEntityCache channelEntity, IEntityCache componentEntity, InteractionTransactionInfo info)
        {
            if (channelTypeMediumValue == null || channelEntity == null || componentEntity == null)
            {
                return;
            }

            Initialize(channelTypeMediumValue.Id, channelEntity.Id, channelEntity.ToString(), channelEntity.CachedEntityTypeId, componentEntity.Id, componentEntity.ToString(), info);
        }
Esempio n. 13
0
 internal CypherSession(string uri, IWebClient webClient, string username, string password)
 {
     _uri           = uri;
     _webClient     = webClient;
     _username      = username;
     _password      = password;
     _entityCache   = new DictionaryEntityCache();
     _webSerializer = new DefaultJsonSerializer(_entityCache);
 }
Esempio n. 14
0
 public CypherClientFactory(string baseUri, string username, string password, IWebClient webClient, IWebSerializer serializer, IEntityCache entityCache)
 {
     _baseUri     = baseUri;
     _username    = username;
     _password    = password;
     _webClient   = webClient;
     _serializer  = serializer;
     _entityCache = entityCache;
 }
Esempio n. 15
0
 internal TransactionalCypherClient(string baseUri, string username, string password, IWebClient webClient, IWebSerializer serializer, IEntityCache entityCache)
 {
     _transactionUri = UriHelper.Combine(baseUri, "transaction/");
     _username       = username;
     _password       = password;
     _webClient      = webClient;
     _serializer     = serializer;
     _entityCache    = entityCache;
 }
Esempio n. 16
0
 public EventBasedEntityRepository(
     IEntityBuildersFactory entityBuildersFactory,
     IEntityCache entityCache,
     IEventRepository eventRepository)
 {
     _entityBuildersFactory = entityBuildersFactory;
     _entityCache           = entityCache;
     _eventRepository       = eventRepository;
 }
Esempio n. 17
0
        public static void RemoveWhere <TKey, TEntity>(this IEntityCache <TKey, TEntity> cache, Func <CachedEntity <TKey, TEntity>, bool> predicate)
        {
            IEnumerable <CachedEntity <TKey, TEntity> > selectedEntities = cache.Find(predicate);

            foreach (CachedEntity <TKey, TEntity> entity in selectedEntities)
            {
                cache.Remove(entity.Key);
            }
        }
Esempio n. 18
0
        public MongoUserDataStore(IMongoConnection databaseConnection, IOptionsMonitor <DatabaseOptions> databaseOptions, IHostApplicationLifetime hostLifetime, ILogger <MongoUserDataStore> log, IEntityCache <ulong, UserData> userDataCache, IOptionsMonitor <CachingOptions> cachingOptions)
            : base(databaseConnection, databaseOptions, hostLifetime, log)
        {
            this._userDataCache  = userDataCache;
            this._log            = log;
            this._cachingOptions = cachingOptions;

            base.MongoConnection.ClientChanged += OnClientChanged;
            OnClientChanged(base.MongoConnection.Client);
        }
Esempio n. 19
0
        public MongoCommunityGoalsHistoryStore(IMongoConnection databaseConnection, IOptionsMonitor <DatabaseOptions> databaseOptions, IHostApplicationLifetime hostLifetime, ILogger <MongoCommunityGoalsHistoryStore> log, IEntityCache <int, CommunityGoal> cgCache, IOptionsMonitor <CachingOptions> cachingOptions)
            : base(databaseConnection, databaseOptions, hostLifetime, log)
        {
            this._cgCache        = cgCache;
            this._log            = log;
            this._cachingOptions = cachingOptions;

            base.MongoConnection.ClientChanged += OnClientChanged;
            OnClientChanged(base.MongoConnection.Client);
        }
Esempio n. 20
0
 /// <summary>
 /// Constructor.  Accepts dependency injected services.
 /// </summary>
 /// <param name="context">Repository pattern db context.</param>
 /// <param name="cache">Redis cache wrapper.</param>
 public GuidInfosController(
     IGuidRepositoryContext context,
     IEntityCache <GuidInfoEntity> cache,
     ISystemClock clock
     )
 {
     _context = context;
     _cache   = cache;
     _clock   = clock;
 }
Esempio n. 21
0
        public MongoPatchbotGameStore(IMongoConnection databaseConnection, IOptionsMonitor <DatabaseOptions> databaseOptions, IHostApplicationLifetime hostLifetime, ILogger <MongoPatchbotGameStore> log, IEntityCache <string, PatchbotGame> patchbotGameCache, IOptionsMonitor <CachingOptions> cachingOptions)
            : base(databaseConnection, databaseOptions, hostLifetime, log)
        {
            this._patchbotGameCache = patchbotGameCache;
            this._log            = log;
            this._cachingOptions = cachingOptions;

            base.MongoConnection.ClientChanged += OnClientChanged;
            OnClientChanged(base.MongoConnection.Client);
        }
Esempio n. 22
0
        public MongoStellarisModsStore(IMongoConnection databaseConnection, IOptionsMonitor <DatabaseOptions> databaseOptions, IOptionsMonitor <CachingOptions> cachingOptions, ILogger <MongoStellarisModsStore> log, IEntityCache <ObjectId, StellarisMod> stellarisModsCache)
        {
            this._databaseConnection = databaseConnection;
            this._databaseOptions    = databaseOptions;
            this._cachingOptions     = cachingOptions;
            this._log = log;
            this._stellarisModsCache = stellarisModsCache;

            this._databaseConnection.ClientChanged += OnClientChanged;
        }
        public LocalCacheService(IConnectionMultiplexer connectionMultiplexer, IEntityCache <TEntity> entityCache, ILogger logger, IEntityCacheOptions redisConfiguration) : base(redisConfiguration)
        {
            _entityCache        = entityCache;
            _logger             = logger;
            _redisConfiguration = redisConfiguration;

            // Configure redis things
            ConnectionMultiplexer = connectionMultiplexer;
            Db = connectionMultiplexer.GetDatabase();
            SubscribtionChannel = new RedisChannel($"__keyspace@0__:{KeyPrefix}:*", RedisChannel.PatternMode.Pattern);
        }
Esempio n. 24
0
 public BreakSerializer(IAuditEventRepository auditEventRepository, IFeatureManager featureManager,
                        ISqlServerTenantDbContext dbContext,
                        IRepositoryFactory repositoryFactory, IConfiguration applicationConfiguration, IMapper mapper, IClock clock)
     : base(auditEventRepository, featureManager, repositoryFactory, applicationConfiguration, mapper, clock)
 {
     _dbContext      = dbContext;
     _mapper         = mapper;
     _salesAreaCache =
         new SqlServerEntityCache <Guid, SalesAreaEntity>(_dbContext, x => x.Id,
                                                          trackingChanges: false);
 }
Esempio n. 25
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);
        }
Esempio n. 26
0
        public MongoGameServerStore(IMongoConnection databaseConnection, ILogger <MongoGameServerStore> log, IEntityCache <string, GameServer> cache,
                                    IOptionsMonitor <DatabaseOptions> databaseOptions, IOptionsMonitor <CachingOptions> cachingOptions)
        {
            this._databaseConnection = databaseConnection;
            this._databaseOptions    = databaseOptions;
            this._cache          = cache;
            this._cachingOptions = cachingOptions;
            this._log            = log;

            this._databaseConnection.ClientChanged += OnClientChanged;
            this.OnClientChanged(this._databaseConnection.Client);
        }
Esempio n. 27
0
        public HomeViewModel(IEntityCache cache, ILocalStorage storage, 
            ILocationService locationService,
            ILocationTrackingSensor sensor)
        {
            _cache = cache;
            _storage = storage;
            _locationService = locationService;
            _sensor = sensor;
            Title = "Home";
            NextPageCommand = new Command(_nextPage);
            ShowNativeViewCommand = new Command(_onShowNativeView);

            RepeatersCommand = new Command(_onRepeaters);
        }
Esempio n. 28
0
        public virtual void RestoreFromStream(Stream stream)
        {
            Debug.Assert(stream.CanRead,
                         string.Format("stream \"{0}\" doesn't support Read operation", stream.GetType().FullName));

            BinaryFormatter bf = new BinaryFormatter();

            _cache = (EntityCache <T>)(bf.Deserialize(stream));

            // suppose we should call AfterEntitiesLoaded() or overload Save/RestoreFromStream()
            // for specific local services to implement custom client serialization
            // of fields that was marked as non-serialized for better remoting performance
            AfterEntitiesLoaded(_cache.GetAll());
        }
Esempio n. 29
0
        public HomeViewModel(IEntityCache cache, ILocalStorage storage,
                             ILocationService locationService,
                             ILocationTrackingSensor sensor)
        {
            _cache                = cache;
            _storage              = storage;
            _locationService      = locationService;
            _sensor               = sensor;
            Title                 = "Home";
            NextPageCommand       = new Command(_nextPage);
            ShowNativeViewCommand = new Command(_onShowNativeView);

            RepeatersCommand = new Command(_onRepeaters);
        }
        public SQLiteWorkDatabase(IEntityCache <IArtist> artistCache, IEntityCache <IWork> workCache)
            : base("alexandria", "Work")
        {
            if (artistCache == null)
            {
                throw new ArgumentNullException("artistCache");
            }
            if (workCache == null)
            {
                throw new ArgumentNullException("workCache");
            }

            this.artistCache = artistCache;
            this.workCache   = workCache;
        }
Esempio n. 31
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InteractionTransaction"/> class.
        /// </summary>
        /// <param name="channelMediumTypeValue">The channel medium type value.</param>
        /// <param name="channelEntity">The channel entity.</param>
        /// <param name="componentEntity">The component entity.</param>
        public InteractionTransaction(DefinedValueCache channelMediumTypeValue, IEntityCache channelEntity, IEntityCache componentEntity)
        {
            if (channelEntity == null || componentEntity == null)
            {
                _logInteraction = false;
                return;
            }

            _channelMediumTypeValue = channelMediumTypeValue;
            _channelEntityId        = channelEntity.Id;
            _channelName            = channelEntity.ToString();
            _componentEntityTypeId  = channelEntity.CachedEntityTypeId;
            _componentEntityId      = componentEntity.Id;
            _componentName          = componentEntity.ToString();

            Initialize();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InteractionTransaction" /> class.
        /// </summary>
        /// <param name="channelTypeMediumValue">The channel medium type value.</param>
        /// <param name="channelEntity">The channel entity.</param>
        /// <param name="componentEntityCache">The component entity cache.</param>
        /// <param name="info">The information about the <see cref="Interaction" /> object graph to be logged.
        /// In the case of conflicting values (i.e. channelEntity.Id vs info.ChannelEntityId), any values explicitly set on the <paramref name="info" /> parameter will take precedence.</param>
        public InteractionTransaction(DefinedValueCache channelTypeMediumValue, IEntityCache channelEntity, IEntityCache componentEntityCache, InteractionTransactionInfo info)
        {
            if (channelTypeMediumValue == null || componentEntityCache == null)
            {
                return;
            }

            if (info?.InteractionChannelId == default && channelEntity == null)
            {
                // we need either an InteractionChannelId or a channelEntity
                return;
            }

            // NOTE: Just in case this seem confusing, the EntityType of ChannelEntity tells us what the *component* entity type id is!
            var componentEntityTypeId = channelEntity?.CachedEntityTypeId;

            Initialize(channelTypeMediumValue.Id, channelEntity?.Id, channelEntity?.ToString(), componentEntityTypeId, componentEntityCache.Id, componentEntityCache.ToString(), info);
        }
        public EntityRepository(ILogger logger, IEntityCache<IArtist> artistCache, IEntityStore<IArtist> artistStore, IEntityCache<IWork> workCache, IEntityStore<IWork> workStore)
        {
            if (logger == null)
                throw new ArgumentNullException("logger");
            if (artistCache == null)
                throw new ArgumentNullException("artistCache");
            if (artistStore == null)
                throw new ArgumentNullException("artistStore");
            if (workCache == null)
                throw new ArgumentNullException("workCache");
            if (workStore == null)
                throw new ArgumentNullException("workStore");

            this.logger = logger;
            this.artistCache = artistCache;
            this.artistStore = artistStore;
            this.workCache = workCache;
            this.workStore = workStore;
        }
Esempio n. 34
0
        static void Main(string[] args)
        {
            logger = Log4NetLogger.GetDefaultLogger(typeof(Program));

            try
            {
                logger.Info("Ebla Started");

                Console.WriteLine("Ebla version 3.0.0.0");
                Console.WriteLine("Enter \"{0}\" for instructions", commandHelp);

                artistCache = new EntityCache<IArtist>();
                workCache = new EntityCache<IWork>();
                artistStore = new SQLiteArtistDatabase();
                workStore = new SQLiteWorkDatabase(artistCache, workCache);
                repository = new EntityRepository(logger, artistCache, artistStore, workCache, workStore);
                repository.Initialize();

                tagger = new Tagger();

                mediaFactory = new MediaFactory(logger);
                mediaImporter = new MediaImporter(logger, mediaFactory, repository, tagger);

                var exit = false;
                while (!exit)
                {
                    Console.Write(prompt);
                    exit = Execute(Console.ReadLine());
                }
            }
            catch (Exception ex)
            {
                logger.Error("Program.Main", ex);

                Console.WriteLine("ERROR");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.ReadLine();
            }
        }
Esempio n. 35
0
 public FindByIdCommand(Type entityType, int id, IEntityCache entityCache)
 {
     this.entityType = entityType;
     this.id = id;
     this.entityCache = (EntityCache) entityCache;
 }
 public GeneralSettingsService(IEntityCache entityCache)
 {
     _entityCache = entityCache;
 }
 public static RecognitionsViewModel FromDomain(IEntityCache<User> users, IEnumerable<UserAward> awards)
 {
     return new RecognitionsViewModel
                {
                    Recognitions = awards.OrderByDescending(x => x.Created.Date).Select(x => new Public.Controllers.UserAwardViewModel
                     {
                         Id = x.Document.Id,
                         Date = x.Created.Date,
                         Certificate = x.Certificate,
                         Message = x.Message,
                         Amount = x.Amount,
                         NominatorName = (users.TryGet(x.Nominator) ?? new User {Login = "******"}).DisplayName,
                         RecipientName = (users.TryGet(x.Recipient) ?? new User {Login = "******"}).DisplayName,
                     })
                };
 }