예제 #1
0
        private async Task RebuildStaticDataAsync()
        {
            if (!Network.HasInternetConnection || await EveUtils.GetServerStatusAsync() != EveServerStatus.Online)
            {
                throw new EveServersOfflineException("Not connected to the internet or Eve servers are offline.");
            }

            await this.RebuildRegionsAndSolarSystems();

            await this.RebuildRefTypeItem();

            this.solarSystemCache = null;
            this.regionCache      = null;
            this.refTypeItemCache = null;
        }
예제 #2
0
        public async Task UpdateStaticDataAsync(bool force = false)
        {
            if (force)
            {
                await this.RebuildStaticDataAsync();

                return;
            }

            await this.LoadCache();

            var myVersion     = (await Serializer.DeserializeAsync <ServerVersion>("ServerVersion"))?.Version;
            var serverVersion = await EveUtils.GetServerVersionAsync();

            if (myVersion != serverVersion || this.CacheRebuildRequired)
            {
                await this.RebuildStaticDataAsync();

                await Serializer.SerializeAsync(new ServerVersion { Version = serverVersion }, "ServerVersion");
            }
        }
예제 #3
0
        public async Task <byte[]> GetImageAsync(ImageType type, long id, double daysToCache = 1, int imageSize = 256)
        {
            var filename = string.Format("{0}_{1}_{2}.png", type, id, imageSize);

            if (imageCache.ContainsKey(filename))
            {
                return(imageCache[filename]);
            }

            var folder       = ApplicationData.Current.TemporaryFolder;
            var serverStatus = await EveUtils.GetServerStatusAsync();

            byte[] data = null;

            if (await folder.ExistsAsync(filename))
            {
                var file = await folder.GetFileAsync(filename);

                if ((await file.GetDateModifiedAsync()).AddDays(daysToCache) < DateTime.Now && Network.HasInternetConnection && serverStatus == EveServerStatus.Online)
                {
                    await file.DeleteAsync();
                }
                else
                {
                    data = await(await folder.GetFileAsync(filename)).ReadBytesAsync();
                }
            }

            if (data == null)
            {
                if (!await folder.ExistsAsync(filename) && Network.HasInternetConnection && serverStatus == EveServerStatus.Online)
                {
                    string url = string.Empty;

                    switch (type)
                    {
                    case ImageType.Alliance:
                        url = this.Server.ImageAllianceUrl;
                        break;

                    case ImageType.Character:
                        url = this.Server.ImageCharacterUrl;
                        break;

                    case ImageType.Corporation:
                        url = this.Server.ImageCorpUrl;
                        break;

                    case ImageType.Item:
                        url = this.Server.ImageItemUrl;
                        break;
                    }

                    await GetAndSaveImageAsync(string.Format(url, id, imageSize), filename);

                    data = await(await folder.GetFileAsync(filename)).ReadBytesAsync();
                }
                else if (!await folder.ExistsAsync(filename))
                {
                    return(null);
                }
            }

            if (data != null)
            {
                imageCache.TryAdd(filename, data);
            }

            return(data);
        }