コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EtpUri"/> struct.
        /// </summary>
        /// <param name="uri">The URI string.</param>
        public EtpUri(string uri)
        {
            _match  = Pattern.Match(uri);
            _parent = new EtpUri?[] { null };

            Uri     = uri;
            IsValid = _match.Success || IsRoot(uri);


            DataSpace  = GetValue(_match, 3);
            Family     = GetValue(_match, 5);
            Version    = FormatVersion(GetValue(_match, 6), Family);
            ObjectType = null;
            ObjectId   = null;
            Query      = GetValue(_match, 15);
            Hash       = GetValue(_match, 16);

            var format = GetQueryStringFormat(Query, GetValue(_match, 8));

            Format      = string.IsNullOrWhiteSpace(format) ? EtpContentType.Xml : format;
            ContentType = new EtpContentType(Family, Version, null, Format);

            if (!HasRepeatValues(_match))
            {
                return;
            }

            var last = GetObjectIds().Last();

            ObjectType  = last.ObjectType;
            ObjectId    = last.ObjectId;
            ContentType = new EtpContentType(Family, Version, ObjectType, Format);
        }
コード例 #2
0
        /// <summary>
        /// Creates an ETP URI segment from the specified object string.
        /// </summary>
        /// <param name="object">The object string.</param>
        /// <param name="defaultFamily">The default family if the object does not specify it.</param>
        /// <param name="defaultVersion">The default family version if the object string does not specify it.</param>
        /// <returns></returns>
        private static Segment CreateSegment(string @object, string defaultFamily, string defaultVersion)
        {
            var match = Definition.EtpObjectOrFolderRegex.Match(@object);

            var objectType = GetFirstMatch(match, Definition.ObjectTypeGroup);
            var objectId   = GetFirstMatch(match, Definition.ObjectIdGroup);

            if (objectId != null)
            {
                objectId = WebUtility.UrlDecode(objectId);
            }
            var objectVersion = GetFirstMatch(match, Definition.ObjectVersionGroup);

            CorrectCommonObjectFamilyAndVersion(objectType, ref defaultFamily, ref defaultVersion);

            var family = GetFirstMatch(match, Definition.FamilyGroup) ?? defaultFamily;

            family = EtpDataObjectType.TryGetFamily(family);

            var shortVersion = GetFirstMatch(match, Definition.ShortVersionGroup);
            var version      = EtpDataObjectType.TryGetFamilyVersionFromShortVersion(family, shortVersion) ?? defaultVersion;

            objectType = EtpContentType.FormatObjectType(objectType, version);

            return(new Segment(family, version, objectType, objectId, objectVersion?.Replace("''", "'")));
        }
コード例 #3
0
        public void EtpContentType_Rejects_Content_Type_Without_Version()
        {
            var expected    = "application/x-witsml+xml";
            var contentType = new EtpContentType(expected);

            Assert.IsFalse(contentType.IsValid);
        }
コード例 #4
0
        public void EtpContentType_Can_Parse_Witsml_1411_Well_Content_Type()
        {
            var expected    = "application/x-witsml+xml;version=1.4.1.1;type=well";
            var contentType = new EtpContentType(expected);

            Assert.IsTrue(contentType.IsValid);
            Assert.AreEqual("well", contentType.ObjectType);
            Assert.AreEqual("1.4.1.1", contentType.Version);
        }
コード例 #5
0
        public void EtpContentType_Can_Parse_Witsml_20_TrajectoryStation_Content_Type()
        {
            var expected    = "application/x-witsml+xml;version=2.0;type=part_TrajectoryStation";
            var contentType = new EtpContentType(expected);

            Assert.IsTrue(contentType.IsValid);
            Assert.AreEqual("TrajectoryStation", contentType.ObjectType);
            Assert.AreEqual("2.0", contentType.Version);
        }
コード例 #6
0
        public void EtpContentType_For_Can_Create_1411_Well_Content_Type()
        {
            var expected    = "application/x-witsml+xml;version=1.4.1.1";
            var contentType = new EtpContentType(expected).For("well");

            Assert.IsTrue(contentType.IsValid);
            Assert.AreEqual("well", contentType.ObjectType);
            Assert.AreEqual("1.4.1.1", contentType.Version);
            Assert.AreEqual(expected + ";type=well", (string)contentType);
        }
