/// <summary> /// Tries to get the ETP URI prefix up to the specified object type. /// </summary> /// <param name="uri">The URI to create the prefix from.</param> /// <param name="objecType">The object type to end the prefix with.</param> /// <param name="success"><c>true</c> if successful; <c>false</c> otherwise.</param> /// <returns>The prefix of the input URI or the original URI without its query if not successful.</returns> public static EtpUri TryGetObjectTypePrefix(this EtpUri uri, string objecType, out bool success) { success = false; uri = new EtpUri(uri.GetLeftPart()); if (!uri.IsValid || string.IsNullOrEmpty(objecType)) { return(uri); } var constructedUri = uri.GetUriFamily(); foreach (var s in uri.GetObjectIds()) { if (!string.IsNullOrEmpty(s.ObjectType) && objecType.EqualsIgnoreCase(s.ObjectType)) { constructedUri = constructedUri.Append(s.ObjectType, s.ObjectId); success = true; break; } else { constructedUri = constructedUri.Append(s.ObjectType, s.ObjectId); } } if (success) { return(constructedUri); } else { return(uri); } }
/// <summary> /// Gets the <see cref="EtpUri"/> for a given <see cref="Energistics.DataAccess.WITSML200.AbstractObject"/> and parentUri. /// </summary> /// <param name="entity">The entity.</param> /// <param name="parentUri">The parent URI.</param> /// <returns>An <see cref="EtpUri"/> instance</returns> public static EtpUri GetUri(this Witsml200.AbstractObject entity, EtpUri parentUri) { // Remove query string parameters, if any var uri = parentUri.GetLeftPart(); if (!IsRootUri(uri)) { // Remove trailing separator uri = uri.TrimEnd('/'); } return(new EtpUri(uri) .Append(ObjectTypes.GetObjectType(entity), entity.Uuid)); }
/// <summary> /// Gets the URI without any query string parameters. /// </summary> /// <param name="uri">The URI.</param> /// <returns>A new <see cref="EtpUri"/> instance.</returns> public static EtpUri WithoutQuery(this EtpUri uri) { return(new EtpUri(uri.GetLeftPart())); }