private void UpdateRepresentationAttribute(RepresentationAttribute representationAttribute, SchemaAttributeResponse schemaAttr) { representationAttribute.SchemaAttribute = schemaAttr; if (schemaAttr.Type != "complex") { return; } var complex = representationAttribute as ComplexRepresentationAttribute; var complexSchema = schemaAttr as ComplexSchemaAttributeResponse; foreach (var child in complex.Values) { if (schemaAttr.MultiValued) { var subComplex = child as ComplexRepresentationAttribute; foreach (var c in subComplex.Values) { var sra = complexSchema.SubAttributes.First(s => s.Id == c.SchemaAttribute.Id); UpdateRepresentationAttribute(c, sra); } } else { var subRepresentationAttr = complexSchema.SubAttributes.First(s => s.Id == child.SchemaAttribute.Id); UpdateRepresentationAttribute(child, subRepresentationAttr); } } }
protected override int CompareTo(RepresentationAttribute attr) { var complex = attr as ComplexRepresentationAttribute; if (complex == null || complex.Values == null) { return(1); } if (Values == null) { return(-1); } var sourcePrimary = Values.FirstOrDefault(p => p.SchemaAttribute != null && p.SchemaAttribute.Name == Common.Constants.MultiValueAttributeNames.Primary); var targetPrimary = complex.Values.FirstOrDefault(p => p.SchemaAttribute != null && p.SchemaAttribute.Name == Common.Constants.MultiValueAttributeNames.Primary); if (sourcePrimary == null || targetPrimary == null) { return(0); } return(sourcePrimary.CompareTo(targetPrimary)); }
protected virtual int CompareTo(RepresentationAttribute attr) { return(0); }
public virtual bool SetValue(RepresentationAttribute attr) { return(false); }
public Models.RepresentationAttribute Transform(RepresentationAttribute attr) { var record = new Models.RepresentationAttribute { Id = Guid.NewGuid().ToString(), Children = new List <Models.RepresentationAttribute>() }; if (attr.SchemaAttribute != null) { record.SchemaAttributeId = attr.SchemaAttribute.Id; } var complexAttr = attr as ComplexRepresentationAttribute; if (complexAttr != null) { if (complexAttr.Values != null) { foreach (var child in complexAttr.Values) { var transformed = Transform(child); if (transformed == null) { continue; } transformed.Parent = record; record.Children.Add(transformed); } } return(record); } if (attr.SchemaAttribute.MultiValued) { var singular = attr as SingularRepresentationAttribute <IEnumerable <string> >; if (singular != null) { var representationAttributeValues = new List <RepresentationAttributeValue>(); switch (attr.SchemaAttribute.Type) { case Common.Constants.SchemaAttributeTypes.Boolean: case Common.Constants.SchemaAttributeTypes.String: case Common.Constants.SchemaAttributeTypes.Integer: case Common.Constants.SchemaAttributeTypes.Decimal: foreach (var value in singular.Value) { representationAttributeValues.Add(new RepresentationAttributeValue { Id = Guid.NewGuid().ToString(), Value = value.ToString() }); } break; case Common.Constants.SchemaAttributeTypes.DateTime: foreach (var value in singular.Value) { DateTime dt; if (DateTime.TryParse(value, out dt)) { representationAttributeValues.Add(new RepresentationAttributeValue { Id = Guid.NewGuid().ToString(), Value = dt.ToUnix().ToString() }); } } break; } record.Values = representationAttributeValues; } } else { var value = attr.GetValue(); switch (attr.SchemaAttribute.Type) { case Common.Constants.SchemaAttributeTypes.Boolean: case Common.Constants.SchemaAttributeTypes.String: record.Value = value == null ? string.Empty : value.ToString(); break; case Common.Constants.SchemaAttributeTypes.Decimal: var dec = (decimal)value; record.ValueNumber = (double)dec; break; case Common.Constants.SchemaAttributeTypes.Integer: var i = (int)value; record.ValueNumber = i; break; case Common.Constants.SchemaAttributeTypes.DateTime: var d = (DateTime)value; record.ValueNumber = d.ToUnix(); break; } } return(record); }