Exemplo n.º 1
0
        internal static void GetAdDescriptorBasedOnUICulture(this AdSettings adsettings, string culture)
        {
            if (String.IsNullOrEmpty(culture))
            {
                culture = GlobalConfig.DEFAULT_CULTURE;
            }
            var cultureShortName = culture.Substring(0, 2);
            var descriptor       = adsettings.CultureDescriptors.Where(x => x.CultureName == culture).FirstOrDefault();

            if (descriptor != null)
            {
                adsettings.CurrentCulture = descriptor;
                return;
            }
            var sameLanguageDescriptor = adsettings.CultureDescriptors.Where(x => x.CultureName.StartsWith(cultureShortName)).FirstOrDefault();

            if (sameLanguageDescriptor != null)
            {
                adsettings.CurrentCulture = sameLanguageDescriptor;
                return;
            }
            var defaultDescriptor = adsettings.CultureDescriptors.Where(x => x.CultureName.ToLower() == GlobalConfig.DEFAULT_CULTURE || string.IsNullOrEmpty(x.CultureName)).FirstOrDefault();

            if (defaultDescriptor != null)
            {
                adsettings.CurrentCulture = defaultDescriptor;
                return;
            }
        }
Exemplo n.º 2
0
 internal static void RemoveAdFromFailedAds(this AdSettings adsettings, AdType adType)
 {
     if (adsettings._failedAdTypes.Contains(adType))
     {
         adsettings._failedAdTypes.Remove(adType);
     }
 }
Exemplo n.º 3
0
 internal static void AdFailed(this AdSettings adsettings, Model.AdType AdType)
 {
     if (!adsettings._failedAdTypes.Contains(AdType))
     {
         adsettings._failedAdTypes.Add(AdType);
     }
 }
Exemplo n.º 4
0
        internal static void Serialise(this AdSettings adsettings, Stream output)
        {
            XmlSerializer xs = new XmlSerializer(typeof(AdSettings));

            try
            {
                xs.Serialize(output, adsettings);
            }
            catch
            {
                throw new XmlException("Config file was not in the expected format or not found");
            }
        }
Exemplo n.º 5
0
        //internal static void Serialise(this AdSettings adsettings)
        //{
        //    string output;
        //    XmlSerializer xs = new XmlSerializer(typeof(AdSettings));
        //    try
        //    {
        //        using (TextWriter stringWriter = new StringWriter())
        //        {
        //            xs.Serialize(stringWriter,adsettings);
        //            output = stringWriter.
        //        }
        //    }
        //    catch (Exception Ex)
        //    {
        //        throw new XmlException("Unable to save AdSettings", Ex.InnerException);
        //    }
        //    return adsettings;
        //}

        internal static AdSettings Deserialise(this AdSettings adsettings, Stream input)
        {
            XmlSerializer xs = new XmlSerializer(typeof(AdSettings));

            try
            {
                adsettings = (AdSettings)xs.Deserialize(input);
            }
            catch
            {
                throw new XmlException("Config file was not in the expected format or not found");
            }
            return(adsettings);
        }
Exemplo n.º 6
0
        internal static AdSettings Deserialise(this AdSettings adsettings, string input)
        {
            XmlSerializer xs = new XmlSerializer(typeof(AdSettings));

            try
            {
                using (TextReader stringReader = new StringReader(input))
                {
                    adsettings = (AdSettings)xs.Deserialize(stringReader);
                }
            }
            catch (Exception Ex)
            {
                throw new XmlException("Unable to unpack AdSettings", Ex.InnerException);
            }
            return(adsettings);
        }
