public virtual async Task <IEnumerable <T> > GetItemsAsync(bool forceRefresh = false) { if (items == null || items.Count == 0) { items = await Connection.Table <T>().ToListAsync(); } if ((items.Count == 0 || forceRefresh) && CrossConnectivity.Current.IsConnected) { if (forceRefresh) { await Connection.DropTableAsync <T>(); await Connection.CreateTableAsync <T>(); } var ricerca = new DocsMarshal.Entities.ProfileSearch(); ricerca.sessionID = Manager.SessionId; ricerca.classTypeExternalId = ClassTypeExternalId; var risultato = await Manager.Profile.Search.Query.ExecuteAsync(ricerca); var ritorno = new List <T>(); foreach (var elemento in risultato.GetResultAsProfiles()) { ritorno.Add(Filler(elemento)); } foreach (var item in ritorno) { await Connection.InsertOrReplaceAsync(item); } items = await Connection.Table <T>().ToListAsync(); } return(items); }
protected virtual void SetDefaultSearchParams(DocsMarshal.Entities.ProfileSearch search) { search.sessionID = Orchestrator.SessionId; search.classTypeExternalId = ClassTypeExternalId; if (DomainOriented) { search.domainExternalId = GetCurrentDomainExternalId(); } }
protected virtual async Task <IEnumerable <T> > GetItemsAsync(DocsMarshal.Entities.ProfileSearch ricerca, bool forceRefresh = false, bool useCache = true) { var connection = GetConnection(); var isConnected = IsDeviceConnectedToInternet(); // force a refresh if the cache expired if (useCache && isConnected && !forceRefresh) { var lastUpdate = GetLastUpdate(); forceRefresh = !lastUpdate.HasValue || ShouldRefreshCache(lastUpdate.Value); #if DEBUG System.Diagnostics.Debug.WriteLine($"CACHE {(forceRefresh ? "MISS" : "HIT")} - {GetCacheKey()} - Last Update {(lastUpdate == null ? "NULL" : lastUpdate.Value.ToString("dd/MM/yyyy HH:mm:ss"))}"); #endif } if (useCache && (!forceRefresh || !isConnected)) { return(await connection.Table <T>().ToListAsync()); } if (!isConnected) { throw new Exception("Could not execute search because the device is disconnected"); } if (ricerca == null) { ricerca = new Entities.ProfileSearch(); } SetDefaultSearchParams(ricerca); var risultato = await Orchestrator.Profile.Search.Query.ExecuteAsync(ricerca); var ritorno = new List <T>(); foreach (var elemento in risultato.GetResultAsProfiles()) { ritorno.Add(FromProfileToEntity(elemento)); } if (useCache) { await EmptyTable(connection, typeof(T)); await connection.InsertAllAsync(ritorno); SetLastUpdate(DateTime.Now); } return(ritorno); }