Exemple #1
0
		public virtual void SetDomainMap(IDomainMap value)
		{
			m_DomainMap = (DomainMap) value;
			foreach (IPropertyMap propertyMap in m_PropertyMaps)
			{
				propertyMap.SetClassMap(this);
			}
		}
		protected virtual IDomainMap DeserializeDomainMap(XmlNode xmlDom)
		{
			IDomainMap domainMap = new DomainMap();
			XmlNodeList xmlClasses;
			XmlNodeList xmlSources;
			string str;
			string[] arr;
			if (!(xmlDom.Attributes["name"] == null))
			{
				domainMap.Name = xmlDom.Attributes["name"].Value;
			}
			if (!(xmlDom.Attributes["assembly"] == null))
			{
				domainMap.AssemblyName = xmlDom.Attributes["assembly"].Value;
			}
			if (!(xmlDom.Attributes["language"] == null))
			{
				domainMap.CodeLanguage = (CodeLanguage) Enum.Parse(typeof (CodeLanguage), xmlDom.Attributes["language"].Value);
			}
			if (!(xmlDom.Attributes["validation"] == null))
			{
				domainMap.ValidationMode = (ValidationMode) Enum.Parse(typeof (ValidationMode), xmlDom.Attributes["validation"].Value);
			}
			if (!(xmlDom.Attributes["root"] == null))
			{
				domainMap.RootNamespace = xmlDom.Attributes["root"].Value;
			}
			if (!(xmlDom.Attributes["source"] == null))
			{
				domainMap.Source = xmlDom.Attributes["source"].Value;
			}
			if (!(xmlDom.Attributes["doc-source"] == null))
			{
				domainMap.DocSource = xmlDom.Attributes["doc-source"].Value;
			}
			if (!(xmlDom.Attributes["read-only"] == null))
			{
				domainMap.IsReadOnly = ParseBool(xmlDom.Attributes["read-only"].Value);
			}
			if (!(xmlDom.Attributes["field-prefix"] == null))
			{
				domainMap.FieldPrefix = xmlDom.Attributes["field-prefix"].Value;
			}
			if (!(xmlDom.Attributes["field-strategy"] == null))
			{
				domainMap.FieldNameStrategy = (FieldNameStrategyType) Enum.Parse(typeof (FieldNameStrategyType), xmlDom.Attributes["field-strategy"].Value);
			}
			if (!(xmlDom.Attributes["base"] == null))
			{
				domainMap.InheritsTransientClass = xmlDom.Attributes["base"].Value;
			}
			if (!(xmlDom.Attributes["implements"] == null))
			{
				str = xmlDom.Attributes["implements"].Value;
				if (str.Length > 0)
				{
					arr = str.Split(',');
					foreach (string iStr in arr)
					{
						str = iStr.Trim();
						if (str.Length > 0)
						{
							domainMap.ImplementsInterfaces.Add(str);
						}
					}
				}
			}
			if (!(xmlDom.Attributes["imports"] == null))
			{
				str = xmlDom.Attributes["imports"].Value;
				if (str.Length > 0)
				{
					arr = str.Split(',');
					foreach (string iStr in arr)
					{
						str = iStr.Trim();
						if (str.Length > 0)
						{
							domainMap.ImportsNamespaces.Add(str);
						}
					}
				}
			}
			if (!(xmlDom.Attributes["ttl"] == null))
			{
				domainMap.TimeToLive = Int32.Parse(xmlDom.Attributes["ttl"].Value);
			}
			if (!(xmlDom.Attributes["ttl-behavior"] == null))
			{
				domainMap.TimeToLiveBehavior = (TimeToLiveBehavior) Enum.Parse(typeof (TimeToLiveBehavior), xmlDom.Attributes["ttl-behavior"].Value);
			}
			if (!(xmlDom.Attributes["load"] == null))
			{
				domainMap.LoadBehavior = (LoadBehavior) Enum.Parse(typeof (LoadBehavior), xmlDom.Attributes["load"].Value);
			}
			if (!(xmlDom.Attributes["merge"] == null))
			{
				domainMap.MergeBehavior = (MergeBehaviorType) Enum.Parse(typeof (MergeBehaviorType), xmlDom.Attributes["merge"].Value);
			}
			if (!(xmlDom.Attributes["refresh"] == null))
			{
				domainMap.RefreshBehavior = (RefreshBehaviorType) Enum.Parse(typeof (RefreshBehaviorType), xmlDom.Attributes["refresh"].Value);
			}
			if (!(xmlDom.Attributes["optimistic-delete"] == null))
			{
				domainMap.DeleteOptimisticConcurrencyBehavior = (OptimisticConcurrencyBehaviorType) Enum.Parse(typeof (OptimisticConcurrencyBehaviorType), xmlDom.Attributes["optimistic-delete"].Value);
			}
			if (!(xmlDom.Attributes["optimistic-update"] == null))
			{
				domainMap.UpdateOptimisticConcurrencyBehavior = (OptimisticConcurrencyBehaviorType) Enum.Parse(typeof (OptimisticConcurrencyBehaviorType), xmlDom.Attributes["optimistic-update"].Value);
			}
			if (!(xmlDom.Attributes["serializer"] == null))
			{
				if (xmlDom.Attributes["serializer"].Value.ToLower(CultureInfo.InvariantCulture) == "dotnet" || xmlDom.Attributes["serializer"].Value.ToLower(CultureInfo.InvariantCulture) == "dotnetserializer")
				{
					domainMap.MapSerializer = MapSerializer.DotNetSerializer;
				}
				else if (xmlDom.Attributes["serializer"].Value.ToLower(CultureInfo.InvariantCulture) == "custom" || xmlDom.Attributes["serializer"].Value.ToLower(CultureInfo.InvariantCulture) == "customserializer")
				{
					domainMap.MapSerializer = MapSerializer.CustomSerializer;
				}
				else
				{
					domainMap.MapSerializer = MapSerializer.DefaultSerializer;
				}
			}
			else
			{
				domainMap.MapSerializer = MapSerializer.DefaultSerializer;
			}
			if (!(xmlDom.Attributes["target-languages"] == null))
			{
				str = xmlDom.Attributes["target-languages"].Value;
				if (str.Length > 0)
				{
					arr = str.Split(',');
					foreach (string iStr in arr)
					{
						str = iStr.Trim();
						if (str.Length > 0)
						{
							if (str.ToLower(CultureInfo.InvariantCulture) == "cs" || str.ToLower(CultureInfo.InvariantCulture) == "c-sharp" || str.ToLower(CultureInfo.InvariantCulture) == "csharp" || str.ToLower(CultureInfo.InvariantCulture) == "c#")
							{
								domainMap.VerifyCSharpReservedWords = true;
							}
							else if (str.ToLower(CultureInfo.InvariantCulture) == "vb" || str.ToLower(CultureInfo.InvariantCulture) == "vb-net" || str.ToLower(CultureInfo.InvariantCulture) == "vb.net")
							{
								domainMap.VerifyVbReservedWords = true;
							}
							else if (str.ToLower(CultureInfo.InvariantCulture) == "delphi" || str.ToLower(CultureInfo.InvariantCulture) == "delphi.net")
							{
								domainMap.VerifyDelphiReservedWords = true;
							}
						}
					}
				}
			}
			ArrayList metaData = domainMap.MetaData;
			DeserializeMetaData(xmlDom, ref metaData);
			xmlClasses = xmlDom.SelectNodes("class");
			foreach (XmlNode xmlClass in xmlClasses)
			{
				DeserializeClassMap(domainMap, xmlClass);
			}
			xmlSources = xmlDom.SelectNodes("source");
			foreach (XmlNode xmlSource in xmlSources)
			{
				DeserializeSourceMap(domainMap, xmlSource);
			}
			XmlNodeList xmlCodeMaps = xmlDom.SelectNodes("code");
			foreach (XmlNode xmlCodeMap in xmlCodeMaps)
			{
				DeserializeCodeMap(domainMap, xmlCodeMap);
			}
			return domainMap;
		}
		public override IMap DeepClone()
		{
			IDomainMap domainMap = new DomainMap();
			DeepCopy(domainMap);
			return domainMap;
		}
        public static IDomainMap LoadFromAttributes(Assembly asm, bool useCache,bool validate)
        {
            IDomainMap domainMap = new DomainMap();

            foreach (DomainMapAttribute domainMapAttribute in asm.GetCustomAttributes(typeof(DomainMapAttribute), false))
            {
                DomainMap.FromDomainMapAttribute(domainMapAttribute, asm, domainMap);
                break;
            }

            foreach (SourceMapAttribute sourceMapAttribute in asm.GetCustomAttributes(typeof(SourceMapAttribute), false))
            {
                ISourceMap sourceMap = new SourceMap();
                sourceMap.DomainMap = domainMap;

                SourceMap.FromSourceMapAttribute(sourceMapAttribute, sourceMap);
                break;
            }

            //Make this 2-pass so that mapped inheritance hierarchies can be found.

            foreach (Type type in asm.GetTypes())
            {
                foreach (ClassMapAttribute classMapAttribute in type.GetCustomAttributes(typeof(ClassMapAttribute), false))
                {
                    IClassMap classMap = new ClassMap();
                    classMap.DomainMap = domainMap;
                    classMap.Name = type.Name;
                    string waste = classMapAttribute.DocElement ; // The idiot compiler won't compile unless I use the stinkin' classMapAttribute somehow...
                    break;
                }
            }

            foreach (Type type in asm.GetTypes())
            {
                foreach (ClassMapAttribute classMapAttribute in type.GetCustomAttributes(typeof(ClassMapAttribute), false))
                {
                    IClassMap classMap = domainMap.MustGetClassMap(type);
                    ClassMap.FromClassMapAttribute(classMapAttribute, type, classMap);

                    foreach (PropertyInfo propInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                    {
                        foreach (PropertyMapAttribute propertyMapAttribute in propInfo.GetCustomAttributes(typeof(PropertyMapAttribute), false))
                        {
                            IPropertyMap propertyMap = new PropertyMap();
                            propertyMap.ClassMap = classMap;
                            PropertyMap.FromPropertyMapAttribute(propertyMapAttribute, propInfo, propertyMap);

                            break;
                        }
                    }

                    break;
                }
            }

            RecalculateModel(domainMap);

            domainMap.Dirty = false;

            if (validate)
                ((DomainMap)domainMap).Validate();

            return domainMap;
        }