// *** Constructors ***

        public ShareSourceManager(INavigationManager navigationManager)
        {
            if (navigationManager == null)
                throw new ArgumentNullException(nameof(navigationManager));

            _navigationManager = navigationManager;
            navigationManager.NavigationStack.NavigatedTo += NavigationManager_NavigatedTo;
        }
        // *** Methods ***

        public void NavigateTo(object page, INavigationBase navigationManager)
        {
            _navigationManager = navigationManager;

            if (!_eventHandlersRegistered)
            {
                RegisterEventHandlers();
                _eventHandlersRegistered = true;
            }

            SetWindowContent(page);
        }
            private static void IncludeCollection <TEntity, TIncludingEntity, TIncludedEntity>(
                QueryContext queryContext,
                IEnumerable <ValueBuffer> innerValueBuffers,
                Func <QueryContext, ValueBuffer, TIncludedEntity> innerShaper,
                TEntity entity,
                INavigationBase navigation,
                INavigationBase inverseNavigation,
                Action <TIncludingEntity, TIncludedEntity> fixup,
                bool trackingQuery)
                where TIncludingEntity : class, TEntity
                where TEntity : class
                where TIncludedEntity : class
            {
                if (entity is TIncludingEntity includingEntity)
                {
                    var collectionAccessor = navigation.GetCollectionAccessor();
                    collectionAccessor.GetOrCreate(includingEntity, forMaterialization: true);

                    if (trackingQuery)
                    {
                        queryContext.SetNavigationIsLoaded(entity, navigation);
                    }
                    else
                    {
                        navigation.SetIsLoadedWhenNoTracking(entity);
                    }

                    foreach (var valueBuffer in innerValueBuffers)
                    {
                        var relatedEntity = innerShaper(queryContext, valueBuffer);

                        if (!trackingQuery)
                        {
                            fixup(includingEntity, relatedEntity);
                            if (inverseNavigation != null)
                            {
                                inverseNavigation.SetIsLoadedWhenNoTracking(relatedEntity);
                            }
                        }
                    }
                }
            }
Beispiel #4
0
        public void GetRelationshipType_Customer_CustomerSetting_Should_Return_OneToOne()
        {
            // Arrange
            var context  = _fixture.GetContext();
            var customer = new MockNorthwind().Customers[0];

            customer.CustomerSetting = new CustomerSetting
            {
                CustomerId = customer.CustomerId,
                Customer   = customer,
                Setting    = "Setting 1"
            };
            INavigationBase nav = context.Entry(customer).Navigation(nameof(customer.CustomerSetting)).Metadata;

            // Act
            RelationshipType?relType = nav.GetRelationshipType();

            // Assert
            Assert.Equal(RelationshipType.OneToOne, relType);
        }
Beispiel #5
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public virtual async Task LoadAsync(
            INavigationBase navigation,
            InternalEntityEntry entry,
            CancellationToken cancellationToken = default)
        {
            if (entry.EntityState == EntityState.Detached)
            {
                throw new InvalidOperationException(CoreStrings.CannotLoadDetached(navigation.Name, entry.EntityType.DisplayName()));
            }

            // Short-circuit for any null key values for perf and because of #6129
            var keyValues = GetLoadValues(navigation, entry);

            if (keyValues != null)
            {
                await Query(navigation, keyValues).LoadAsync(cancellationToken)
                .ConfigureAwait(false);
            }

            entry.SetIsLoaded(navigation);
        }
