Skip to content

Commit

Permalink
First checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
samueldjack committed Jun 15, 2012
0 parents commit 2dab21e
Show file tree
Hide file tree
Showing 40 changed files with 5,664 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_ReSharper*
VirtualCollection/Bin/
*.user
VirtualCollection/obj/
*.suo
20 changes: 20 additions & 0 deletions VirtualCollection.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtualCollection", "VirtualCollection\VirtualCollection.csproj", "{19D96D76-77F4-456C-A04B-44F5FF9172E3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{19D96D76-77F4-456C-A04B-44F5FF9172E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19D96D76-77F4-456C-A04B-44F5FF9172E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19D96D76-77F4-456C-A04B-44F5FF9172E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19D96D76-77F4-456C-A04B-44F5FF9172E3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
8 changes: 8 additions & 0 deletions VirtualCollection/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="VirtualCollection.App"
>
<Application.Resources>

</Application.Resources>
</Application>
72 changes: 72 additions & 0 deletions VirtualCollection/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using VirtualCollection.Demo;

namespace VirtualCollection
{
public partial class App : Application
{

public App()
{
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
this.UnhandledException += this.Application_UnhandledException;

InitializeComponent();
}

private void Application_Startup(object sender, StartupEventArgs e)
{
Schedulers.UIThread = TaskScheduler.FromCurrentSynchronizationContext();

this.RootVisual = new MainPage();
}

private void Application_Exit(object sender, EventArgs e)
{

}

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
// If the app is running outside of the debugger then report the exception using
// the browser's exception mechanism. On IE this will display it a yellow alert
// icon in the status bar and Firefox will display a script error.
if (!System.Diagnostics.Debugger.IsAttached)
{

// NOTE: This will allow the application to continue running after an exception has been thrown
// but not handled.
// For production applications this error handling should be replaced with something that will
// report the error to the website and stop the application.
e.Handled = true;
Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
}
}

private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
{
try
{
string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");

System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
}
catch (Exception)
{
}
}
}
}
59 changes: 59 additions & 0 deletions VirtualCollection/BusynessIndicator.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<UserControl x:Class="VirtualCollection.BusynessIndicator"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Controls="clr-namespace:VirtualCollection" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400"
FontSize="12">

<Grid x:Name="LayoutRoot" DataContext="{Binding RelativeSource={RelativeSource AncestorType=Controls:BusynessIndicator}}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="BusyStates">
<VisualState x:Name="Busy">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="Glint"
Storyboard.TargetProperty="(Shape.Fill).(LinearGradientBrush.Transform).(TransformGroup.Children)[0].X"
Duration="00:00:.15" From="0" To="20" RepeatBehavior="Forever"/>
<DoubleAnimation Storyboard.TargetName="Glint"
Storyboard.TargetProperty="Opacity"
Duration="00:00:.15" To="0.7"
BeginTime="0:0:0.5"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Idle">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="Glint"
Storyboard.TargetProperty="Opacity"
Duration="00:00:.15" To="0" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="Container" Height="6" VerticalAlignment="Top" >
<Grid>
<Grid Visibility="Visible">
<Border Background="#E4E2E3"
Opacity="1"
RenderTransformOrigin="0.5,0.5"
CornerRadius="0,0,2,2"/>
<Rectangle x:Name="Glint" RadiusX="0" RadiusY="0" StrokeThickness="1" Margin="0" Opacity="0" >
<Rectangle.Fill>
<LinearGradientBrush SpreadMethod="Repeat" MappingMode="Absolute" EndPoint="0,1" StartPoint="20,1">
<LinearGradientBrush.Transform >
<TransformGroup>
<TranslateTransform X="0" />
<SkewTransform AngleX="-30" />
</TransformGroup>
</LinearGradientBrush.Transform>
<GradientStop Color="#78AB2148" Offset="0"/>
<GradientStop Color="#AB2148" Offset=".25"/>
<GradientStop Color="#78AB2148" Offset="0.85"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Grid>
</Border>
</Grid>
</UserControl>
65 changes: 65 additions & 0 deletions VirtualCollection/BusynessIndicator.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Windows;
using System.Windows.Controls;
using VirtualCollection.VirtualCollection;

namespace VirtualCollection
{
public partial class BusynessIndicator : UserControl
{
public static readonly DependencyProperty BusyBodyProperty =
DependencyProperty.Register("BusyBody", typeof(INotifyBusyness), typeof(BusynessIndicator), new PropertyMetadata(default(INotifyBusyness), HandleSourceChanged));

private static void HandleSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var notifier = d as BusynessIndicator;

if (e.OldValue != null)
{
(e.OldValue as INotifyBusyness).IsBusyChanged -= notifier.IsBusyChanged;
}

if (e.NewValue != null)
{
(e.NewValue as INotifyBusyness).IsBusyChanged += notifier.IsBusyChanged;
}
}

private void IsBusyChanged(object sender, EventArgs e)
{
if (Dispatcher.CheckAccess())
{
UpdateState();
}
else
{
Dispatcher.BeginInvoke(UpdateState);
}
}

private void UpdateState()
{
if (BusyBody != null && BusyBody.IsBusy)
{
VisualStateManager.GoToState(this, "Busy", true);
}
else
{
VisualStateManager.GoToState(this, "Idle", true);
}
}

public INotifyBusyness BusyBody
{
get { return (INotifyBusyness)GetValue(BusyBodyProperty); }
set { SetValue(BusyBodyProperty, value); }
}

public BusynessIndicator()
{
InitializeComponent();

VisualStateManager.GoToState(this, "Idle", true);
}
}
}
55 changes: 55 additions & 0 deletions VirtualCollection/Demo/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Data.Services.Client;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using VirtualCollection.Framework.MVVM;
using VirtualCollection.Netflix;
using VirtualCollection.VirtualCollection;

