/// <summary>
        /// Find is getting data from remote (redis) storage. After this
        /// it writes updated version of data into locaL (litedb) storage
        /// </summary>
        /// <param name="key"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        private T Find <T>(string key)
        {
            var liteDbService = new LiteDbService();
            var dynamicConfig = new DynamicConfig
            {
                ApplicationName = ApplicationName,
                Name            = key,
                IsActive        = 1
            };

            var configurationReaderFactory = new ConfigurationServiceFactory();
            var reader = configurationReaderFactory.ProduceReader("Redis", ConnectionString);

            var redisResult = reader.Read <DynamicConfig>(dynamicConfig);

            // If redis result fits with requested data type
            if (redisResult?.Value is T)
            {
                liteDbService.RemoveConfig(key);
                liteDbService.AddConfig(redisResult);
                return((T)Convert.ChangeType(redisResult.Value, typeof(T)));
            }

            return(default(T));
        }
Ejemplo n.º 2
0
        protected override IGetCacheVersionService RealCreate()
        {
            IConfigurationService  configurationService   = ConfigurationServiceFactory.Get();
            GetCacheVersionService getCacheVersionService = new GetCacheVersionService(configurationService);

            return(getCacheVersionService);
        }
Ejemplo n.º 3
0
        protected override IWorkflowContextService RealCreate()
        {
            var paUserRepository     = PAUserRepositoryFactory.Get();
            var configurationService = ConfigurationServiceFactory.Get();
            WorkflowContextService workflowContextService = new WorkflowContextService(configurationService, paUserRepository);

            return(workflowContextService);
        }
Ejemplo n.º 4
0
        protected override IPluginContextService RealCreate()
        {
            var paUserRepository     = PAUserRepositoryFactory.Get();
            var configurationService = ConfigurationServiceFactory.Get();
            PluginContextService pluginContextService = new PluginContextService(configurationService, paUserRepository);

            return(pluginContextService);
        }
Ejemplo n.º 5
0
        protected override ILanguageTranslateService RealCreate()
        {
            //throw new Exception();
            IPAWebResourceRepository paWebResourceRepository  = PAWebResourceRepositoryFactory.Get();
            IConfigurationService    configurationService     = ConfigurationServiceFactory.Get();
            LanguageTranslateService languageTranslateService = new LanguageTranslateService(paWebResourceRepository, configurationService);

            return(languageTranslateService);
        }
Ejemplo n.º 6
0
        public IEnumerable <string> GetConnectionStrings()
        {
            ConfigurationService configurationService = ConfigurationServiceFactory.InitializeConfigurationService();

            var allConnectionsStrings = new List <string>();

            foreach (ConnectionInfo connectionInfo in configurationService.GetConnections())
            {
                if (connectionInfo.Name.Contains("connectionString"))
                {
                    allConnectionsStrings.Add(connectionInfo.ConnectionString);
                }
            }
            return(allConnectionsStrings);
        }
        /// <summary>
        /// ConfigJob is the definition of scheduled job of worker.
        /// It's comparing local (litedb) data with remote (redis) storage data. Also it's
        /// making neccessary updates on local.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="refreshTimerIntervalInMs"></param>
        /// <returns></returns>
        private async Task <bool> ConfigJob(string key, TimeSpan refreshTimerIntervalInMs)
        {
            var isCancelled = _cancellationToken.IsCancellationRequested;

            // if task not cancelled
            if (!isCancelled)
            {
                await Task.Delay(refreshTimerIntervalInMs, _cancellationToken);

                var liteDbService = new LiteDbService();
                var dynamicConfig = new DynamicConfig
                {
                    ApplicationName = ApplicationName,
                    Name            = key,
                    IsActive        = 1
                };

                var configurationReaderFactory = new ConfigurationServiceFactory();
                var reader = configurationReaderFactory.ProduceReader("Redis", ConnectionString);

                var redisResult  = reader.Read <DynamicConfig>(dynamicConfig);
                var liteDbResult = liteDbService.GetConfig(key);

                if (redisResult != null && liteDbResult != null)
                {
                    // Comparing data changes
                    if (redisResult.Value != liteDbResult.Value)
                    {
                        liteDbService.RemoveConfig(key);
                        liteDbService.AddConfig(redisResult);
                        return(true);
                    }
                }
            }

            return(false);
        }