public override Target this[string id]
        {
            get
            {
                Target target = null;
                if (_plusTree == null)
                {
                    return(target);
                }
                if (_targetCache != null)
                {
                    target = _targetCache[id];
                    if (target != null)
                    {
                        return(target);
                    }
                }

                if (_plusTree.ContainsKey(id))
                {
                    target = (Target)_plusTree[id];
                    if (target != null && _targetCache != null)
                    {
                        _targetCache.Add(target);
                    }
                }

                return(target);
            }
        }
Esempio n. 2
0
 public object this[string key]
 {
     get
     {
         if (treeCache.ContainsKey(key))
         {
             return(treeCache[key]);
         }
         return(null);
     }
     set
     {
         treeCache[key] = value;
         SaveCache();
     }
 }
        private void Initialize(string workingDir, bool createNotFound)
        {
            if (String.IsNullOrEmpty(workingDir))
            {
                throw new InvalidOperationException();
            }

            if (!Directory.Exists(workingDir))
            {
                Directory.CreateDirectory(workingDir);
            }
            if (_isSystem)
            {
                _treeFileName  = Path.Combine(workingDir, "SLinkT2.6.10621.1.dat");
                _blockFileName = Path.Combine(workingDir, "SLinkB2.6.10621.1.dat");
            }
            else
            {
                string tempFile = Path.GetFileNameWithoutExtension(
                    Path.GetTempFileName());

                _treeFileName  = Path.Combine(workingDir, tempFile + "Tree.dat");
                _blockFileName = Path.Combine(workingDir, tempFile + "Block.dat");
            }

            if (File.Exists(_treeFileName) && File.Exists(_blockFileName))
            {
                _isExisted = true;
                _plusTree  = SerializedTree.ReOpen(_treeFileName, _blockFileName);
                if (_plusTree.ContainsKey("$DataCount$"))
                {
                    _count = Convert.ToInt32(_plusTree["$DataCount$"]);
                }
            }
            else
            {
                _count = 0;
                if (createNotFound)
                {
                    _plusTree = SerializedTree.Initialize(_treeFileName,
                                                          _blockFileName, 64);
                }
            }

            if (_plusTree != null)
            {
                _targetCache = new DatabaseTargetCache(100);
            }
        }
Esempio n. 4
0
 public bool Contains(string key)
 {
     return(_treeCache.ContainsKey(key));
 }