Esempio n. 1
0
        /// <summary>
        /// Asynchronously downloads an image from the provided url.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="useCache">if set to <c>true</c> [use cache].</param>
        public static async Task <Image> GetImageAsync(Uri url, bool useCache = true)
        {
            DownloadResult <Image> result;

            // Cache not to be used ?
            if (!useCache)
            {
                result = await HttpWebClientService.DownloadImageAsync(url).ConfigureAwait(false);

                return(GetImage(result));
            }

            Image image = GetImageFromCache(GetCacheName(url));

            if (image != null)
            {
                return(image);
            }

            // Downloads the image and adds it to cache
            result = await HttpWebClientService.DownloadImageAsync(url).ConfigureAwait(false);

            image = GetImage(result);

            if (image != null)
            {
                await AddImageToCacheAsync(image, GetCacheName(url)).ConfigureAwait(false);
            }

            return(image);
        }
Esempio n. 2
0
        /// <summary>
        /// Tracks the event asynchronously.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="category">The category.</param>
        /// <param name="action">The action.</param>
        private static void TrackEventAsync(Type type, string category, string action)
        {
            InitEvent(type, category, action);

            // Sent notification
            if (NetworkMonitor.IsNetworkAvailable)
            {
                HttpWebClientService.DownloadImageAsync(new Uri(NetworkConstants.GoogleAnalyticsUrl),
                                                        new RequestParams(BuildQueryString())).ContinueWith(task =>
                {
                    if (EveMonClient.IsDebugBuild)
                    {
                        EveMonClient.Trace($"GAnalyticsTracker.TrackEventAsync - ({category} - {action})",
                                           printMethod: false);
                        if (task.Result.Error != null)
                        {
                            EveMonClient.Trace($"GAnalyticsTracker.TrackEventAsync - {task.Result.Error.Message}",
                                               printMethod: false);
                        }
                        else
                        {
                            EveMonClient.Trace($"GAnalyticsTracker.TrackEventAsync - in {TimeSpan.FromDays(1)}",
                                               printMethod: false);
                        }
                    }
                    Dispatcher.Schedule(TimeSpan.FromDays(1), () => TrackStart(type, DailyStartText));
                }, EveMonClient.CurrentSynchronizationContext);
            }
            else
            {
                // Reschedule later
                Dispatcher.Schedule(TimeSpan.FromMinutes(1), () => TrackEventAsync(type,
                                                                                   category, action));
                if (EveMonClient.IsDebugBuild)
                {
                    EveMonClient.Trace($"GAnalyticsTracker.TrackEventAsync - in {TimeSpan.FromMinutes(1)}",
                                       printMethod: false);
                }
            }
        }