예제 #1
0
        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");
            }
        }
예제 #2
0
 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);
 }
예제 #3
0
        private void WriteStream(string fileName, byte[] dataToWrite)
        {
            CachedFile cachedFile = GetStream(fileName);

            lock (cachedFile)
            {
                cachedFile.MemoryStream = new MemoryStream();
                AppendStream(cachedFile, dataToWrite);
            }
        }
예제 #4
0
        private void AppendStream(string fileName, byte[] dataToWrite)
        {
            CachedFile cachedFile = GetStream(fileName);

            lock (cachedFile)
            {
                if (cachedFile.MemoryStream == null)
                {
                    cachedFile.MemoryStream = LoadFromFile(fileName);
                }

                AppendStream(cachedFile, dataToWrite);
            }
        }
예제 #5
0
        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());
            }
        }
예제 #6
0
        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);
        }