Exemplo n.º 1
0
        /// <summary>
        /// If valid, returns the uri that matches the requested query hierarchy.
        /// </summary>
        /// <param name="uri">The uri.</param>
        /// <param name="query">The hierarchy query.</param>
        /// <returns></returns>
        public static EtpUri GetValidHierarchyUri(this EtpUri uri, EtpUri query)
        {
            var hierarchyUris = uri.GetRelatedHierarchyUris();

            var queryObjectIds = query.GetObjectIds().ToList();

            return(hierarchyUris.FirstOrDefault(x =>
            {
                var uriObjectIds = x.GetObjectIds().ToList();

                if (uriObjectIds.Count != queryObjectIds.Count)
                {
                    return false;
                }

                for (var i = 0; i < uriObjectIds.Count; ++i)
                {
                    if (!uriObjectIds[i].ObjectType.EqualsIgnoreCase(queryObjectIds[i].ObjectType) || !uriObjectIds[i].ObjectId.IsMatch(queryObjectIds[i].ObjectId))
                    {
                        return false;
                    }
                }

                return true;
            }));
        }