/// <summary> /// assigns the content's descriptions to the thing /// assign = set content.Description to the leaf with CommonSchema.DescriptionMarker /// set content.Source to the leaf with CommonSchema.SourceMarker /// if the leaf doesn't exist, it will be created /// </summary> /// <param name="thing"></param> /// <param name="content"></param> /// <param name="thingGraph"></param> public virtual void AssignContentDescription(IThing thing, Content <Stream> content, IThingGraph thingGraph) { var streamThing = thing as IStreamThing; if (streamThing == null) { return; } var schema = new CommonSchema(thingGraph, streamThing); if (content.Description != null) { if (schema.Description != null) { schema.Description.Data = content.Description; } else { schema.Description = Factory.CreateItem(content.Description);; } } if (content.Source != null) { var sourceThing = schema.GetTheLeaf(CommonSchema.SourceMarker); if (sourceThing == null) { sourceThing = Factory.CreateItem(content.Source); schema.SetTheLeaf(CommonSchema.SourceMarker, sourceThing); } else { sourceThing.Data = content.Source; } } }
public static void SetSource(this IThingGraph source, IThing thing, object name) { if (source != null) { var schema = new CommonSchema(source, thing); var desc = schema.GetTheLeaf(CommonSchema.SourceMarker); if (desc != null) { if (desc != thing) { source.DoChangeData(desc, name); } } else { var factory = Registry.Pooled <IThingFactory>(); schema.SetTheLeaf(CommonSchema.SourceMarker, factory.CreateItem(source, name)); } } }