Exemplo n.º 7
0
        internal static AdProvider GetAd(this AdSettings adsettings)
        {
            //Need to handle Groups and Order

            if (adsettings == null || adsettings.CurrentCulture == null)
            {
                return(new AdRotator.AdProviders.AdProviderNone());
            }

            var validDescriptors = adsettings.CurrentCulture.Items
                                   .Where(x => !adsettings._failedAdTypes.Contains(((AdProvider)x).AdProviderType) &&
                                          AdRotatorComponent.PlatformSupportedAdProviders.Contains(((AdProvider)x).AdProviderType) &&
                                          ((AdProvider)x).Probability > 0);

            var defaultHouseAd = (AdProvider)adsettings.CurrentCulture.Items.FirstOrDefault(x => ((AdProvider)x).AdProviderType == AdType.DefaultHouseAd && !adsettings._failedAdTypes.Contains(AdType.DefaultHouseAd));

            if (validDescriptors != null)
            {
                validDescriptors = validDescriptors.ToList();

                var    totalValueBetweenValidAds = validDescriptors.Sum(x => ((AdProvider)x).Probability);
                var    randomValue  = AdRotator.AdRotatorComponent._rnd.NextDouble() * totalValueBetweenValidAds;
                double totalCounter = 0;
                foreach (AdProvider probabilityDescriptor in validDescriptors)
                {
                    totalCounter += probabilityDescriptor.Probability;
                    if (randomValue < totalCounter)
                    {
                        adsettings.CurrentAdType = probabilityDescriptor.AdProviderType;
                        return(probabilityDescriptor);
                    }
                }
            }

            if (defaultHouseAd != null)
            {
                adsettings.CurrentAdType = AdType.DefaultHouseAd;
                return(defaultHouseAd);
            }

            return(new AdProviders.AdProviderNone());
        }
Exemplo n.º 8
0
 internal static void ClearFailedAds(this AdSettings adsettings)
 {
     adsettings._failedAdTypes.Clear();
 }
Exemplo n.º 9
0
        internal static AdProvider GetAd(this AdSettings adsettings, AdMode mode)
        {
            //Need to handle Groups and Order

            if (adsettings == null || adsettings.CurrentCulture == null)
            {
                return(new AdRotator.AdProviders.AdProviderNone());
            }

            var validDescriptors = adsettings.CurrentCulture.Items
                                   .Where(x => !adsettings._failedAdTypes.Contains(((AdProvider)x).AdProviderType) &&
                                          AdRotatorComponent.PlatformSupportedAdProviders.Contains(((AdProvider)x).AdProviderType) &&
                                          (((AdProvider)x).Probability > 0) || ((AdProvider)x).AdOrder > 0).Cast <AdProvider>().ToArray();

            var defaultHouseAd = (AdProvider)adsettings.CurrentCulture.Items.FirstOrDefault(x => ((AdProvider)x).AdProviderType == AdType.DefaultHouseAd && !adsettings._failedAdTypes.Contains(AdType.DefaultHouseAd));

            if (validDescriptors != null && validDescriptors.Length > 0)
            {
                switch (mode)
                {
                case AdMode.Random:
                    validDescriptors = RandomPermutation <AdProvider>(validDescriptors);

                    var    totalValueBetweenValidAds = validDescriptors.Sum(x => ((AdProvider)x).Probability);
                    var    randomValue  = AdRotator.AdRotatorComponent._rnd.NextDouble() * totalValueBetweenValidAds;
                    double totalCounter = 0;
                    foreach (AdProvider probabilityDescriptor in validDescriptors)
                    {
                        totalCounter += probabilityDescriptor.Probability;
                        if (randomValue < totalCounter)
                        {
                            adsettings.CurrentAdType = probabilityDescriptor.AdProviderType;
                            return(probabilityDescriptor);
                        }
                    }
                    break;

                case AdMode.Stepped:
                case AdMode.Ordered:
                    validDescriptors = validDescriptors.OrderBy(x => x.AdOrder).Cast <AdProvider>().ToArray();
                    if (mode == AdMode.Ordered)
                    {
                        return(validDescriptors[0]);
                    }
                    adsettings.CurrentAdProvider = validDescriptors[adsettings.CurrentAdOrderIndex];
                    adsettings.CurrentAdOrderIndex++;
                    if (adsettings.CurrentAdOrderIndex > validDescriptors.Length - 1)
                    {
                        adsettings.CurrentAdOrderIndex = 0;
                    }
                    return(adsettings.CurrentAdProvider);
                }
            }

            if (defaultHouseAd != null)
            {
                adsettings.CurrentAdType = AdType.DefaultHouseAd;
                return(defaultHouseAd);
            }

            return(new AdProviders.AdProviderNone());
        }
