コード例 #1
0
 public virtual Authenticate AuthenticateToServer(UserConfiguration config)
 {
     var tmp = new Authenticate(config.ServerUrl, config.User, config.Password);
     _handshake = tmp;
     _container.Register<Handshake>().To(_handshake);
     return tmp;
 }
コード例 #2
0
        public void AlbumArtLoaderCachesNewArtTest()
        {
            var container = new Athena.IoC.Container();
            var model = new AmpacheModel();
            container.Register<AmpacheModel>().To(model);
            var defaultStream = new MemoryStream();

            var persistor = Substitute.For<IPersister<AlbumArt>>();
            container.Register<IPersister<AlbumArt>>().To(persistor);
            persistor.IsPersisted(Arg.Any<IEntity>()).Returns(false);
            var art = new AlbumArt();
            persistor.IsPersisted(Arg.Is(art)).Returns(false);
            int timesCalled = 0;
            persistor.When(x => x.Persist(Arg.Any<AlbumArt>())).Do( x => { ++timesCalled; });
            art.ArtStream = new MemoryStream(new byte[8]);
            persistor.SelectBy<AmpacheSong>(Arg.Any<AmpacheSong>()).Returns(new [] {art});
            var prefs = new UserConfiguration();
            prefs.CacheArt = true;
            model.Configuration = prefs;

            var target = new AlbumArtLoader(container, defaultStream);
            var sng = new AmpacheSong();
            sng.ArtUrl = "test";
            model.PlayingSong = sng;

            System.Threading.Thread.Sleep(100);
            Assert.That(model.AlbumArtStream, Is.SameAs(art.ArtStream));
            Assert.That(timesCalled, Is.EqualTo(1));
        }
コード例 #3
0
ファイル: Background.cs プロジェクト: jcwmoore/ampache-net
 public void PersistUserConfig(UserConfiguration config)
 {
     _container.Resolve<IPersister<UserConfiguration>>().Persist(config);
     if(config.CacheArt == false && Directory.Exists(AmpacheSelectionFactory.ArtLocalDirectory)){
         var files = Directory.GetFiles(AmpacheSelectionFactory.ArtLocalDirectory).Where(f=>!f.Contains("ampachenet.db3")).ToList();
         files.ForEach(f => File.Delete(f));
     }
 }
コード例 #4
0
 public void BackgroundListensForConfigChangesTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(persister);
     bool persisted = false;
     var config = new UserConfiguration();
     persister.When(x => x.Persist(config)).Do(p => persisted = true);
     var target = new BackgroundHandle(null, path, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     System.Threading.Thread.Sleep(100);
     target.Model.Configuration = config;
     Assert.That(persisted, Is.True);
 }
コード例 #5
0
ファイル: Configuration.cs プロジェクト: jcwmoore/ampache-net
 public bool TrySaveConfiguration(UserConfiguration config)
 {
     if(_model != null && config != null)
     {
         try
         {
             var tmp = _model.Factory.AuthenticateToServer(config);
             _model.UserMessage = _successMessage ?? "Success";
             _model.Configuration = config;
             return true;
         }
         catch (Exception ex)
         {
             _model.UserMessage = ex.Message;
         }
     }
     return false;
 }
コード例 #6
0
ファイル: Background.cs プロジェクト: jcwmoore/ampache-net
        public virtual void Start(MemoryStream defaultArtStream)
        {
            if(defaultArtStream == null)
            {
                throw new ArgumentNullException("defaultArtStream");
            }
            _loader = new AlbumArtLoader(_container, defaultArtStream);

            _model.Factory = CreateFactory();
            var tmpConfig = LoadPersistedConfiguration();
            if(tmpConfig == null)
            {
                tmpConfig = new UserConfiguration();
                tmpConfig.AllowSeeking = true;
                tmpConfig.CacheArt = true;
                tmpConfig.Password = string.Empty;
                tmpConfig.User = string.Empty;
                tmpConfig.ServerUrl = string.Empty;
            }
            _model.Configuration = tmpConfig;
            if (_model.Configuration.ServerUrl != string.Empty)
            {
                var task = new Task(() => _model.Factory.AuthenticateToServer(_model.Configuration));
                task.ContinueWith((t) => _model.UserMessage = t.Exception.InnerExceptions.First().Message, TaskContinuationOptions.OnlyOnFaulted)
                    .ContinueWith((t) => _model.PropertyChanged += Handle_modelPropertyChanged, TaskContinuationOptions.NotOnCanceled);
                task.ContinueWith((t) => _model.UserMessage = _successConnectionMessage, TaskContinuationOptions.NotOnFaulted)
                    .ContinueWith((t) => _model.Playlist = LoadPersistedSongs(), TaskContinuationOptions.NotOnCanceled)
                    .ContinueWith((t) => _model.PropertyChanged += Handle_modelPropertyChanged, TaskContinuationOptions.NotOnCanceled);
                task.Start();
            }
            else
            {
                _model.PropertyChanged += Handle_modelPropertyChanged;
            }
            StartAutoShutOff();
        }
