Ejemplo n.º 1
0
        public static SDataSchema Read(TextReader reader, string targetElementName)
        {
            var xsd = XmlSchema.Read(reader, null);

            var schemaSet = new XmlSchemaSet();
            schemaSet.Add(xsd);
            schemaSet.Compile();

            var resources = new Dictionary<string, SDataResource>();

            foreach (DictionaryEntry entry in xsd.Elements)
            {
                var name = (XmlQualifiedName) entry.Key;

                if (name.Namespace != xsd.TargetNamespace)
                {
                    continue;
                }

                var resource = new SDataResource();
                resource.Load(name, schemaSet);
                resources.Add(name.Name, resource);
            }

            return new SDataSchema
                   {
                       TargetElementName = targetElementName,
                       Namespace = xsd.TargetNamespace,
                       Resources = resources
                   };
        }
        /// <summary>
        /// Initialises a new instance of the <see cref="SDataResource"/> class
        /// by cloning the details of the specified instance.
        /// </summary>
        /// <param name="source">Instance of the <see cref="SDataResource"/> to clone.</param>
        public SDataResource(SDataResource source)
            : base(source)
        {
            _oSource = source;

            if (_oSource != null && _oSource.IsLoading)
                _oSource.Loaded += Clone_Loaded;
            else
                Clone(_oSource);
        }
        private void Clone(SDataResource source)
        {
            _strTypeName = source.TypeName;
            _oBaseType = source.BaseType;

            if (source.RelationshipInformation != null)
                _oRelationshipInformation = new SMERelationshipProperty(source.RelationshipInformation);

            if (source.ResourceInformation != null)
                _oResourceInfo = new SMEResource(source.ResourceInformation);

            _oProperties = new List<SMEProperty>();
            _oNameToProperty = new Dictionary<string, SMEProperty>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var property in source.Properties)
                AddProperty(property);

            _oNamespaces = new XmlNamespaceManager(new NameTable());

            foreach (var ns in source.Namespaces.GetNamespacesInScope(XmlNamespaceScope.All))
            {
                // Don't add default namespaces
                if (!String.IsNullOrEmpty(ns.Key))
                    _oNamespaces.AddNamespace(ns.Key, ns.Value);
            }
        }
        private void Clone_Loaded(SDataResource metadata)
        {
            var original = metadata;

            original.Loaded -= Clone_Loaded;
            Clone(metadata);
        }
        private static SMEProperty GetMetadataProperty(XmlSchemaComplexType complexType, XmlQualifiedName name, XmlSchemaSet schemaSet)
        {
            // Find the metadata for the complex type
            var existing = MetadataManager.GetMetadata(complexType.QualifiedName, schemaSet);
            SMEProperty metaDataProperty;

            if (existing != null)
            {
                // Create a delegate property
                metaDataProperty = new SDataResource(existing);

                // Change the relevant properties
                metaDataProperty.Name = name.Name;
                if (string.IsNullOrEmpty(metaDataProperty.Namespace))
                    metaDataProperty.Namespace = name.Namespace;
            }
            else
            {
                metaDataProperty = null;
            }

            return metaDataProperty;
        }