Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/fitzchak1/ravendb
Browse files Browse the repository at this point in the history
  • Loading branch information
ayende committed Dec 8, 2011
2 parents 332b15a + ee621a8 commit 72b0bcf
Show file tree
Hide file tree
Showing 21 changed files with 715 additions and 614 deletions.
24 changes: 24 additions & 0 deletions Bundles/Raven.Bundles.sln
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raven.Bundles.MoreLikeThis"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raven.Client.MoreLikeThis", "Raven.Client.MoreLikeThis\Raven.Client.MoreLikeThis.csproj", "{039CB1C3-C4F3-4D87-A2C0-7531E386E6A3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RavensNest.OAuth", "..\..\RavensNest\RavensNest.OAuth\RavensNest.OAuth.csproj", "{CA139FC8-4671-4817-8C25-43F5F0C8DCD7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApplication1", "..\..\temp\ConsoleApplication1\ConsoleApplication1.csproj", "{D2390328-CC2C-4DE2-A554-D032B1F3BB4E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -288,6 +292,26 @@ Global
{039CB1C3-C4F3-4D87-A2C0-7531E386E6A3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{039CB1C3-C4F3-4D87-A2C0-7531E386E6A3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{039CB1C3-C4F3-4D87-A2C0-7531E386E6A3}.Release|x86.ActiveCfg = Release|Any CPU
{CA139FC8-4671-4817-8C25-43F5F0C8DCD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA139FC8-4671-4817-8C25-43F5F0C8DCD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA139FC8-4671-4817-8C25-43F5F0C8DCD7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{CA139FC8-4671-4817-8C25-43F5F0C8DCD7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{CA139FC8-4671-4817-8C25-43F5F0C8DCD7}.Debug|x86.ActiveCfg = Debug|Any CPU
{CA139FC8-4671-4817-8C25-43F5F0C8DCD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA139FC8-4671-4817-8C25-43F5F0C8DCD7}.Release|Any CPU.Build.0 = Release|Any CPU
{CA139FC8-4671-4817-8C25-43F5F0C8DCD7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{CA139FC8-4671-4817-8C25-43F5F0C8DCD7}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{CA139FC8-4671-4817-8C25-43F5F0C8DCD7}.Release|x86.ActiveCfg = Release|Any CPU
{D2390328-CC2C-4DE2-A554-D032B1F3BB4E}.Debug|Any CPU.ActiveCfg = Debug|x86
{D2390328-CC2C-4DE2-A554-D032B1F3BB4E}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{D2390328-CC2C-4DE2-A554-D032B1F3BB4E}.Debug|Mixed Platforms.Build.0 = Debug|x86
{D2390328-CC2C-4DE2-A554-D032B1F3BB4E}.Debug|x86.ActiveCfg = Debug|x86
{D2390328-CC2C-4DE2-A554-D032B1F3BB4E}.Debug|x86.Build.0 = Debug|x86
{D2390328-CC2C-4DE2-A554-D032B1F3BB4E}.Release|Any CPU.ActiveCfg = Release|x86
{D2390328-CC2C-4DE2-A554-D032B1F3BB4E}.Release|Mixed Platforms.ActiveCfg = Release|x86
{D2390328-CC2C-4DE2-A554-D032B1F3BB4E}.Release|Mixed Platforms.Build.0 = Release|x86
{D2390328-CC2C-4DE2-A554-D032B1F3BB4E}.Release|x86.ActiveCfg = Release|x86
{D2390328-CC2C-4DE2-A554-D032B1F3BB4E}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 4 additions & 2 deletions Raven.Abstractions/Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ namespace Raven.Abstractions
{
public static class Default
{
public static string[] DateTimeFormatsToRead = new[] { "o", "yyyy-MM-ddTHH:mm:ss.fffffffzzz" };
public static string DateTimeFormatsToWrite = "o" ;
public static string[] OnlyDateTimeFormat = new[] {"yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffff"};
public static string[] DateTimeFormatsToRead = new[] { "o", "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffff", "yyyy-MM-ddTHH:mm:ss.fffffffzzz" };
public static string DateTimeOffsetFormatsToWrite = "o";
public static string DateTimeFormatsToWrite= "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffff";

public static JsonConverter[] Converters = new JsonConverter[]
{
Expand Down
5 changes: 3 additions & 2 deletions Raven.Abstractions/Json/JsonDateTimeISO8601Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
var dateTime = ((DateTime)value);
if (dateTime.Kind == DateTimeKind.Unspecified)
dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Local);
writer.WriteValue(dateTime.ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture));
var postFix = dateTime.Kind == DateTimeKind.Utc ? "Z" : "";
writer.WriteValue(dateTime.ToString(Default.DateTimeFormatsToWrite + postFix, CultureInfo.InvariantCulture));
}
else if (value is DateTimeOffset)
writer.WriteValue(((DateTimeOffset) value).ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture));
writer.WriteValue(((DateTimeOffset) value).ToString(Default.DateTimeOffsetFormatsToWrite, CultureInfo.InvariantCulture));
else
throw new ArgumentException(string.Format("Not idea how to process argument: '{0}'", value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public void GenericWriteJson<TKey,TValue>(JsonWriter writer, Dictionary<TKey,TVa
var dateTime = ((DateTime)key);
if (dateTime.Kind == DateTimeKind.Unspecified)
dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Local);
writer.WritePropertyName(dateTime.ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture));
var postFix = dateTime.Kind == DateTimeKind.Utc ? "Z" : "";
writer.WritePropertyName(dateTime.ToString(Default.DateTimeFormatsToWrite + postFix, CultureInfo.InvariantCulture));
}
else if (key is DateTimeOffset)
writer.WritePropertyName(((DateTimeOffset)key).ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture));
writer.WritePropertyName(((DateTimeOffset)key).ToString(Default.DateTimeOffsetFormatsToWrite, CultureInfo.InvariantCulture));
else
throw new ArgumentException(string.Format("Not idea how to process argument: '{0}'", value));

Expand Down
7 changes: 6 additions & 1 deletion Raven.Abstractions/Linq/DynamicJsonObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,13 @@ public object TransformToValue(RavenJToken jToken)
if (s != null)
{
DateTime dateTime;
if (DateTime.TryParseExact(s, Default.DateTimeFormatsToRead, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out dateTime))
if (DateTime.TryParseExact(s, Default.OnlyDateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out dateTime))
return dateTime;
DateTimeOffset dateTimeOffset;
if (DateTimeOffset.TryParseExact(s, Default.DateTimeFormatsToRead, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out dateTimeOffset))
{
return dateTimeOffset;
}
}
return value ?? new DynamicNullObject { IsExplicitNull = true };
}
Expand Down
6 changes: 3 additions & 3 deletions Raven.Client.Lightweight/Document/AbstractDocumentQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1363,12 +1363,12 @@ private string TransformToEqualValue(WhereParams whereParams)

if (whereParams.Value is DateTime)
{
return DateTools.DateToString((DateTime)whereParams.Value, DateTools.Resolution.MILLISECOND);
return DateTools.DateToString(((DateTime)whereParams.Value), DateTools.Resolution.MILLISECOND);
}

if (whereParams.Value is DateTimeOffset)
{
return DateTools.DateToString(((DateTimeOffset)whereParams.Value).DateTime, DateTools.Resolution.MILLISECOND);
return DateTools.DateToString(((DateTimeOffset)whereParams.Value).UtcDateTime, DateTools.Resolution.MILLISECOND);
}

if(whereParams.FieldName == Constants.DocumentIdFieldName && whereParams.Value is string == false)
Expand All @@ -1393,7 +1393,7 @@ private string TransformToRangeValue(WhereParams whereParams)
return Constants.EmptyStringNotAnalyzed;

if (whereParams.Value is DateTime)
return DateTools.DateToString((DateTime)whereParams.Value, DateTools.Resolution.MILLISECOND);
return DateTools.DateToString(((DateTime)whereParams.Value), DateTools.Resolution.MILLISECOND);
if (whereParams.Value is DateTimeOffset)
return DateTools.DateToString(((DateTimeOffset)whereParams.Value).UtcDateTime, DateTools.Resolution.MILLISECOND);

Expand Down
18 changes: 17 additions & 1 deletion Raven.Client.Lightweight/Document/DocumentConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public DocumentConvention()
#else
FindClrTypeName = entityType => entityType.AssemblyQualifiedName;
#endif

TransformTypeTagNameToDocumentKeyPrefix = DefaultTransformTypeTagNameToDocumentKeyPrefix;
FindFullDocumentKeyFromNonStringIdentifier = DefaultFindFullDocumentKeyFromNonStringIdentifier;
FindIdentityPropertyNameFromEntityName = entityName => "Id";
FindTypeTagName = DefaultTypeTagName;
Expand All @@ -73,6 +73,17 @@ public DocumentConvention()
FindIdValuePartForValueTypeConversion = (entity, id) => id.Split(new[] {IdentityPartsSeparator}, StringSplitOptions.RemoveEmptyEntries) .Last();
}

public static string DefaultTransformTypeTagNameToDocumentKeyPrefix(string typeTagName)
{
var count = typeTagName.Count(char.IsUpper);

if (count <= 1) // simple name, just lower case it
return typeTagName.ToLowerInvariant();

// multiple capital letters, so probably something that we want to preserve caps on.
return typeTagName;
}

///<summary>
/// Find the full document name assuming that we are using the standard conventions
/// for generating a document key
Expand Down Expand Up @@ -384,6 +395,11 @@ public string GetClrTypeName(Type entityType)
/// Saves Enums as integers and instruct the Linq provider to query enums as integer values.
/// </summary>
public bool SaveEnumsAsIntegers { get; set; }

/// <summary>
/// Translate the type tag name to the document key prefix
/// </summary>
public Func<string, string> TransformTypeTagNameToDocumentKeyPrefix { get; set; }
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public string GenerateDocumentKey(DocumentConvention conventions, object entity)
{
var typeTagName = conventions.GetTypeTagName(entity.GetType());
if (string.IsNullOrEmpty(typeTagName)) //ignore empty tags
return null;
var tag = typeTagName.ToLowerInvariant();
return null;
var tag = conventions.TransformTypeTagNameToDocumentKeyPrefix(typeTagName);
HiLoKeyGenerator value;
if (keyGeneratorsByTag.TryGetValue(tag, out value))
return value.GenerateDocumentKey(conventions, entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,14 @@ private IEnumerable<AbstractField> CreateFields(string name, object value, Index
if (value is DateTime)
{
var val = (DateTime) value;
yield return CreateFieldWithCaching(name, val.ToString(Default.DateTimeFormatsToWrite), indexDefinition.GetStorage(name, defaultStorage),
var postFix = val.Kind == DateTimeKind.Utc ? "Z" : "";
yield return CreateFieldWithCaching(name, val.ToString(Default.DateTimeFormatsToWrite) + postFix, indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED_NO_NORMS));
}
else if(value is DateTimeOffset)
{
var val = (DateTimeOffset)value;
yield return CreateFieldWithCaching(name, val.ToString(Default.DateTimeFormatsToWrite), indexDefinition.GetStorage(name, defaultStorage),
yield return CreateFieldWithCaching(name, val.ToString(Default.DateTimeOffsetFormatsToWrite), indexDefinition.GetStorage(name, defaultStorage),
indexDefinition.GetIndex(name, Field.Index.NOT_ANALYZED_NO_NORMS));
}
else
Expand Down
Loading

0 comments on commit 72b0bcf

Please sign in to comment.