/// <summary> /// Create columns for edge oject (GK and TK) /// </summary> /// <param name="obj"></param> /// <param name="columnName"></param> /// <returns></returns> private IEnumerable <Column> CreateEdgeObjColumns(EdgeObject obj, string columnName = "") { var columnList = new List <Column>(); if (obj.EdgeType == null) { throw new ConfigurationErrorsException(String.Format("EdgeType is not set for object {0}", obj.GetType())); } // if column name is not set according to EdgeField set it according to EdgeType columnName = String.IsNullOrEmpty(columnName) ? obj.EdgeType.Name : columnName; // add 3 columns: GK (to be set later in Identify stage), TK (temp key) and type (from EdgeTypes) columnList.Add(new Column { Name = String.Format("{0}_gk", columnName), Value = obj.GK, Nullable = true }); columnList.Add(new Column { Name = String.Format("{0}_tk", columnName), Value = obj.TK, DbType = SqlDbType.NVarChar, Size = 500, Nullable = true }); columnList.Add(new Column { Name = String.Format("{0}_type", columnName), Value = obj.EdgeType.TypeID, DbType = SqlDbType.Int, Nullable = true }); return(columnList); }
/// <summary> /// Get EdgeObject fields which are configured in MD_EdgeField table according to object type /// get fields values by reflection and compose values and columns string for INSERT /// </summary> /// <param name="edgeObject"></param> /// <param name="columns"></param> /// <param name="values"></param> /// <param name="paramList"></param> private void BuildEdgeObjectFields(EdgeObject edgeObject, ref string columns, ref string values, ICollection <SqlParameter> paramList) { // get the list of configured fields in MD_EdgeFields according to the object type foreach (var field in edgeObject.EdgeType.Fields) { // add extra field column var edgeFieldObj = edgeObject.GetObjectDimensions().Where(x => x.Field == field.Field).Select(x => x.Value).FirstOrDefault() as EdgeObject; if (edgeFieldObj != null) { AddColumn(ref columns, ref values, paramList, String.Format("{0}_gk", field.ColumnName), edgeFieldObj.GK); AddColumn(ref columns, ref values, paramList, String.Format("{0}_tk", field.ColumnName), edgeFieldObj.TK); AddColumn(ref columns, ref values, paramList, String.Format("{0}_type", field.ColumnName), edgeFieldObj.EdgeType.TypeID); } else { // 1st try to get field from extra fields by name if (edgeObject.Fields != null && edgeObject.Fields.FirstOrDefault(x => x.Key.Name == field.Field.Name).Key != null) { var extraField = edgeObject.Fields.FirstOrDefault(x => x.Key.Name == field.Field.Name); AddColumn(ref columns, ref values, paramList, field.ColumnName, extraField.Value); } else { // try to get field by reflection by configured edge field name var member = edgeObject.GetType().GetMember(field.Field.Name); if (member.Length > 0) { var memberInfo = edgeObject.GetType().GetMember(field.Field.Name)[0]; var value = (memberInfo is FieldInfo ? (memberInfo as FieldInfo).GetValue(edgeObject) : null) ?? (memberInfo is PropertyInfo ? (memberInfo as PropertyInfo).GetValue(edgeObject, null) : null); var type = memberInfo is FieldInfo ? (memberInfo as FieldInfo).FieldType : memberInfo is PropertyInfo ? (memberInfo as PropertyInfo).PropertyType : null; // edge object if (value is EdgeObject) { var edgeObj = value as EdgeObject; AddColumn(ref columns, ref values, paramList, String.Format("{0}_gk", field.ColumnName), edgeObj.GK); AddColumn(ref columns, ref values, paramList, String.Format("{0}_tk", field.ColumnName), edgeObj.TK); AddColumn(ref columns, ref values, paramList, String.Format("{0}_type", field.ColumnName), edgeObj.EdgeType.TypeID); } else if (value != null) // primitive types { // special case for enum value - parse to INT if (type.BaseType == typeof(Enum)) { value = (int)Enum.Parse(type, value.ToString()); } AddColumn(ref columns, ref values, paramList, field.ColumnName, value); } } } } } }
/// <summary> /// Add EdgeObject to cache, which contains distinct EdgeObjects, /// in order to import EdgeObjects into EdgeObjects delivery tables when import metrics finishes /// </summary> /// <param name="obj"></param> public void AddToCache(EdgeObject obj) { var key = String.Format("{0}_{1}", obj.EdgeType.Name, obj.TK); if (!_objectsCache.ContainsKey(key)) { _objectsCache.Add(key, obj); } }
/// <summary> /// Handle specific fields of th EdgeObject which are defined hard coded in Object table /// </summary> /// <param name="edgeObject"></param> /// <param name="columns"></param> /// <param name="values"></param> /// <param name="paramList"></param> private void BuildSpecificFields(EdgeObject edgeObject, ref string columns, ref string values, ICollection <SqlParameter> paramList) { // fields defined for channel specific objects if (edgeObject is ChannelSpecificObject) { var channelObj = edgeObject as ChannelSpecificObject; AddColumn(ref columns, ref values, paramList, "ChannelID", channelObj.Channel.ID); //AddColumn(ref columns, ref values, paramList, "OriginalID", channelObj.OriginalID); //AddColumn(ref columns, ref values, paramList, "Status", (int)channelObj.Status); } }
/// <summary> /// Set EdgeObject Account adn Channel according to Metrics /// </summary> /// <param name="obj"></param> private EdgeObject NormalizeEdgeObject(EdgeObject obj) { if (CurrentMetricsUnit == null || obj == null) { return(null); } obj.Account = CurrentMetricsUnit.Account; if (obj is ChannelSpecificObject) { (obj as ChannelSpecificObject).Channel = CurrentMetricsUnit.Channel; } return(obj); }
void CreateNodes(Node node, NodeObject parent, int layer) { GameObject go = Instantiate(nodeObject); NodeObject nodeObj = go.GetComponent <NodeObject>(); nodes.Add(nodeObj); nodeObj.node = node; // In the Json, the splitrule is only a string, we want to know which actual class the rule belongs to nodeObj.DetectSplitrule(); nodeObj.parent = parent; nodeObj.layer = layer; if (layer > highestNodeLayer) { highestNodeLayer = layer; } //if the parent is not null, set the previous node as the parent of this node if (parent != null) { //go.transform.SetParent(parent.transform); parent.childrenObjects.Add(nodeObj); } // if children are null, then it is a leaf if (node.children.Length == 0) { Debug.Log("Null children", nodeObj); return; } for (int i = 0; i < node.children.Length; i++) { if (node.children[i] != null) { // set up the edge EdgeObject edge = Instantiate(edgeObject); edge.transform.SetParent(go.transform); nodeObj.edges.Add(edge); edge.splitText.text = node.children[i].split; CreateNodes(node.children[i].targetNode, nodeObj, nodeObj.layer + 1); } } }
public static void test() { EdgeScene e = new EdgeScene(); EdgeObject o = new EdgeObject(); o.Points = new Dictionary<string, float>[2]; o.Points[0] = new Dictionary<string, float>(); o.Points[0].Add("x", 0.03434f); o.Points[0].Add("y", 0.03434f); o.Points[1] = new Dictionary<string, float>(); o.Points[1].Add("x", 0.03434f); o.Points[1].Add("y", 0.03434f); e.Objects.Add("5", o); Console.Write(JsonConvert.SerializeObject(e)); Console.Write("a"); }