Esempio n. 1
0
        public UIElement LoadBanner(BannerDefinition banner)
        {
            var baseName  = PathSafe.Combine(_fileCache.CacheDirectory, $"{banner.BundleId}-v{banner.Version}");
            var filename  = baseName + ".zip";
            var directory = baseName + "-extracted";

            if (!DirectoryContainsBanner(directory, banner))
            {
                ExtractZipFile(filename, directory);
            }

            FrameworkElement bannerControl;

            switch (banner.BundleType)
            {
            case BundleType.Xaml:
                bannerControl = LoadXamlBanner(banner, directory);
                break;

            case BundleType.Image:
                bannerControl = LoadImageBanner(banner, directory);
                break;

            default: throw new Exception("Unknown banner type!");
            }

            WpfHelper.RegisterOpen(bannerControl, url => HandleClick(banner, url));
            var loadOnce = new LoadOnceHandler();

            bannerControl.Loaded += (sender, args) => HandleLoaded(banner, loadOnce);

            return(bannerControl);
        }
Esempio n. 2
0
        private void HandleLoaded(BannerDefinition banner, LoadOnceHandler loadOnce)
        {
            if (loadOnce.IsLoaded)
            {
                return;
            }

            try
            {
                loadOnce.IsLoaded = true;
                var metric = _bannerMetricFactory.BuildMetric(banner, BannerMetricType.Impression);
                _usageStatisticsSender.SendAsync(metric);
            }
            catch { }
        }