/// <summary> /// Given a query and an update date, check if the query info is current. /// </summary> /// <param name="queryId"></param> /// <param name="dateLastModified"></param> /// <param name="dateUpdated"></param> /// <returns>Unknown/Invalid/UpToDate</returns> static public DataUpdateStatus CheckDataStatus(string queryId, DateTime dateLastModified, out DateTime dateUpdated) { dateUpdated = GxContext.StartupDate; // by default the data is as old as the startup moment of the app if (enabled) { if (!QueryTables.ContainsKey(queryId)) // There is no table definition for the query -> status unknown { return(DataUpdateStatus.Unknown); } ICacheService2 updatedTablesBulk = updatedTables as ICacheService2; IDictionary <string, DateTime> dateUpdates; List <string> qTables = QueryTables[queryId]; if (updatedTablesBulk != null) { dateUpdates = updatedTablesBulk.GetAll <DateTime>(CacheFactory.CACHE_SD, qTables); //Value is Date.MinValue for non-existing key in cache } else { dateUpdates = new Dictionary <string, DateTime>(); foreach (string tbl in qTables) { if (updatedTables.Get <DateTime>(CacheFactory.CACHE_SD, tbl, out DateTime tblDt)) { dateUpdates[tbl] = tblDt; } } } DateTime maxDateUpdated = dateUpdates.Values.Max(); //Get the newest modification date. if (maxDateUpdated > dateUpdated) { dateUpdated = maxDateUpdated; } if (dateUpdated > dateLastModified) // If any of the query tables were modified -> the status of the info is INVALID, you have to refresh { return(DataUpdateStatus.Invalid); } return(DataUpdateStatus.UpToDate); } else { return(DataUpdateStatus.Unknown); } }
/// <summary> /// Commit of updated data. The tables modified so far are registered with the commit timestamp. /// </summary> public void ReccordUpdates() { if (enabled && tablesUpdatedInUTL.Count > 0) { DateTime dt = DateTime.Now.ToUniversalTime(); dt = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, DateTimeKind.Utc); ICacheService2 updatedTablesBulk = updatedTables as ICacheService2; if (updatedTablesBulk != null) { updatedTablesBulk.SetAll(CacheFactory.CACHE_SD, tablesUpdatedInUTL.Select(tbl => NormalizeKey(tbl)), Enumerable.Repeat(dt, tablesUpdatedInUTL.Count)); } else { foreach (string tbl in tablesUpdatedInUTL) { updatedTables.Set(CacheFactory.CACHE_SD, NormalizeKey(tbl), dt); } } tablesUpdatedInUTL.Clear(); } }