Exemplo n.º 1
0
    public void Set(byte[] value, string id, string version = null)
    {
        string path = _cachePath + "/" + id;

        if (!Has(id) || !_fileSystem.FileExists(path) || !MatchesVersion(id, version))
        {
            SaveFile(path, value);
        }

        _cacheEntries[id] = new FileCacheEntry(id, version, path, DateTime.Now.ToString(DATE_FORMAT));
    }
Exemplo n.º 2
0
    private void DeleteFile(FileCacheEntry ce)
    {
        if (ce.Data == null)
        {
            return;
        }

        string path = ce.Data;

        if (_fileSystem.FileExists(path))
        {
            _fileSystem.DeleteFile(path);
        }
    }
Exemplo n.º 3
0
            private void StartWatcher(FileCache cache, string path, string filter)
            {
                FileCacheEntry entry = this;

                // Initialize a new filesystem watcher
                _watcher.Created += (sender, e) => OnCreated(sender, e, cache, entry);
                _watcher.Changed += (sender, e) => OnChanged(sender, e, cache, entry);
                _watcher.Deleted += (sender, e) => OnDeleted(sender, e, cache, entry);
                _watcher.Renamed += (sender, e) => OnRenamed(sender, e, cache, entry);
                _watcher.Path     = path;
                _watcher.IncludeSubdirectories = true;
                _watcher.Filter              = filter;
                _watcher.NotifyFilter        = NotifyFilters.FileName | NotifyFilters.LastWrite;
                _watcher.EnableRaisingEvents = true;
            }
Exemplo n.º 4
0
            private static void OnRenamed(object sender, RenamedEventArgs e, FileCache cache, FileCacheEntry entry)
            {
                var oldKey  = e.OldFullPath.Replace(entry._path, entry._prefix);
                var oldFile = e.OldFullPath;
                var newKey  = e.FullPath.Replace(entry._path, entry._prefix);
                var newFile = e.FullPath;

                // Skip missing files
                if (!File.Exists(newFile))
                {
                    return;
                }
                // Skip directory updates
                if (IsDirectory(newFile))
                {
                    return;
                }

                cache.RemoveFileInternal(entry._path, oldKey);
                cache.InsertFileInternal(entry._path, newFile, newKey, entry._timespan, entry._handler);
            }
Exemplo n.º 5
0
            private static void OnDeleted(object sender, FileSystemEventArgs e, FileCache cache, FileCacheEntry entry)
            {
                var key  = e.FullPath.Replace(entry._path, entry._prefix);
                var file = e.FullPath;

                cache.RemoveFileInternal(entry._path, key);
            }
Exemplo n.º 6
0
            private static void OnChanged(object sender, FileSystemEventArgs e, FileCache cache, FileCacheEntry entry)
            {
                if (e.ChangeType != WatcherChangeTypes.Changed)
                {
                    return;
                }

                var key  = e.FullPath.Replace(entry._path, entry._prefix);
                var file = e.FullPath;

                // Skip missing files
                if (!File.Exists(file))
                {
                    return;
                }
                // Skip directory updates
                if (IsDirectory(file))
                {
                    return;
                }

                cache.InsertFileInternal(entry._path, file, key, entry._timespan, entry._handler);
            }
Exemplo n.º 7
0
 private DateTime GetEntryLastUseDate(FileCacheEntry entry)
 {
     return(DateTime.ParseExact(entry.LastUseDate, DATE_FORMAT, null));
 }