/// <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}")); } }
/// <summary> /// Creates a Base URI for the specified ETP version with the specified family, version and dataspace. /// </summary> /// <param name="etpVersion">The ETP version.</param> /// <param name="family">The family.</param> /// <param name="version">The version.</param> /// <param name="dataspace">The dataspace.</param> /// <returns>The ETP URI Base.</returns> private static string CreateBaseUri(EtpVersion etpVersion, string family, string version, string dataspace) { var sb = new StringBuilder(); var appendSlash = false; if (etpVersion == EtpVersion.v11) { sb.Append($"{RootUri11.Uri}"); } else { sb.Append($"{RootUri12.Uri}"); } if (!string.IsNullOrEmpty(dataspace)) { if (etpVersion == EtpVersion.v11) { sb.Append(dataspace); } else { sb.Append($"dataspace({dataspace})"); } appendSlash = true; } if (etpVersion == EtpVersion.v11 && !string.IsNullOrEmpty(family) && !string.IsNullOrEmpty(version)) { if (appendSlash) { sb.Append("/"); } var shortVersion = EtpDataObjectType.TryGetFamilyShortVersionFromVersion(family, version); sb.Append($"{family}{shortVersion}"); } return(sb.ToString()); }
/// <summary> /// Converts the URI to an ETP 1.2 URI. /// </summary> /// <returns>The converted URI.</returns> public EtpUri AsEtp12() { if (IsEtp12 || !IsValid) { return(this); } var Base = CreateBaseUri(EtpVersion.v12, NamespaceFamily, NamespaceVersion, Dataspace); var sb = new StringBuilder(Base); var appendSlash = Base[Base.Length - 1] != '/'; foreach (var segment in GetSegments()) { if (appendSlash) { sb.Append("/"); } var shortVersion = EtpDataObjectType.TryGetFamilyShortVersionFromVersion(segment.Family, segment.Version); sb.Append($"{segment.Family}{shortVersion}.{segment.ObjectType}"); if (!string.IsNullOrEmpty(segment.ObjectId)) { if (!string.IsNullOrEmpty(segment.ObjectVersion)) { sb.Append($"(uuid={segment.ObjectId},version='{segment.ObjectVersion.Replace("'","''")}')"); } else { sb.Append($"({segment.ObjectId})"); } } appendSlash = true; } sb.Append(Query); sb.Append(Hash); return(new EtpUri(sb.ToString())); }