Beispiel #6
0
        private static object[] GetLoadValues(INavigationBase navigation, InternalEntityEntry entry)
        {
            var properties = ((INavigation)navigation).IsOnDependent
                ? ((INavigation)navigation).ForeignKey.Properties
                : ((INavigation)navigation).ForeignKey.PrincipalKey.Properties;

            var values = new object[properties.Count];

            for (var i = 0; i < values.Length; i++)
            {
                var value = entry[properties[i]];
                if (value == null)
                {
                    return(null);
                }

                values[i] = value;
            }

            return(values);
        }
    protected NavigationEntry(InternalEntityEntry internalEntry, INavigationBase navigationBase, bool collection)
        : base(internalEntry, navigationBase)
    {
        if (collection &&
            !navigationBase.IsCollection)
        {
            throw new InvalidOperationException(
                      CoreStrings.CollectionIsReference(
                          navigationBase.Name, internalEntry.EntityType.DisplayName(),
                          nameof(ChangeTracking.EntityEntry.Collection), nameof(ChangeTracking.EntityEntry.Reference)));
        }

        if (!collection &&
            navigationBase.IsCollection)
        {
            throw new InvalidOperationException(
                      CoreStrings.ReferenceIsCollection(
                          navigationBase.Name, internalEntry.EntityType.DisplayName(),
                          nameof(ChangeTracking.EntityEntry.Reference), nameof(ChangeTracking.EntityEntry.Collection)));
        }
    }
 private static void IncludeReference <TEntity, TIncludingEntity, TIncludedEntity>(
     QueryContext queryContext,
     TEntity entity,
     TIncludedEntity relatedEntity,
     INavigationBase navigation,
     INavigationBase inverseNavigation,
     Action <TIncludingEntity, TIncludedEntity> fixup,
     bool trackingQuery)
     where TIncludingEntity : class, TEntity
     where TEntity : class
     where TIncludedEntity : class
 {
     if (entity is TIncludingEntity includingEntity)
     {
         if (trackingQuery &&
             navigation.DeclaringEntityType.FindPrimaryKey() != null)
         {
             // For non-null relatedEntity StateManager will set the flag
             if (relatedEntity == null)
             {
                 queryContext.SetNavigationIsLoaded(includingEntity, navigation);
             }
         }
         else
         {
             navigation.SetIsLoadedWhenNoTracking(includingEntity);
             if (relatedEntity != null)
             {
                 fixup(includingEntity, relatedEntity);
                 if (inverseNavigation != null &&
                     !inverseNavigation.IsCollection)
                 {
                     inverseNavigation.SetIsLoadedWhenNoTracking(relatedEntity);
                 }
             }
         }
     }
 }
Beispiel #9
0
    static (Type itemType, bool isCollection) GetNavigationType(INavigationBase navigation)
    {
        var  navigationType = navigation.ClrType;
        Type?collectionType;

        if (navigationType.IsGenericType && navigationType.GetGenericTypeDefinition() == typeof(ICollection <>))
        {
            collectionType = navigationType;
        }
        else
        {
            collectionType = navigationType.GetInterfaces()
                             .SingleOrDefault(x => x.IsGenericType &&
                                              x.GetGenericTypeDefinition() == typeof(ICollection <>));
        }

        if (collectionType == null)
        {
            return(navigationType, false);
        }

        return(collectionType.GetGenericArguments().Single(), true);
    }
Beispiel #10
0
 /// <summary>Static getter for Keywords</summary>
 public static IEnumerable <string> GetKeywords(INavigationBase that)
 {
     return(that.GetPropertyValue <IEnumerable <string> >("keywords"));
 }
