Exemplo n.º 1
0
        /// <summary>
        /// Gets the child data properties for the specified type.
        /// </summary>
        /// <param name="parentXmlPath">The parent XML path</param>
        /// <param name="parentType">The type to create the child properties for.</param>
        /// <param name="hierarchy">The property hierarchy</param>
        /// <returns>
        /// The list of nested properties if this is a complex type; an empty list otherwise.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="parentType"/> or <paramref name="parentXmlPath"/> or <paramref name="hierarchy"/> are null.</exception>
        protected static IReadOnlyCollection <DataProperty> CreateChildPropertiesCore(Type parentType, string parentXmlPath, HashSet <Tuple <Type, string, Type> > hierarchy)
        {
            parentType.NotNull(nameof(parentType));
            parentXmlPath.NotNull(nameof(parentXmlPath));
            hierarchy.NotNull(nameof(hierarchy));

            if (parentType?.GetCustomAttribute <XmlTypeAttribute>() == null)
            {
                return(new List <DataProperty>());
            }

            var types = EnergisticsHelper.GetTypeAndAllDerivedTypes(parentType);

            var childProperties = new List <DataProperty>();

            foreach (var t in types)
            {
                var properties = t.GetProperties().Where(EnergisticsHelper.IsDataProperty);

                foreach (var p in properties)
                {
                    childProperties.Add(new DataProperty(t, p, parentXmlPath, hierarchy));
                }
            }

            return(childProperties);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the mapping from data standard families to available data schema versions.
        /// </summary>
        private static void InitFamilyVersions()
        {
            if (_familyVersionsInitialized)
            {
                return;
            }

            lock (FamilyVersions)
            {
                if (_familyVersionsInitialized)
                {
                    return;
                }

                _familyVersionsInitialized = true;
                var dataObjectTypes = EnergisticsHelper.GetAllDataObjectTypes().ToList();

                var standardFamilies = dataObjectTypes.Select(t => t.GetCustomAttribute <EnergisticsDataObjectAttribute>().StandardFamily).Distinct();

                foreach (var standardFamily in standardFamilies)
                {
                    var familyTypes        = dataObjectTypes.Where(t => t.GetCustomAttribute <EnergisticsDataObjectAttribute>().StandardFamily == standardFamily);
                    var dataSchemaVersions = familyTypes.Select(t => t.GetCustomAttribute <EnergisticsDataObjectAttribute>().DataSchemaVersion).Distinct().OrderBy(v => v.ToString());

                    FamilyVersions.Add(standardFamily, dataSchemaVersions.ToList());
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FamilyVersionObjectCollection"/> class.
        /// </summary>
        /// <param name="familyVersion">The family version.</param>
        /// <exception cref="ArgumentNullException"><paramref name="familyVersion"/> is null.</exception>
        public FamilyVersionObjectCollection(FamilyVersion familyVersion)
        {
            familyVersion.NotNull(nameof(familyVersion));

            FamilyVersion = familyVersion;
            var dataObjectTypes = EnergisticsHelper.GetAllDataObjectTypes(familyVersion.StandardFamily, familyVersion.DataSchemaVersion);

            _dataObjects = dataObjectTypes.Select(dt => new DataObject(dt)).OrderBy(edo => edo.Name).ToList();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new <see cref="DataProperty"/> from the specified property and the XML path to the property.
        /// </summary>
        /// <param name="property">The property to initialize from</param>
        /// <param name="parentXmlPath">The parent XML path</param>
        /// <param name="hierarchy">The property hierarchy</param>
        /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="hierarchy"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="parentXmlPath"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="property"/> is not a (nested) data property on an Energistics Data Object.</exception>
        protected DataProperty(Type parentType, PropertyInfo property, string parentXmlPath, HashSet <Tuple <Type, string, Type> > hierarchy)
        {
            property.NotNull(nameof(property));
            parentXmlPath.NotNull(nameof(parentXmlPath));
            hierarchy.NotNull(nameof(hierarchy));
            if (!EnergisticsHelper.IsDataProperty(property))
            {
                throw new ArgumentException($"{property.Name} is not a (nested) data property on an Energistics Data Object", nameof(property));
            }

            Property = property;

            var recurse    = true;
            var addedTypes = new List <Tuple <Type, string, Type> >(2);

            XmlPath = parentXmlPath;
            if (EnergisticsHelper.IsArray(property))
            {
                XmlName = property.GetCustomAttribute <XmlArrayAttribute>().ElementName;
                var t = new Tuple <Type, string, Type>(parentType, XmlName, property.PropertyType);
                if (hierarchy.Add(t))
                {
                    addedTypes.Add(t);
                }
                else
                {
                    recurse = false;
                }
                XmlPath += "/" + XmlName;
            }
            if (EnergisticsHelper.IsArrayItem(property))
            {
                XmlName = property.GetCustomAttribute <XmlArrayItemAttribute>().ElementName;
                var t = new Tuple <Type, string, Type>(parentType, XmlName, PropertyType);
                if (hierarchy.Add(t))
                {
                    addedTypes.Add(t);
                }
                else
                {
                    recurse = false;
                }
                XmlPath += "/" + XmlName;
            }
            else if (!EnergisticsHelper.IsArray(property))
            {
                XmlName = EnergisticsHelper.GetXmlName(property);
                var t = new Tuple <Type, string, Type>(parentType, XmlName, PropertyType);
                if (hierarchy.Add(t))
                {
                    addedTypes.Add(t);
                }
                else
                {
                    recurse = false;
                }
                XmlPath += "/" + XmlName;
            }

            var propertyNamespace = property.PropertyType.GetCustomAttribute <XmlTypeAttribute>()?.Namespace ?? string.Empty;

            // Do not recurse properties that are themselves DataObjects or are from namespaces outside Energistics (e.g. CRS definitions)
            if (!recurse || EnergisticsHelper.IsDataObjectType(property.PropertyType))
            {
                ChildProperties = new List <DataProperty>();
            }
            else if (!string.IsNullOrEmpty(propertyNamespace) && !propertyNamespace.ContainsIgnoreCase("resqml") && !propertyNamespace.ContainsIgnoreCase("witsml") && !propertyNamespace.ContainsIgnoreCase("prodml") && !propertyNamespace.ContainsIgnoreCase("energistics"))
            {
                ChildProperties = new List <DataProperty>();
            }
            else
            {
                ChildProperties = CreateChildPropertiesCore(PropertyType, XmlPath, hierarchy);
            }

            foreach (var t in addedTypes)
            {
                hierarchy.Remove(t);
            }
        }