예제 #1
0
        public int TryGetValue(IDbConnection connection, string systemName, IGDetailSystemLocalStorageCache cache)
        {
            _checkAndInit(connection, cache);
            int id;

            _storage.TryGetValue(systemName, out id);
            return(id);
        }
        public GGeometryPlanetService(IGGeometryPlanetRepository planetGeometryRepo,
                                      IGGeometryPlanetLocalStorageCache planetGeometryCache,
                                      IGDetailPlanetLocalStorageCache planetDetailCache, IGDetailSystemLocalStorageCache systemDetailCache)
        {
            _planetGeometryRepo  = planetGeometryRepo;
            _planetGeometryCache = planetGeometryCache;

            _planetDetailCache = planetDetailCache;
            _systemDetailCache = systemDetailCache;
        }
예제 #3
0
 private void _checkAndInit(IDbConnection connection, IGDetailSystemLocalStorageCache cache)
 {
     if (!Equals(_cache, cache))
     {
         _cache = cache;
     }
     if (_storage == null)
     {
         var systems = cache.LocalGetAll(connection);
         if (systems != null && systems.Any())
         {
             _storage = new ConcurrentDictionary <string, int>(systems.ToDictionary(i => i.Name, i => i.Id));
         }
         else
         {
             _storage = new ConcurrentDictionary <string, int>();
         }
     }
 }
예제 #4
0
        public Dictionary <string, int> TryFind(IDbConnection connection, string partName,
                                                IGDetailSystemLocalStorageCache cache)
        {
            if (string.IsNullOrWhiteSpace(partName))
            {
                throw new ArgumentNullException(Error.IsEmpty, nameof(partName));
            }
            var keys    = GetAllKeys(connection, cache);
            var contain = keys.Where(i => i.IndexOf(partName, StringComparison.OrdinalIgnoreCase) != -1).ToList();
            var result  = new Dictionary <string, int>();

            foreach (var i in contain)
            {
                int id;
                _storage.TryGetValue(i, out id);
                result.Add(i, id);
            }
            return(result);
        }
 public SystemService(IGDetailSystemRepository detailSystemRepo,
                      IGDetailSystemLocalStorageCache detailSystemCache, IGGeometryStarRepository geometryStarRepo,
                      IGGeometryStarLocalStorageCache geometryStarCache, IGGeometrySystemRepository geometrySystemRepo,
                      IGGeometrySystemLocalStorageCache geometrySystemCache, IGSystemRepository systemRepo,
                      IGSystemLocalStorageCache systemCache, ISystemNameSercherPkCache systemNameSercherPkCache,
                      IGGalaxyService galaxyService, IGSectorsService sectorsService)
 {
     _detailSystemRepo         = detailSystemRepo;
     _detailSystemCache        = detailSystemCache;
     _geometryStarRepo         = geometryStarRepo;
     _geometryStarCache        = geometryStarCache;
     _geometrySystemRepo       = geometrySystemRepo;
     _geometrySystemCache      = geometrySystemCache;
     _systemRepo               = systemRepo;
     _systemCache              = systemCache;
     _systemNameSercherPkCache = systemNameSercherPkCache;
     _galaxyService            = galaxyService;
     _sectorsService           = sectorsService;
 }
예제 #6
0
        public bool TryUpdateKey(IDbConnection connection, int systemId, string oldName, string newName,
                                 IGDetailSystemLocalStorageCache cache, bool updateParentCahce = true)
        {
            _checkAndInit(connection, cache);
            int id;

            if (!_storage.TryUpdateKey(oldName, newName, out id))
            {
                return(false);
            }
            if (!updateParentCahce)
            {
                return(true);
            }
            var user = cache.GetById(connection, id, true);

            user.Name = newName;
            var result = cache.UpdateLocalItem(connection, user);

            return(result.Name == newName);
        }
예제 #7
0
        public int GetOrAdd(IDbConnection connection, string systemName, IGDetailSystemLocalStorageCache cache)
        {
            var val = TryGetValue(connection, systemName, cache);

            if (val != 0)
            {
                return(val);
            }
            var cacheSystem = cache.LocalOperation(connection, col => col.FirstOrDefault(i => i.Name == systemName));

            if (cacheSystem != null && cacheSystem.Id != 0)
            {
                return(_storage.AddOrUpdateSimple(cacheSystem.Name, cacheSystem.Id));
            }
            var repo      = cache.GetRepository();
            var tableName = repo.SchemeTableName;
            var sql       = $"SELECT TOP(1) * FROM {tableName} WHERE name=@systemName";
            var system    = repo.Provider.Text <g_detail_system>(connection, sql, new { systemName }).Single();

            cache.UpdateLocalItem(connection, repo.ConvertToWorkModel(system));
            return(_storage.AddOrUpdateSimple(system.name, system.Id));
        }
예제 #8
0
 public Dictionary <string, int> GetAll(IDbConnection connection, IGDetailSystemLocalStorageCache cache)
 {
     _checkAndInit(connection, cache);
     return(_storage.Select(i => new { i.Key, i.Value }).ToDictionary(i => i.Key, i => i.Value));
 }
예제 #9
0
 public int AddOrUpdate(IDbConnection connection, string systemName, int systemId,
                        IGDetailSystemLocalStorageCache cache)
 {
     _checkAndInit(connection, cache);
     return(_storage.AddOrUpdateSimple(systemName, systemId));
 }
예제 #10
0
 public List <string> GetAllKeys(IDbConnection connection, IGDetailSystemLocalStorageCache cache)
 {
     _checkAndInit(connection, cache);
     return(_storage.Select(i => i.Key).ToList());
 }