/// <summary> /// Search for name /// if something is found, /// get the described thing for it /// </summary> /// <param name="thingGraph"></param> /// <param name="name"></param> /// <param name="exact"></param> /// <returns></returns> public static IEnumerable <IThing> Search(this IThingGraph thingGraph, object name, bool exact) { var schemaGraph = thingGraph as SchemaThingGraph; bool isSchemaGraph = schemaGraph != null; var schema = new CommonSchema(); foreach (var thing in thingGraph.GetByData(name, exact)) { IThing described = null; if (isSchemaGraph) { described = schemaGraph.DescribedThing(thing); } else { described = schema.GetTheRoot(thingGraph, thing, CommonSchema.DescriptionMarker); } if (described != null) { yield return(described); } else { yield return(thing); } } }
public virtual WebContent GetContentFromGraph(IThingGraph graph, IThing thing, Uri uri) { var schema = new CommonSchema(); WebContent result = null; try { var schemaGraph = graph as SchemaThingGraph; if (thing != null && schemaGraph != null) { var searchGraph = schemaGraph.Source; var content = uri.Segments[uri.Segments.Length - 1]; foreach (var link in searchGraph.Edges(thing)) { var adj = link.Leaf; if (adj != thing && (adj is IStreamThing)) { var desc = schemaGraph.Description(adj); if (desc != null && desc.ToString() == content) { return(GetContentFromThing(schemaGraph, adj)); } } } } if (schemaGraph != null) { foreach (var found in schemaGraph.GetByData(uri.AbsoluteUri, true)) { var target = schema.GetTheRoot(schemaGraph, found, CommonSchema.SourceMarker); if (target is IStreamThing) { return(GetContentFromThing(schemaGraph, target)); } } } } catch (Exception e) { Trace.WriteLine(e.Message); return(null); } return(result); }