当前位置: 首页>>代码示例>>C#>>正文


C# IDataService.GetType方法代码示例

本文整理汇总了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");
            }

        }
开发者ID:jbienzms,项目名称:XPlatformCloudKit,代码行数:69,代码来源:ItemsShowcaseViewModel.cs


注:本文中的IDataService.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。