Beispiel #11
0
        private static IClrCollectionAccessor CreateGeneric <TEntity, TCollection, TElement>(INavigationBase navigation)
            where TEntity : class
            where TCollection : class, IEnumerable <TElement>
            where TElement : class
        {
            var entityParameter = Expression.Parameter(typeof(TEntity), "entity");
            var valueParameter  = Expression.Parameter(typeof(TCollection), "collection");

            var memberInfoForRead = navigation.GetMemberInfo(forMaterialization: false, forSet: false);

            navigation.TryGetMemberInfo(forConstruction: false, forSet: true, out var memberInfoForWrite, out _);
            navigation.TryGetMemberInfo(forConstruction: true, forSet: true, out var memberInfoForMaterialization, out _);

            var memberAccessForRead = (Expression)Expression.MakeMemberAccess(entityParameter, memberInfoForRead);

            if (memberAccessForRead.Type != typeof(TCollection))
            {
                memberAccessForRead = Expression.Convert(memberAccessForRead, typeof(TCollection));
            }

            var getterDelegate = Expression.Lambda <Func <TEntity, TCollection> >(
                memberAccessForRead,
                entityParameter).Compile();

            Action <TEntity, TCollection>?setterDelegate = null;
            Action <TEntity, TCollection>?setterDelegateForMaterialization = null;
            Func <TEntity, Action <TEntity, TCollection>, TCollection>?createAndSetDelegate = null;
            Func <TCollection>?createDelegate = null;

            if (memberInfoForWrite != null)
            {
                setterDelegate = CreateSetterDelegate(entityParameter, memberInfoForWrite, valueParameter);
            }

            if (memberInfoForMaterialization != null)
            {
                setterDelegateForMaterialization = CreateSetterDelegate(entityParameter, memberInfoForMaterialization, valueParameter);
            }

            var concreteType = new CollectionTypeFactory().TryFindTypeToInstantiate(
                typeof(TEntity),
                typeof(TCollection),
                navigation.DeclaringEntityType.Model[CoreAnnotationNames.FullChangeTrackingNotificationsRequiredAnnotation] != null);

            if (concreteType != null)
            {
                var isHashSet = concreteType.IsGenericType && concreteType.GetGenericTypeDefinition() == typeof(HashSet <>);
                if (setterDelegate != null ||
                    setterDelegateForMaterialization != null)
                {
                    if (isHashSet)
                    {
                        createAndSetDelegate = (Func <TEntity, Action <TEntity, TCollection>, TCollection>)_createAndSetHashSet
                                               .MakeGenericMethod(typeof(TEntity), typeof(TCollection), typeof(TElement))
                                               .CreateDelegate(typeof(Func <TEntity, Action <TEntity, TCollection>, TCollection>));
                    }
                    else if (IsObservableHashSet(concreteType))
                    {
                        createAndSetDelegate = (Func <TEntity, Action <TEntity, TCollection>, TCollection>)_createAndSetObservableHashSet
                                               .MakeGenericMethod(typeof(TEntity), typeof(TCollection), typeof(TElement))
                                               .CreateDelegate(typeof(Func <TEntity, Action <TEntity, TCollection>, TCollection>));
                    }
                    else
                    {
                        createAndSetDelegate = (Func <TEntity, Action <TEntity, TCollection>, TCollection>)_createAndSet
                                               .MakeGenericMethod(typeof(TEntity), typeof(TCollection), concreteType)
                                               .CreateDelegate(typeof(Func <TEntity, Action <TEntity, TCollection>, TCollection>));
                    }
                }

                if (isHashSet)
                {
                    createDelegate = (Func <TCollection>)_createHashSet
                                     .MakeGenericMethod(typeof(TCollection), typeof(TElement))
                                     .CreateDelegate(typeof(Func <TCollection>));
                }
                else if (IsObservableHashSet(concreteType))
                {
                    createDelegate = (Func <TCollection>)_createObservableHashSet
                                     .MakeGenericMethod(typeof(TCollection), typeof(TElement))
                                     .CreateDelegate(typeof(Func <TCollection>));
                }
                else
                {
                    createDelegate = (Func <TCollection>)_create
                                     .MakeGenericMethod(typeof(TCollection), concreteType)
                                     .CreateDelegate(typeof(Func <TCollection>));
                }
            }

            return(new ClrICollectionAccessor <TEntity, TCollection, TElement>(
                       navigation.Name,
                       getterDelegate,
                       setterDelegate,
                       setterDelegateForMaterialization,
                       createAndSetDelegate,
                       createDelegate));
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public virtual void NavigationCollectionChanged(
     InternalEntityEntry entry,
     INavigationBase navigationBase,
     IEnumerable <object> added,
     IEnumerable <object> removed)
 => _navigationFixer.NavigationCollectionChanged(entry, navigationBase, added, removed);
Beispiel #13
0
 public void RecordReferencedUntrackedEntity(
     object referencedEntity,
     INavigationBase navigation,
     InternalEntityEntry referencedFromEntry)
 => throw new NotImplementedException();
Beispiel #14
0
 public static IEnumerable <string> GetKeywords(INavigationBase that) => that.Value <IEnumerable <string> >("keywords");
Beispiel #15
0
 protected NavigationEntry(InternalEntityEntry internalEntry, INavigationBase navigation)
     : base(internalEntry, navigation)
 {
 }
Beispiel #16
0
            // *** Constructors ***

            public GoBackCommand(INavigationBase navigationManager)
            {
                this.navigationManager = navigationManager;
            }
Beispiel #17
0
 /// <summary>
 ///     Creates a new instance of the <see cref="MaterializeCollectionNavigationExpression" /> class.
 /// </summary>
 /// <param name="subquery">An expression reprensenting how to get value from query to create the collection.</param>
 /// <param name="navigation">A navigation associated with this collection.</param>
 public MaterializeCollectionNavigationExpression(Expression subquery, INavigationBase navigation)
 {
     Subquery   = subquery;
     Navigation = navigation;
 }
        // *** Constructors ***

        public NavigationContext(INavigationBase current)
        {
            _current = current;
        }
Beispiel #19
0
            // *** Constructors ***

            public NavigateToCommand(INavigationBase navigationManager, string pageName, object arguments)
            {
                this.navigationManager = navigationManager;
                this.pageName          = pageName;
                this.arguments         = arguments;
            }
 public NavigationView(INavigationBase navigationManager)
     : base(s_emptyPage)
 {
     _navigationManager = navigationManager;
 }
Beispiel #21
0
            // *** Constructors ***

            public NavigateToCommand(INavigationBase navigationManager, string pageName, object arguments)
            {
                this.navigationManager = navigationManager;
                this.pageName = pageName;
                this.arguments = arguments;
            }
Beispiel #22
0
 /// <summary>Static getter for Hide in Navigation</summary>
 public static bool GetUmbracoNavihide(INavigationBase that)
 {
     return(that.GetPropertyValue <bool>("umbracoNavihide"));
 }
        // *** Methods ***

        public void NavigateTo(object page, INavigationBase navigationManager)
        {
            NavigateToCalls.Add(Tuple.Create(page, navigationManager));
        }
 public static string GetSeoMetaDescription(INavigationBase that) => that.Value <string>("seoMetaDescription");
            // *** Constructors ***

            public NavigateToCommand(INavigationBase navigationManager, string pageName, object arguments)
            {
                _navigationManager = navigationManager;
                _pageName = pageName;
                _arguments = arguments;
            }
 private CollectionShaperExpression AddCollectionProjection(
     ShapedQueryExpression subquery,
     INavigationBase navigation,
     Type elementType)
 => new CollectionShaperExpression(
            // *** Constructors ***

            public NavigateToState(INavigationBase navigationManager, string pageName, object arguments)
            {
                this.NavigationManager = navigationManager;
                this.PageName = pageName;
                this.Arguments = arguments;
            }
Beispiel #28
0
 public NavigationView(INavigationBase navigationManager)
     : base(s_emptyPage)
 {
     _navigationManager = navigationManager;
 }
            // *** Constructors ***

            public GoBackCommand(INavigationBase navigationManager)
            {
                _navigationManager = navigationManager;

                navigationManager.NavigationStack.PropertyChanged += NavigationStack_PropertyChanged;
            }
Beispiel #30
0
 protected NavigationEntry([NotNull] InternalEntityEntry internalEntry, [NotNull] INavigationBase navigation)
     : base(internalEntry, navigation)
 {
 }
 public CollectionEntry(InternalEntityEntry internalEntry, INavigationBase navigationBase)
     : base(internalEntry, navigationBase)
 {
 }
Beispiel #32
0
    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public void DetectNavigationChange(InternalEntityEntry entry, INavigationBase navigationBase)
    {
        var snapshotValue = entry.GetRelationshipSnapshotValue(navigationBase);
        var currentValue  = entry[navigationBase];
        var stateManager  = entry.StateManager;

        if (navigationBase.IsCollection)
        {
            var snapshotCollection = (IEnumerable?)snapshotValue;
            var currentCollection  = (IEnumerable?)currentValue;

            var removed = new HashSet <object>(LegacyReferenceEqualityComparer.Instance);
            if (snapshotCollection != null)
            {
                foreach (var entity in snapshotCollection)
                {
                    removed.Add(entity);
                }
            }

            var added = new HashSet <object>(LegacyReferenceEqualityComparer.Instance);
            if (currentCollection != null)
            {
                foreach (var entity in currentCollection)
                {
                    if (!removed.Remove(entity))
                    {
                        added.Add(entity);
                    }
                }
            }

            if (added.Count > 0 ||
                removed.Count > 0)
            {
                if (_loggingOptions.IsSensitiveDataLoggingEnabled)
                {
                    if (navigationBase is INavigation navigation)
                    {
                        _logger.CollectionChangeDetectedSensitive(entry, navigation, added, removed);
                    }
                    else if (navigationBase is ISkipNavigation skipNavigation)
                    {
                        _logger.SkipCollectionChangeDetectedSensitive(entry, skipNavigation, added, removed);
                    }
                }
                else
                {
                    if (navigationBase is INavigation navigation)
                    {
                        _logger.CollectionChangeDetected(entry, navigation, added, removed);
                    }
                    else if (navigationBase is ISkipNavigation skipNavigation)
                    {
                        _logger.SkipCollectionChangeDetected(entry, skipNavigation, added, removed);
                    }
                }

                stateManager.InternalEntityEntryNotifier.NavigationCollectionChanged(entry, navigationBase, added, removed);
            }
        }
        else if (!ReferenceEquals(currentValue, snapshotValue))
        {
            Check.DebugAssert(navigationBase is INavigation, "Issue #21673. Non-collection skip navigations not supported.");

            var navigation = (INavigation)navigationBase;
            if (_loggingOptions.IsSensitiveDataLoggingEnabled)
            {
                _logger.ReferenceChangeDetectedSensitive(entry, navigation, snapshotValue, currentValue);
            }
            else
            {
                _logger.ReferenceChangeDetected(entry, navigation, snapshotValue, currentValue);
            }

            stateManager.InternalEntityEntryNotifier.NavigationReferenceChanged(entry, navigation, snapshotValue, currentValue);
        }
    }
        public void NavigateTo(object page, INavigationBase navigationManager)
        {
            //Ensures the nav menu reflects reality when navigation is triggered outside of the nav menu buttons.

            if (AppFrame.Content != null)
            {
                var item = (from p in this.navlist where p.DestPageName == navigationManager.NavigationStack.CurrentPage.PageName select p).SingleOrDefault();
                if (item == null && navigationManager.NavigationStack.CanGoBack)
                {
                    // In cases where a page drills into sub-pages then we'll highlight the most recent
                    // navigation menu item that appears in the BackStack
                    foreach (var entry in navigationManager.NavigationStack.Reverse())
                    {
                        item = (from p in this.navlist where p.DestPageName == entry.PageName select p).SingleOrDefault();
                        if (item != null)
                            break;
                    }
                }

                var container = (ListViewItem)NavMenuList.ContainerFromItem(item);

                // While updating the selection state of the item prevent it from taking keyboard focus.  If a
                // user is invoking the back button via the keyboard causing the selected nav menu item to change
                // then focus will remain on the back button.
                if (container != null) container.IsTabStop = false;
                NavMenuList.SetSelectedItem(container);
                if (container != null) container.IsTabStop = true;
            }

            // Perform the navigation
            this.NavigationManager = navigationManager;
            AppFrame.Content = page;
            Window.Current.Content = this;

            // After a successful navigation set keyboard focus to the loaded page
            if (page is Page && page != null)
            {
                var control = (Page)page;
                control.Loaded += Page_Loaded;
            }
        }
Beispiel #34
0
 /// <summary>
 ///     Sets the navigation for given entity as loaded.
 /// </summary>
 /// <param name="entity">The entity instance.</param>
 /// <param name="navigation">The navigation property.</param>
 public virtual void SetNavigationIsLoaded(object entity, INavigationBase navigation)
 // InitializeStateManager will populate the field before calling here
 => _stateManager !.TryGetEntry(entity) !.SetIsLoaded(navigation);
Beispiel #35
0
        // *** Constructors ***

        public ShareSourceManager(INavigationManager navigationManager)
        {
            this.navigationManager = navigationManager;
            navigationManager.NavigatedTo += NavigationManager_NavigatedTo;
        }
Beispiel #36
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public virtual IClrCollectionAccessor?Create(INavigationBase navigation)
 => !navigation.IsCollection || navigation.IsShadowProperty() ? null : Create(navigation, navigation.TargetEntityType);
Beispiel #37
0
 public void NavigationReferenceChanged(
     InternalEntityEntry entry, INavigationBase navigationBase, object oldValue, object newValue)
 {
 }
Beispiel #38
0
 /// <summary>Static getter for Description</summary>
 public static string GetSeoMetaDescription(INavigationBase that)
 {
     return(that.GetPropertyValue <string>("seoMetaDescription"));
 }
Beispiel #39
0
 public void NavigationCollectionChanged(
     InternalEntityEntry entry, INavigationBase navigationBase, IEnumerable <object> added, IEnumerable <object> removed)
 => CollectionChanged.Add(Tuple.Create(entry, navigationBase, added, removed));
 public static global::System.Collections.Generic.IEnumerable <string> GetKeywords(INavigationBase that) => that.Value <global::System.Collections.Generic.IEnumerable <string> >("keywords");
Beispiel #41
0
        private static Expression <Func <TSourceEntity, IEnumerable <TEntity> > > BuildSelectManyLambda(INavigationBase navigation)
        {
            var entityParameter = Expression.Parameter(typeof(TSourceEntity), "e");

            return(Expression.Lambda <Func <TSourceEntity, IEnumerable <TEntity> > >(
                       Expression.MakeMemberAccess(
                           entityParameter,
                           navigation.PropertyInfo),
                       entityParameter));
        }
 public static bool GetUmbracoNavihide(INavigationBase that) => that.Value <bool>("umbracoNavihide");
        // *** Methods ***

        public void NavigateTo(object page, INavigationBase navigationManager)
        {
            _navigationManager = navigationManager;

            SetWindowContent(page);
        }