Beispiel #1
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));
        }
Beispiel #2
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)));
 }
Beispiel #3
0
        public void ObjectTypes_GetVersion_Returns_Empty_Version_From_Invalid_Xml()
        {
            var version = ObjectTypes.GetVersion((XElement)null);

            Assert.AreEqual(string.Empty, version);
        }
Beispiel #4
0
 public void ObjectTypes_GetSchemaType_Returns_Data_Object_Xsd_Type_Name()
 {
     Assert.AreEqual("obj_well", ObjectTypes.GetSchemaType(new Witsml141.Well()));
     Assert.AreEqual("Well", ObjectTypes.GetSchemaType(typeof(Witsml200.Well)));
     Assert.IsNull(ObjectTypes.GetSchemaType(null));
 }
Beispiel #5
0
        public void ObjectTypes_GetObjectGroupType_Returns_Correct_WbGeometry_Type_For_141()
        {
            var objectType = ObjectTypes.GetObjectGroupType(ObjectTypes.WbGeometry, OptionsIn.DataVersion.Version141);

            Assert.AreEqual(typeof(Witsml141.WellboreGeometryList), objectType);
        }
Beispiel #6
0
        public void ObjectTypes_GetObjectTypeFromGroup_Returns_Unknown_For_Invalid_Xml()
        {
            var typeFound = ObjectTypes.GetObjectTypeFromGroup(null);

            Assert.AreEqual(ObjectTypes.Unknown, typeFound);
        }
Beispiel #7
0
        public void ObjectTypes_GetObjectType_Returns_Unknown_For_Invalid_Xml()
        {
            var typeFound = ObjectTypes.GetObjectType((XElement)null);

            Assert.AreEqual(ObjectTypes.Unknown, typeFound);
        }
Beispiel #8
0
 /// <summary>
 /// Gets the <see cref="EtpUri"/> for a given <see cref="Energistics.DataAccess.RESQML210.AbstractObject"/>.
 /// </summary>
 /// <param name="entity">The <see cref="Energistics.DataAccess.RESQML210.AbstractObject"/> entity.</param>
 /// <returns>An <see cref="EtpUri"/> instance.</returns>
 public static EtpUri GetUri(this Resqml210.AbstractObject entity)
 {
     return(entity.GetUriFamily()
            .Append(ObjectTypes.GetObjectType(entity), entity.Uuid));
 }