コード例 #7
0
 public BackgroundHandle(UserConfiguration config, string art, AmpacheSelectionFactory factory, AmpacheModel model, Athena.IoC.Container container)
     : this(config, art, model, container)
 {
     _factory = factory;
 }
コード例 #8
0
 public BackgroundHandle(UserConfiguration config, string art, AmpacheModel model, Athena.IoC.Container container)
     : this(config, art)
 {
     _model = model;
     _container = container;
 }
コード例 #9
0
 public BackgroundHandle(UserConfiguration config, string art)
 {
     _successConnectionMessage = SUCCESS_MESSAGE;
     _config = config;
     FinalizedCalled = false;
     SavedSongsCalled = false;
     LoadSongsCalled = false;
     AutoShutOffCallCount = 0;
     StopShutOffCallCount = 0;
 }
コード例 #10
0
 public void BackgroundStartPopulatesModelPlaylistWhenUserConfigExistsTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var config = new UserConfiguration();
     config.ServerUrl = "test";
     config.User = "******";
     config.Password = "******";
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     persister.SelectBy(Arg.Any<int>()).Returns(config);
     container.Register<IPersister<UserConfiguration>>().To(persister);
     var factory = Substitute.For<AmpacheSelectionFactory>();
     factory.AuthenticateToServer(config).Returns(x => (Authenticate)null);
     container.Register<IPersister<UserConfiguration>>();
     var target = new BackgroundHandle(config, path, factory, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     var exp = target.Model.Playlist;
     Assert.That(exp, Is.Not.Null);
 }
コード例 #11
0
 public void BackgroundStartPopulatesModelFactoryWhenUserConfigExistsTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var config = new UserConfiguration();
     config.ServerUrl = "test";
     config.User = "******";
     config.Password = "******";
     var persister = Substitute.For<IPersister<AmpacheSong>>();
     container.Register<IPersister<AmpacheSong>>().To(persister);
     var configpersist = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(configpersist);
     configpersist.SelectBy(Arg.Any<int>()).Returns(config);
     var sngs = new List<AmpacheSong>();
     sngs.Add(new AmpacheSong(){Url = "http://test"});
     sngs.Add(new AmpacheSong(){Url = "http://test"});
     persister.SelectAll().Returns(sngs);
     var factory = Substitute.For<AmpacheSelectionFactory>();
     factory.AuthenticateToServer(config).Returns(x => (Authenticate)null);
     var mockHs = new MockHandShake();
     mockHs.Setup("test", "test");
     factory.Handshake.Returns(mockHs);
     var target = new BackgroundHandle(config, path, factory, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     System.Threading.Thread.Sleep(100);
     var exp = target.Model.Factory;
     Assert.That(exp, Is.Not.Null);
     var userMessage = target.Model.UserMessage;
     Assert.That(userMessage, Is.Not.Null);
     Assert.That(userMessage, Is.EqualTo(BackgroundHandle.SUCCESS_MESSAGE));
     Assert.That(target.Model.Playlist, Is.EquivalentTo(sngs));
 }
コード例 #12
0
 void HandleOkClick(object sender, EventArgs e)
 {
     var dlg = ProgressDialog.Show(this, GetString(Resource.String.connecting), GetString(Resource.String.connectingToAmpache));
     bool success = false;
     var config = new UserConfiguration();
     config.AllowSeeking = FindViewById<CompoundButton>(Resource.Id.chkSeeking).Checked;
     config.CacheArt = FindViewById<CompoundButton>(Resource.Id.chkArtCache).Checked;
     config.Password =  FindViewById<EditText>(Resource.Id.txtPasswordConfig).Text;
     config.User =  FindViewById<EditText>(Resource.Id.txtConfigUser).Text;
     config.ServerUrl =  FindViewById<EditText>(Resource.Id.txtConfigUrl).Text;
     Task.Factory.StartNew(() => success = TrySaveConfiguration(config))
                 .ContinueWith((t) => RunOnUiThread(()=> dlg.Dismiss()))
                 .ContinueWith(delegate(Task obj) { if(success) { Finish(); _config = null; } });
 }
コード例 #13
0
 public void UserConfigurationPersisterPersistedTest()
 {
     var config = new UserConfiguration();
     config.AllowSeeking = false;
     config.CacheArt = false;
     config.CacheSongs = true;
     config.Password = @"password's";
     config.User = "******";
     config.ServerUrl = "testserver";
     var conn = new SQLiteConnection("Data Source=:memory:");
     using(var cmd = conn.CreateCommand())
     using(var target = new UserConfigurationPersister(conn)){
         target.Persist(config);
         string format = @"select value from properties where key = '{0}';";
         cmd.CommandText = string.Format(format, "url");
         Assert.That(cmd.ExecuteScalar(), Is.EqualTo(config.ServerUrl));
         cmd.CommandText = string.Format(format, "user");
         Assert.That(cmd.ExecuteScalar(), Is.EqualTo(config.User.Replace(@"'", @"&quot;")));
         cmd.CommandText = string.Format(format, "password");
         Assert.That(cmd.ExecuteScalar(), Is.EqualTo(config.Password.Replace(@"'", @"&quot;")));
         cmd.CommandText = string.Format(format, "allowSeeking");
         Assert.That(bool.Parse(cmd.ExecuteScalar().ToString()), Is.EqualTo(config.AllowSeeking));
         cmd.CommandText = string.Format(format, "cacheArt");
         Assert.That(bool.Parse(cmd.ExecuteScalar().ToString()), Is.EqualTo(config.CacheArt));
     }
 }
