/// <summary> /// The method deserializes all the files in the path and returns a list of the generic typed objects. /// </summary> /// <param name="path"> /// The path where the persisted objects are located. /// </param> /// <returns> /// A list of the generic typed objects /// </returns> public static IList <T> GetAllPersistedObjects(string path) { var listOfObjects = new List <T>(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var directory = new DirectoryInfo(path); var fileInfos = directory.GetFiles().OrderBy(f => f.LastWriteTime); foreach (var file in fileInfos) { try { var persistedObject = PersistenceHelp <T> .Load(file.FullName); listOfObjects.Add(persistedObject); } catch (Exception ex) { var msg = string.Format("Cannot Load '{0}'. Reason: {1}", file.Name, ex.Message); // TODO: Log the exception when we integrate with the logger. } } return(listOfObjects); }
/// <summary> /// Retrieves an object instance. This is static so that we don't have to /// create the object, call this method, and then assign it. /// </summary> /// <param name="folder"> /// The folder. /// </param> /// <param name="key"> /// The key. /// </param> /// <param name="namespaceToIgnore"> /// This is used when we need to ignore the namespace (e.g. the namespace was changed from version /// to version). /// </param> /// <returns> /// Instance referenced by the key. Null if the object is not found. /// In case of errors, the exception is logged /// by the <see cref="PersistenceHelp{T}"/>. /// </returns> public static T Retrieve(string folder, string key, string namespaceToIgnore) { return(PersistenceHelp <T> .Load(GetFilePath(folder, key), namespaceToIgnore)); }
/// <summary> /// Retrieves an object instance. This is static so that we don't have to /// create the object, call this method, and then assign it. /// </summary> /// <param name="folder"> /// Folder where the persisted objects are located. /// </param> /// <param name="key"> /// Key to retrieve the object. /// </param> /// <returns> /// Instance referenced by the key. Null if the object is not found. /// In case of errors, the exception is logged /// by the <see cref="PersistenceHelp{T}"/>. /// </returns> public static T Retrieve(string folder, string key) { return(PersistenceHelp <T> .Load(GetFilePath(folder, key))); }