Skip to content

Commit

Permalink
Merge branch '2.5' into RavenDB-825
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkadiusz Palinski committed Apr 18, 2013
2 parents a2da636 + e780271 commit dc5f0fd
Show file tree
Hide file tree
Showing 76 changed files with 2,770 additions and 750 deletions.
3 changes: 0 additions & 3 deletions NuGet/RavenDB.Client.nuspec
Expand Up @@ -12,9 +12,6 @@
<projectUrl>http://www.ravendb.net/</projectUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<tags>nosql ravendb raven document database client</tags>
<dependencies>
<dependency id="Microsoft.CompilerServices.AsyncTargetingPack" version=""/>
</dependencies>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System.ComponentModel.Composition" targetFramework="net40" />
</frameworkAssemblies>
Expand Down
10 changes: 8 additions & 2 deletions Raven.Abstractions/Connection/HttpRavenRequest.cs
Expand Up @@ -169,6 +169,9 @@ private void SendRequestToServer(Action<WebResponse> action)
{
try
{
if (WebRequest.Method != "GET" && postedData == null && postedStream == null && postedToken == null)
WebRequest.ContentLength = 0;

using (var res = WebRequest.GetResponse())
{
action(res);
Expand Down Expand Up @@ -196,10 +199,13 @@ private void SendRequestToServer(Action<WebResponse> action)
ravenJObject = RavenJObject.Parse(error);
}
catch { }

e.Data["original-value"] = error;
if (ravenJObject == null)
throw;
throw new WebException("Error: " + ravenJObject.Value<string>("Error"), e);
throw new WebException("Error: " + ravenJObject.Value<string>("Error"), e)
{
Data = {{"original-value", error}}
};
}
}

Expand Down
2 changes: 2 additions & 0 deletions Raven.Abstractions/Connection/WebResponseExtensions.cs
Expand Up @@ -3,6 +3,7 @@
// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -42,6 +43,7 @@ public static Stream GetResponseStreamWithHttpDecompression(this WebResponse res
public static Stream GetResponseStreamWithHttpDecompression(this WebResponse response)
{
var stream = response.GetResponseStream();
Debug.Assert(stream != null, "stream != null");
var encoding = response.Headers["Content-Encoding"];
if (encoding != null && encoding.Contains("gzip"))
stream = new System.IO.Compression.GZipStream(stream, System.IO.Compression.CompressionMode.Decompress);
Expand Down
2 changes: 1 addition & 1 deletion Raven.Abstractions/Data/IndexQuery.cs
Expand Up @@ -239,7 +239,7 @@ public void AppendQueryString(StringBuilder path, bool includePageSizeEvenIfNotE
path.Append("&skipTransformResults=true");
}

if (ResultsTransformer != null)
if (string.IsNullOrEmpty(ResultsTransformer) == false)
{
path.AppendFormat("&resultsTransformer={0}", Uri.EscapeDataString(ResultsTransformer));
}
Expand Down
9 changes: 9 additions & 0 deletions Raven.Abstractions/Data/ReplicationInfoStatus.cs
@@ -0,0 +1,9 @@
namespace Raven.Abstractions.Data
{
public class ReplicationInfoStatus
{
public string Url { get; set; }
public string Status { get; set; }
public int Code { get; set; }
}
}
30 changes: 30 additions & 0 deletions Raven.Abstractions/Exceptions/IndexCompilationException.cs
@@ -0,0 +1,30 @@
using System;
using System.Runtime.Serialization;
using Raven.Abstractions.Extensions;

namespace Raven.Abstractions.Exceptions
{
public class IndexCompilationException : Exception
{
public IndexCompilationException(string message) : base(message)
{
}

public IndexCompilationException(string message, Exception innerException) : base(message, innerException)
{
}

public override string ToString()
{
return this.ExceptionToString(description =>
description.AppendFormat(
", IndexDefinitionProperty='{0}', ProblematicText='{1}'",
IndexDefinitionProperty,
ProblematicText));
}

public string IndexDefinitionProperty { get; set; }

public string ProblematicText { get; set; }
}
}
36 changes: 36 additions & 0 deletions Raven.Abstractions/Extensions/ExceptionExtensions.cs
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Raven.Imports.Newtonsoft.Json;
using Raven.Imports.Newtonsoft.Json.Linq;

Expand Down Expand Up @@ -96,5 +97,40 @@ public static string TryReadErrorPropertyFromJson(this string errorString)
return string.Empty;
}
}

public static T TryReadErrorResponseObject<T>(this Exception ex, T protoTypeObject = null) where T : class
{
var response = TryReadResponseIfWebException(ex);
if (string.IsNullOrEmpty(response))
{
return null;
}

return JsonConvert.DeserializeObject<T>(response);
}

