Exemplo n.º 1
0
        public static EtpDataObjectType TryGetCorrectedDataObjectType(EtpUri uri)
        {
            if (uri.IsEtp12)
            {
                return(uri.DataObjectType);
            }

            var originalType = uri.DataObjectType;

            var segments = uri.GetSegments().ToList();

            if (segments.Count < 2)
            {
                return(originalType);
            }

            var supportedTypes = new HashSet <EtpDataObjectType>();
            HashSet <EtpDataObjectType> primaryTypes, secondaryTypes;

            if (SupportedSourceTypes.TryGetValue(segments[0].DataObjectType, out primaryTypes))
            {
                supportedTypes.UnionWith(primaryTypes);
            }
            if (SupportedSecondarySourceTypes.TryGetValue(segments[0].DataObjectType, out secondaryTypes))
            {
                supportedTypes.UnionWith(secondaryTypes);
            }
            if (supportedTypes.Count == 0)
            {
                return(originalType);
            }

            for (int i = 1; i < segments.Count; i++)
            {
                var correctedType = supportedTypes.FirstOrDefault(dt => string.Equals(segments[i].ObjectType, dt.ObjectType, StringComparison.OrdinalIgnoreCase));
                if (correctedType == null)
                {
                    return(originalType);
                }

                if (i == segments.Count - 1)
                {
                    return(correctedType);
                }

                supportedTypes = new HashSet <EtpDataObjectType>();
                if (SupportedSourceTypes.TryGetValue(correctedType, out primaryTypes))
                {
                    supportedTypes.UnionWith(primaryTypes);
                }
                if (SupportedSecondarySourceTypes.TryGetValue(correctedType, out secondaryTypes))
                {
                    supportedTypes.UnionWith(secondaryTypes);
                }
                if (supportedTypes.Count == 0)
                {
                    return(originalType);
                }
            }

            return(originalType);
        }