コード例 #7
0
        public void EtpContentType_Can_Parse_Base_Content_Type_With_Trailing_Semicolon()
        {
            var expected    = "application/x-witsml+xml;version=2.0";
            var contentType = new EtpContentType(expected);

            Assert.IsTrue(contentType.IsValid);
            Assert.IsTrue(contentType.IsBaseType);
            Assert.AreEqual("witsml", contentType.Family);
            Assert.AreEqual("2.0", contentType.Version);
        }
コード例 #8
0
        public void EtpContentType_Can_Be_Parsed_With_Json_Format()
        {
            var expected    = "application/x-witsml+json;version=1.4.1.1;type=well";
            var contentType = new EtpContentType(expected);

            Assert.IsTrue(contentType.IsValid);
            Assert.AreEqual("well", contentType.ObjectType);
            Assert.AreEqual("1.4.1.1", contentType.Version);
            Assert.AreEqual("json", contentType.Format);
        }
コード例 #9
0
ファイル: EtpContentType.cs プロジェクト: lanicon/etp.net
        /// <summary>
        /// Determines whether the specified <see cref="EtpContentType" />, is equal to this instance.
        /// </summary>
        /// <param name="other">The <see cref="EtpContentType" /> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="EtpContentType" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public bool Equals(EtpContentType other)
        {
            if (other == null)
            {
                return(false);
            }
            var contentType      = ToString() ?? string.Empty;
            var otherContentType = other.ToString() ?? string.Empty;

            return(string.Equals(contentType, otherContentType, StringComparison.OrdinalIgnoreCase));
        }
コード例 #10
0
ファイル: EtpDataObjectType.cs プロジェクト: lanicon/etp.net
        /// <summary>
        /// Initializes a new instance of the <see cref="EtpDataObjectType" /> class
        /// with the family and version of the specified type and the specified object type.
        /// </summary>
        /// <param name="contentType">The type providing the family and version.</param>
        /// <param name="objectType">The object type.</param>
        public EtpDataObjectType(EtpContentType contentType, string objectType)
        {
            IsValid = true;

            Family       = contentType.Family;
            Version      = contentType.Version;
            ShortVersion = TryGetFamilyShortVersionFromVersion(Family, Version);
            ObjectType   = GetObjectType(objectType, ShortVersion);

            _dataType = string.Format(Format, Family, ShortVersion, ObjectType);
        }
コード例 #11
0
        /// <summary>
        /// Appends the specified object type and optional object identifier to the <see cref="EtpUri" />.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="objectId">The object identifier.</param>
        /// <param name="encode">if set to <c>true</c> encode the object identifier value.</param>
        /// <returns>A new <see cref="EtpUri" /> instance.</returns>
        public EtpUri Append(string objectType, string objectId = null, bool encode = false)
        {
            objectType = EtpContentType.FormatObjectType(objectType, Version);

            if (encode)
            {
                objectId = WebUtility.UrlEncode(objectId);
            }

            return(string.IsNullOrWhiteSpace(objectId) ?
                   new EtpUri(Uri + "/" + objectType) :
                   new EtpUri(Uri + $"/{ objectType }({ objectId })"));
        }
コード例 #12
0
        public void EtpContentType_Can_Be_Converted_To_DataObjectType()
        {
            var contentType = new EtpContentType("application/x-witsml+xml;version=1.4.1.1;type=well");

            Assert.IsTrue(contentType.IsValid);
            Assert.AreEqual("well", contentType.ObjectType);
            Assert.AreEqual("1.4.1.1", contentType.Version);
            Assert.AreEqual(Formats.Xml, contentType.Format);

            var converted = "witsml14.well";
            var dataType  = contentType.ToDataObjectType();

            Assert.IsTrue(dataType.IsValid);
            Assert.AreEqual("well", dataType.ObjectType);
            Assert.AreEqual("1.4.1.1", dataType.Version);
            Assert.AreEqual(converted, dataType.ToString());
        }
