Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ayende/ravendb
Browse files Browse the repository at this point in the history
  • Loading branch information
Fitzchak Yitzchaki committed Jan 7, 2013
2 parents f550e85 + c1d21c0 commit 08aa244
Show file tree
Hide file tree
Showing 81 changed files with 1,376 additions and 390 deletions.
1 change: 0 additions & 1 deletion Bundles/Raven.Bundles.Tests/Expiration/WithCascade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public WithCascade()
};
ravenConfiguration.PostInit();
ravenDbServer = new RavenDbServer(ravenConfiguration);
database::Raven.Bundles.Expiration.ExpirationReadTrigger.GetCurrentUtcDate = () => DateTime.UtcNow;
documentStore = new DocumentStore
{
Url = "http://localhost:8079"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public CanReplicateToSql()
}
};
documentStore.Initialize();
database::Raven.Bundles.Expiration.ExpirationReadTrigger.GetCurrentUtcDate = () => DateTime.UtcNow;

documentStore.DatabaseCommands.PutIndex(
"Questions/Votes",
Expand Down
2 changes: 1 addition & 1 deletion Imports/Newtonsoft.Json/Src/Newtonsoft.Json/JsonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ protected JsonReader()
_currentState = State.Start;
_stack = new List<JsonPosition>(4);
_dateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
_dateParseHandling = DateParseHandling.DateTime;
_dateParseHandling = DateParseHandling.None;

CloseInput = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Raven.Abstractions/Connection/HttpRavenRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public T ExecuteRequest<T>()
return result;
}

public void ExecuteRequest(Action<StreamReader> action)
public void ExecuteRequest(Action<TextReader> action)
{
SendRequestToServer(response =>
{
Expand Down
2 changes: 1 addition & 1 deletion Raven.Abstractions/Data/ApiKeyDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public string ConnectionString
if (string.IsNullOrWhiteSpace(Name) || string.IsNullOrWhiteSpace(Secret))
return null;

return string.Format(@"ApiKey = {0}, Database = {1}", FullApiKey, DbName);
return string.Format(@"ApiKey = {0}; Database = {1}", FullApiKey, DbName);
}
}

Expand Down
1 change: 1 addition & 0 deletions Raven.Abstractions/Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public static class Default
{
public static readonly string[] OnlyDateTimeFormat = new[]
{
"yyyy'-'MM'-'dd'T'HH':'mm':'ss",
"yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffff",
"yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffff'Z'"
};
Expand Down
4 changes: 3 additions & 1 deletion Raven.Abstractions/Json/Linq/DictionaryWithParentSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public ICollection<string> Keys

foreach (var key in LocalChanges.Keys)
{
if (LocalChanges[key] == DeletedMarker)
RavenJToken value;
if (LocalChanges.TryGetValue(key, out value) == false ||
value == DeletedMarker)
continue;
ret.Add(key);
++counter;
Expand Down
4 changes: 4 additions & 0 deletions Raven.Abstractions/Smuggler/SmugglerApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ private Guid ExportDocuments(SmugglerOptions options, JsonTextWriter jsonWriter,
ModifyBatchSize(options, currentProcessingTime);

var final = documents.Where(options.MatchFilters).ToList();

if (options.ShouldExcludeExpired)
final = documents.Where(options.ExcludeExpired).ToList();

final.ForEach(item => item.WriteTo(jsonWriter));
totalCount += final.Count;

Expand Down
36 changes: 36 additions & 0 deletions Raven.Abstractions/Smuggler/SmugglerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public SmugglerOptions()
Timeout = 30 * 1000; // 30 seconds
BatchSize = 1024;
LastAttachmentEtag = LastDocsEtag = Guid.Empty;
ShouldExcludeExpired = false;
}

/// <summary>
Expand Down Expand Up @@ -79,8 +80,43 @@ public virtual bool MatchFilters(RavenJToken item)
}
return true;
}

/// <summary>
/// Should we exclude any documents which have already expired by checking the expiration meta property created by the expiration bundle
/// </summary>
public bool ShouldExcludeExpired { get; set; }

public virtual bool ExcludeExpired(RavenJToken item)
{
var metadata= item.Value<RavenJObject>("@metadata");

const string RavenExpirationDate = "Raven-Expiration-Date";

// check for expired documents and exclude them if expired
if (metadata == null)
{
return false;
}
var property = metadata[RavenExpirationDate];
if (property == null)
return false;

DateTime dateTime;
try
{
dateTime = property.Value<DateTime>();
}
catch (FormatException)
{
return false;
}

return dateTime >= SystemTime.UtcNow;
}
}



