public void Flush() { try { lock (PadLock) { string[] keys = CachedFiles.Keys.ToArray(); foreach (string key in keys) { CachedFile cachedFile = CachedFiles[key]; if (!cachedFile.Flushed) { FileIO.CreateDirectory(Path.GetDirectoryName(cachedFile.FileName)); FileIO.WriteFile(cachedFile.FileName, cachedFile.MemoryStream.ToArray()); cachedFile.Flushed = true; } if (!cachedFile.Permanent && DateTime.Now.Subtract(cachedFile.LastAccessed).TotalHours > 24) { CachedFiles.Remove(key); } } } } catch { GlobalReference.GlobalValues.Logger.Log(Logging.LogSettings.LogLevel.INFO, "File system is down"); } }
private void AppendStream(CachedFile cachedFile, byte[] dataToWrite) { //we are already locked from the calling method cachedFile.LastAccessed = DateTime.Now; cachedFile.Flushed = false; cachedFile.MemoryStream.Seek(0, SeekOrigin.End); cachedFile.MemoryStream.Write(dataToWrite, 0, dataToWrite.Length); }
private void WriteStream(string fileName, byte[] dataToWrite) { CachedFile cachedFile = GetStream(fileName); lock (cachedFile) { cachedFile.MemoryStream = new MemoryStream(); AppendStream(cachedFile, dataToWrite); } }
private void AppendStream(string fileName, byte[] dataToWrite) { CachedFile cachedFile = GetStream(fileName); lock (cachedFile) { if (cachedFile.MemoryStream == null) { cachedFile.MemoryStream = LoadFromFile(fileName); } AppendStream(cachedFile, dataToWrite); } }
private byte[] ReadStream(string fileName) { CachedFile cachedFile = GetStream(fileName); lock (cachedFile) { if (cachedFile.MemoryStream == null) { cachedFile.MemoryStream = LoadFromFile(fileName); } cachedFile.LastAccessed = DateTime.Now; return(cachedFile.MemoryStream.ToArray()); } }
private CachedFile GetStream(string fileName) { CachedFile cachedFile = null; lock (PadLock) { CachedFiles.TryGetValue(fileName, out cachedFile); if (cachedFile == null) { cachedFile = new CachedFile(fileName, IsPermanent(fileName)); CachedFiles.Add(fileName, cachedFile); } } return(cachedFile); }