Permalink
Browse files

Merge branch 'master' of https://github.com/fitzchak1/ravendb

  • Loading branch information...
2 parents 82c1cc3 + b3372da commit 625696d170b36356be6b2f87da3dd7cca2a5fa17 @ayende ayende committed Nov 20, 2011
@@ -233,7 +233,7 @@ private void AddOperationHeaders(HttpWebRequest webRequest)
public IAsyncDatabaseCommands ForDatabase(string database)
{
var databaseUrl = url;
- var indexOfDatabases = databaseUrl.IndexOf("/databases/");
+ var indexOfDatabases = databaseUrl.IndexOf("/databases/", StringComparison.Ordinal);
if (indexOfDatabases != -1)
databaseUrl = databaseUrl.Substring(0, indexOfDatabases);
if (databaseUrl.EndsWith("/") == false)
@@ -248,7 +248,7 @@ public IAsyncDatabaseCommands ForDatabase(string database)
/// </summary>
public IAsyncDatabaseCommands GetRootDatabase()
{
- var indexOfDatabases = url.IndexOf("/databases/");
+ var indexOfDatabases = url.IndexOf("/databases/", StringComparison.Ordinal);
if (indexOfDatabases == -1)
return this;
@@ -960,7 +960,7 @@ public IDatabaseCommands With(ICredentials credentialsForSession)
public IDatabaseCommands ForDatabase(string database)
{
var databaseUrl = url;
- var indexOfDatabases = databaseUrl.IndexOf("/databases/");
+ var indexOfDatabases = databaseUrl.IndexOf("/databases/", StringComparison.Ordinal);
if (indexOfDatabases != -1)
databaseUrl = databaseUrl.Substring(0, indexOfDatabases);
if (databaseUrl.EndsWith("/") == false)
@@ -975,7 +975,7 @@ public IDatabaseCommands ForDatabase(string database)
/// </summary>
public IDatabaseCommands GetRootDatabase()
{
- var indexOfDatabases = url.IndexOf("/databases/");
+ var indexOfDatabases = url.IndexOf("/databases/", StringComparison.Ordinal);
if (indexOfDatabases == -1)
return this;
@@ -162,9 +162,9 @@ public static string DefaultTypeTagName(Type t)
if(t.IsGenericType)
{
var name = t.GetGenericTypeDefinition().Name;
- if(name.Contains("`"))
+ if(name.Contains('`'))
{
- name = name.Substring(0, name.IndexOf("`"));
+ name = name.Substring(0, name.IndexOf('`'));
}
var sb = new StringBuilder(Inflector.Pluralize(name));
foreach (var argument in t.GetGenericArguments())
@@ -85,7 +85,7 @@ public HttpJsonRequest CreateRequest(string relativeUrl, string method)
public IAsyncDatabaseCommands ForDatabase(string database)
{
var databaseUrl = url;
- var indexOfDatabases = databaseUrl.IndexOf("/databases/");
+ var indexOfDatabases = databaseUrl.IndexOf("/databases/", StringComparison.Ordinal);
if (indexOfDatabases != -1)
databaseUrl = databaseUrl.Substring(0, indexOfDatabases);
if (databaseUrl.EndsWith("/") == false)
@@ -112,7 +112,7 @@ public IAsyncDatabaseCommands With(ICredentials credentialsForSession)
/// </summary>
public IAsyncDatabaseCommands GetRootDatabase()
{
- var indexOfDatabases = url.IndexOf("/databases/");
+ var indexOfDatabases = url.IndexOf("/databases/", StringComparison.Ordinal);
if (indexOfDatabases == -1)
return this;
@@ -73,7 +73,7 @@ public bool HasWhereClause
{
if(hasWhereClause == null)
{
- hasWhereClause = ViewText.IndexOf("where", StringComparison.InvariantCultureIgnoreCase) > -1;
+ hasWhereClause = ViewText.IndexOf("where", StringComparison.OrdinalIgnoreCase) > -1;
}
return hasWhereClause.Value;
}
@@ -605,12 +605,12 @@ private static void AddHttpCompressionIfClientCanAcceptIt(IHttpContext ctx)
// gzip must be first, because chrome has an issue accepting deflate data
// when sending it json text
- if ((acceptEncoding.IndexOf("gzip", StringComparison.InvariantCultureIgnoreCase) != -1))
+ if ((acceptEncoding.IndexOf("gzip", StringComparison.OrdinalIgnoreCase) != -1))
{
ctx.SetResponseFilter(s => new GZipStream(s, CompressionMode.Compress, true));
ctx.Response.AddHeader("Content-Encoding", "gzip");
}
- else if (acceptEncoding.IndexOf("deflate", StringComparison.InvariantCultureIgnoreCase) != -1)
+ else if (acceptEncoding.IndexOf("deflate", StringComparison.OrdinalIgnoreCase) != -1)
{
ctx.SetResponseFilter(s => new DeflateStream(s, CompressionMode.Compress, true));
ctx.Response.AddHeader("Content-Encoding", "deflate");
@@ -239,7 +239,7 @@ public static void ResolveAnalyzers(IndexDefinition indexDefinition)
{
// Stick Lucene.Net's namespace to all analyzer aliases that are missing a namespace
var analyzerNames = (from analyzer in indexDefinition.Analyzers
- where analyzer.Value.IndexOf(".") == -1
+ where analyzer.Value.IndexOf('.') == -1
select analyzer).ToArray();
// Only do this for analyzer that actually exist; we do this here to be able to throw a correct error later on
@@ -30,7 +30,7 @@ public ExecuteQueryCommand(QueryModel model, IAsyncDatabaseCommands databaseComm
this.databaseCommands = databaseCommands;
}
- public override void Execute(object parameter)
+ public override void Execute(object _)
{
query = model.Query.Value;
ClearRecentQuery();
@@ -101,7 +101,8 @@ private void SuggestResults()
foreach (var fieldAndTerm in QueryEditor.GetCurrentFieldsAndTerms(model.Query.Value))
{
databaseCommands.SuggestAsync(model.IndexName, new SuggestionQuery {Field = fieldAndTerm.Field, Term = fieldAndTerm.Term, MaxSuggestions = 10})
- .ContinueOnSuccessInTheUIThread(result => model.Suggestions.AddRange(result.Suggestions.Select(term => new FieldAndTerm(fieldAndTerm.Field, term))));
+ .ContinueOnSuccessInTheUIThread(result => model.Suggestions.AddRange(
+ result.Suggestions.Select(term => new FieldAndTerm(fieldAndTerm.Field, fieldAndTerm.Term){SuggestedTerm = term})));
}
}
}
@@ -10,5 +10,6 @@ public FieldAndTerm(string field, string term)
public string Field { get; set; }
public string Term { get; set; }
+ public string SuggestedTerm { get; set; }
}
}
@@ -194,16 +194,14 @@
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Did you mean " />
- <TextBlock Text="{Binding Term}"
- Margin="2,0,0,0"
- FontStyle="Italic" />
- <TextBlock Margin="2,0,0,0"
- Text=" for the field " />
+ <HyperlinkButton Content="{Binding SuggestedTerm}"
+ FontStyle="Italic"
+ Command="{Binding Path=DataContext.RepairTermInQuery, ElementName=this}"
+ CommandParameter="{Binding}" />
+ <TextBlock Text=" for the field " />
<TextBlock Text="{Binding Field}"
- Margin="2,0,0,0"
FontStyle="Italic" />
- <TextBlock Margin="2,0,0,0"
- Text=" ?" />
+ <TextBlock Text=" ?" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
@@ -84,7 +84,21 @@ public CreateSampleDataCommand(HomeModel model, IAsyncDatabaseCommands databaseC
public override void Execute(object parameter)
{
-
+ var enumerator = CreateSampleData().GetEnumerator();
+ if (enumerator.MoveNext() == false)
+ return;
+ ProcessTasks(enumerator);
+ }
+
+ private static Task ProcessTasks(IEnumerator<Task> enumerator)
+ {
+ return enumerator.Current.ContinueWith(task =>
+ {
+ task.Wait();//would throw on error
+ if (enumerator.MoveNext() == false)
+ return task;
+ return ProcessTasks(enumerator);
+ }).Unwrap();
}
private IEnumerable<Task> CreateSampleData()
@@ -105,34 +119,34 @@ private IEnumerable<Task> CreateSampleData()
var ravenJObject = index.Value<RavenJObject>("definition");
var putDoc = databaseCommands
.PutIndexAsync(indexName,
- ravenJObject.JsonDeserialization<IndexDefinition>(),
- true);
+ ravenJObject.JsonDeserialization<IndexDefinition>(),
+ true);
yield return putDoc;
}
var batch = databaseCommands.BatchAsync(
musicStoreData.Value<RavenJArray>("Docs").OfType<RavenJObject>().Select(
doc =>
- {
- var metadata = doc.Value<RavenJObject>("@metadata");
- doc.Remove("@metadata");
- return new PutCommandData
- {
- Document = doc,
- Metadata = metadata,
- Key = metadata.Value<string>("@id"),
- };
- }).ToArray()
+ {
+ var metadata = doc.Value<RavenJObject>("@metadata");
+ doc.Remove("@metadata");
+ return new PutCommandData
+ {
+ Document = doc,
+ Metadata = metadata,
+ Key = metadata.Value<string>("@id"),
+ };
+ }).ToArray()
);
-
+
yield return batch;
model.IsGeneratingSampleData = false;
}
}
}
-#endregion
+ #endregion
}
}
@@ -273,5 +273,32 @@ public string ViewTitle
}
public BindableCollection<FieldAndTerm> Suggestions { get; private set; }
+ public ICommand RepairTermInQuery
+ {
+ get { return new RepairTermInQueryCommand(this); }
+ }
+
+ private class RepairTermInQueryCommand : Command
+ {
+ private readonly QueryModel model;
+ private FieldAndTerm fieldAndTerm;
+
+ public RepairTermInQueryCommand(QueryModel model)
+ {
+ this.model = model;
+ }
+
+ public override bool CanExecute(object parameter)
+ {
+ fieldAndTerm = parameter as FieldAndTerm;
+ return fieldAndTerm != null;
+ }
+
+ public override void Execute(object parameter)
+ {
+ model.Query.Value = model.Query.Value.Replace(fieldAndTerm.Term, fieldAndTerm.SuggestedTerm);
+ model.Execute.Execute(null);
+ }
+ }
}
}
@@ -150,7 +150,7 @@ private static IndexQuery EncodeAndDecodeIndexQuery(IndexQuery query)
// indexQueryUrl is in the form "/path?querystring#anchor"
- string indexQueryQuerystring = indexQueryUrl.Substring(indexQueryUrl.IndexOf("?")+1);
+ string indexQueryQuerystring = indexQueryUrl.Substring(indexQueryUrl.IndexOf('?') + 1);
int indexOfPoint = indexQueryQuerystring.IndexOf('#');
if (indexOfPoint != -1)

0 comments on commit 625696d

Please sign in to comment.