Exemple #1
0
        private static void LoadCache()
        {
            lock (entriesCacheLock)
            {
                entriesCache = new List <DiaryEntry>();

                var filePaths = Directory.GetFiles(BaseFilePath);
                foreach (var filePath in filePaths)
                {
                    var diaryEntryFile = new DiaryEntryFile(filePath);
                    entriesCache.Add(diaryEntryFile.GetDiaryEntry());
                }
            }
        }
Exemple #2
0
        public void Delete([FromBody] int entryId)
        {
            lock (entriesCacheLock)
            {
                var existingEntry = EntriesCache.FirstOrDefault(e => e.Id == entryId);
                if (existingEntry != null)
                {
                    EntriesCache.Remove(existingEntry);

                    var existingFilePath = CombinePaths(BaseFilePath, DiaryEntryFile.CreateFileName(existingEntry));
                    if (File.Exists(existingFilePath))
                    {
                        File.Delete(existingFilePath);
                    }
                }
            }
        }
Exemple #3
0
        public void Post([FromBody] DiaryEntry entry)
        {
            lock (entriesCacheLock)
            {
                var existingEntry = EntriesCache.FirstOrDefault(e => e.Id == entry.Id);
                if (existingEntry != null)
                {
                    EntriesCache.Remove(existingEntry);
                    var existingFilePath = CombinePaths(BaseFilePath, DiaryEntryFile.CreateFileName(existingEntry));
                    if (File.Exists(existingFilePath))
                    {
                        File.Delete(existingFilePath);
                    }
                }

                Directory.CreateDirectory(BaseFilePath);

                var diaryEntryFile = new DiaryEntryFile(CombinePaths(BaseFilePath, DiaryEntryFile.CreateFileName(entry)));
                diaryEntryFile.SaveDiaryEntry(entry);

                EntriesCache.Add(entry);
            }
        }