コード例 #1
0
        /// <summary>
        /// Creates an <see cref="IEnergisticsCollection"/> container and wraps the current entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns>A <see cref="IEnergisticsCollection"/> instance.</returns>
        public static IEnergisticsCollection CreateCollection(this IDataObject entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var type       = entity.GetType();
            var objectType = ObjectTypes.GetObjectType(type);
            var version    = ObjectTypes.GetVersion(type);

            var groupType = ObjectTypes.GetObjectGroupType(objectType, version);
            var property  = ObjectTypes.GetObjectTypeListPropertyInfo(objectType, version);
            var group     = Activator.CreateInstance(groupType) as IEnergisticsCollection;
            var list      = Activator.CreateInstance(property.PropertyType) as IList;

            if (list == null)
            {
                return(group);
            }

            list.Add(entity);
            property.SetValue(group, list);

            return(group);
        }
コード例 #2
0
        public void ObjectTypes_GetVersion_Returns_Version_From_Valid_Xml()
        {
            var document = WitsmlParser.Parse(_wellsXml);
            var version  = ObjectTypes.GetVersion(document.Root);

            Assert.AreEqual(OptionsIn.DataVersion.Version141.Value, version);
        }
コード例 #3
0
        /// <summary>
        /// Serialize WITSML query results to XML and remove empty elements and xsi:nil attributes.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="nilOnly">if set to <c>true</c> only elements with nil="true" are removed.</param>
        /// <param name="removeTypePrefix">if set to <c>true</c> any type prefix will be removed.</param>
        /// <returns>The serialized XML string.</returns>
        public static string ToXml(object obj, bool nilOnly = false, bool removeTypePrefix = false)
        {
            _log.Debug("Serializing object to XML.");

            if (obj == null)
            {
                return(string.Empty);
            }

            var xml    = EnergisticsConverter.ObjectToXml(obj);
            var xmlDoc = Parse(xml);
            var root   = xmlDoc.Root;

            if (root == null)
            {
                return(string.Empty);
            }

            var elementName = ObjectTypes.GetElementNameOverride(obj.GetType());

            root = root.UpdateRootElementName(obj.GetType(), removeTypePrefix, elementNameOverride: elementName);

            if (ObjectTypes.GetVersion(root).StartsWith("1."))
            {
                foreach (var element in root.Elements())
                {
                    RemoveEmptyElements(element, nilOnly);
                }
            }
            else
            {
                RemoveEmptyElements(root, nilOnly);
            }

            return(root.ToString(SaveOptions.OmitDuplicateNamespaces));
        }
コード例 #4
0
 public void ObjectTypes_GetVersion_Returns_Version_From_Type()
 {
     Assert.AreEqual(OptionsIn.DataVersion.Version131.Value, ObjectTypes.GetVersion(typeof(Witsml131.WellList)));
     Assert.AreEqual(OptionsIn.DataVersion.Version141.Value, ObjectTypes.GetVersion(typeof(Witsml141.Well)));
     Assert.AreEqual(OptionsIn.DataVersion.Version200.Value, ObjectTypes.GetVersion(typeof(Witsml200.Well)));
 }
コード例 #5
0
        public void ObjectTypes_GetVersion_Returns_Empty_Version_From_Invalid_Xml()
        {
            var version = ObjectTypes.GetVersion((XElement)null);

            Assert.AreEqual(string.Empty, version);
        }