コード例 #13
0
        /// <summary>
        /// Appends the specified object type and optional object identifier to the <see cref="EtpUri" />.
        /// </summary>
        /// <param name="family">The object family.</param>
        /// <param name="version">The object version.</param>
        /// <param name="objectType">The object type.</param>
        /// <param name="objectId">The object identifier.</param>
        /// <param name="objectVersion">The object version.</param>
        /// <param name="encode">if set to <c>true</c> encode the object identifier value.</param>
        /// <returns>A new <see cref="EtpUri" /> instance.</returns>
        public EtpUri Append(string family, string version, string objectType, string objectId = null, string objectVersion = null, bool encode = false)
        {
            objectType = EtpContentType.FormatObjectType(objectType, version);
            CorrectCommonObjectFamilyAndVersion(objectType, ref family, ref version);

            if (encode && objectId != null)
            {
                objectId = WebUtility.UrlEncode(objectId);
            }

            var    uri   = UriWithoutSuffix ?? string.Empty;
            string slash = null;

            if (uri.Length == 0 || uri[uri.Length - 1] != '/')
            {
                slash = "/";
            }

            if (IsEtp11)
            {
                if (objectId != null)
                {
                    objectId = $"({objectId})";
                }

                return(new EtpUri($"{uri}{slash}{objectType}{objectId}{Query}{Hash}"));
            }
            else
            {
                family  = family ?? Family;
                version = version ?? Version;
                var shortVersion = EtpDataObjectType.TryGetFamilyShortVersionFromVersion(family, version);

                string objectIdAndVersion = null;
                if (objectId != null && objectVersion != null)
                {
                    objectIdAndVersion = $"(uuid={objectId},version='{objectVersion.Replace("'","''")}')";
                }
                else if (objectId != null)
                {
                    objectIdAndVersion = $"({objectId})";
                }

                return(new EtpUri($"{uri}{slash}{family}{shortVersion}.{objectType}{objectIdAndVersion}{Query}{Hash}"));
            }
        }
コード例 #14
0
        public void EtpContentType_Can_Be_Converted_From_Json_To_Xml_Format()
        {
            var expected    = "application/x-witsml+json;version=1.4.1.1;type=well";
            var contentType = new EtpContentType(expected);

            Assert.IsTrue(contentType.IsValid);
            Assert.AreEqual("well", contentType.ObjectType);
            Assert.AreEqual("1.4.1.1", contentType.Version);
            Assert.AreEqual("json", contentType.Format);

            var converted = "application/x-witsml+xml;version=1.4.1.1;type=well";

            contentType = contentType.AsXml();

            Assert.IsTrue(contentType.IsValid);
            Assert.AreEqual("well", contentType.ObjectType);
            Assert.AreEqual("1.4.1.1", contentType.Version);
            Assert.AreEqual(Formats.Xml, contentType.Format);
            Assert.AreEqual(converted, contentType.ToString());
        }
コード例 #15
0
ファイル: EtpUri.cs プロジェクト: sysnainemcs/etp-devkit
        /// <summary>
        /// Gets a collection of <see cref="Segment"/> items.
        /// </summary>
        /// <returns>A collection of <see cref="Segment"/> items.</returns>
        public IEnumerable <Segment> GetObjectIds()
        {
            if (HasRepeatValues(_match))
            {
                var objectTypeGroup = _match.Groups[12];
                var objectIdGroup   = _match.Groups[14];

                for (int i = 0; i < objectTypeGroup.Captures.Count; i++)
                {
                    var objectType = objectTypeGroup.Captures[i].Value;

                    var objectId = objectIdGroup.Captures.Count > i
                        ? WebUtility.UrlDecode(objectIdGroup.Captures[i].Value)
                        : null;

                    yield return(new Segment(
                                     EtpContentType.FormatObjectType(objectType, Version),
                                     objectId));
                }
            }
        }
