/// <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("''", "'"))); }
/// <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 })")); }
/// <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> /// 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)); } } }