Example #1
0
 public CachedFile([NotNull] FileInfo backingFile, bool? requireToExistAlready = null)
 {
     _backingFile = backingFile;
     if (!_backingFile.Exists)
     {
         if (requireToExistAlready == true)
             throw new FileNotFoundException("Data file not found.", _backingFile.FullName);
         _backingFile.CreateText().Close();
     }
     else if (requireToExistAlready == false)
     {
         throw new FileNotFoundException("Expected to create new data file, but file already exists.", _backingFile.FullName);
     }
     _dataState = _DataState.FileIsCanonical;
 }
Example #2
0
 private string _EnsureMemoryCacheIsUpToDate()
 {
     lock (_fileLock)
     {
         if (_dataState != _DataState.FileIsCanonical)
         {
             return(_cachedValue);
         }
         using (var reader = _backingFile.OpenText())
         {
             _cachedValue = reader.ReadToEnd();
         }
         _dataState = _DataState.Synchronized;
         return(_cachedValue);
     }
 }
Example #3
0
 public CachedFile([NotNull] FileInfo backingFile, bool?requireToExistAlready = null)
 {
     _backingFile = backingFile;
     if (!_backingFile.Exists)
     {
         if (requireToExistAlready == true)
         {
             throw new FileNotFoundException("Data file not found.", _backingFile.FullName);
         }
         _backingFile.CreateText().Close();
     }
     else if (requireToExistAlready == false)
     {
         throw new FileNotFoundException("Expected to create new data file, but file already exists.", _backingFile.FullName);
     }
     _dataState = _DataState.FileIsCanonical;
 }
Example #4
0
 private string _EnsureMemoryCacheIsUpToDate()
 {
     lock (_fileLock)
     {
         if (_dataState != _DataState.FileIsCanonical)
             return _cachedValue;
         using (var reader = _backingFile.OpenText())
         {
             _cachedValue = reader.ReadToEnd();
         }
         _dataState = _DataState.Synchronized;
         return _cachedValue;
     }
 }