[Flags]
public enum ItemType
{
Expand Down
5 changes: 0 additions & 5 deletions Raven.Client.Embedded/EmbeddedAsyncServerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,6 @@ public Task<string[]> GetTermsAsync(string index, string field, string fromValue
return new CompletedTask<string[]>(databaseCommands.GetTerms(index, field, fromValue, pageSize).ToArray());
}

public Task EnsureSilverlightStartUpAsync()
{
throw new NotSupportedException("Method to be removed from IAsyncDatabaseCommands (RavenDB-761)");
}

public IDisposable DisableAllCaching()
{
return databaseCommands.DisableAllCaching();
Expand Down
22 changes: 2 additions & 20 deletions Raven.Client.Lightweight/Connection/Async/AsyncServerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,8 @@ public Task StartRestoreAsync(string restoreLocation, string databaseLocation, s
return request.ExecuteWriteAsync(new RavenJObject
{
{"RestoreLocation", restoreLocation},
{"DatabaseLocation", databaseLocation}
{"DatabaseLocation", databaseLocation},
{"DatabaseName", name}
}.ToString(Formatting.None))
.ContinueWith(task =>
{
Expand Down Expand Up @@ -1201,25 +1202,6 @@ public IDisposable DisableAllCaching()
return jsonRequestFactory.DisableAllCaching();
}

/// <summary>
/// Ensures that the silverlight startup tasks have run
/// </summary>
public Task EnsureSilverlightStartUpAsync()
{
#if !SILVERLIGHT
throw new NotSupportedException("Only applicable in silverlight");
#else
return ExecuteWithReplication("GET", url =>
{
return url
.SilverlightEnsuresStartup()
.NoCache()
.ToJsonRequest(this, credentials, convention)
.ReadResponseBytesAsync();
});
#endif
}

///<summary>
/// Get the possible terms for the specified field in the index asynchronously
/// You can page through the results by use fromValue parameter as the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,6 @@ public interface IAsyncDatabaseCommands : IDisposable, IHoldProfilingInformation
///<returns></returns>
Task<string[]> GetTermsAsync(string index, string field, string fromValue, int pageSize);

/// <summary>
/// Ensures that the silverlight startup tasks have run
/// </summary>
Task EnsureSilverlightStartUpAsync();

/// <summary>
/// Disable all caching within the given scope
/// </summary>
Expand Down
11 changes: 9 additions & 2 deletions Raven.Client.Lightweight/Connection/HttpJsonRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,13 @@ public string ContentType
get { return webRequest.ContentType; }
set { webRequest.ContentType = value; }
}
public TimeSpan Timeout
{
set
{
webRequest.Timeout = (int)value.TotalMilliseconds;
}
}

private void WriteMetadata(RavenJObject metadata)
{
Expand Down Expand Up @@ -806,11 +813,11 @@ public Task<Stream> GetRawRequestStream()
return Task.Factory.FromAsync<Stream>(webRequest.BeginGetRequestStream, webRequest.EndGetRequestStream, null);
}

public void RawExecuteRequest()
public WebResponse RawExecuteRequest()
{
try
{
webRequest.GetResponse().Close();
return webRequest.GetResponse();
}
catch (WebException we)
{
Expand Down
8 changes: 7 additions & 1 deletion Raven.Client.Lightweight/Connection/ObservableLineStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Raven.Abstractions.Extensions;
Expand Down Expand Up @@ -103,8 +104,13 @@ public void Start()
// explicitly ignoring this
}
var aggregateException = task.Exception;
if (aggregateException.ExtractSingleInnerException() is ObjectDisposedException)
var exception = aggregateException.ExtractSingleInnerException();
if (exception is ObjectDisposedException)
return; // this isn't an error
var we = exception as WebException;
if (we != null && we.Status == WebExceptionStatus.RequestCanceled)
return; // not an error, actually
foreach (var subscriber in subscribers)
{
subscriber.OnError(aggregateException);
Expand Down
5 changes: 0 additions & 5 deletions Raven.Client.Lightweight/Connection/RavenUrlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public static string Databases(this string url, int pageSize, int start)
return start > 0 ? databases + "&start=" + start : databases;
}

public static string SilverlightEnsuresStartup(this string url)
{
return url + "/silverlight/ensureStartup";
}

public static string Terms(this string url, string index, string field, string fromValue, int pageSize)
{
return url + "/terms/" + index + "?field=" + field + "&fromValue=" + fromValue + "&pageSize=" + pageSize;
Expand Down
18 changes: 18 additions & 0 deletions Raven.Client.Lightweight/Connection/ServerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,24 @@ public void Dispose()
{
Dispose();
}

public RavenJToken GetOperationStatus(long id)
{
var request = jsonRequestFactory.CreateHttpJsonRequest(
new CreateHttpJsonRequestParams(this, url + "/operation/status?id" + id, "GET", credentials, convention)
.AddOperationHeaders(OperationsHeaders));
try
{
return request.ReadResponseJson();
}
catch (WebException e)
{
var httpWebResponse = e.Response as HttpWebResponse;
if (httpWebResponse == null || httpWebResponse.StatusCode != HttpStatusCode.NotFound)
throw;
return null;
}
}
}
}
#endif
27 changes: 26 additions & 1 deletion Raven.Client.Lightweight/Document/RemoteBulkInsertOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Threading;
using System.Threading.Tasks;
using Raven.Abstractions.Data;
using Raven.Client.Connection;
using Raven.Client.Extensions;
using Raven.Imports.Newtonsoft.Json;
using Raven.Imports.Newtonsoft.Json.Bson;
using Raven.Json.Linq;

Expand All @@ -24,6 +26,7 @@ public interface ILowLevelBulkInsertOperation : IDisposable

public class RemoteBulkInsertOperation : ILowLevelBulkInsertOperation
{
private readonly ServerClient client;
private readonly MemoryStream bufferedStream = new MemoryStream();
private readonly HttpJsonRequest httpJsonRequest;
private readonly BlockingCollection<RavenJObject> items;
Expand All @@ -32,6 +35,7 @@ public class RemoteBulkInsertOperation : ILowLevelBulkInsertOperation

public RemoteBulkInsertOperation(BulkInsertOptions options, ServerClient client)
{
this.client = client;
items = new BlockingCollection<RavenJObject>(options.BatchSize*8);
string requestUrl = "/bulkInsert?";
if (options.CheckForUpdates)
Expand All @@ -46,6 +50,8 @@ public RemoteBulkInsertOperation(BulkInsertOptions options, ServerClient client)


httpJsonRequest = client.CreateRequest("POST", requestUrl, disableRequestCompression: true);
// the request may take a long time to process, so we need to set a large timeout value
httpJsonRequest.Timeout = TimeSpan.FromHours(6);
nextTask = httpJsonRequest.GetRawRequestStream()
.ContinueWith(task =>
{
Expand Down Expand Up @@ -97,7 +103,26 @@ public void Dispose()
{
report("Finished writing all results to server");
}
httpJsonRequest.RawExecuteRequest();
long id;
using (var response = httpJsonRequest.RawExecuteRequest())
using(var stream = response.GetResponseStream())
using(var streamReader = new StreamReader(stream))
{
var result = RavenJObject.Load(new JsonTextReader(streamReader));
id = result.Value<long>("OperationId");
}
while (true)
{
var status = client.GetOperationStatus(id);
if (status == null)
break;
if (status.Value<bool>("Completed"))
break;
Thread.Sleep(500);
}
if (report != null)
{
report("Done writing to server");
Expand Down
11 changes: 8 additions & 3 deletions Raven.Client.Lightweight/Indexes/ExpressionStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,14 @@ protected override Expression VisitConstant(ConstantExpression node)
Out(s);
return node;
}
Out('"');
Out(node.Value.ToString());
Out('"');
if (convention.SaveEnumsAsIntegers)
Out((Convert.ToInt32(node.Value)).ToString());
else
{
Out('"');
Out(node.Value.ToString());
Out('"');
}
return node;
}
if (node.Value is decimal)
Expand Down
13 changes: 10 additions & 3 deletions Raven.Client.Lightweight/Linq/LinqPathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,17 @@ public object GetValueFromExpression(Expression expression, Type type)
object value;
if (GetValueFromExpressionWithoutConversion(expression, out value))
{
if (type.IsEnum && (value is IEnumerable == false) && // skip arrays, lists
conventions.SaveEnumsAsIntegers == false)
if (value is IEnumerable)
return value;

var nonNullableType = Nullable.GetUnderlyingType(type) ?? type;
if (value is Enum || nonNullableType.IsEnum)
{
return Enum.GetName(type, value);
if (value == null)
return null;
if (conventions.SaveEnumsAsIntegers == false)
return Enum.GetName(nonNullableType, value);
return Convert.ToInt32(value);
}
return value;
}
Expand Down
5 changes: 5 additions & 0 deletions Raven.Client.Silverlight/Connection/HttpJsonRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ private Task RecreateWebRequest(Action<HttpWebRequest> result)

private static Task noopWaitForTask = new CompletedTask();


public TimeSpan Timeout
{
set { } // can't set timeout in Silverlight
}
/// <summary>
/// Gets or sets the response headers.
/// </summary>
Expand Down
Loading

0 comments on commit 08aa244

Please sign in to comment.