Last active
December 19, 2015 00:39
-
-
Save anuith/5869895 to your computer and use it in GitHub Desktop.
Sample data source class to use in design-time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Collections.Generic; | |
using System.Collections.ObjectModel; | |
using System.ComponentModel; | |
using System.Runtime.CompilerServices; | |
using Windows.ApplicationModel.Resources.Core; | |
using Windows.Foundation; | |
using Windows.Foundation.Collections; | |
using Windows.UI.Xaml.Data; | |
using Windows.UI.Xaml.Media; | |
using Windows.UI.Xaml.Media.Imaging; | |
using System.Collections.Specialized; | |
using System.Threading.Tasks; | |
using Windows.ApplicationModel; | |
using Windows.Storage; | |
using Windows.Data.Json; | |
// The data model defined by this file serves as a representative example of a strongly-typed | |
// model that supports notification when members are added, removed, or modified. The property | |
// names chosen coincide with data bindings in the standard item templates. | |
// | |
// Applications may use this model as a starting point and build on it, or discard it entirely and | |
// replace it with something appropriate to their needs. | |
namespace KRATIBMoviesSample.Data | |
{ | |
/// <summary> | |
/// Creates a collection of groups and items with hard-coded content. | |
/// | |
/// SampleDataSource initializes with placeholder data rather than live production | |
/// data so that sample data is provided at both design-time and run-time. | |
/// </summary> | |
public sealed class MoviesSampleDataSource | |
{ | |
private static MoviesSampleDataSource _sampleDataSource = new MoviesSampleDataSource(); | |
private ObservableCollection<MovieDataYear> _allGroups = new ObservableCollection<MovieDataYear>(); | |
public ObservableCollection<MovieDataYear> AllGroups | |
{ | |
get { return this._allGroups; } | |
} | |
public static IEnumerable<MovieDataYear> GetGroups(string uniqueId) | |
{ | |
if (!uniqueId.Equals("AllGroups")) throw new ArgumentException("Only 'AllGroups' is supported as a collection of groups"); | |
return _sampleDataSource.AllGroups; | |
} | |
public static MovieDataYear GetGroup(string uniqueId) | |
{ | |
// Simple linear search is acceptable for small data sets | |
var matches = _sampleDataSource.AllGroups.Where((group) => group.UniqueId.Equals(uniqueId)); | |
if (matches.Count() == 1) return matches.First(); | |
return null; | |
} | |
public static MovieDataItem GetItem(string uniqueId) | |
{ | |
// Simple linear search is acceptable for small data sets | |
var matches = _sampleDataSource.AllGroups.SelectMany(group => group.Items).Where((item) => item.UniqueId.Equals(uniqueId)); | |
if (matches.Count() == 1) return matches.First(); | |
return null; | |
} | |
public MoviesSampleDataSource() | |
{ | |
var group1 = new MovieDataYear("Year-2013", "2013", 2013); | |
group1.Items.Add(new MovieDataItem("Movie-Iron-Man-3", // uniqueId | |
"Iron Man 3", // Name | |
"It's about Tony Stark", // Description | |
new String[] { "Action", "Drama" }, // Genres | |
"PG-13", | |
new DateTime(2013, 01, 01), // DatePublished | |
group1, | |
new TimeSpan(0, 130, 0), // Duration | |
"Assets/posters/iron_man_3.jpg")); // PosterImagePath | |
group1.Items.Add(new MovieDataItem("Movie-Iron-Man-4", | |
"Iron Man 4", | |
"It's about Tony Stark", | |
new String[] { "Action", "Comedy" }, | |
"PG-13", | |
new DateTime(2013, 02, 01), | |
group1, | |
new TimeSpan(0, 140, 0), | |
"Assets/posters/iron_man_3.jpg")); | |
this.AllGroups.Add(group1); | |
var group2 = new MovieDataYear("Year-2014", "2014", 2014); | |
group2.Items.Add(new MovieDataItem("Movie-Iron-Man-5", | |
"Iron Man 5", | |
"It's about Tony Stark laughing", | |
new String[] { "Action", "Strategy" }, | |
"PG-13", | |
new DateTime(2014, 01, 01), | |
group2, | |
new TimeSpan(0, 130, 0), | |
"Assets/posters/iron_man_3.jpg")); | |
group2.Items.Add(new MovieDataItem("Movie-Iron-Man-6", | |
"Iron Man 6", | |
"It's about Tony Stark laughing", | |
new String[] { "Action", "Comedy" }, | |
"PG-13", | |
new DateTime(2014, 02, 01), | |
group2, | |
new TimeSpan(0, 140, 0), | |
"Assets/posters/iron_man_3.jpg")); | |
group2.Items.Add(new MovieDataItem("Movie-Iron-Man-7", | |
"Iron Man 7", | |
"It's about Tony Stark laughing", | |
new String[] { "Action", "Comedy" }, | |
"PG-13", | |
new DateTime(2014, 03, 01), | |
group2, | |
new TimeSpan(0, 140, 0), | |
"Assets/posters/iron_man_3.jpg")); | |
this.AllGroups.Add(group2); | |
var group3 = new MovieDataYear("Year-2015", "2015", 2015); | |
group3.Items.Add(new MovieDataItem("Movie-Iron-Man-5", | |
"Iron Man 5", | |
"It's about Tony Stark laughing", | |
new String[] { "Action", "Strategy" }, | |
"PG-13", | |
new DateTime(2015, 01, 01), | |
group3, | |
new TimeSpan(0, 130, 0), | |
"Assets/posters/iron_man_3.jpg")); | |
this.AllGroups.Add(group3); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment