Commits

Mark Heath committed 0033163

changes to isolated store to allow us to query which contests are available

Comments (0)

Files changed (8)

MusicRater/App.xaml.cs

         private void Application_Startup(object sender, StartupEventArgs e)
         {
             var mainPage = new MainPage();
-            mainPage.DataContext = new MainPageViewModel(mainPage.mediaElement1);
+            mainPage.DataContext = new MainPageViewModel(mainPage.mediaElement1, new IsolatedStore());
             this.RootVisual = mainPage;
         }
 

MusicRater/Persistence/IIsolatedStore.cs

 
 namespace MusicRater
 {
-    public interface IIsolatedStore : IDisposable
+    public interface IIsolatedStore
     {
         bool FileExists(string fileName);
         Stream CreateFile(string fileName);
         Stream OpenFile(string fileName);
+        IEnumerable<string> GetFileNames(string pattern);
     }
 }

MusicRater/Persistence/IsolatedStore.cs

 using System.Windows.Shapes;
 using System.IO.IsolatedStorage;
 using System.IO;
+using System.Collections.Generic;
 
 namespace MusicRater
 {
             this.isoStore.Dispose();
             GC.SuppressFinalize(this);
         }
+
+        public IEnumerable<string> GetFileNames(string pattern)
+        {
+            return isoStore.GetFileNames(pattern);
+        }
     }
 }

MusicRater/Persistence/IsolatedStoreTrackLoader.cs

 
         public void BeginLoad()
         {
-            using (RatingsRepository repo = new RatingsRepository(isoStore))
-            {
-                repo.Load(this.contest);
-            }
-            KvrTrackLoader.Shuffle(this.contest.Tracks, new Random());            
+            RatingsRepository repo = new RatingsRepository(isoStore);
+            repo.Load(this.contest);
+            
+            KvrTrackLoader.Shuffle(this.contest.Tracks, new Random());
             if (Loaded != null)
             {
                 Loaded(this, new LoadedEventArgs() { Tracks = this.contest.Tracks });

MusicRater/Persistence/RatingsRepository.cs

 
 namespace MusicRater
 {
-    public class RatingsRepository : IDisposable
+    public class RatingsRepository
     {
         private readonly IIsolatedStore isolatedStore;
 
             this.isolatedStore = isolatedStore;
         }
 
+        public IEnumerable<string> GetContestFiles()
+        {
+            return this.isolatedStore.GetFileNames("*.xml");
+        }
+
         public void Save(Contest contest)
         {
             var trackNodes = from t in contest.Tracks
             }
             return t;
         }
-
-        public void Dispose()
-        {
-            this.isolatedStore.Dispose();
-        }
     }
 }

MusicRater/ViewModels/MainPageViewModel.cs

 {
     public class MainPageViewModel : ViewModelBase
     {
-        private MediaElement me;        
+        private MediaElement me;
         private TrackViewModel selectedTrack;
         private DispatcherTimer timer;
         private bool dirtyFlag;
         private bool isLoading;
         private Contest contest;
+        private IIsolatedStore isoStore;
         
-        public MainPageViewModel(MediaElement me)
+        public MainPageViewModel(MediaElement me, IIsolatedStore isolatedStore)
         {
+            this.isoStore = isolatedStore;
+
             this.me = me;
             this.me.AutoPlay = false;
             this.me.BufferingProgressChanged += (s, e) => { this.BufferingProgress = me.BufferingProgress; RaisePropertyChanged("BufferingProgress"); };
             this.contest = new Contest("KVR-OSC-34.xml", "http://www.archive.org/download/KvrOsc34Sonigen/KvrOsc34Sonigen_files.xml");
 
             var kvrLoader = new KvrTrackLoader(this.contest);
-            var isoLoader = new IsolatedStoreTrackLoader(this.contest, new IsolatedStore());
+            var isoLoader = new IsolatedStoreTrackLoader(this.contest, this.isoStore);
             ITrackLoader loader = new CombinedTrackLoader(kvrLoader, isoLoader);
             loader.Loaded += new EventHandler<LoadedEventArgs>(loader_Loaded);
             this.IsLoading = true;
             }
             if (dirtyFlag == true)
             {
-                using (RatingsRepository repo = new RatingsRepository(new IsolatedStore()))
-                { 
-                    repo.Save(this.contest);
-                }
+                RatingsRepository repo = new RatingsRepository(this.isoStore);
+                repo.Save(this.contest);
                 dirtyFlag = false;
             }
         }
         private void Open()
         {
             var w = new OpenContestWindow();
-            w.DataContext = new OpenContestWindowViewModel();
+            w.DataContext = new OpenContestWindowViewModel(this.isoStore);
             w.Show();
         }
 

MusicRater/ViewModels/OpenContestWindowViewModel.cs

 using System.Windows.Media.Animation;
 using System.Windows.Shapes;
 using GalaSoft.MvvmLight;
+using MusicRater.Model;
+using System.Collections.ObjectModel;
 
 namespace MusicRater
 {
     public class OpenContestWindowViewModel : ViewModelBase
     {
+        public ObservableCollection<string> ContestFiles { get; private set; }
+        
+        public OpenContestWindowViewModel(IIsolatedStore store)
+        {
+            this.ContestFiles = new ObservableCollection<string>();
+            
+            foreach(var fileName in store.GetFileNames("*.xml"))
+            {
+                this.ContestFiles.Add(fileName);
+            }
+        }
 
     }
 }

MusicRater/Views/OpenContestWindow.xaml

            Title="OpenContestWindow">
     <Grid x:Name="LayoutRoot" Margin="2">
         <Grid.RowDefinitions>
-            <RowDefinition />
+            <RowDefinition Height="190*" />
+            <RowDefinition Height="Auto" />
             <RowDefinition Height="Auto" />
         </Grid.RowDefinitions>
-
-        <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
-        <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />
+        <ListBox ItemsSource="{Binding ContestFiles}">
+            
+        </ListBox>
+        <StackPanel Grid.Row="1" Margin="2" >
+            <TextBlock VerticalAlignment="Center" Margin="2,0">
+                To add a new contest, enter the URL for the Archive.org XML files list and click Add:
+            </TextBlock>
+            <TextBox Grid.Row="1" Width="300" HorizontalAlignment="Left" />
+        </StackPanel>
+        
+        
+        <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="2" />
+        <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="2" />
     </Grid>
 </controls:ChildWindow>