/// <remarks>Code from http://stackoverflow.com/questions/1886611/c-overriding-tostring-method-for-custom-exceptions </remarks>
public static string ExceptionToString(
this Exception ex,
Action<StringBuilder> customFieldsFormatterAction)
{
var description = new StringBuilder();
description.AppendFormat("{0}: {1}", ex.GetType().Name, ex.Message);

if (customFieldsFormatterAction != null)
customFieldsFormatterAction(description);

if (ex.InnerException != null)
{
description.AppendFormat(" ---> {0}", ex.InnerException);
description.AppendFormat(
"{0} --- End of inner exception stack trace ---{0}",
Environment.NewLine);
}

description.Append(ex.StackTrace);

return description.ToString();
}
}
}
1 change: 1 addition & 0 deletions Raven.Abstractions/Indexing/SpatialOptions.cs
Expand Up @@ -95,6 +95,7 @@ public enum SpatialSearchStrategy
{
GeohashPrefixTree,
QuadPrefixTree,
BoundingBox
}

public enum SpatialRelation
Expand Down
19 changes: 19 additions & 0 deletions Raven.Abstractions/Indexing/SpatialOptionsFactory.cs
Expand Up @@ -51,6 +51,16 @@ public SpatialOptions Default(SpatialUnits circleRadiusUnits = SpatialUnits.Kilo
return GeohashPrefixTreeIndex(0, circleRadiusUnits);
}

public SpatialOptions BoundingBoxIndex(SpatialUnits circleRadiusUnits = SpatialUnits.Kilometers)
{
return new SpatialOptions
{
Type = SpatialFieldType.Geography,
Strategy = SpatialSearchStrategy.BoundingBox,
Units = circleRadiusUnits
};
}

