Exemple #1
0
        internal Collection(ResourceClassBase resourceClass, AssociationView association, FilterContext filterContext)
            : base(resourceClass, association.Name)
        {
            Association   = association;
            FilterContext = filterContext ?? FilterContext.NullFilterContext;

            ItemType = new ResourceChildItem(resourceClass.ResourceModel, association.OtherEntity, FilterContext, resourceClass);

            if (FilterContext.Definition != null)
            {
                // Make sure the XML element matches what we are expecting
                if (FilterContext.Definition.Name != "Collection")
                {
                    throw new ArgumentException(
                              string.Format(
                                  "The filter context definition XML element reference was a '{0}' element rather than the expected 'Collection' element.",
                                  FilterContext.Definition.Name));
                }

                var filterElt = FilterContext.Definition.Element("Filter");

                if (filterElt != null)
                {
                    ValueFilters = new[]
                    {
                        new CollectionItemValueFilter(filterElt)
                    };
                }
                else
                {
                    ValueFilters = new CollectionItemValueFilter[0];
                }
            }
        }
Exemple #2
0
        private object AssembleHref(
            ResourceProfileData profileData,
            ResourceClassBase resource,
            AssociationView association = null)
        {
            if (resource.IsAggregateRoot())
            {
                return(new
                {
                    StandardLink = new
                    {
                        ResourceName = resource.Name,
                        ResourceBaseRoute = GetResourceCollectionRelativeRoute(resource as Resource),
                    }
                });
            }

            if (association == null)
            {
                return(ResourceRenderer.DoNotRenderProperty);
            }

            return(new
            {
                StandardLink = new
                {
                    Rel = association.OtherEntity.Name,
                    ResourceBaseRoute =
                        $"/{association.OtherEntity.SchemaUriSegment()}/{association.OtherEntity.PluralName.ToCamelCase()}",
                }
            });
        }
Exemple #3
0
        internal EmbeddedObject(ResourceClassBase resourceClass, AssociationView association, FilterContext childFilterContext)
            : base(resourceClass, association.Name)
        {
            Association = association;
            ObjectType  = new ResourceChildItem(resourceClass.ResourceModel, association.OtherEntity, childFilterContext, resourceClass);

            _parentFullName = Association.ThisEntity.FullName;
        }
Exemple #4
0
        public static string GetMappedAssociationPropertyName(this AssociationView association)
        {
            if (association.AssociationType == AssociationViewType.OneToOneOutgoing)
            {
                return(association.Name + OneToOneEntityPropertyNameSuffix);
            }

            return(association.Name);
        }
Exemple #5
0
        /// <summary>
        /// Gets the "name" assigned to the HbmBag in the dynamic NHibernate mapping created for aggregate extensions.
        /// </summary>
        /// <param name="association">The <see cref="Association"/> contained in the mapped bag.</param>
        /// <returns>The name of the bag.</returns>
        public static string GetAggregateExtensionBagName(this AssociationView association)
        {
            if (association.AssociationType != AssociationViewType.OneToMany && association.AssociationType != AssociationViewType.OneToOneOutgoing)
            {
                throw new Exception($"For aggregate extensions, the association must be {AssociationViewType.OneToMany} or {AssociationViewType.OneToOneOutgoing}.");
            }

            return($"{association.OtherEntity.SchemaProperCaseName()}_{association.OtherEntity.PluralName}");
        }
 private IEnumerable <object> GetContextualNavigableChildren(AssociationView a, ClassContext classContext)
 {
     yield return(new
     {
         ClassNameSuffix = QueryModelSuffix,
         ChildClassName = a.OtherEntity.Name,
         AssociationName = a.Name,
         IsChildForConcreteBase = classContext.IsConcreteEntityBaseClass
     });
 }
 private object GetContextualNonNavigableChild(AssociationView a)
 {
     return(new
     {
         AggregateRelativeNamespace = a.OtherEntity.GetRelativeAggregateNamespace(
             a.OtherEntity.ResolvedEdFiEntity().SchemaProperCaseName(),
             isQueryModel: true,
             isExtensionContext: !a.OtherEntity.ResolvedEdFiEntity().IsEdFiStandardEntity),
         ChildClassName = a.OtherEntity.ResolvedEdFiEntityName() + QueryModelSuffix,
         AssociationName = a.Name
     });
 }
