Beispiel #1
0
        static bool UpdateGameData(string gameId, IGameDataProvider gameDataProvider, bool forceUpdate = false)
        {
            if (!forceUpdate &&
                Games[gameId].LastDataUpdate.TryGetValue(gameDataProvider.GetGameDataType(), out DateTime lastUpdate) &&
                lastUpdate.AddDays(Settings.Default.MaxGameDataAge) > DateTime.Now)
            {
                return(false);
            }

            var oldData = Games[gameId].Data.SingleOrDefault(d => d.DataType == gameDataProvider.GetGameDataType());

            // add new data
            if (oldData == null)
            {
                var newData = gameDataProvider.GetGameData(Games[gameId].Title);
                if (newData != null)
                {
                    Games[gameId].Data = Games[gameId].Data.Concat(new GameData[] { newData }).ToArray();

                    // set last update to current time
                    Games[gameId].LastDataUpdate.AddOrUpdate(gameDataProvider.GetGameDataType(), DateTime.UtcNow, (id, oldValue) => DateTime.UtcNow);
                    return(true);
                }
            }
            else
            {
                // TODO merge new data with old
                //oldData.Merge(newData);

                Games[gameId].LastDataUpdate.AddOrUpdate(gameDataProvider.GetGameDataType(), DateTime.UtcNow, (id, oldValue) => DateTime.UtcNow);
            }

            return(false);
        }