Esempio n. 1
0
 /// <summary>
 /// Add a feed url to the system.
 /// </summary>
 /// <exception cref="UserMessageException">If the feed name already exists or the feed is invalid.</exception>
 /// <param name="name">Feed name</param>
 /// <param name="feed">Feed url</param>
 public void AddFeed(string name, string feed)
 {
     try
     {
         Log.InfoFormat("Validating feed for {0} {1}", name, feed);
         if (!SingletonContext.ValidateFeedUrl(feed))
         {
             Log.InfoFormat("Feed not valid for {0} {1}", name, feed);
             throw new UserMessageException("{0} is not a valid feed.", feed);
         }
         Log.InfoFormat("Checking if feed name already exists for {0} {1}", name, feed);
         if (SimpleConfig.Get().GetFeeds().Any(x => x.Name.ToLower() == name.ToLower()))
         {
             Log.InfoFormat("Feed name already exists for {0} {1}", name, feed);
             throw new UserMessageException("Feed name {0} already exists.", name);
         }
         Log.InfoFormat("Adding feed {0} {1}", name, feed);
         SimpleConfig.Get().AddFeed(new NamedUrl(name, feed));
         Log.InfoFormat("Firing update feed list {0} {1}", name, feed);
         this.FireOnUpdateFeedList();
         Log.InfoFormat("Feed {0} {1} added.", name, feed);
     }
     finally
     {
         Log.InfoFormat("Finished {0} {1}", name, feed);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Remove a feed url from the system.
 /// </summary>
 /// <param name="name">Feed name</param>
 public void RemoveFeed(string name)
 {
     Log.InfoFormat("Removing feed {0}", name);
     SimpleConfig.Get().RemoveFeed(new NamedUrl(name, ""));
     Log.InfoFormat("Firing update feed list {0}", name);
     this.FireOnUpdateFeedList();
     Log.InfoFormat("Removed feed {0}", name);
 }
Esempio n. 3
0
        public static bool getFilterGame(string name)
        {
            bool ret = true;

            if (!Boolean.TryParse(SimpleConfig.Get().ReadValue("FilterGames_" + name, "true"), out ret))
            {
                ret = true;
                SimpleConfig.Get().WriteValue("FilterGames_" + name, true.ToString(CultureInfo.InvariantCulture));
            }
            return(ret);
        }
Esempio n. 4
0
        public static T GetGameSetting <T>(Octgn.DataNew.Entities.Game game, string propName, T def)
        {
            var defSettings = new Hashtable();

            defSettings["name"] = game.Name;
            var settings = SimpleConfig.Get().ReadValue("GameSettings_" + game.Id.ToString(), defSettings);

            if (settings.ContainsKey(propName))
            {
                if (settings[propName] is T)
                {
                    return((T)settings[propName]);
                }
            }
            SetGameSetting(game, propName, def);
            return(def);
        }
Esempio n. 5
0
        public static void SetGameSetting <T>(DataNew.Entities.Game game, string propName, T val)
        {
            var defSettings = new Hashtable();

            defSettings["name"] = game.Name;
            var settings = SimpleConfig.Get().ReadValue("GameSettings_" + game.Id.ToString(), defSettings);

            if (!settings.ContainsKey(propName))
            {
                settings.Add(propName, val);
            }
            else
            {
                settings[propName] = val;
            }

            SimpleConfig.Get().WriteValue("GameSettings_" + game.Id.ToString(), settings);
        }
Esempio n. 6
0
        public void AddFeed_ThrowsIfGameAlreadyExists()
        {
            bool pass               = false;
            var  curSimpleConfig    = SimpleConfig.Get();
            var  curGameFeedManager = GameFeedManager.Get();
            var  gameListWithFeed   = new List <NamedUrl>();

            gameListWithFeed.Add(new NamedUrl("asdf", "asdf"));
            try
            {
                // Fake out the simple config so it returns what we want.
                // This also sets the singleton context to this fake object.
                var fakeSimpleConfig = A.Fake <ISimpleConfig>();
                A.CallTo(fakeSimpleConfig).DoesNothing();
                A.CallTo(() => fakeSimpleConfig.GetFeeds()).Returns(gameListWithFeed);
                SimpleConfig.SingletonContext = fakeSimpleConfig;

                // Fake out the GameFeedManager so that we can make sure ValidateFeed does what we want.
                var fakeGf = A.Fake <IGameFeedManager>(x => x.Wrapping(curGameFeedManager));
                GameFeedManager.SingletonContext = fakeGf;
                A.CallTo(() => fakeGf.ValidateFeedUrl(A <string> ._)).Returns(true);

                // Now we pass in a game feed by the name asdf, and it should throw an error since it
                // already exists in the list above.

                try
                {
                    fakeGf.AddFeed("asdf", "asdf");
                }
                catch (TargetInvocationException e)
                {
                    if (e.InnerException is UserMessageException)
                    {
                        pass = true;
                    }
                }
            }
            finally
            {
                SimpleConfig.SingletonContext    = curSimpleConfig;
                GameFeedManager.SingletonContext = curGameFeedManager;
            }
            Assert.True(pass);
        }
Esempio n. 7
0
        public void RemoveFeed_JustCallsSimpleConfigRemoveFeed()
        {
            var curSimple = SimpleConfig.Get();

            try
            {
                var fake = A.Fake <ISimpleConfig>();
                A.CallTo(fake).DoesNothing();
                SimpleConfig.SingletonContext = fake;

                GameFeedManager.Get().RemoveFeed("asdf");

                A.CallTo(() => fake.RemoveFeed(A <NamedUrl> ._)).MustHaveHappened(Repeated.Exactly.Once);
            }
            finally
            {
                SimpleConfig.SingletonContext = curSimple;
            }
        }
Esempio n. 8
0
        public void GetFeeds_JustCallsSimpleConfigGetFeeds()
        {
            var curSimple = SimpleConfig.Get();

            try
            {
                var fake = A.Fake <ISimpleConfig>();
                A.CallTo(fake).DoesNothing();
                SimpleConfig.SingletonContext = fake;

                var res = GameFeedManager.Get().GetFeeds();
                Assert.IsNull(res);
                A.CallTo(() => fake.GetFeeds()).MustHaveHappened(Repeated.Exactly.Once);
            }
            finally
            {
                SimpleConfig.SingletonContext = curSimple;
            }
        }
Esempio n. 9
0
        public void AddFeed_CallsValidate()
        {
            var fakeSimpleConfig = A.Fake <ISimpleConfig>();

            A.CallTo(fakeSimpleConfig).DoesNothing();
            A.CallTo(() => fakeSimpleConfig.GetFeeds()).Returns(new List <NamedUrl>());
            var curSimpleConfig = SimpleConfig.Get();

            SimpleConfig.SingletonContext = fakeSimpleConfig;

            var cur = GameFeedManager.Get();

            GameFeedManager.SingletonContext = A.Fake <IGameFeedManager>(x => x.Wrapping(cur));
            A.CallTo(() => GameFeedManager.SingletonContext.ValidateFeedUrl(A <string> ._)).Returns(true);
            GameFeedManager.Get().AddFeed("asdfASDFasdfASDF", "asdf");
            A.CallTo(() => GameFeedManager.SingletonContext.ValidateFeedUrl(A <string> ._)).MustHaveHappened(Repeated.Exactly.Once);
            GameFeedManager.SingletonContext = cur;

            SimpleConfig.SingletonContext = curSimpleConfig;
        }
Esempio n. 10
0
        public void AddFeed_CallsSimpleConfigAddFeedIfItPasses()
        {
            bool pass               = false;
            var  curSimpleConfig    = SimpleConfig.Get();
            var  curGameFeedManager = GameFeedManager.Get();
            var  gameListWithFeed   = new List <NamedUrl>();

            try
            {
                // Fake out the simple config so it returns what we want.
                // This also sets the singleton context to this fake object.
                var fakeSimpleConfig = A.Fake <ISimpleConfig>();
                A.CallTo(fakeSimpleConfig).DoesNothing();
                A.CallTo(() => fakeSimpleConfig.GetFeeds()).Returns(gameListWithFeed);
                SimpleConfig.SingletonContext = fakeSimpleConfig;

                // Fake out the GameFeedManager so that we can make sure ValidateFeed does what we want.
                var fakeGf = A.Fake <IGameFeedManager>(x => x.Wrapping(curGameFeedManager));
                GameFeedManager.SingletonContext = fakeGf;
                A.CallTo(() => fakeGf.ValidateFeedUrl(A <string> ._)).Returns(true);

                // Now we pass in a game feed by the name asdf, and it should throw an error since it
                // already exists in the list above.

                fakeGf.AddFeed("asdf", "asdf");

                // Make sure that SimpleConfig.AddFeed was called once
                A.CallTo(() => fakeSimpleConfig.AddFeed(A <NamedUrl> ._)).MustHaveHappened(Repeated.Exactly.Once);
                Assert.Pass();
            }
            finally
            {
                SimpleConfig.SingletonContext    = curSimpleConfig;
                GameFeedManager.SingletonContext = curGameFeedManager;
            }
            Assert.Fail();
        }
Esempio n. 11
0
 /// <summary>
 /// Gets all saved game feeds
 /// </summary>
 /// <returns>Saved game feeds</returns>
 public IEnumerable <NamedUrl> GetFeeds()
 {
     Log.Info("Getting Feeds");
     return(SimpleConfig.Get().GetFeeds());
 }
Esempio n. 12
0
			public T Get<T>(string name, T defval, Predicate<T> validator)
			{
				var key = _key + "." + name;
				return _config.Get(key, defval, validator);
			}
Esempio n. 13
0
 static Prefs()
 {
     _hideLoginNotifications = SimpleConfig.Get().ReadValue("Options_HideLoginNotifications", false);
 }
Esempio n. 14
0
 /// <summary>
 /// Gets all saved game feeds
 /// </summary>
 /// <returns>Saved game feeds</returns>
 public IEnumerable <NamedUrl> GetFeeds(bool localOnly = false)
 {
     Log.Info("Getting Feeds");
     return(SimpleConfig.Get().GetFeeds(localOnly));
 }
Esempio n. 15
0
 public static void setFilterGame(string name, bool value)
 {
     SimpleConfig.Get().WriteValue("FilterGames_" + name, value.ToString(CultureInfo.InvariantCulture));
 }