/// <summary> /// Reads all of the data files in the configured folder into memory. /// This can be expensive, but it's only called when the repository is created. /// </summary> private void InitializeDictionary() { IFileInfo[] entityDataFiles = GetDataFileInfoList(); foreach (var entityDataFile in entityDataFiles) { int idValue; string fileContents = _fileFacade.ReadTextFile(entityDataFile.FullName); Match fileNameWithLargestId = _dataFileNamePattern.Match(entityDataFile.Name); int.TryParse(fileNameWithLargestId.Groups[1].Value, out idValue); var jsonEntity = new JsonEntity <T>(idValue); jsonEntity.JsonData = fileContents; _context[idValue] = jsonEntity; } }
/// <summary> /// Operation to create a new instance of T /// </summary> /// <returns>The newly-created item</returns> /// <remarks> /// This method does not add an item to the repository by default /// </remarks> public IJsonEntity <T> Create() { JsonEntity <T> entity; _readWriteLock.EnterWriteLock(); try { entity = new JsonEntity <T>(_nextId); _nextId++; } finally { _readWriteLock.ExitWriteLock(); } return(entity); }