コード例 #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EtpUri"/> struct.
        /// </summary>
        /// <param name="uri">The URI string.</param>
        public EtpUri(string uri)
        {
            var uriMatch = Definition.EtpUriRegex.Match(uri);

            _parent = null;

            Uri = uri;

            IsValid = uriMatch.Success;

            if (!IsValid)
            {
                return;
            }

            if (WasGroupMatched(uriMatch, Definition.Etp11UriGroup))
            {
                EtpVersion = EtpVersion.v11;
            }
            else
            {
                EtpVersion = EtpVersion.v12;
            }

            Query = GetFirstMatch(uriMatch, Definition.QueryGroup) ?? string.Empty;
            Hash  = GetFirstMatch(uriMatch, Definition.HashGroup) ?? string.Empty;

            Dataspace = GetFirstMatch(uriMatch, Definition.DataspaceGroup) ?? string.Empty;

            var family = GetFirstMatch(uriMatch, Definition.FamilyGroup);

            NamespaceFamily = EtpDataObjectType.TryGetFamily(family);

            var shortVersion = GetFirstMatch(uriMatch, Definition.ShortVersionGroup);

            NamespaceVersion = EtpDataObjectType.TryGetFamilyVersionFromShortVersion(family, shortVersion);

            _objectSegments = GetAllMatches(uriMatch, Definition.ObjectOrFolderGroup);
            if (_objectSegments != null)
            {
                var segment = CreateSegment(_objectSegments[_objectSegments.Length - 1], NamespaceFamily, NamespaceVersion);

                Family  = segment.Family;
                Version = segment.Version;

                ObjectType    = segment.ObjectType;
                ObjectId      = segment.ObjectId;
                ObjectVersion = segment.ObjectVersion;
            }
            else
            {
                Family  = NamespaceFamily;
                Version = NamespaceVersion;
            }

            DataObjectType = new EtpDataObjectType(Family, Version, ObjectType);

            Format = GetQueryStringFormat(Query, Formats.Xml);

            ContentType = new EtpContentType(Family, Version, ObjectType, Format);

            IsRootUri          = WasGroupMatched(uriMatch, Definition.RootUriGroup);
            IsFamilyVersionUri = WasGroupMatched(uriMatch, Definition.FamilyVersionUriGroup);
            IsDataspaceUri     = IsRootUri /* Default Dataspace */ || WasGroupMatched(uriMatch, Definition.DataspaceUriGroup);
            IsDataRootUri      = (IsEtp11 && IsFamilyVersionUri) || (IsEtp12 && IsDataspaceUri);

            IsBaseUri = IsRootUri || IsDataspaceUri || IsFamilyVersionUri;

            IsQueryUri        = WasGroupMatched(uriMatch, Definition.QueryUriGroup);
            IsObjectUri       = WasGroupMatched(uriMatch, Definition.ObjectUriGroup);
            IsFolderUri       = WasGroupMatched(uriMatch, Definition.FolderUriGroup);
            IsHierarchicalUri = WasGroupMatched(uriMatch, Definition.HierarchicalUriGroup) || WasGroupMatched(uriMatch, Definition.TemplateUriGroup);

            HasEmptyObjectId = WasGroupMatched(uriMatch, Definition.EmptyIdGroup);

            var canonical = WasGroupMatched(uriMatch, Definition.CanonicalUriGroup) ||
                            (IsObjectUri && NamespaceVersion.StartsWith("1"));                           // Special case for 1.x URIs.

            if (WasGroupMatched(uriMatch, Definition.DataspaceGroup) && string.IsNullOrEmpty(Dataspace)) // Disallow eml:///dataspace()
            {
                canonical = false;
            }
            if (HasEmptyObjectId || WasGroupMatched(uriMatch, Definition.EmptyVersionGroup)) // Disallow empty object IDs or empty object versions
            {
                canonical = false;
            }

            IsCanonicalUri = canonical;

            IsAlternateUri      = !IsCanonicalUri; // Allow for special cases.
            IsHierarchicalUri   = WasGroupMatched(uriMatch, Definition.HierarchicalUriGroup);
            IsFolderTemplateUri = WasGroupMatched(uriMatch, Definition.FolderUriGroup) || WasGroupMatched(uriMatch, Definition.FolderTemplateUriGroup);
            IsObjectTemplateUri = WasGroupMatched(uriMatch, Definition.ObjectTemplateUriGroup);
            IsTemplateUri       = IsFolderTemplateUri || IsObjectTemplateUri;

            if (IsBaseUri)
            {
                UriBase = UriWithoutSuffix;
            }
            else
            {
                UriBase = GetFirstMatch(uriMatch, Definition.BaseGroup) + "/";
            }
        }
コード例 #17
0
 /// <summary>
 /// Determines whether the specified <see cref="EtpContentType" />, is equal to this instance.
 /// </summary>
 /// <param name="other">The <see cref="EtpContentType" /> to compare with this instance.</param>
 /// <returns>
 ///   <c>true</c> if the specified <see cref="EtpContentType" /> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 public bool Equals(EtpContentType other)
 {
     return(string.Equals(other, this, StringComparison.InvariantCultureIgnoreCase));
 }
コード例 #18
0
 /// <summary>
 /// Determines whether this instance is related to the specified <see cref="EtpContentType"/>.
 /// </summary>
 /// <param name="other">The other content type.</param>
 /// <returns>
 ///   <c>true</c> if the two <see cref="EtpContentType"/> instances share the same family and
 ///   version; otherwise, <c>false</c>.
 /// </returns>
 public bool IsRelatedTo(EtpContentType other)
 {
     return(string.Equals(Family, other.Family, StringComparison.InvariantCultureIgnoreCase) &&
            string.Equals(Version, other.Version, StringComparison.InvariantCultureIgnoreCase));
 }