コード例 #14
0
 public void UserConfigurationPersisterSelectAllTest()
 {
     var config = new UserConfiguration();
     config.AllowSeeking = false;
     config.CacheArt = false;
     config.CacheSongs = true;
     config.Password = @"password's";
     config.User = "******";
     config.ServerUrl = "testserver";
     var conn = new SQLiteConnection("Data Source=:memory:");
     using(var cmd = conn.CreateCommand())
     using(var target = new UserConfigurationPersister(conn)){
         target.Persist(config);
         var actual = target.SelectAll().ToList();
         Assert.That(actual.Count, Is.EqualTo(1));
         var res = actual.First();
         Assert.That(res.AllowSeeking, Is.EqualTo(config.AllowSeeking));
         Assert.That(res.CacheArt, Is.EqualTo(config.CacheArt));
         Assert.That(res.ServerUrl, Is.EqualTo(config.ServerUrl));
         Assert.That(res.User, Is.EqualTo(config.User));
         Assert.That(res.Password, Is.EqualTo(config.Password));
     }
 }
コード例 #15
0
 void HandleTextChanged(object sender, Android.Text.TextChangedEventArgs e)
 {
     if(_config == null)
     {
         _config = new UserConfiguration();
     }
     _config.Password = FindViewById<EditText>(Resource.Id.txtPasswordConfig).Text;
     _config.ServerUrl = FindViewById<EditText>(Resource.Id.txtConfigUrl).Text;
     _config.User = FindViewById<EditText>(Resource.Id.txtConfigUser).Text;
 }
コード例 #16
0
        public void AlbumArtLoaderUsesLoadedArtAfterLoadingTest()
        {
            var container = new Athena.IoC.Container();
            var model = new AmpacheModel();
            container.Register<AmpacheModel>().To(model);
            var defaultStream = new MemoryStream();

            var persistor = Substitute.For<IPersister<AlbumArt>>();
            container.Register<IPersister<AlbumArt>>().To(persistor);
            persistor.IsPersisted(Arg.Any<IEntity>()).Returns(false);
            var art = new AlbumArt();
            art.ArtStream = new MemoryStream();
            persistor.SelectBy<AmpacheSong>(Arg.Any<AmpacheSong>()).Returns(new [] {art});
            var prefs = new UserConfiguration();
            prefs.CacheArt = false;
            model.Configuration = prefs;

            var target = new AlbumArtLoader(container, defaultStream);
            var sng = new AmpacheSong();
            sng.ArtUrl = "test";
            model.PlayingSong = sng;

            System.Threading.Thread.Sleep(100);
            Assert.That(model.AlbumArtStream, Is.SameAs(art.ArtStream));
        }
コード例 #17
0
        public void ConfigurationTrySaveConfigurationSuccessfulTest()
        {
            var model = new AmpacheModel();
            var factory = Substitute.For<AmpacheSelectionFactory>();
            model.Factory = factory;
            factory.AuthenticateToServer(Arg.Any<UserConfiguration>()).Returns((Authenticate)null);

            var target = new Configuration(model);
            Assert.That(model.UserMessage, Is.Null);
            var conf = new UserConfiguration();
            var actual = target.TrySaveConfiguration(conf);
            Assert.That(actual, Is.True);
            Assert.That(model.UserMessage, Is.Not.Null);
            Assert.That(model.Configuration, Is.SameAs(conf));
        }
コード例 #18
0
        public void ConfigurationTrySaveConfigurationErrorTest()
        {
            var model = new AmpacheModel();
            var factory = Substitute.For<AmpacheSelectionFactory>();
            model.Factory = factory;
            var message = "error message";
            factory.When(x => x.AuthenticateToServer(Arg.Any<UserConfiguration>())).Do((obj) => { throw new Exception(message); });

            var target = new Configuration(model);
            Assert.That(model.UserMessage, Is.Null);
            var conf = new UserConfiguration();
            var actual = target.TrySaveConfiguration(conf);
            Assert.That(actual, Is.False);
            Assert.That(model.UserMessage, Is.SameAs(message));
            Assert.That(model.Configuration, Is.Null);
        }
コード例 #19
0
 void HandleCancelClick(object sender, EventArgs e)
 {
     _config = null;
     Finish();
 }