Exemple #8
0
        public object AssembleReferenceFullyDefined(ResourceClassBase resource, AssociationView association = null)
        {
            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            // populates the reference is fully defined method for an aggregate reference.
            if (resource.HasBackReferences() && resource.IsAggregateRoot() || !resource.IdentifyingProperties.Any())
            {
                return(ResourceRenderer.DoNotRenderProperty);
            }

            var ids = association != null
                ? Resources.GetIdentifyingPropertiesWithAttributes(resource, association)
                      .OrderBy(x => x.Target.PropertyName)
                      .ToList()
                : resource.IdentifyingProperties.Where(x => !x.IsLocallyDefined)
                      .OrderBy(x => x.PropertyName)
                      .Select(
                x => new HrefData
            {
                Source    = x,
                Target    = x,
                IsUnified = false
            })
                      .ToList();

            if (!ids.Any())
            {
                return(ResourceRenderer.DoNotRenderProperty);
            }

            ResourceProperty first = ids.First()
                                     .Source;

            ResourceProperty last = ids.Last()
                                    .Source;

            return(ids
                   .Select(
                       x =>
                       new PropertyData(x.Source)
            {
                IsFirstProperty = x.Source == first,
                IsLastProperty = x.Source == last,
                IsReferencedProperty = x.IsUnified
            }.Render())
                   .ToList());
        }
Exemple #9
0
        private IEnumerable <object> GetContextualNavigableChildren(AssociationView a, ClassContext classContext)
        {
            var childContexts = GetContextualClassAndPropertyNameSuffixes(a.OtherEntity);

            foreach (var childContext in childContexts)
            {
                yield return(new
                {
                    ClassNameSuffix = QueryModelSuffix + childContext.ClassNameSuffix, ChildClassName = a.OtherEntity.Name,
                    AssociationName = a.Name + childContext.PropertyNameSuffix,
                    IsChildForConcreteBase = classContext.IsConcreteEntityBaseClass
                });
            }
        }
Exemple #10
0
        public Reference(ResourceClassBase resourceClass, AssociationView association, string displayName)
            : base(resourceClass, displayName)
        {
            Association                 = association;
            ReferencedResourceName      = association.OtherEntity.Name;
            ReferenceTypeName           = association.OtherEntity.Name + "Reference";
            _referencedResourceFullName = association.OtherEntity.FullName;

            _properties = new Lazy <IReadOnlyList <ResourceProperty> >(
                () => association.ThisProperties
                .Select(p => new ResourceProperty(resourceClass, p))
                .ToList());

            _referenceTypeProperties = new Lazy <IReadOnlyList <ResourceProperty> >(
                () => resourceClass.ResourceModel.GetResourceByFullName(association.OtherEntity.FullName)
                .IdentifyingProperties);
        }
Exemple #11
0
 /// <summary>
 /// Launches the association window.
 /// </summary>
 /// <param name="useDispatcher">if set to <c>true</c> [use dispatcher].</param>
 private void LaunchAssociationWindow(bool useDispatcher)
 {
     if (useDispatcher)
     {
         Application.Current.Dispatcher.Invoke(
             delegate
         {
             this.associationViewModel.UpdateColours(this.model.BackGroundColor, this.model.ForeGroundColor);
             var window = new AssociationView(this.associationViewModel);
             window.ShowDialog();
         });
     }
     else
     {
         this.associationViewModel.UpdateColours(this.model.BackGroundColor, this.model.ForeGroundColor);
         var window = new AssociationView(this.associationViewModel);
         window.ShowDialog();
     }
 }
Exemple #12
0
        private IEnumerable <object> GetContextualNonNavigableChildren(AssociationView a)
        {
            var childContexts = GetContextualClassAndPropertyNameSuffixes(a.OtherEntity);

            foreach (var childContext in childContexts)
            {
                yield return(new
                {
                    AggregateRelativeNamespace =
                        a.OtherEntity.GetRelativeAggregateNamespace(
                            a.OtherEntity.ResolvedEdFiEntity()
                            .SchemaProperCaseName(),
                            isQueryModel: true,
                            isExtensionContext: !a.OtherEntity.ResolvedEdFiEntity()
                            .IsEdFiStandardEntity),
                    ChildClassName = a.OtherEntity.ResolvedEdFiEntityName() + QueryModelSuffix,
                    ChildClassNameSuffix = childContext.ClassNameSuffix, AssociationName = a.Name, childContext.PropertyNameSuffix
                });
            }
        }