namespace VirtualCollection.Demo
{
public class MainViewModel : ViewModel
{
private string _search;
private NetflixTitleSource _source;

public string Search
{
get { return _search; }
set
{
_search = value;
_source.Search = value;
RaisePropertyChanged(() => Search);
}
}

public int count;

public VirtualCollection<Title> Items { get; private set; }


public MainViewModel()
{
_source = new NetflixTitleSource();
Items = new VirtualCollection<Title>(_source, 25, 25);
}

protected override void OnViewLoaded()
{
base.OnViewLoaded();

Items.Refresh();
}
}
}
93 changes: 93 additions & 0 deletions VirtualCollection/Demo/NetflixTitleSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Services.Client;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using VirtualCollection.Netflix;
using VirtualCollection.VirtualCollection;

namespace VirtualCollection.Demo
{
public class NetflixTitleSource : VirtualCollectionSource<Title>
{
private string _search;

public string Search
{
get { return _search; }
set
{
_search = value;
Refresh(RefreshMode.ClearStaleData);
}
}

protected override Task<int> GetCount()
{
return GetQueryResults(0, 1, null)
.ContinueWith(t => (int)t.Result.TotalCount, TaskContinuationOptions.ExecuteSynchronously);
}

protected override Task<IList<Title>> GetPageAsyncOverride(int start, int pageSize, IList<SortDescription> sortDescriptions)
{
return GetQueryResults(start, pageSize, sortDescriptions)
.ContinueWith(t => (IList<Title>)((IEnumerable<Title>)t.Result).ToList(), TaskContinuationOptions.ExecuteSynchronously);
}

private Task<QueryOperationResponse<Title>> GetQueryResults(int start, int pageSize, IList<SortDescription> sortDescriptions)
{
var context = new NetflixCatalog(new Uri("http://odata.netflix.com/Catalog"));

var orderByString = CreateOrderByString(sortDescriptions);
var query = context.Titles
.AddQueryOption("$skip", start)
.AddQueryOption("$top", pageSize)
.IncludeTotalCount();

if (!string.IsNullOrEmpty(Search))
{
query = query.AddQueryOption("$filter", "substringof('" + Search + "',Name) eq true");
}

if (orderByString.Length > 0)
{
query = query.AddQueryOption("$orderby", orderByString);
}

return Task.Factory.FromAsync<IEnumerable<Title>>(query.BeginExecute, query.EndExecute, null)
.ContinueWith(t => (QueryOperationResponse<Title>)t.Result, TaskContinuationOptions.ExecuteSynchronously);
}

private string CreateOrderByString(IList<SortDescription> sortDescriptions)
{
var sb = new StringBuilder();

if (sortDescriptions != null)
{
foreach (var sortDescription in sortDescriptions)
{
if (sb.Length > 0)
{
sb.Append(",");
}

sb.Append(sortDescription.PropertyName + " " +
(sortDescription.Direction == ListSortDirection.Ascending ? "asc" : "desc"));
}
}

return sb.ToString();
}
}
}
Loading

0 comments on commit 2dab21e

Please sign in to comment.