public static void Save(IAtmlObject atmlObject, Capability capability) { string id = atmlObject.GetAtmlId(); var dao = new EquipmentDAO(); if (capability.SignalDescription != null) { List <Signal> signals = SignalManager.ExtractSignalsFromExtension(capability.SignalDescription); foreach (Signal signal in signals) { string signalName = signal.name; string signalNameSpace = signal.GetSignalNameSpace(); string capabilityName = capability.name; object[] items = signal.Items; foreach (object item in items) { var element = item as XmlElement; if (element != null) { XmlSchemaComplexType complexType; string elementName = element.Name; string localName = element.LocalName; XmlSchema schema = SchemaManager.GetSchema(element.NamespaceURI); SchemaManager.GetComplexType(element.NamespaceURI, localName, out complexType); var xmlSchemaObjects = new Dictionary <string, XmlSchemaObject>(); SchemaManager.ExtractAttributes(complexType, xmlSchemaObjects); foreach (XmlAttribute attribute in element.Attributes) { string propertyName = attribute.Name; string value = attribute.Value; try { XmlSchemaAttribute schemaAttribute; SchemaManager.FindAttribute(element.NamespaceURI, localName, propertyName, out schemaAttribute); bool isPhysicalType = false; string typeName = ""; if (schemaAttribute != null) { XmlSchemaSimpleType simpleType = schemaAttribute.AttributeSchemaType; XmlQualifiedName qn = schemaAttribute.SchemaTypeName; isPhysicalType = SchemaManager.IsPhysicalType(simpleType); if (!isPhysicalType) { isPhysicalType = SchemaManager.IsPhysicalType(qn); } } Physical physical; try { physical = new Physical(value); } catch (Exception) { continue; } RangingInformation range = physical.GetMergedRange(); //TODO: need SignalType, SignalNamespace if (range != null) { InstrumentCapabilitiesBean bean = dao.GetSignalCapabilityAttribute(Guid.Parse(id), capabilityName, signalName, propertyName); if (bean == null) { bean = new InstrumentCapabilitiesBean(); bean.DataState = BASEBean.eDataState.DS_ADD; } else { bean.DataState = atmlObject.IsDeleted() ? BASEBean.eDataState.DS_DELETE : BASEBean.eDataState.DS_EDIT; } //bean.signalType =; bean.capabilityName = capabilityName; bean.signalNamespace = signalNameSpace; bean.IncludeKeyOnInsert = true; bean.instrumentUuid = id; bean.attribute = propertyName; bean.signalName = signalName; if (range.FromQuantity != null) { bean.lowValue = range.FromQuantity.NominalValue; bean.lowUnit = range.FromQuantity.Unit.BaseUnitString; } if (range.ToQuantity != null) { bean.highValue = range.ToQuantity.NominalValue; bean.highUnit = range.ToQuantity.Unit.BaseUnitString; } bean.save(); } } catch (Exception) { throw; } } } else { string signalFunctionName = item.GetType().Name; PropertyInfo piName = item.GetType().GetProperty("name"); if (piName != null) { object value = piName.GetValue(item, null); //if (value != null) // propertyName = value as string; } foreach ( PropertyInfo pi in item.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { string propertyName = pi.Name; object value = pi.GetValue(item, null); if (value != null) { try { //TODO: need SignalType, SignalNamespace if ( !SchemaManager.IsPhysicalType("urn:IEEE-1641:2010:STDBSC", signalFunctionName, propertyName)) { continue; } var physicalValue = new Physical(value.ToString()); Console.WriteLine(physicalValue.ToString()); RangingInformation range = physicalValue.GetMergedRange(); InstrumentCapabilitiesBean bean = dao.GetSignalCapabilityAttribute(Guid.Parse(id), capabilityName, signalName, pi.Name); if (bean == null) { bean = new InstrumentCapabilitiesBean(); bean.DataState = BASEBean.eDataState.DS_ADD; } else { bean.DataState = atmlObject.IsDeleted() ? BASEBean.eDataState.DS_DELETE : BASEBean.eDataState.DS_EDIT; } //bean.signalType =; bean.capabilityName = capabilityName; bean.signalNamespace = signalNameSpace; bean.IncludeKeyOnInsert = true; bean.instrumentUuid = id; bean.attribute = pi.Name; bean.signalName = signalName; if (range != null) { if (range.FromQuantity != null) { bean.lowValue = range.FromQuantity.NominalValue; bean.lowUnit = range.FromQuantity.Unit.BaseUnitString; } if (range.ToQuantity != null) { bean.highValue = range.ToQuantity.NominalValue; bean.highUnit = range.ToQuantity.Unit.BaseUnitString; } } bean.save(); } catch (Exception err) { LogManager.Error(err, "Error Saving Capability [{0}] - Item:{1}, Value:{2}", capability.name, item.GetType().Name, value ); } } } } } } } }