Exemplo n.º 10
0
        /// <summary>
        /// Fetches the ad settings file from the address specified
        /// </summary>
        public void FetchAdSettingsFile(Object stateInfo)
        {
            var request = (HttpWebRequest)HttpWebRequest.Create(new Uri(_settingsURL));
            request.BeginGetResponse(r =>
            {
                try
                {
                    var httpRequest = (HttpWebRequest)r.AsyncState;
                    var httpResponse = (HttpWebResponse)httpRequest.EndGetResponse(r);
                    var settingsStream = httpResponse.GetResponseStream();

                    var s = new XmlSerializer(typeof(AdSettings));
                    _settings = (AdSettings)s.Deserialize(settingsStream);
                    // Only persist the settings if they've been retreived from the remote file
                    SaveAdSettings(_settings);
                    _remoteAdSettingsFetched = true;
                    _initialised = true;
                    OnLog("Setings retrieved from remote");
                    LoadAdSettings();
                }
                catch
                {
                    _remoteAdSettingsFetched = true;
                    IsNetworkAvailable = false;
                    _initialised = true;
                    LoadAdSettings();
                }
            }, request);

        }
Exemplo n.º 11
0
 private void FinishLoadingSettings()
 {
     if (_settings == null)
     {
         _settings = GetDefaultSettings();
     }
     if (_settings == null)
     {
         OnLog("Ad control disabled no settings available");
         Visibility = Visibility.Collapsed;
         IsEnabled = false;
     }
     else
     {
         //Everything OK, continue loading
         _initialised = true;
         Invalidate();
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// Loads the ad settings object either from isolated storage or from the resource path defined in DefaultSettingsFileUri.
        /// </summary>
        /// <returns></returns>
        private void LoadAdSettings()
        {
            //If not checked remote && network available - get remote
            if (!_remoteAdSettingsFetched && !String.IsNullOrEmpty(_settingsURL) && IsNetworkAvailable)
            {
                FetchAdSettingsThreaded();
                return;
            }

            if (!String.IsNullOrEmpty(_settingsURL))
            {
                bool success = false;
                // if successful set and invalidate
                try
                {
                    var isfData = IsolatedStorageFile.GetUserStoreForApplication();
                    IsolatedStorageFileStream isfStream = null;
                    if (isfData.FileExists(SETTINGS_FILE_NAME))
                    {
                        using (isfStream = new IsolatedStorageFileStream(SETTINGS_FILE_NAME, FileMode.Open, isfData))
                        {
                            XmlSerializer xs = new XmlSerializer(typeof(AdSettings));
                            try
                            {
                                _settings = (AdSettings)xs.Deserialize(isfStream);
                                success = true;
                                FinishLoadingSettings();
                            }
                            catch { }
                        }
                    }
                }
                finally
                {
                    if (!success) Dispatcher.BeginInvoke(() => FinishLoadingSettings());
                }
            }
            else
            {
                FinishLoadingSettings();
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Saves the passed settings file to isolated storage
 /// </summary>
 /// <param name="settings"></param>
 private void SaveAdSettings(AdSettings settings)
 {
     var SETTINGS_FILE_NAME = string.IsNullOrEmpty(LocalSettingsLocation) ? GlobalConfig.DEFAULT_SETTINGS_FILE_NAME : LocalSettingsLocation;
     try
     {
         XmlSerializer xs = new XmlSerializer(typeof(AdSettings));
         using (var stream = fileHelper.OpenStream("", SETTINGS_FILE_NAME, ""))
         {
             xs.Serialize(stream, settings);
         }
     }
     catch
     {
         throw new FileNotFoundException(string.Format("Could not locate the local Settings file"));
     }
 }
Exemplo n.º 14
0
 //Not Finished (SJ)
 //Needs testing (GO)
 public async Task LoadSettingsFileProject()
 {
     if (LocalSettingsLocation != null)
     {
         try
         {
             await Task.Factory.StartNew(() =>
                 {
                     using (var stream = fileHelper.FileOpenRead(new Uri(LocalSettingsLocation, UriKind.Relative), LocalSettingsLocation))
                     {
                         try
                         {
                             if(stream != null) _settings = _settings.Deserialise(stream);
                         }
                         catch { }
                     }
                 });
         }
         catch
         {
             throw new FileNotFoundException(string.Format("The ad configuration file {0} could not be found. Either the path is incorrect or the build type is not set correctly", LocalSettingsLocation));
         }
     }
 }
Exemplo n.º 15
0
 public async Task LoadSettingsFileRemote(string RemoteSettingsLocation)
 {
     var settings = await Networking.Network.GetStringFromURLAsync(RemoteSettingsLocation);
     if (settings != null) _settings = _settings.Deserialise(settings);
 }
Exemplo n.º 16
0
 public async Task LoadSettingsFileLocal()
 {
     // if successful set and invalidate
     // If not loadSettings again
     var SETTINGS_FILE_NAME = string.IsNullOrEmpty(LocalSettingsLocation) ? GlobalConfig.DEFAULT_SETTINGS_FILE_NAME : LocalSettingsLocation;
     try
     {
         await Task.Factory.StartNew(() =>
             {
                 if (fileHelper.FileExists(SETTINGS_FILE_NAME))
                 {
                     using (var stream = fileHelper.FileOpenRead("", SETTINGS_FILE_NAME))
                     {
                         try
                         {
                             if(stream != null) _settings = _settings.Deserialise(stream);
                         }
                         catch { }
                     }
                 }
             });
     }
     catch
     {
         throw new FileNotFoundException("Could not locate the local Settings file");
     }
 }
Exemplo n.º 17
0
 /// <summary>
 /// Saves the passed settings file to isolated storage
 /// </summary>
 /// <param name="settings"></param>
 private static void SaveAdSettings(AdSettings settings)
 {
     try
     {
         XmlSerializer xs = new XmlSerializer(typeof(AdSettings));
         IsolatedStorageFileStream isfStream = new IsolatedStorageFileStream(SETTINGS_FILE_NAME, FileMode.Create, IsolatedStorageFile.GetUserStoreForApplication());
         xs.Serialize(isfStream, settings);
         isfStream.Close();
     }
     catch
     {
     }
 }
Exemplo n.º 18
0
        public static AdSettings createdemodate()
        {
            var response = new AdSettings()
            {
                CultureDescriptors = new List<AdCultureDescriptor>()
                {
                    new AdCultureDescriptor()
                    {
                        Items = new List<object>()
                        {
                             new AdProviderPubCenter() { Probability=35, AppId = "test_client", SecondaryId="Image480_80" },
                             new AdProviderPubCenter() { Probability=35, AppId = "test_client", SecondaryId="Image480_80" },
                             new AdProviderPubCenter() { Probability=35, AppId = "test_client", SecondaryId="Image480_80" },
                             new AdGroup()
                             {
                                 AdOrder = 2,
                                 AdSlideDirection = AdSlideDirection.Top,
                                 Items = new List<AdProvider>()
                                 {
                                     new AdProviderDefaultHouseAd() { AppId = "1", AdOrder= 1 },
                                     new AdProviderDefaultHouseAd() { AppId = "2", AdOrder= 2 },
                                     new AdProviderDefaultHouseAd() { AppId = "3", AdOrder= 3 },
                                 }.ToArray()
                             }
                        }.ToArray(),
                        CultureName = "en-US",
                        AdSlideDirection = AdSlideDirection.Bottom,
                        AdSlideDisplaySeconds = 10,
                        AdSlideHiddenSeconds = 20,
                        AdRefreshSeconds = 10
                    },
                    new AdCultureDescriptor()
                    {
                        Items = new List<object>()
                        {
                             new AdGroup()
                             {
                                 AdOrder = 2,
                                 AdSlideDirection = AdSlideDirection.Top,
                                 Items = new List<AdProvider>()
                                 {
                                     new AdProviderDefaultHouseAd() { AppId = "ShowME", AdOrder= 1 },
                                     new AdProviderDefaultHouseAd() { AppId = "ThenShowME", AdOrder= 2 },
                                     new AdProviderDefaultHouseAd() { AppId = "DisplayMeLast", AdOrder= 3 },
                                 }.ToArray()
                             },
                             new AdGroup()
                             {
                                 AdOrder = 2,
                                 AdSlideDirection = AdSlideDirection.None,
                                 EnabledInTrialOnly = true,
                                 Items = new List<AdProvider>()
                                 {
                                     new AdProviderPubCenter() { Probability=35, AppId = "test_client", SecondaryId="Image480_80" },
                                     new AdProviderAdDuplex() { Probability=35, AppId = "0" },
                                     new AdProviderAdMob() { Probability=35, AppId = "0" },
                                     new AdProviderSmaato() { Probability=35, AppId = "0" },
                                     new AdProviderPubCenter() { Probability=35, AppId = "test_client", SecondaryId="Image80_80" },
                                 }.ToArray()
                             }

                        }.ToArray(),
                        CultureName = "Default"
                    },
                }.ToArray()
            };
            return response;
        }