示例#1
0
        /// <summary>
        /// Gets the list of potential uris that represent the same object hierarchy.  Assumes URI is well formed.
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public static List <EtpUri> GetRelatedHierarchyUris(this EtpUri uri)
        {
            // By default WITSML 2.x objects return top-level URIs in their channel metadata
            // Ensure that it is first in the list to speed up any related processing that is
            // looking for those type of URIs...
            // WITSML 1.x object require the full hierarchy regardless.
            var uris = new List <EtpUri>()
            {
                uri.ToTopLevelUri()
            };

            if (!uri.IsValid)
            {
                return(uris);
            }

            var uriHierarchy = uri.GetObjectIds().ToList();

            if (!uriHierarchy.Any())
            {
                return(uris);
            }

            var uriHierarchyMap = uriHierarchy
                                  .ToLookup(x => x.ObjectType, x => x.ObjectId, StringComparer.InvariantCultureIgnoreCase)
                                  .ToDictionary(x => x.Key, x => x.First(), StringComparer.InvariantCultureIgnoreCase);

            var isWitsml20 = EtpUris.Witsml200.IsRelatedTo(uri);

            if (!isWitsml20)
            {
                return(uris);
            }

            if (ObjectTypes.Well.EqualsIgnoreCase(uri.ObjectType))
            {
                return(uris);
            }

            var rootUri = EtpUris.Witsml200;

            string wellObjectId;

            uriHierarchyMap.TryGetValue(ObjectTypes.Well, out wellObjectId);

            string wellboreObjectId;

            uriHierarchyMap.TryGetValue(ObjectTypes.Wellbore, out wellboreObjectId);

            string logObjectId;

            uriHierarchyMap.TryGetValue(ObjectTypes.Log, out logObjectId);

            string channelSetObjectId;

            uriHierarchyMap.TryGetValue(ObjectTypes.ChannelSet, out channelSetObjectId);

            if (ObjectTypes.Wellbore.EqualsIgnoreCase(uri.ObjectType))
            {
                var hierarchyUri = rootUri
                                   .Append(ObjectTypes.Well, wellObjectId)
                                   .Append(ObjectTypes.Wellbore, uri.ObjectId);

                uris.Add(hierarchyUri);
            }
            else
            {
                EtpUri hierarchyUri;

                if (ObjectTypes.Channel.EqualsIgnoreCase(uri.ObjectType))
                {
                    hierarchyUri = rootUri
                                   .Append(ObjectTypes.ChannelSet, channelSetObjectId)
                                   .Append(ObjectTypes.Channel, uri.ObjectId);

                    uris.Add(hierarchyUri);

                    hierarchyUri = rootUri
                                   .Append(ObjectTypes.Log, logObjectId)
                                   .Append(ObjectTypes.ChannelSet, channelSetObjectId)
                                   .Append(ObjectTypes.Channel, uri.ObjectId);

                    uris.Add(hierarchyUri);

                    hierarchyUri = rootUri
                                   .Append(ObjectTypes.Wellbore, wellboreObjectId)
                                   .Append(ObjectTypes.Log, logObjectId)
                                   .Append(ObjectTypes.ChannelSet, channelSetObjectId)
                                   .Append(ObjectTypes.Channel, uri.ObjectId);

                    uris.Add(hierarchyUri);

                    hierarchyUri = rootUri
                                   .Append(ObjectTypes.Well, wellObjectId)
                                   .Append(ObjectTypes.Wellbore, wellboreObjectId)
                                   .Append(ObjectTypes.Log, logObjectId)
                                   .Append(ObjectTypes.ChannelSet, channelSetObjectId)
                                   .Append(ObjectTypes.Channel, uri.ObjectId);

                    uris.Add(hierarchyUri);
                }
                else if (ObjectTypes.ChannelSet.EqualsIgnoreCase(uri.ObjectType))
                {
                    hierarchyUri = rootUri
                                   .Append(ObjectTypes.Log, logObjectId)
                                   .Append(ObjectTypes.ChannelSet, uri.ObjectId);

                    uris.Add(hierarchyUri);

                    hierarchyUri = rootUri
                                   .Append(ObjectTypes.Wellbore, wellboreObjectId)
                                   .Append(ObjectTypes.Log, logObjectId)
                                   .Append(ObjectTypes.ChannelSet, uri.ObjectId);

                    uris.Add(hierarchyUri);

                    hierarchyUri = rootUri
                                   .Append(ObjectTypes.Well, wellObjectId)
                                   .Append(ObjectTypes.Wellbore, wellboreObjectId)
                                   .Append(ObjectTypes.Log, logObjectId)
                                   .Append(ObjectTypes.ChannelSet, uri.ObjectId);

                    uris.Add(hierarchyUri);
                }

                hierarchyUri = rootUri
                               .Append(ObjectTypes.Wellbore, wellboreObjectId)
                               .Append(uri.ObjectType, uri.ObjectId);

                uris.Add(hierarchyUri);

                hierarchyUri = rootUri
                               .Append(ObjectTypes.Well, wellObjectId)
                               .Append(ObjectTypes.Wellbore, wellboreObjectId)
                               .Append(uri.ObjectType, uri.ObjectId);

                uris.Add(hierarchyUri);
            }

            return(uris);
        }