Permalink
Browse files

Fixed RavenDB-328: Query error now disappears when retrying query.

Re-organised VirtualCollection code a little. VirtualCollection is no longer responsible for handling errors that occur in data-fetch tasks: VirtualCollectionSource handles these in coopreation with the parent viewmodels.

Enabled VirtualCollectionSource to keep track of when it is busy

VirtualCollection now nulls out any data items in pages that it failed to fetch.
  • Loading branch information...
1 parent f94f745 commit 47b33a38e56e480707dd0c6b47aeb07ab9203d2f @samueldjack samueldjack committed Jun 15, 2012
@@ -46,7 +46,7 @@ protected override Task<int> GetCount()
TaskContinuationOptions.ExecuteSynchronously);
}
- public override Task<IList<ViewableDocument>> GetPageAsync(int start, int pageSize, IList<SortDescription> sortDescriptions)
+ protected override Task<IList<ViewableDocument>> GetPageAsyncOverride(int start, int pageSize, IList<SortDescription> sortDescriptions)
{
return GetQueryResults(start, pageSize)
.ContinueWith(task =>
@@ -78,7 +78,8 @@ private Task<QueryResult> GetQueryResults(int start, int pageSize)
return ApplicationModel.DatabaseCommands
.QueryAsync("Raven/DocumentsByEntityName",
new IndexQuery {Start = start, PageSize = pageSize, Query = "Tag:" + collectionName},
- new string[] {});
+ new string[] {})
+ .Catch();
}
}
}
@@ -26,14 +26,15 @@ protected override Task<int> GetCount()
}
}
- public override Task<IList<ViewableDocument>> GetPageAsync(int start, int pageSize, IList<SortDescription> sortDescriptions)
+ protected override Task<IList<ViewableDocument>> GetPageAsyncOverride(int start, int pageSize, IList<SortDescription> sortDescriptions)
{
return ApplicationModel.DatabaseCommands.GetDocumentsAsync(start, pageSize)
.ContinueWith(t =>
{
var docs = (IList<ViewableDocument>)t.Result.Select(x => new ViewableDocument(x)).ToArray();
return docs;
- });
+ })
+ .Catch();
}
}
}
@@ -56,7 +56,7 @@ public override void Execute(object parameter)
private void ClearRecentQuery()
{
- model.Error = null;
+ model.ClearQueryError();
model.Suggestions.Clear();
}
@@ -27,6 +27,7 @@ public class QueryDocumentsCollectionSource : VirtualCollectionSource<ViewableDo
private string _indexName;
private readonly object _lockObject = new object();
+ public event EventHandler<QueryErrorEventArgs> QueryError;
public event EventHandler<QueryStatisticsUpdatedEventArgs> QueryStatisticsUpdated;
public IndexQuery TemplateQuery
@@ -58,7 +59,7 @@ protected override Task<int> GetCount()
TaskContinuationOptions.ExecuteSynchronously);
}
- public override Task<IList<ViewableDocument>> GetPageAsync(int start, int pageSize, IList<SortDescription> sortDescriptions)
+ protected override Task<IList<ViewableDocument>> GetPageAsyncOverride(int start, int pageSize, IList<SortDescription> sortDescriptions)
{
return GetQueryResults(start, pageSize)
.ContinueWith(task =>
@@ -134,13 +135,24 @@ private Task<QueryResult> GetQueryResults(int start, int pageSize)
Statistics = statistics
});
+ if (task.IsFaulted)
+ {
+ OnQueryError(new QueryErrorEventArgs() { Exception = task.Exception});
+ }
+
return task.Result;
}, TaskContinuationOptions.ExecuteSynchronously);
}
protected void OnQueryStatisticsUpdated(QueryStatisticsUpdatedEventArgs e)
{
- EventHandler<QueryStatisticsUpdatedEventArgs> handler = QueryStatisticsUpdated;
+ var handler = QueryStatisticsUpdated;
+ if (handler != null) handler(this, e);
+ }
+
+ protected void OnQueryError(QueryErrorEventArgs e)
+ {
+ var handler = QueryError;
if (handler != null) handler(this, e);
}
}
@@ -151,4 +163,9 @@ public class QueryStatisticsUpdatedEventArgs : EventArgs
public TimeSpan QueryTime { get; set; }
}
+
+ public class QueryErrorEventArgs : EventArgs
+ {
+ public Exception Exception { get; set; }
+ }
}
@@ -12,10 +12,18 @@
xmlns:Controls="clr-namespace:System.Windows.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:Models="clr-namespace:Raven.Studio.Models" mc:Ignorable="d"
+ xmlns:Models="clr-namespace:Raven.Studio.Models"
+ xmlns:Behaviors="clr-namespace:Raven.Studio.Behaviors" mc:Ignorable="d"
d:DataContext="{d:DesignInstance Models:QueryModel}">
-
- <Grid Margin="{StaticResource Margin_ContentPage}">
+ <Infrastructure:PageView.Resources>
+ <Storyboard x:Key="ShowErrorPanel">
+ <DoubleAnimation Storyboard.TargetName="QueryErrorPanel" Storyboard.TargetProperty="Height" To="50" Duration="0:0:0.1"/>
+ </Storyboard>
+ <Storyboard x:Key="HideErrorPanel">
+ <DoubleAnimation Storyboard.TargetName="QueryErrorPanel" Storyboard.TargetProperty="Height" To="0" Duration="0:0:0.1"/>
+ </Storyboard>
+ </Infrastructure:PageView.Resources>
+ <Grid Margin="{StaticResource Margin_ContentPage}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
@@ -147,6 +155,24 @@
</i:Interaction.Triggers>
</Editors:QueryEditor>
+ <Border Background="{StaticResource Brush_ErrorBackground}"
+ Grid.Row="1" Height="0"
+ VerticalAlignment="Bottom"
+ x:Name="QueryErrorPanel">
+ <i:Interaction.Triggers>
+ <ei:DataTrigger Binding="{Binding IsErrorVisible.Value}" Value="True" Comparison="Equal">
+ <ei:ControlStoryboardAction Storyboard="{StaticResource ShowErrorPanel}" ControlStoryboardOption="Play"/>
+ </ei:DataTrigger>
+ <ei:DataTrigger Binding="{Binding IsErrorVisible.Value}" Value="False" Comparison="Equal">
+ <ei:ControlStoryboardAction Storyboard="{StaticResource HideErrorPanel}" ControlStoryboardOption="Play"/>
+ </ei:DataTrigger>
+ </i:Interaction.Triggers>
+ <TextBlock Text="{Binding QueryErrorMessage.Value}" Foreground="White" Margin="5" VerticalAlignment="Top"
+ TextWrapping="Wrap"
+ Behaviors:FadeTrimming.IsEnabled="True"
+ Behaviors:FadeTrimming.ShowTextInToolTipWhenTrimmed="True"/>
+ </Border>
+
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
@@ -241,14 +267,6 @@
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
- <TextBlock Grid.Row="0"
- Text="Error"
- Style="{StaticResource Style_TextBlock_PagePartHeader}"
- Visibility="{Binding Error, Converter={StaticResource HiddenWhenNull}}" />
-
- <TextBlock Grid.Row="1"
- Text="{Binding Error}"
- Visibility="{Binding Error, Converter={StaticResource HiddenWhenNull}}" />
<Grid Grid.Row="2">
<Grid.RowDefinitions>
@@ -8,7 +8,6 @@ namespace Raven.Studio.Infrastructure
public interface IVirtualCollectionSource<T>
{
event EventHandler<VirtualCollectionSourceChangedEventArgs> CollectionChanged;
- event EventHandler<DataFetchErrorEventArgs> DataFetchError;
int Count { get; }
@@ -29,7 +28,13 @@ public VirtualCollectionSourceChangedEventArgs(ChangeType changeType)
public enum ChangeType
{
+ /// <summary>
+ /// Current data is invalid and should be cleared
+ /// </summary>
Reset,
+ /// <summary>
+ /// Current data may still be valid, and can be shown whilst refreshing
+ /// </summary>
Refresh,
}
}
@@ -0,0 +1,16 @@
+using System;
+
+namespace Raven.Studio.Infrastructure
+{
+ public class ItemsRealizedEventArgs : EventArgs
+ {
+ public ItemsRealizedEventArgs(int startIndex, int count)
+ {
+ StartingIndex = startIndex;
+ Count = count;
+ }
+
+ public int StartingIndex { get; private set; }
+ public int Count { get; private set; }
+ }
+}
@@ -0,0 +1,8 @@
+namespace Raven.Studio.Infrastructure
+{
+ public enum RefreshMode
+ {
+ PermitStaleDataWhilstRefreshing,
+ ClearStaleData,
+ }
+}
Oops, something went wrong.

0 comments on commit 47b33a3

Please sign in to comment.