Exemple #13
0
        internal Extension(
            ResourceClassBase resourceClass,
            AssociationView association,
            FilterContext childFilterContext,
            Func <IEnumerable <AssociationView> > collectionAssociations,
            Func <IEnumerable <AssociationView> > embeddedObjectAssociations)
            : base(resourceClass, association.Name)
        {
            Association = association;

            ObjectType = new ResourceChildItem(
                resourceClass.ResourceModel,
                association.OtherEntity,
                childFilterContext,
                resourceClass,
                collectionAssociations,
                embeddedObjectAssociations);

            ParentFullName = Association.ThisEntity.FullName;
        }
 public CompositeDefinitionProcessorContext(
     XElement compositeDefinitionElement,
     IResourceModel resourceModel,
     XElement currentElement,
     ResourceClassBase currentResourceClass,
     AssociationView joinAssociation,
     string entityMemberName,
     string memberDisplayName,
     int childIndex,
     ResourceMemberBase resourceMember)
 {
     ChildIndex                 = childIndex;
     CurrentResourceMember      = resourceMember;
     CompositeDefinitionElement = compositeDefinitionElement;
     ResourceModel              = resourceModel;
     CurrentElement             = currentElement;
     CurrentResourceClass       = currentResourceClass;
     JoinAssociation            = joinAssociation;
     EntityMemberName           = entityMemberName;
     MemberDisplayName          = memberDisplayName;
 }
        private static string GetHqlMemberPath(AssociationView association)
        {
            string hqlMemberPath;

            if (association.OtherEntity.IsAggregateExtensionTopLevelEntity)
            {
                hqlMemberPath = $"AggregateExtensions.{association.GetAggregateExtensionBagName()}";
            }
            else if (association.AssociationType == AssociationViewType.ToExtension)
            {
                hqlMemberPath = $"Extensions.{association.OtherEntity.SchemaProperCaseName()}";
            }
            else if (!association.IsNavigable)
            {
                hqlMemberPath = association.Name + "ReferenceData";
            }
            else
            {
                hqlMemberPath = association.Name;
            }

            return(hqlMemberPath);
        }
Exemple #16
0
        /// <summary>
        /// Gets the target columns of the association based on the nHibernate order, which keeps association columns grouped together
        /// </summary>
        /// <param name="associationView"></param>
        /// <returns></returns>
        // Note this is different than alphabetical in a few edge cases, which is why this is required.
        public static IEnumerable <EntityProperty> GetOrderedAssociationTargetColumns(this AssociationView associationView)
        {
            return(RecursivelyGetOrderedAssociationTargetColumns(associationView, new AssociationView[0])
                   .Select(p => p));

            IEnumerable <EntityProperty> RecursivelyGetOrderedAssociationTargetColumns(
                AssociationView childAssociationView,
                IEnumerable <AssociationView> associationViews)
            {
                var orderedChildProperties = childAssociationView.PropertyMappings
                                             .Where(pm => !pm.ThisProperty.IsFromParent)
                                             .OrderBy(pm => pm.ThisProperty.PropertyName)
                                             .Select(pm => pm.OtherProperty);

                foreach (var property in orderedChildProperties)
                {
                    var propertyToYield = property;

                    // Find the mapped original property
                    foreach (var av in associationViews)
                    {
                        propertyToYield = av.PropertyMappingByThisName[propertyToYield.PropertyName]
                                          .OtherProperty;
                    }

                    yield return(propertyToYield);
                }

                // Get the parent entity
                var parentEntity = childAssociationView.ThisEntity.Parent;

                if (parentEntity != null)
                {
                    var parentAssociationView   = childAssociationView.ThisEntity.ParentAssociation;
                    var parentsChildAssociation = parentAssociationView.Inverse;

                    var newAssociationViews = new[]
                    {
                        childAssociationView
                    }.Concat(associationViews);

                    foreach (var property in RecursivelyGetOrderedAssociationTargetColumns(parentsChildAssociation, newAssociationViews))
                    {
                        yield return(property);
                    }
                }
            }
        }
Exemple #17
0
 public Collection(ResourceClassBase resourceClass, ResourceChildItem itemType, AssociationView association, string memberDisplayName)
     : base(resourceClass, memberDisplayName, memberDisplayName.ToCamelCase())
 {
     ItemType    = itemType;
     Association = association;
 }
