/// <summary> /// This reconstructs the relations table /// </summary> /// <returns>The relations table</returns> internal Dictionary<ZObject, object> Relations() { // Link the relations structures var r2 = new Dictionary<ZObject,object>(); foreach (var I in relations) { var v = I.Value; // If it's an array, it's a relation 1 if (v is IList) { // Go thru, get the objects and populate a dictionary var d = new Dictionary<ZObject, ZObject>(); foreach (var item in (IList) v) { var obj = (ZObject) objects[item]; d[obj] = obj; } // there, done r2[(ZObject) objects[I.Key]] = d; } // If it's a dictionary it's a relation 2 else if (v is Dictionary<string,object>) { var d = (Dictionary<string,object>)v; // each key is an array of arrays... // First get the immediate vs derived bool immediate = false; object b; if (d.TryGetValue("derive", out b) && b is bool) immediate = !(bool)b; // Next get the values var n = new SparseGraph<ZObject>(immediate); object val; if (d.TryGetValue("spec", out val)) { var d2 = (Dictionary<string,object>)val; foreach (var edges in d2) { var src = (ZObject)objects[edges.Key]; foreach (var edge in (IList)edges.Value) { // Get the nodes for the sink and gate var tuple = (IList) edge; var sink = (ZObject) objects[tuple[0]]; ZObject gate = null; if (tuple.Count > 1 && null != tuple[1]) gate = (ZObject) objects[tuple[1]]; // add them n.After(src, new Edge<ZObject>(sink, gate)); } } } // Add the relation to the table r2[(ZObject) objects[I.Key]] = n; } } // Return the relations return r2; }