WIP - gets 'inbound' routing working to generate culture specific URLs
This commit is contained in:
@@ -83,6 +83,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
class ContentDataSerializer : ISerializer<ContentData>
|
||||
{
|
||||
private static readonly DictionaryOfPropertyDataSerializer PropertiesSerializer = new DictionaryOfPropertyDataSerializer();
|
||||
private static readonly DictionaryOfCultureVariationSerializer CultureVariationsSerializer = new DictionaryOfCultureVariationSerializer();
|
||||
|
||||
public ContentData ReadFrom(Stream stream)
|
||||
{
|
||||
@@ -94,7 +95,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
VersionDate = PrimitiveSerializer.DateTime.ReadFrom(stream),
|
||||
WriterId = PrimitiveSerializer.Int32.ReadFrom(stream),
|
||||
TemplateId = PrimitiveSerializer.Int32.ReadFrom(stream),
|
||||
Properties = PropertiesSerializer.ReadFrom(stream)
|
||||
Properties = PropertiesSerializer.ReadFrom(stream),
|
||||
CultureInfos = CultureVariationsSerializer.ReadFrom(stream)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -107,6 +109,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
PrimitiveSerializer.Int32.WriteTo(value.WriterId, stream);
|
||||
PrimitiveSerializer.Int32.WriteTo(value.TemplateId, stream);
|
||||
PropertiesSerializer.WriteTo(value.Properties, stream);
|
||||
CultureVariationsSerializer.WriteTo(value.CultureInfos, stream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +134,69 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
}
|
||||
*/
|
||||
|
||||
private class DictionaryOfCultureVariationSerializer : ISerializer<IReadOnlyDictionary<string, CultureVariation>>
|
||||
{
|
||||
public IReadOnlyDictionary<string, CultureVariation> ReadFrom(Stream stream)
|
||||
{
|
||||
var dict = new Dictionary<string, CultureVariation>();
|
||||
|
||||
// read values count
|
||||
var pcount = PrimitiveSerializer.Int32.ReadFrom(stream);
|
||||
|
||||
// read each property
|
||||
for (var i = 0; i < pcount; i++)
|
||||
{
|
||||
// read lang id
|
||||
// fixme: This will need to change to string when stephane is done his culture work
|
||||
var key = PrimitiveSerializer.String.ReadFrom(stream);
|
||||
|
||||
var val = new CultureVariation();
|
||||
|
||||
// read variation info
|
||||
//TODO: This is supporting multiple properties but we only have one currently
|
||||
var type = PrimitiveSerializer.Char.ReadFrom(stream);
|
||||
switch(type)
|
||||
{
|
||||
case 'N':
|
||||
val.Name = PrimitiveSerializer.String.ReadFrom(stream);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
dict[key] = val;
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
|
||||
private static readonly IReadOnlyDictionary<string, CultureVariation> Empty = new Dictionary<string, CultureVariation>();
|
||||
|
||||
public void WriteTo(IReadOnlyDictionary<string, CultureVariation> value, Stream stream)
|
||||
{
|
||||
var valToSerialize = value;
|
||||
if (valToSerialize == null)
|
||||
{
|
||||
valToSerialize = Empty;
|
||||
}
|
||||
|
||||
// write values count
|
||||
PrimitiveSerializer.Int32.WriteTo(valToSerialize.Count, stream);
|
||||
|
||||
// write each name
|
||||
foreach (var kvp in valToSerialize)
|
||||
{
|
||||
// write alias
|
||||
PrimitiveSerializer.String.WriteTo(kvp.Key, stream);
|
||||
|
||||
// write name
|
||||
PrimitiveSerializer.Char.WriteTo('N', stream);
|
||||
PrimitiveSerializer.String.WriteTo(kvp.Value.Name, stream);
|
||||
//TODO: This is supporting multiple properties but we only have one currently
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class DictionaryOfPropertyDataSerializer : ISerializer<IDictionary<string, PropertyData[]>>
|
||||
{
|
||||
public IDictionary<string, PropertyData[]> ReadFrom(Stream stream)
|
||||
|
||||
@@ -8,8 +8,14 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
{
|
||||
public bool Published { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The collection of language Id to name for the content item
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, CultureVariation> CultureInfos { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
public int VersionId { get; set; }
|
||||
//TODO: This will not make a lot of sense since we'll have dates for each variant publishing, need to wait on Stephane
|
||||
public DateTime VersionDate { get; set; }
|
||||
public int WriterId { get; set; }
|
||||
public int TemplateId { get; set; }
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
{
|
||||
/// <summary>
|
||||
/// The content item 1:M data that is serialized to JSON
|
||||
/// </summary>
|
||||
internal class ContentSerializedData
|
||||
{
|
||||
[JsonProperty("properties")]
|
||||
public Dictionary<string, PropertyData[]> PropertyData { get; set; }
|
||||
|
||||
[JsonProperty("cultureData")]
|
||||
public Dictionary<string, CultureVariation> CultureData { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the culture variation information on a content item
|
||||
/// </summary>
|
||||
internal class CultureVariation
|
||||
{
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
//TODO: We may want some date stamps here
|
||||
}
|
||||
}
|
||||
@@ -190,6 +190,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
}
|
||||
else
|
||||
{
|
||||
var deserialized = DeserializeData(dto.EditData);
|
||||
|
||||
d = new ContentData
|
||||
{
|
||||
Name = dto.EditName,
|
||||
@@ -198,7 +200,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
VersionId = dto.VersionId,
|
||||
VersionDate = dto.EditVersionDate,
|
||||
WriterId = dto.EditWriterId,
|
||||
Properties = DeserializeData(dto.EditData)
|
||||
Properties = deserialized.PropertyData,
|
||||
CultureInfos = deserialized.CultureData
|
||||
};
|
||||
}
|
||||
|
||||
@@ -212,6 +215,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
}
|
||||
else
|
||||
{
|
||||
var deserialized = DeserializeData(dto.PubData);
|
||||
|
||||
p = new ContentData
|
||||
{
|
||||
Name = dto.PubName,
|
||||
@@ -220,7 +225,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
VersionId = dto.VersionId,
|
||||
VersionDate = dto.PubVersionDate,
|
||||
WriterId = dto.PubWriterId,
|
||||
Properties = DeserializeData(dto.PubData)
|
||||
Properties = deserialized.PropertyData,
|
||||
CultureInfos = deserialized.CultureData
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -244,6 +250,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
if (dto.EditData == null)
|
||||
throw new Exception("No data for media " + dto.Id);
|
||||
|
||||
var deserialized = DeserializeData(dto.EditData);
|
||||
|
||||
var p = new ContentData
|
||||
{
|
||||
Name = dto.EditName,
|
||||
@@ -252,7 +260,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
VersionId = dto.VersionId,
|
||||
VersionDate = dto.EditVersionDate,
|
||||
WriterId = dto.CreatorId, // what-else?
|
||||
Properties = DeserializeData(dto.EditData)
|
||||
Properties = deserialized.PropertyData,
|
||||
CultureInfos = deserialized.CultureData
|
||||
};
|
||||
|
||||
var n = new ContentNode(dto.Id, dto.Uid,
|
||||
@@ -268,7 +277,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
return s;
|
||||
}
|
||||
|
||||
private static Dictionary<string, PropertyData[]> DeserializeData(string data)
|
||||
private static ContentSerializedData DeserializeData(string data)
|
||||
{
|
||||
// by default JsonConvert will deserialize our numeric values as Int64
|
||||
// which is bad, because they were Int32 in the database - take care
|
||||
@@ -278,7 +287,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
Converters = new List<JsonConverter> { new ForceInt32Converter() }
|
||||
};
|
||||
|
||||
return JsonConvert.DeserializeObject<Dictionary<string, PropertyData[]>>(data, settings);
|
||||
return JsonConvert.DeserializeObject<ContentSerializedData>(data, settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user