private Thing CreateObject(Thing type, VersionHistory vh, NameVal[] props) { Thing thing = new Thing(); thing.vh = vh; thing.type = type; thing.timestamp = DateTime.Now; thing.props = new PropVal[props.Length]; for (int i = 0; i < props.Length; i++) { NameVal prop = props[i]; PropDef def = (PropDef)root.propDefIndex[prop.name]; if (def == null) { def = new PropDef(); def.name = prop.name; root.propDefIndex.Put(def); } object val = prop.val; PropVal pv = new PropVal(def, val); Key key = new Key(new object[]{def, val}); if (val is string) { root.strPropIndex.Put(key, thing); foreach (string keyword in ((string)val).ToLower().Split(keywordSeparators)) { if (keyword.Length > 0 && !keywordStopList.ContainsKey(keyword)) { root.inverseIndex.Put(keyword, thing); } } } else if (val is double) { root.numPropIndex.Put(key, thing); } else if (val is DateTime) { root.timePropIndex.Put(key, thing); } else if (val is VersionHistory || val == null) { root.refPropIndex.Put(key, thing); if (prop.name == Symbols.Rectangle) { PropVal[] coord = ((VersionHistory)val).Latest.props; RectangleR2 r = new RectangleR2((double)coord[0].val, (double)coord[1].val, (double)coord[2].val, (double)coord[3].val); root.spatialIndex.Put(r, thing); } else if (prop.name == Symbols.Point) { PropVal[] coord = ((VersionHistory)val).Latest.props; double x = (double)coord[0].val; double y = (double)coord[1].val; RectangleR2 r = new RectangleR2(x, y, x, y); root.spatialIndex.Put(r, thing); } } else { throw new InvalidOperationException("Invalid propery value type " + prop.val.GetType()); } thing.props[i] = pv; } thing.Modify(); vh.versions.Add(thing); root.timeIndex.Put(thing); root.latest.Add(thing); return thing; }
private Thing CreateObject(Thing type, VersionHistory vh, NameVal[] props) { Thing thing = new Thing(); thing.vh = vh; thing.type = type; thing.timestamp = DateTime.Now; thing.props = new PropVal[props.Length]; for (int i = 0; i < props.Length; i++) { NameVal prop = props[i]; PropDef def = (PropDef)root.propDefIndex[prop.name]; if (def == null) { def = new PropDef(); def.name = prop.name; root.propDefIndex.Put(def); } object val = prop.val; PropVal pv = new PropVal(def, val); Key key = new Key(new object[] { def, val }); if (val is string) { root.strPropIndex.Put(key, thing); foreach (string keyword in ((string)val).ToLower().Split(keywordSeparators)) { if (keyword.Length > 0 && !keywordStopList.ContainsKey(keyword)) { root.inverseIndex.Put(keyword, thing); } } } else if (val is double) { root.numPropIndex.Put(key, thing); } else if (val is DateTime) { root.timePropIndex.Put(key, thing); } else if (val is VersionHistory || val == null) { root.refPropIndex.Put(key, thing); if (prop.name == Symbols.Rectangle) { PropVal[] coord = ((VersionHistory)val).Latest.props; RectangleR2 r = new RectangleR2((double)coord[0].val, (double)coord[1].val, (double)coord[2].val, (double)coord[3].val); root.spatialIndex.Put(r, thing); } else if (prop.name == Symbols.Point) { PropVal[] coord = ((VersionHistory)val).Latest.props; double x = (double)coord[0].val; double y = (double)coord[1].val; RectangleR2 r = new RectangleR2(x, y, x, y); root.spatialIndex.Put(r, thing); } } else { throw new InvalidOperationException("Invalid propery value type " + prop.val.GetType()); } thing.props[i] = pv; } thing.Modify(); vh.versions.Add(thing); root.timeIndex.Put(thing); root.latest.Add(thing); return(thing); }