protected IThing GetSheetThing(IThingGraph thingGraph, long id) { if (id == -1) { return(null); } var result = thingGraph.GetById(id); if (result != null) { if (!(result is IStreamThing && ((IStreamThing)result).StreamType == ContentTypes.LimadaSheet)) { Registry.Pooled <IExceptionHandler> ().Catch( new ArgumentException($"id {id:X16} does not belong to a sheet") , MessageType.OK); } } return(result); }
protected virtual bool AddToSheets(IThingGraph graph, Int64 sheetId) { var thing = graph.GetById(sheetId) as IStreamThing; if (thing != null && thing.StreamType == ContentTypes.LimadaSheet) { var add = graph.Edges(thing).Where(l => l.Marker.Id != CommonSchema.DescriptionMarker.Id).Count() == 0; if (add) { var sheets = TryAddSomeThing(graph, TopicSchema.Sheets); var sheetMarker = TryAddSomeThing(graph, TopicSchema.SheetMarker); TryAddSomeThing(graph, TopicSchema.TopicToSheetsLink); var factory = Registry.Factory.Create <IThingFactory> (); var link = factory.CreateEdge(sheets, thing, sheetMarker); graph.Add(link); } return(add); } return(false); }
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); }
public void ProveEdge(IThingGraph thingGraph, ILink link) { bool delete = false; var idLink = ((ILink <Id>)link); delete = idLink.Root == 0 || idLink.Leaf == 0; if (!delete) { var root = link.Root; var leaf = link.Leaf; var marker = link.Marker; delete = root == null || leaf == null || root.Id == 0 || leaf.Id == 0; } if (!delete) { thingGraph.Add(link); } else { thingGraph.Remove(link); } }
void Prove(IEnumerable <IThing> things, IEnumerable <IThing> expected, IThingGraph graph) { var completed = things.CompletedThings(graph); var result = new Set <IThing> (); result.UnionWith(completed); ReportDetail("** Completed:"); foreach (var thing in completed) { ReportDetail(thing.ToString()); } foreach (var thing in expected) { var compareThing = thing; Assert.IsTrue(result.Contains(compareThing), "Expected:" + thing.ToString()); } Assert.AreEqual(expected.Count <IThing>(), result.Count); }
public static IThingGraph BackGraph(this IGraphSceneMesh <IVisual, IVisualEdge> mesh, Iori iori) { IThingGraph thingGraph = null; var backHandler = mesh.BackHandler <IThing, ILink> (); Func <IThingGraph, IThingGraph> register = s => { if (s == null) { return(null); } var g = backHandler.WrapGraph(s) as IThingGraph; backHandler.RegisterBackGraph(g); return(g); }; if (iori != null) { thingGraph = backHandler .BackGraphs .Select(g => new { Iori = GetIori(g), Graph = g }) .Where(i => i.Iori != null && i.Iori.ToString() == iori.ToString()) .Select(i => i.Graph as IThingGraph) .FirstOrDefault(); if (thingGraph == null) { thingGraph = register(ThingMeshHelper.OpenGraph(iori)); } } if (thingGraph == null && iori == null) { Trace.WriteLine("Warning! iori is null!"); thingGraph = register(new ThingGraph()); } return(thingGraph); }
protected void SaveStream(IThingGraph thingGraph, ContentStreamViewer viewer) { if (thingGraph == null || !viewer.CanSave()) { return; } var thing = thingGraph.GetById(viewer.ContentId) as IStreamThing; if (thing != null) { var content = new Content <Stream> (); viewer.Save(content); new ThingContentFacade().AssignContent(thingGraph, thing, content); if (content.Data != null) { content.Data.Dispose(); } content.Data = null; content = null; thing.State.Clean = true; } }
protected override ThingGraphContent OpenInternal(Iori source) { try { IThingGraph thingGraph = null; var fileName = source.ToFileName(); if (File.Exists(fileName)) { using (var file = new FileStream(fileName, FileMode.Open)) thingGraph = Open(file); } else { thingGraph = new ThingGraph(); } return(new ThingGraphContent { Data = thingGraph, Source = source, ContentType = XmlThingGraphSpot.ContentType }); } catch (Exception ex) { Registry.Pooled <IExceptionHandler>() .Catch(new Exception("File load failed: " + ex.Message, ex), MessageType.OK); } return(null); }
public static void DeepCopy(this IThingGraph source, IEnumerable <IThing> items, IThingGraph target) { if (source != null && target != null) { var walk = source.Walk(); var queue = new Queue <IThing>(items); while (queue.Count != 0) { var item = queue.Dequeue(); if (!walk.Visited.Contains(item)) { if (item is ILink) { target.Add((ILink)item); } else { target.Add(item); } foreach (var levelItem in walk.DeepWalk(item, 0)) { var link = levelItem.Node as ILink; if (link != null) { target.Add(link); queue.Enqueue(link.Marker); } else { target.Add(levelItem.Node); } } } } } }
public void Open() { if (Current != null) { Trace.WriteLine(string.Format("Provider already opened {0}", Current.Description)); var conn = Current.Data as IGatewayConnection; if (conn != null) { Trace.WriteLine(string.Format("Connection already opened {0}/{1}", conn.Gateway.IsOpen, conn.Gateway.Iori.ToFileName())); } } else { var ioManager = new ThingGraphIoManager { }; var sinkIo = ioManager.GetSinkIO(Iori, IoMode.Read) as ThingGraphIo; try { var sink = sinkIo.Open(Iori); if (sink != null) { Trace.WriteLine(string.Format("DataBase opened {0}", Iori.ToFileName())); Current = sink; var graph = new SchemaThingGraph(Current.Data); PrepareGraph(graph); _thingGraph = graph; } else { throw new Exception("Database not found: " + Iori.ToString()); } } catch (Exception e) { Trace.WriteLine(e.Message); _thingGraph = new ThingGraph(); Trace.WriteLine(string.Format("Empty Graph created {0}", Iori.ToFileName())); } } }
public void ValidateTitle(DigidocSchema schema, IThingGraph graph, IThing thing, IThing title) { Assert.AreSame(schema.Title, title); this.ReportDetail(GraphTestUtils.ReportGraph <IThing, ILink>(graph, "* Title added")); bool found = false; bool firstMarker = false; foreach (ILink link in graph.Edges(thing)) { if (link.Marker == DigidocSchema.DocumentTitle) { Assert.IsFalse(firstMarker, "second title found"); firstMarker = true; } if (link.Leaf == schema.Title && link.Marker == DigidocSchema.DocumentTitle && link.Leaf == title) { Assert.IsFalse(found); found = true; } } Assert.IsTrue(found, "Title not found"); }
public void ValidateDescription(CommonSchema schema, IThingGraph graph, IThing thing, IThing description) { Assert.AreSame(schema.Description, description); this.ReportDetail(GraphTestUtils.ReportGraph <IThing, ILink>(graph, "* Descriptioin added")); bool found = false; bool firstMarker = false; foreach (ILink link in graph.Edges(thing)) { if (link.Marker == CommonSchema.DescriptionMarker) { Assert.IsFalse(firstMarker, "second descriptionmarker found"); firstMarker = true; } if (link.Leaf == schema.Description && link.Marker == CommonSchema.DescriptionMarker && link.Leaf == description) { Assert.IsFalse(found); found = true; } } Assert.IsTrue(found); }
/// <summary> /// returns all things of source /// extract all things of source stored in a sheet /// and returns them /// </summary> /// <param name="sourceView"></param> /// <param name="sink"></param> public virtual IEnumerable <IThing> ExpandThings(IThingGraph thingGraph, IEnumerable <IThing> source) { var result = new Stack <IThing>(source); while (result.Count > 0) { var thing = result.Pop(); yield return(thing); var streamThing = thing as IStreamThing; if (streamThing != null && streamThing.StreamType == ContentTypes.LimadaSheet) { var ser = new ThingXmlIdSerializer(); ser.Graph = thingGraph; streamThing.DeCompress(); ser.Read(streamThing.Data); streamThing.ClearRealSubject(); ser.Things.ForEach(t => result.Push(t)); } } }
public IThing CreatePage(IThingGraph graph, IThing document, Content <Stream> stream, object pageNr) { if (graph == null || document == null) { return(null); } var page = Factory.CreateItem <Stream>(null) as IStreamThing; page.ContentContainer = graph.ContentContainer; if (stream != null) { new ThingContentFacade(Factory).AssignContent(page, stream); } var pageEdge = Factory.CreateEdge(document, page, DigidocSchema.DocumentPage); graph.Add(pageEdge); var number = Factory.CreateItem(pageNr); var numberEdge = Factory.CreateEdge(pageEdge, number, DigidocSchema.PageNumber); graph.Add(number); graph.Add(numberEdge); return(page); }
public IThingGraph RawImport(Iori source, IThingGraph sink, bool repair) { this.Log = new StringWriter(); var links = new List <ILink>(); if (repair) { var db4oGraph = sink as ThingGraph; if (db4oGraph != null) { ReportClazzes(db4oGraph.Gateway as Gateway); } } var gateway = new Gateway(); if (!repair) { gateway.Configuration.AllowVersionUpdates = true; gateway.Configuration.DetectSchemaChanges = true; //gateway.Configuration.RecoveryMode(true); } ConfigureAliases(gateway.Configuration); gateway.Open(source); var session = gateway.Session; ReportClazzes(gateway); SchemaFacade.InitSchemata(); var cache = new Dictionary <IReflectClass, Tuple <IReflectClass, List <IReflectField>, Type> >(); foreach (var item in session.Query <object>()) { var thing = item as IThing; if (thing != null) { ReportDetail(thing.Id.ToString()); } var go = item as GenericObject; if (go != null) { IReflectClass clazz = go.GetGenericClass(); Tuple <IReflectClass, List <IReflectField>, Type> defs = null; if (!cache.TryGetValue(clazz, out defs)) { var name = clazz.GetName(); name = name.Substring(0, name.LastIndexOf(',')); var newType = typeof(IThing).Assembly.GetType(name); var fields = new List <IReflectField>(); var iClazz = clazz; while (iClazz != null) { fields.AddRange(iClazz.GetDeclaredFields()); iClazz = iClazz.GetSuperclass(); } defs = Tuple.Create(clazz, fields, newType); cache.Add(clazz, defs); } var newThing = Activator.CreateInstance(defs.Item3, new object[] { null }); foreach (var field in defs.Item2) { var val = field.Get(go); FieldInfo info = null; var type = defs.Item3; while (info == null && type != null) { info = type.GetField(field.GetName(), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy); if (info == null) { info = type.GetField(field.GetName(), BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy); } if (info == null && field.GetName() == "_writeDate") { info = type.GetField("_changeDate", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy); } type = type.BaseType; } if (info != null && val != null && val.GetType() == info.FieldType) { info.SetValue(newThing, val); } } ReportDetail(newThing.ToString()); if (repair) { var link = newThing as Link; if (link != null) { link.GetByID = (id) => sink.GetById(id); links.Add(newThing as ILink); } else if (newThing is IThing) { sink.Add(newThing as IThing); } else if (newThing is IIdContent <long> ) { sink.ContentContainer.Add(newThing as IIdContent <long>); } } } } if (repair) { ReportDetail("write links..."); foreach (var link in links) { var idLink = link as ILink <Id>; if (link.Marker == null && idLink.Marker != 0) { IThing marker = null; if (Schema.IdentityMap.TryGetValue(idLink.Marker, out marker)) { link.Marker = marker; } } if (link.Marker == null) { link.Marker = CommonSchema.EmptyMarker; } if (link.Root != null && link.Leaf != null) { sink.Add(link); } } } gateway.Close(); ReportDetail("done:\t"); if (this.Log != null) { var logfilename = source.ToFileName() + ".log"; if (File.Exists(logfilename)) { File.Delete(logfilename); } var logfile = new StreamWriter(logfilename); logfile.Write(this.Log.ToString()); logfile.Close(); } return(sink); }
public IThingGraph Use(Iori source, IThingGraph sink) { return(this.RawImport(source, sink, true)); }
public Schema(IThingGraph graph, IThing target) : this() { this.Graph = graph; this.Subject = target; }
public virtual ILink SetDescription(IThingGraph graph, IThing marker, IThing value) { return(SetTheLeaf(graph, marker, DescriptionMarker, value)); }
public virtual IThing GetDescription(IThingGraph graph, IThing marker) { return(GetTheLeaf(graph, marker, DescriptionMarker)); }
public IEnumerable <IThing> Pages(IThingGraph graph, IThing document) { return(PageLinks(graph, document) .Select(link => link.Leaf)); }
public DigidocSchema(IThingGraph graph, IThing document) : base(graph, document) { }
public static void RemoveBackGraph(this IGraphSceneDisplayMesh <IVisual, IVisualEdge> mesh, IThingGraph backGraph) { var backMesh = mesh.BackHandler <IThing, ILink> (); mesh.Displays .Join(backMesh.ScenesOfBackGraph(backGraph), d => d.Data, s => s, (d, s) => d) .ForEach(d => { mesh.ClearDisplaysOf(d.Data); mesh.RemoveScene(d.Data); }); backMesh.ScenesOfBackGraph(backGraph).ToArray().ForEach(s => mesh.RemoveScene(s)); backMesh.UnregisterBackGraph(backGraph); }
public VisualThingGraph(IGraph <IVisual, IVisualEdge> sink, IThingGraph source, VisualThingTransformer transformer) : base(sink, source, transformer) { }
public VisualThingGraph(IGraph <IVisual, IVisualEdge> sink, IThingGraph source) : this(sink, source, new VisualThingTransformer()) { }
public IThing CreateItem(IThingGraph graph, object data) { return(CreateItem(Isaac.Long, graph, data)); }
public static void ApplyBackGraph(this IGraphSceneDisplayMesh <IVisual, IVisualEdge> mesh, IThingGraph root) { var backMesh = mesh.BackHandler <IThing, ILink> (); var g = backMesh.WrapGraph(root); backMesh.RegisterBackGraph(g); var displays = mesh.Displays; displays.ForEach(d => { var scene = backMesh.CreateScene(g); mesh.AddScene(scene); d.Data = scene; }); }
public ILink CreateEdge(Id id, IThingGraph graph, object data) { return(CreateEdge(id, data)); }
/// <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 ILink CreateEdge(IThingGraph graph, object data) { return(CreateEdge(Isaac.Long, graph, data)); }
public CommonSchema(IThingGraph graph, IThing thing) : base(graph, thing) { }