public SpatialOptions GeohashPrefixTreeIndex(int maxTreeLevel, SpatialUnits circleRadiusUnits = SpatialUnits.Kilometers)
{
if (maxTreeLevel == 0)
Expand Down Expand Up @@ -82,6 +92,15 @@ public SpatialOptions QuadPrefixTreeIndex(int maxTreeLevel, SpatialUnits circleR

public class CartesianSpatialOptionsFactory
{
public SpatialOptions BoundingBoxIndex()
{
return new SpatialOptions
{
Type = SpatialFieldType.Cartesian,
Strategy = SpatialSearchStrategy.BoundingBox
};
}

public SpatialOptions QuadPrefixTreeIndex(int maxTreeLevel, SpatialBounds bounds)
{
if (maxTreeLevel == 0)
Expand Down
2 changes: 2 additions & 0 deletions Raven.Abstractions/Raven.Abstractions.csproj
Expand Up @@ -594,6 +594,7 @@
<Compile Include="Data\MoreLikeThisQueryResult.cs" />
<Compile Include="Data\PeriodicBackupSetup.cs" />
<Compile Include="Data\QueryHeaderInformation.cs" />
<Compile Include="Data\ReplicationInfoStatus.cs" />
<Compile Include="Data\RestoreStatus.cs" />
<Compile Include="Data\ScriptedPatchRequest.cs" />
<Compile Include="Data\AggregationOperation.cs" />
Expand Down Expand Up @@ -645,6 +646,7 @@
<Compile Include="Data\UserInfo.cs" />
<Compile Include="Data\UuidType.cs" />
<Compile Include="Exceptions\BadRequestException.cs" />
<Compile Include="Exceptions\IndexCompilationException.cs" />
<Compile Include="Exceptions\IndexDisabledException.cs" />
<Compile Include="Exceptions\IndexDoesNotExistsException.cs" />
<Compile Include="Exceptions\OperationVetoedException.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Raven.Abstractions/Smuggler/ISmugglerApi.cs
Expand Up @@ -6,6 +6,6 @@ namespace Raven.Abstractions.Smuggler
public interface ISmugglerApi
{
Task<string> ExportData(Stream stream, SmugglerOptions options, bool incremental);
Task ImportData(Stream stream, SmugglerOptions options, bool incremental);
Task ImportData(Stream stream, SmugglerOptions options);
}
}
28 changes: 15 additions & 13 deletions Raven.Abstractions/Smuggler/SmugglerApiBase.cs
Expand Up @@ -220,23 +220,25 @@ private async Task<Etag> ExportDocuments(SmugglerOptions options, JsonTextWriter
while (true)
{
var watch = Stopwatch.StartNew();
var documents = await GetDocuments(lastEtag);
watch.Stop();

while (await documents.MoveNextAsync())
using (var documents = await GetDocuments(lastEtag))
{
var document = documents.Current;
watch.Stop();

while (await documents.MoveNextAsync())
{
var document = documents.Current;

if (!options.MatchFilters(document))
continue;
if (!options.MatchFilters(document))
continue;

if (options.ShouldExcludeExpired && options.ExcludeExpired(document))
continue;
if (options.ShouldExcludeExpired && options.ExcludeExpired(document))
continue;

document.WriteTo(jsonWriter);
totalCount++;
document.WriteTo(jsonWriter);
totalCount++;

lastEtag = Etag.Parse(document.Value<RavenJObject>("@metadata").Value<string>("@etag"));
lastEtag = Etag.Parse(document.Value<RavenJObject>("@metadata").Value<string>("@etag"));
}
}

var databaseStatistics = await GetStats();
Expand Down Expand Up @@ -328,7 +330,7 @@ protected class AttachmentExportInfo

protected abstract Task EnsureDatabaseExists();

public virtual async Task ImportData(Stream stream, SmugglerOptions options, bool importIndexes = true)
public async virtual Task ImportData(Stream stream, SmugglerOptions options)
{
options = options ?? SmugglerOptions;
if (options == null)
Expand Down
12 changes: 11 additions & 1 deletion Raven.Client.Embedded/EmbeddedBulkInsertOperation.cs
Expand Up @@ -2,9 +2,9 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using Raven.Abstractions.Data;
using Raven.Abstractions.Util;
using Raven.Client.Document;
using Raven.Database;
using Raven.Database.Tasks;
using Raven.Json.Linq;
using Task = System.Threading.Tasks.Task;

Expand Down Expand Up @@ -72,6 +72,16 @@ private void ReportProgress(List<JsonDocument> list)
onReport("Writing " + list.Count + " items");
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <returns></returns>
public Task DisposeAsync()
{
Dispose();
return new CompletedTask();
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
Expand Down
38 changes: 37 additions & 1 deletion Raven.Client.Lightweight/Connection/Async/AsyncServerClient.cs
Expand Up @@ -297,6 +297,7 @@ public Task<string> DirectPutIndexAsync(string name, IndexDefinition indexDef, b
var response = we.Response as HttpWebResponse;
if (response == null || response.StatusCode != HttpStatusCode.NotFound)
throw;
}
var request = jsonRequestFactory.CreateHttpJsonRequest(
Expand All @@ -306,7 +307,42 @@ public Task<string> DirectPutIndexAsync(string name, IndexDefinition indexDef, b
var serializeObject = JsonConvert.SerializeObject(indexDef, Default.Converters);
return request.WriteAsync(serializeObject)
.ContinueWith(writeTask => request.ReadResponseJsonAsync()
.ContinueWith(readJsonTask => { return readJsonTask.Result.Value<string>("Index"); })).
.ContinueWith(readJsonTask =>
{
try
{
return readJsonTask.Result.Value<string>("Index");
}
catch (AggregateException e)
{
var we = e.ExtractSingleInnerException() as WebException;
if (we == null)
throw;
var response = we.Response as HttpWebResponse;
if (response.StatusCode == HttpStatusCode.BadRequest)
{
var error = we.TryReadErrorResponseObject(
new { Error = "", Message = "", IndexDefinitionProperty = "", ProblematicText = "" });
if (error == null)
{
throw;
}
var compilationException = new IndexCompilationException(error.Message)
{
IndexDefinitionProperty = error.IndexDefinitionProperty,
ProblematicText = error.ProblematicText
};
throw compilationException;
}
throw;
}
})).
Unwrap();
}).Unwrap();
}
Expand Down
12 changes: 11 additions & 1 deletion Raven.Client.Lightweight/Connection/HttpJsonRequest.cs
Expand Up @@ -23,6 +23,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Raven.Abstractions.Exceptions;
using Raven.Abstractions.Util;
using Raven.Imports.Newtonsoft.Json;
using Raven.Imports.Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -436,6 +437,8 @@ private RavenJToken HandleErrors(WebException e)
return result;
}



using (var sr = new StreamReader(e.Response.GetResponseStreamWithHttpDecompression()))
{
var readToEnd = sr.ReadToEnd();
Expand Down Expand Up @@ -463,7 +466,14 @@ private RavenJToken HandleErrors(WebException e)
{
throw new InvalidOperationException(readToEnd, e);
}

if (ravenJObject.ContainsKey("IndexDefinitionProperty"))
{
throw new IndexCompilationException(ravenJObject.Value<string>("Message"))
{
IndexDefinitionProperty = ravenJObject.Value<string>("IndexDefinitionProperty"),
ProblematicText = ravenJObject.Value<string>("ProblematicText")
};
}
if (ravenJObject.ContainsKey("Error"))
{
var sb = new StringBuilder();
Expand Down
4 changes: 2 additions & 2 deletions Raven.Client.Lightweight/Connection/Operation.cs
Expand Up @@ -46,9 +46,9 @@ public async Task<RavenJToken> WaitForCompletionAsync()
return null;
if (status.Value<bool>("Completed"))
return status.Value<RavenJToken>("State");
#if !MONO

await TaskEx.Delay(500);
#endif

}
}

Expand Down

0 comments on commit dc5f0fd

Please sign in to comment.