Exemple #18
0
        public static IList <HrefData> GetIdentifyingPropertiesWithAttributes(
            ResourceClassBase resource,
            AssociationView association)
        {
            return(resource.IdentifyingProperties
                   .Where(x => !x.IsLocallyDefined)
                   .Select(
                       x =>
            {
                string propertyName = x.IsLookup
                            ? x.PropertyName + "Id"
                            : x.PropertyName;

                if (association.PropertyMappingByThisName.ContainsKey(propertyName))
                {
                    // in the case where we have unified key and roles, we need to use the
                    // context of the call along with the destination

                    var otherResourceProperty = association.PropertyMappingByThisName[propertyName]
                                                .OtherProperty
                                                .ToResourceProperty(resource);

                    if (!x.HasAssociations())
                    {
                        return
                        new HrefData
                        {
                            Source = otherResourceProperty,
                            Target = otherResourceProperty,
                            IsUnified = x.IsUnified()
                        };
                    }

                    var context = resource.Context(x);

                    if (context != null)
                    {
                        return new HrefData
                        {
                            Source =
                                context.PropertyMappingByThisName[propertyName]
                                .OtherProperty
                                .ToResourceProperty(resource),
                            Target = otherResourceProperty,
                            IsUnified = x.IsUnified()
                        };
                    }

                    return
                    new HrefData
                    {
                        Source = otherResourceProperty,
                        Target = otherResourceProperty,
                        IsUnified = x.IsUnified()
                    };
                }

                return new HrefData
                {
                    Source = x,
                    Target = x,
                    IsUnified = x.IsUnified()
                };
            })
                   .ToList());
        }
 public LinkedCollection(Resource resource, AssociationView association)
     : base(resource, association.Name)
 {
     Association = association;
 }
Exemple #20
0
        public object AssembleIdentifiers(
            ResourceProfileData profileData,
            ResourceClassBase resource,
            AssociationView association = null)
        {
            if (profileData == null)
            {
                throw new ArgumentNullException(nameof(profileData));
            }

            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            if (!resource.IdentifyingProperties.Any() && association == null)
            {
                return(ResourceRenderer.DoNotRenderProperty);
            }

            IList <ResourceProperty> properties;

            var activeResource = profileData.GetProfileActiveResource(resource);

            if (resource.IsAggregateRoot())
            {
                properties = activeResource.IdentifyingProperties
                             .OrderBy(x => x.PropertyName)
                             .ToList();
            }
            else
            {
                if (association != null)
                {
                    properties = association.ThisProperties
                                 .Where(x => !(x.IsUnified && x.IsIdentifying))
                                 .Select(
                        x =>
                        association.PropertyMappingByThisName[x.PropertyName]
                        .OtherProperty
                        .ToResourceProperty(resource))
                                 .OrderBy(x => x.PropertyName)
                                 .ToList();
                }
                else
                {
                    properties = resource.IdentifyingProperties
                                 .Where(x => !x.EntityProperty.IsLocallyDefined)
                                 .OrderBy(x => x.PropertyName)
                                 .ToList();
                }
            }

            ResourceProperty first = properties.FirstOrDefault();
            ResourceProperty last  = properties.LastOrDefault();

            return(properties.Any()
                ? properties.Select(
                       y => new PropertyData(y)
            {
                IsFirstProperty = y == first,
                IsLastProperty = y == last
            }.Render())
                   .ToList()
                : ResourceRenderer.DoNotRenderProperty);
        }
 private static string GetExtensionClassSchemaProperCaseName(AssociationView c)
 {
     return(c.OtherEntity.DomainModel.SchemaNameMapProvider.GetSchemaMapByPhysicalName(c.OtherEntity.Schema)
            .ProperCaseName);
 }
Exemple #22
0
 public AssociationController(DefaultMessageBus messageDispatcher, AssociationView associationView)
 {
     _messageDispatcher = messageDispatcher;
     _associationView   = associationView;
 }
