예제 #1
0
        private bool AppendBoundOperationOnDerived(
            IEdmOperation edmOperation,
            bool isCollection,
            IEdmEntityType bindingEntityType,
            OpenApiConvertSettings convertSettings)
        {
            bool found = false;

            bool isEscapedFunction = _model.IsUrlEscapeFunction(edmOperation);

            foreach (var baseType in bindingEntityType.FindAllBaseTypes())
            {
                if (_allNavigationSources.TryGetValue(baseType, out IList <IEdmNavigationSource> baseNavigationSource))
                {
                    foreach (var ns in baseNavigationSource)
                    {
                        if (HasUnsatisfiedDerivedTypeConstraint(
                                ns as IEdmVocabularyAnnotatable,
                                baseType,
                                convertSettings))
                        {
                            continue;
                        }

                        if (isCollection)
                        {
                            if (ns is IEdmEntitySet)
                            {
                                ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataTypeCastSegment(bindingEntityType),
                                                                  new ODataOperationSegment(edmOperation, isEscapedFunction));
                                AppendPath(newPath);
                                found = true;
                            }
                        }
                        else
                        {
                            if (ns is IEdmSingleton)
                            {
                                ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataTypeCastSegment(bindingEntityType),
                                                                  new ODataOperationSegment(edmOperation, isEscapedFunction));
                                AppendPath(newPath);
                                found = true;
                            }
                            else
                            {
                                ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataKeySegment(ns.EntityType()),
                                                                  new ODataTypeCastSegment(bindingEntityType),
                                                                  new ODataOperationSegment(edmOperation, isEscapedFunction));
                                AppendPath(newPath);
                                found = true;
                            }
                        }
                    }
                }
            }

            return(found);
        }
예제 #2
0
        private bool AppendBoundOperationOnDerived(IEdmOperation edmOperation, bool isCollection, IEdmEntityType bindingEntityType)
        {
            bool found = false;

            foreach (var baseType in bindingEntityType.FindAllBaseTypes())
            {
                if (_allNavigationSources.TryGetValue(baseType, out IList <IEdmNavigationSource> baseNavigationSource))
                {
                    foreach (var ns in baseNavigationSource)
                    {
                        if (isCollection)
                        {
                            if (ns is IEdmEntitySet)
                            {
                                ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataTypeCastSegment(bindingEntityType),
                                                                  new ODataOperationSegment(edmOperation));
                                AppendPath(newPath);
                                found = true;
                            }
                        }
                        else
                        {
                            if (ns is IEdmSingleton)
                            {
                                ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataTypeCastSegment(bindingEntityType),
                                                                  new ODataOperationSegment(edmOperation));
                                AppendPath(newPath);
                                found = true;
                            }
                            else
                            {
                                ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataKeySegment(ns.EntityType()),
                                                                  new ODataTypeCastSegment(bindingEntityType),
                                                                  new ODataOperationSegment(edmOperation));
                                AppendPath(newPath);
                                found = true;
                            }
                        }
                    }
                }
            }

            return(found);
        }
예제 #3
0
        private bool AppendBoundOperationOnDerivedNavigationPropertyPath(
            IEdmOperation edmOperation,
            bool isCollection,
            IEdmEntityType bindingEntityType,
            OpenApiConvertSettings convertSettings)
        {
            bool found             = false;
            bool isEscapedFunction = _model.IsUrlEscapeFunction(edmOperation);

            foreach (var baseType in bindingEntityType.FindAllBaseTypes())
            {
                if (_allNavigationPropertyPaths.TryGetValue(baseType, out IList <ODataPath> paths))
                {
                    foreach (var path in paths)
                    {
                        if (path.Kind == ODataPathKind.Ref)
                        {
                            continue;
                        }

                        var npSegment = path.Segments.Last(s => s is ODataNavigationPropertySegment)
                                        as ODataNavigationPropertySegment;
                        if (npSegment == null)
                        {
                            continue;
                        }

                        bool isLastKeySegment = path.LastSegment is ODataKeySegment;

                        if (isCollection)
                        {
                            if (isLastKeySegment)
                            {
                                continue;
                            }

                            if (npSegment.NavigationProperty.TargetMultiplicity() != EdmMultiplicity.Many)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (!isLastKeySegment && npSegment.NavigationProperty.TargetMultiplicity() ==
                                EdmMultiplicity.Many)
                            {
                                continue;
                            }
                        }

                        if (HasUnsatisfiedDerivedTypeConstraint(
                                npSegment.NavigationProperty as IEdmVocabularyAnnotatable,
                                baseType,
                                convertSettings))
                        {
                            continue;
                        }

                        ODataPath newPath = path.Clone();
                        newPath.Push(new ODataTypeCastSegment(bindingEntityType));
                        newPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction));
                        AppendPath(newPath);
                        found = true;
                    }
                }
            }

            return(found);
        }