private int GetInputCount(ODocument node) { var c = 0; var tmp = new object(); while (node.TryGetValue($"INPUT{c}", out tmp)) { c++; } return(c); }
private BusinessObject ConvertItem(Type boType, ODocument item) { var realBo = BoActivator.GetInstance(boType); realBo.Id = item.ORID.ToString(); realBo.Version = item.OVersion; var propertyInfosToSet = (from prop in boType.GetProperties() let docPropAttr = prop.GetCustomAttribute <DocumentPropertyAttribute>() where docPropAttr != null select new { Prop = prop, Info = docPropAttr }).ToList(); foreach (var propertyInfo in propertyInfosToSet) { if (item.TryGetValue(propertyInfo.Info.Key, out var value)) { SetValueWithType(propertyInfo.Prop, realBo, value.ToString()); } } var children = (from prop in boType.GetProperties() let childAttr = prop.GetCustomAttribute <ChildAttribute>() where childAttr != null select new { Prop = prop, Child = childAttr }).ToList(); foreach (var propertyInfo in children) { var outORIDKey = item.Keys.SingleOrDefault(k => k.ToLower() == $"out_{propertyInfo.Child.EdgeClassName.ToLower()}"); if (outORIDKey == null) { continue; } var outORID = item.GetField <List <ORID> >(outORIDKey).Single().ToString(); var childEdge = database.Query(new PreparedQuery($"SELECT * FROM {propertyInfo.Child.EdgeClassName} WHERE @rid=:id") .Set("id", outORID)) .Run() .Single().To <OEdge>(); var child = ExecuteById(propertyInfo.Prop.PropertyType, childEdge.InV.ToString()); propertyInfo.Prop.SetValue(realBo, child); } var referenceLists = (from prop in boType.GetProperties() let attr = prop.GetCustomAttribute <ReferenceListAttribute>() where attr != null select new { Prop = prop, Attr = attr }).ToList(); foreach (var referenceList in referenceLists) { var outORIDKey = item.Keys.SingleOrDefault(k => k.ToLower() == $"out_{referenceList.Attr.EdgeClassName.ToLower()}"); if (outORIDKey == null) { continue; } var outORIDKeys = item.GetField <List <ORID> >(outORIDKey); foreach (var outORID in outORIDKeys) { var referenceBos = database.Query(new PreparedQuery($"SELECT * FROM {referenceList.Attr.EdgeClassName} WHERE @rid=:id") .Set("id", outORID)) .Run() .Select(referenceEdge => referenceEdge.To <OEdge>()) .Select(referenceBo => ExecuteById(referenceList.Prop.PropertyType, referenceBo.InV.ToString())) .ToList(); var list = (IList)referenceList.Prop.GetValue(realBo); foreach (var referenceBo in referenceBos) { list.Add(referenceBo); } } } return(realBo); }