public static EventState Create(IStoreProvider storeProvider, ISettings settings) { var savedEvents = new ConcurrentDictionary <string, FixtureState>(); SetFilePath(settings); try { _logger.InfoFormat("Attempting to load file from filePath {0}", PathFileName); var savedEventStates = storeProvider.Read(PathFileName); if (savedEventStates == null) { savedEvents = new ConcurrentDictionary <string, FixtureState>(); } else { savedEvents = (ConcurrentDictionary <string, FixtureState>) JsonConvert.DeserializeObject(savedEventStates, typeof(ConcurrentDictionary <string, FixtureState>)); } } catch (FileNotFoundException) { savedEvents = new ConcurrentDictionary <string, FixtureState>(); } catch (JsonSerializationException jse) { _logger.ErrorFormat("Error during state deserialization {0}. The state file will be removed!", jse); DeleteState(); } var eventState = new EventState(storeProvider) { Events = savedEvents }; return(eventState); }
public static EventState Create(IStoreProvider storeProvider, ISettings settings) { var savedEvents = new ConcurrentDictionary<string, FixtureState>(); SetFilePath(settings); try { _logger.InfoFormat("Attempting to load file from filePath {0}", PathFileName); var savedEventStates = storeProvider.Read(PathFileName); if (savedEventStates == null) { savedEvents = new ConcurrentDictionary<string, FixtureState>(); } else { savedEvents = (ConcurrentDictionary<string, FixtureState>) JsonConvert.DeserializeObject(savedEventStates, typeof(ConcurrentDictionary<string, FixtureState>)); } } catch (FileNotFoundException) { savedEvents = new ConcurrentDictionary<string, FixtureState>(); } catch (JsonSerializationException jse) { _logger.ErrorFormat("Error during state deserialization {0}. The state file will be removed!", jse); DeleteState(); } var eventState = new EventState(storeProvider) { Events = savedEvents }; return eventState; }