本文整理汇总了C#中IDataService.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IDataService.GetType方法的具体用法?C# IDataService.GetType怎么用?C# IDataService.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataService
的用法示例。
在下文中一共展示了IDataService.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadDataService
private async Task LoadDataService(IDataService dataService, bool overrideCache = false)
{
List<Item> currentItems = new List<Item>();
bool loadedFromCache = false;
if (fileStore != null)
{
string lastRefreshText;
if (fileStore.TryReadTextFile("LastRefresh-" + dataService.GetType().ToString(), out lastRefreshText))
{
var lastRefreshTime = DateTime.Parse(lastRefreshText);
var timeSinceLastRefreshInMinutes = (DateTime.Now - lastRefreshTime).TotalMinutes;
//has cache expired?
if (overrideCache || timeSinceLastRefreshInMinutes > AppSettings.CacheIntervalInMinutes)
{
currentItems = await dataService.GetItems();
}
else //load from cache
{
string cachedItemsText;
pool.WaitOne();
try
{
if (fileStore.TryReadTextFile("CachedItems-" + dataService.GetType().ToString(), out cachedItemsText))
{
currentItems = mvxJsonConverter.DeserializeObject<List<Item>>(cachedItemsText);
loadedFromCache = true;
}
}
catch
{
ServiceLocator.MessageService.ShowErrorAsync("Error Deserializing " + dataService.GetType().ToString(), "Error loading cache");
}
finally
{
pool.Release();
}
}
}
else
{
currentItems = await dataService.GetItems();
}
}
try
{
if (!loadedFromCache && currentItems.Count > 0)
{
if (fileStore.Exists("CachedItems-" + dataService.GetType().ToString()))
fileStore.DeleteFile("CachedItems-" + dataService.GetType().ToString());
if (fileStore.Exists("LastRefresh-" + dataService.GetType().ToString()))
fileStore.DeleteFile("LastRefresh-" + dataService.GetType().ToString());
fileStore.WriteFile("CachedItems-" + dataService.GetType().ToString(), mvxJsonConverter.SerializeObject(currentItems));
fileStore.WriteFile("LastRefresh-" + dataService.GetType().ToString(), DateTime.Now.ToString());
}
items.AddRange(currentItems);
}
catch
{
ServiceLocator.MessageService.ShowErrorAsync("Error retrieving items from " + dataService.GetType().ToString() + "\n\nPossible Causes:\nNo internet connection\nRemote Service unavailable", "Application Error");
}
}