本文整理汇总了C#中N2.Persistence.Serialization.ReadingJournal类的典型用法代码示例。如果您正苦于以下问题:C# ReadingJournal类的具体用法?C# ReadingJournal怎么用?C# ReadingJournal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReadingJournal类属于N2.Persistence.Serialization命名空间,在下文中一共展示了ReadingJournal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadDetail
protected virtual void ReadDetail(XPathNavigator navigator, ContentItem item, ReadingJournal journal)
{
Dictionary<string, string> attributes = GetAttributes(navigator);
Type type = Utility.TypeFromName(attributes["typeName"]);
string name = attributes["name"];
if (type == typeof(ContentItem))
{
SetLinkedItem(navigator.Value, journal, (referencedItem) => item[name] = referencedItem, attributes.GetValueOrDefault("versionKey"));
}
else if(type == typeof(IMultipleValue))
{
var multiDetail = ReadMultipleValue(navigator, item, journal, name);
multiDetail.AddTo(item);
}
else
{
object value = Parse(navigator.Value, type);
if (value is string)
value = PrepareStringDetail(item, name, value as string, attributes.ContainsKey("encoded") && Convert.ToBoolean(attributes["encoded"]));
item.SetDetail(name, value, type);
}
}
示例2: Read
public void Read(XPathNavigator navigator, ContentItem item, ReadingJournal journal)
{
foreach (XPathNavigator detailCollectionElement in EnumerateChildren(navigator))
{
ReadDetailCollection(detailCollectionElement, item, journal);
}
}
示例3: SetLinkedItem
protected static void SetLinkedItem(string value, ReadingJournal journal, Action<ContentItem> setter, string versionKey = null)
{
int referencedItemID = int.Parse(value);
if (referencedItemID != 0)
{
ContentItem referencedItem = journal.Find(referencedItemID);
if (referencedItem != null)
{
setter(referencedItem);
}
else
{
journal.Register(referencedItemID, setter, relationType: "link");
}
}
else if (!string.IsNullOrEmpty(versionKey))
{
ContentItem referencedItem = journal.Find(versionKey);
if (referencedItem != null)
{
setter(referencedItem);
}
else
{
journal.Register(versionKey, setter);
}
}
}
示例4: Read
public void Read(System.Xml.XPath.XPathNavigator navigator, ContentItem item, ReadingJournal journal)
{
foreach (XPathNavigator detailElement in EnumerateChildren(navigator))
{
ReadProperty(detailElement, item, journal);
}
}
示例5: ReadMultipleValue
internal ContentDetail ReadMultipleValue(XPathNavigator navigator, ContentItem item, ReadingJournal journal, string name)
{
var multiDetail = ContentDetail.Multi(name);
foreach (XPathNavigator valueElement in EnumerateChildren(navigator))
{
switch (valueElement.GetAttribute("key", ""))
{
case ContentDetail.TypeKeys.BoolType:
multiDetail.BoolValue = (bool)Parse(valueElement.Value, typeof(bool));
break;
case ContentDetail.TypeKeys.DateTimeType:
multiDetail.DateTimeValue = (DateTime)Parse(valueElement.Value, typeof(DateTime));
break;
case ContentDetail.TypeKeys.DoubleType:
multiDetail.DoubleValue = (double)Parse(valueElement.Value, typeof(double));
break;
case ContentDetail.TypeKeys.IntType:
multiDetail.IntValue = (int)Parse(valueElement.Value, typeof(int));
break;
case ContentDetail.TypeKeys.LinkType:
SetLinkedItem(valueElement.Value, journal, (referencedItem) => multiDetail.LinkedItem = referencedItem);
break;
case ContentDetail.TypeKeys.MultiType:
journal.Error(new InvalidOperationException("Nested multi types not supported"));
break;
case ContentDetail.TypeKeys.ObjectType:
multiDetail.ObjectValue = Parse(valueElement.Value, typeof(object));
break;
case ContentDetail.TypeKeys.StringType:
multiDetail.StringValue = (string)PrepareStringDetail(item, name, valueElement.Value);
break;
}
}
return multiDetail;
}
示例6: Read
public void Read(XPathNavigator navigator, ContentItem item, ReadingJournal journal)
{
foreach (XPathNavigator authorizationElement in EnumerateChildren(navigator))
{
string role = authorizationElement.Value;
item.AuthorizedRoles.Add(new AuthorizedRole(item, role));
}
}
示例7: Handle
private static void Handle(ContentItem item, ReadingJournal journal, int id)
{
var child = journal.Find(id);
if (child != null)
child.AddTo(item);
else
journal.Register(id, (ci) => ci.AddTo(item), isChild: true);
}
示例8: ReadDetailCollection
protected void ReadDetailCollection(XPathNavigator navigator, ContentItem item, ReadingJournal journal)
{
Dictionary<string, string> attributes = GetAttributes(navigator);
string name = attributes["name"];
foreach (XPathNavigator detailElement in EnumerateChildren(navigator))
{
ReadDetail(detailElement, item.GetDetailCollection(name, true), journal);
}
}
示例9: ReadDetail
protected virtual void ReadDetail(XPathNavigator navigator, DetailCollection collection, ReadingJournal journal)
{
Dictionary<string, string> attributes = GetAttributes(navigator);
Type type = Utility.TypeFromName(attributes["typeName"]);
string meta = attributes.ContainsKey("meta") ? attributes["meta"] : null;
if (type == typeof(ContentItem))
{
int referencedItemID = int.Parse(navigator.Value);
ContentItem referencedItem = journal.Find(referencedItemID);
if (referencedItem != null)
{
collection.Add(ContentDetail.New(
collection.EnclosingItem,
attributes["name"],
referencedItem,
meta));
}
else
{
journal.Register(referencedItemID, (item) =>
{
collection.Add(ContentDetail.New(
collection.EnclosingItem,
attributes["name"],
item,
meta));
}, relationType: "collectionlink");
}
}
else if (type == typeof(Enum))
{
if (meta != null)
{
collection.Add(ContentDetail.New(
collection.EnclosingItem,
attributes["name"],
Parse(navigator.Value, Type.GetType(meta))));
}
}
else if (type == typeof(IMultipleValue))
{
var detail = detailReader.ReadMultipleValue(navigator, collection.EnclosingItem, journal, collection.Name);
detail.Meta = meta;
detail.AddTo(collection);
}
else
{
object value = Parse(navigator.Value, type);
if (value is string)
value = detailReader.PrepareStringDetail(collection.EnclosingItem, collection.Name, value as string, attributes.ContainsKey("encoded") && Convert.ToBoolean(attributes["encoded"]));
collection.Add(ContentDetail.New(collection.EnclosingItem, attributes["name"], value, meta));
}
}
示例10: ReadProperty
private void ReadProperty(XPathNavigator navigator, ContentItem item, ReadingJournal journal)
{
Dictionary<string, string> attributes = GetAttributes(navigator);
Type type = Utility.TypeFromName(attributes["typeName"]);
string name = attributes["name"];
if(type == typeof(ContentItem))
SetLinkedItem(navigator.Value, journal, (referencedItem) => item[name] = referencedItem);
else
item[name] = Parse(navigator.Value, type);
}
示例11: SetLinkedItem
protected static void SetLinkedItem(string value, ReadingJournal journal, Action<ContentItem> setter)
{
int referencedItemID = int.Parse(value);
ContentItem referencedItem = journal.Find(referencedItemID);
if (referencedItem != null)
{
setter(referencedItem);
}
else
{
journal.Register(referencedItemID, setter);
}
}
示例12: ReadDetail
protected virtual void ReadDetail(XPathNavigator navigator, DetailCollection collection, ReadingJournal journal)
{
Dictionary<string, string> attributes = GetAttributes(navigator);
Type type = Utility.TypeFromName(attributes["typeName"]);
if (type == typeof(ContentItem))
{
int referencedItemID = int.Parse(navigator.Value);
ContentItem referencedItem = journal.Find(referencedItemID);
if (referencedItem != null)
{
collection.Add(ContentDetail.New(
collection.EnclosingItem,
attributes["name"],
referencedItem));
}
else
{
journal.Register(referencedItemID, (item) =>
{
collection.Add(ContentDetail.New(
collection.EnclosingItem,
attributes["name"],
item));
});
}
}
else if (type == typeof(Enum))
{
if (attributes.ContainsKey("meta"))
{
collection.Add(ContentDetail.New(
collection.EnclosingItem,
attributes["name"],
Parse(navigator.Value, Type.GetType(attributes["meta"]))));
}
}
else if (type == typeof(IMultipleValue))
{
detailReader.ReadMultipleValue(navigator, collection.EnclosingItem, journal, collection.Name).AddTo(collection);
}
else
{
collection.Add(ContentDetail.New(
collection.EnclosingItem,
attributes["name"],
Parse(navigator.Value, type)));
}
}
示例13: ReadDetail
protected virtual void ReadDetail(XPathNavigator navigator, ContentItem item, ReadingJournal journal)
{
Dictionary<string, string> attributes = GetAttributes(navigator);
Type type = Utility.TypeFromName(attributes["typeName"]);
string name = attributes["name"];
string meta = attributes.ContainsKey("meta")
? attributes["meta"]
: null;
if (type == typeof(System.Enum))
{
// we're going to need to do better- we saved a more specific type in 'meta'
try
{
type = Utility.TypeFromName(meta);
}
catch (Exception ex)
{
// This is really bad because it means the enum type has gone away.
logger.Warn(ex);
// Also, another exception is going to be thrown later because the enum won't be able to be decoded. So we'll just load the value
// as a string and hope that someone eventually deals with it. This may automatically happen if the ContentItem used the regular
// GetDetail that returns a System.Object. This is the most robust approach because it is the only way the page MIGHT NOT crash
// when this exception is encountered.
type = typeof(String);
}
}
if (type == typeof(ContentItem))
{
SetLinkedItem(navigator.Value, journal, (referencedItem) => item[name] = referencedItem, attributes.GetValueOrDefault("versionKey"));
}
else if(type == typeof(IMultipleValue))
{
var multiDetail = ReadMultipleValue(navigator, item, journal, name);
multiDetail.Meta = meta;
multiDetail.AddTo(item);
}
else
{
object value = Parse(navigator.Value, type);
if (value is string)
value = PrepareStringDetail(item, name, value as string, attributes.ContainsKey("encoded") && Convert.ToBoolean(attributes["encoded"]));
item.SetDetail(name, value, type);
}
}
示例14: ReadSingleItem
public virtual ContentItem ReadSingleItem(XPathNavigator navigator, ReadingJournal journal)
{
if (navigator.LocalName != "item") throw new DeserializationException("Expected element 'item' but was '" + navigator.LocalName + "'");
Dictionary<string, string> attributes = GetAttributes(navigator);
ContentItem item = CreateInstance(attributes);
ReadDefaultAttributes(attributes, item, journal);
foreach(XPathNavigator current in EnumerateChildren(navigator))
{
if(readers.ContainsKey(current.LocalName))
readers[current.LocalName].Read(current, item, journal);
}
return item;
}
示例15: SetLinkedItems
private void SetLinkedItems(XPathNavigator navigator, ReadingJournal journal, ContentItem item, string name)
{
var items = new ItemList();
foreach (XPathNavigator itemElement in EnumerateChildren(navigator))
{
SetLinkedItem(itemElement.Value, journal, (foundItem) =>
{
items.Add(foundItem);
var property = item.GetContentType().GetProperty(name);
if (property != null)
item[name] = items.ConvertTo(property.PropertyType, name);
else
item[name] = items;
}, itemElement.GetAttribute("versionKey", ""));
}
}