private IAssetType GetAssetType(DatabaseConnection conn, Guid databaseId, int assetTypeId)
        {
            // First, find the type of asset.
            AssetType assetType     = this.GetAssetType(conn, assetTypeId);
            string    assetTypeName = assetType.Name;

            IEnumerable <AssetTypeAttributesMap> maps = conn.AssetTypeAttributesMaps
                                                        .Include(nameof(AssetTypeAttributesMap.AttributeKey))
                                                        .Include(nameof(AssetTypeAttributesMap.AttributeProperties))
                                                        .Where(m => m.AssetType.Id == assetType.Id);

            AssetTypeBuilder assetTypeBuilder = new AssetTypeBuilder(assetTypeName, databaseId);

            foreach (AssetTypeAttributesMap map in maps)
            {
                IAttributeType attributeType = AttributeTypeFactory.CreateAttributeType(map.AttributeKey.AttributeType);
                attributeType.DeserializeDefaultValue(map.AttributeProperties.DefaultValue);
                attributeType.DeserializePossibleValues(map.AttributeProperties.PossibleValues);
                attributeType.Key      = map.AttributeKey.Name;
                attributeType.Required = map.AttributeProperties.Required;

                assetTypeBuilder.AttributeTypes.Add(attributeType);
            }

            return(assetTypeBuilder);
        }
Beispiel #2
0
        public void RetrieveSingleProxyEntity()
        {
            IAttributeType stringType = entityContext.ProxySet <IAttributeType>("AttributeType")
                                        .Where(c => c.ClrName == "System.String")
                                        .Single();

            Assert.AreEqual(stringType.ClrName, "System.String");
            Assert.AreEqual(stringType.SqlServerName, "nvarchar");
        }
        public void Deserialize(JToken rootNode)
        {
            foreach (JToken childNode in rootNode.Children())
            {
                if (childNode.Path == "AssetTypeName")
                {
                    string name = childNode.ToObject <string>();
                    if (string.IsNullOrWhiteSpace(name) == false)
                    {
                        this.Name = name;
                    }
                }
                else if (childNode.Path == "AttributeList")
                {
                    // This is the array of attributes.
                    foreach (JArray attrNode in childNode.Children <JArray>())
                    {
                        foreach (JObject attrProperties in attrNode)
                        {
                            AttributeTypes?attrType = null;
                            foreach (JProperty attrValue in attrProperties.Children <JProperty>())
                            {
                                if (attrValue.Name == "AttributeType")
                                {
                                    attrType = (AttributeTypes)attrValue.ToObject <long>();
                                }
                            }

                            if (attrType == null)
                            {
                                throw new InvalidOperationException("Attribute Type can not be null.");
                            }

                            IAttributeType attributeType = AttributeTypeFactory.CreateAttributeType(attrType.Value);
                            attributeType.Deserialize(attrProperties);
                            this.AttributeTypes.Add(attributeType);
                        }

                        // There should only be one array.  Break.
                        break;
                    }
                }
                else if (childNode.Path == "DatabaseId")
                {
                    string guidStr = childNode.ToObject <string>();
                    Guid   guid    = Guid.Parse(guidStr);
                    this.DatabaseId = guid;
                }
            }
        }
Beispiel #4
0
        public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
        {
            var o = (DeserializeTemplate)nestedObjectDeserializer(typeof(DeserializeTemplate));

            _name = o.Name;
            // Convert to correct IAttribute implementation from the serialization template
            var type = typeof(IAttributeType);

            foreach (var item in AppDomain.CurrentDomain.GetAssemblies()
                     .SelectMany(s => s.GetTypes())
                     .Where(p => type.IsAssignableFrom(p)))
            {
                var s = item.GetCustomAttributes(typeof(AttributeTypeAttribute), true);
                if (s.Length == 1)
                {
                    if (o.Type.ToLower() == ((AttributeTypeAttribute)s[0]).Name.ToLower())
                    {
                        _type = (IAttributeType)Activator.CreateInstance(item.UnderlyingSystemType);
                    }
                }
            }
        }
Beispiel #5
0
 public Attribute(string name, IAttributeType type)
 {
     Name = name;
     Type = type;
 }
Beispiel #6
0
 public static string EscapeKey(this IAttributeType type)
 {
     return(type.Key.NormalizeWhiteSpace('_'));
 }