public static void Refresh() { WeaponModel.Refresh(); ModelDataModel.Refresh(); }
private void ReadFieldElement( XmlReader reader, dynamic model, Dictionary <string, object> record) { var refKey = reader["ref-key"] as string; if (refKey != null) { refKey.Trim(); } var refModel = reader["ref-model"] as string; if (refModel != null) { refModel.Trim(); } var fieldName = (string)reader["name"]; fieldName.Trim(); if (!model.Fields.ContainsKey(fieldName)) { var msg = string.Format("Cannot found field: [{0}]", fieldName); throw new ArgumentOutOfRangeException(msg); } IField metaField = model.Fields[fieldName]; object fieldValue = null; switch (metaField.Type) { case FieldType.BigInteger: fieldValue = reader.ReadElementContentAsLong(); break; case FieldType.Integer: fieldValue = reader.ReadElementContentAsInt(); break; case FieldType.Boolean: fieldValue = reader.ReadElementContentAsBoolean(); break; case FieldType.Double: fieldValue = reader.ReadElementContentAsDouble(); break; case FieldType.DateTime: case FieldType.Date: case FieldType.Time: fieldValue = reader.ReadElementContentAsDateTime(); break; case FieldType.Decimal: fieldValue = reader.ReadElementContentAsDecimal(); break; case FieldType.Chars: case FieldType.Text: case FieldType.Enumeration: fieldValue = reader.ReadElementContentAsString().Trim(); break; case FieldType.Reference: if (string.IsNullOrEmpty(refKey) || string.IsNullOrEmpty(refModel)) { throw new DataException( "Reference field must have 'ref-key' and 'ref-model' attributes"); } var recordId = ModelDataModel.TryLookupResourceId( this.context.DataContext, refModel, refKey); if (recordId == null) { var msg = string.Format( "Cannot found model for reference field: {0}:{1}", refModel, refKey); throw new DataException(msg); } fieldValue = new object[] { refModel, recordId }; break; case FieldType.ManyToOne: if (string.IsNullOrEmpty(refKey)) { throw new DataException("Many-to-one field must have a 'ref-key' attribute"); } fieldValue = ModelDataModel.TryLookupResourceId( this.context.DataContext, metaField.Relation, refKey); if (fieldValue == null) { throw new DataException("Cannot found model for ref-key: " + refKey); } break; default: throw new NotSupportedException(); } record[metaField.Name] = fieldValue; }