Exemple #23
0
        public object Render()
        {
            AssociationView derivedBaseProperty = Property.DerivedBaseProperty();

            var derivedName = derivedBaseProperty != null
                ? derivedBaseProperty.OtherEntity.Name
                : null;

            var desc = this[ResourceRenderer.DescriptionOverride] != null
                ? this[ResourceRenderer.DescriptionOverride]
                       .ScrubForXmlDocumentation()
                : UniqueIdSpecification.IsUniqueId(Property.PropertyName)
                    ? string.Format(
                "A unique alphanumeric code assigned to a {0}.",
                Property.RemoveUniqueIdOrUsiFromPropertyName()
                .ToLower())
                    : Property.Description.ScrubForXmlDocumentation();

            var propertyNamespacePrefix = Property.ProperCaseSchemaName() == null
                ? null
                : $"{Namespaces.Entities.Common.RelativeNamespace}.{Property.ProperCaseSchemaName()}.";

            return(new
            {
                Description = desc,
                Misc = this[ResourceRenderer.MiscellaneousComment],
                JsonPropertyName = Property.JsonPropertyName,
                PropertyName = IsReferencedProperty
                    ? string.Format(
                    "backReference.{0} != null && backReference.{0}.{1}",
                    Property.EntityProperty.Entity.Aggregate.Name,
                    Property.PropertyName)
                    : Property.PropertyName,
                CSharpSafePropertyName = Property.PropertyName.MakeSafeForCSharpClass(Property.ParentFullName.Name),
                ParentName =
                    Property.EntityProperty.IsFromParent
                        ? Property.EntityProperty.Entity.Parent.Name
                        : Property.EntityProperty.Entity.Name,
                PropertyFieldName = Property.EntityProperty.Entity
                                    .ResolvedEdFiEntityName()
                                    .ToCamelCase(),
                PropertyType = Property.PropertyType.ToCSharp(true),
                IsFirstProperty = IsFirstProperty,
                IsLastProperty = IsLastProperty,
                IsUnique = IsUnique,
                NumericAttribute = Property.ToRangeAttributeCSharp(),
                IsDateOnlyProperty = Property.PropertyType.DbType == DbType.Date,
                IsTimeSpanProperty = Property.PropertyType.DbType == DbType.Time,
                ClassName = this[ResourceRenderer.ClassName]
                            ?? Property.EntityProperty.Entity
                            .ResolvedEdFiEntityName(),
                UnifiedKeys = Associations.Any()
                    ? AssembleOtherUnifiedChild(Associations)
                    : null,
                UnifiedExtensions = ExtensionAssociations.Any()
                    ? AssembleOtherUnifiedChild(ExtensionAssociations)
                    : null,
                ImplicitPropertyName = Associations.Any()
                    ? Associations.OrderByDescending(x => x.IsRequired)
                                       .First()
                                       .Name
                    : null,
                ImplicitNullable = Property.PropertyType.IsNullableCSharpType()
                    ? ".GetValueOrDefault()"
                    : null,
                ParentPropertyName = this[ResourceRenderer.ParentPropertyName],
                DerivedName = derivedName,
                PropertyNamespacePrefix = propertyNamespacePrefix,
                NullPropertyPrefix = Property.EntityProperty.Entity.IsEntityExtension
                    ? $"{propertyNamespacePrefix}I{Property.EntityProperty.Entity.Name}."
                    : $"{propertyNamespacePrefix}I{Property.EntityProperty.Entity.ResolvedEdFiEntityName()}."
            });
        }
Exemple #24
0
 public Reference(ResourceClassBase resourceClass, AssociationView association)
     : this(resourceClass, association, association.Name + "Reference")
 {
 }
 /// <summary>
 /// Launches the association window.
 /// </summary>
 /// <param name="useDispatcher">if set to <c>true</c> [use dispatcher].</param>
 private void LaunchAssociationWindow(bool useDispatcher)
 {
     if (useDispatcher)
     {
         Application.Current.Dispatcher.Invoke(
             delegate
             {
                 this.associationViewModel.UpdateColours(this.model.BackGroundColor, this.model.ForeGroundColor);
                 var window = new AssociationView(this.associationViewModel);
                 window.ShowDialog();
             });
     }
     else
     {
         this.associationViewModel.UpdateColours(this.model.BackGroundColor, this.model.ForeGroundColor);
         var window = new AssociationView(this.associationViewModel);
         window.ShowDialog();
     }
 }
 public AssociationViewEdge(Resource.Resource source, Resource.Resource target, AssociationView associationView)
 {
     Source          = source;
     Target          = target;
     AssociationView = associationView;
 }