public Revision <TypedEntity> MapRevision(NodeVersion source, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            var output = new Revision <TypedEntity>();

            MapRevision(source, output, lookupHelper, masterMapper);
            return(output);
        }
 private DateTimeOffset GetLatestStatusDate(NodeVersion source, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
 {
     return(source.NodeVersionStatuses.OrderByDescending(x => x.Date).Select(x => x.Date).FirstOrDefault());
 }
        private int CheckCountIncomingRelations(Node source, IRelatableEntity destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            var output = 0;

            foreach (var relation in source.IncomingRelations)
            {
                if (relation.StartNode.Id == relation.EndNode.Id)
                {
                    throw new InvalidOperationException("Cannot relate nodes to themselves");
                }

                output++;
            }
            return(output);
        }
 public RevisionStatusType MapEntityStatusType(NodeVersionStatusType source, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
 {
     return(new RevisionStatusType((HiveId)source.Id, source.Alias, source.Name, source.IsSystem));
 }
 private NodeVersionStatusHistory GetLatestNodeVersionStatus(NodeVersion source, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
 {
     return(source.NodeVersionStatuses.OrderByDescending(x => x.Date).FirstOrDefault());
 }
Example #6
0
        public void MapAttribute(Attribute source, TypedAttribute destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            destination.AttributeDefinition = MapAttributeDefinition(source.AttributeDefinition, lookupHelper, masterMapper);
            destination.Id = (HiveId)source.Id;

            destination.Values.Clear();

            foreach (var value in source.AttributeStringValues)
            {
                destination.Values.Add(value.ValueKey, value.Value);
            }

            foreach (var value in source.AttributeIntegerValues)
            {
                destination.Values.Add(value.ValueKey, value.Value);
            }

            foreach (var value in source.AttributeDecimalValues)
            {
                destination.Values.Add(value.ValueKey, value.Value);
            }

            foreach (var value in source.AttributeDateValues)
            {
                destination.Values.Add(value.ValueKey, value.Value);
            }

            foreach (var value in source.AttributeLongStringValues)
            {
                destination.Values.Add(value.ValueKey, value.Value);
            }

            //// TODO: Add LanguageInfo to the Values in the persistence (not rdbms) model
            //destination.Values.LazyLoadFactory = () =>
            //{
            //    // Using ConcurrentDictionary as it has a handy AddOrUpdate method meaning a quick
            //    // way of using the last-inserted version, should we hit any ValueKey clashes

            //    var items = new ConcurrentDictionary<string, Lazy<object>>();
            //    foreach (var attributeStringValue in source.AttributeStringValues)
            //    {
            //        var attribValue = attributeStringValue;
            //        var lazyProxyCall = new Lazy<object>(() => attribValue.Value);
            //        items.AddOrUpdate(attribValue.ValueKey, lazyProxyCall, (x,y) => lazyProxyCall);
            //    }

            //    foreach (var attributeIntegerValue in source.AttributeIntegerValues)
            //    {
            //        var attribValue = attributeIntegerValue;
            //        var lazyProxyCall = new Lazy<object>(() => attribValue.Value);
            //        items.AddOrUpdate(attribValue.ValueKey, lazyProxyCall, (x, y) => lazyProxyCall);
            //    }

            //    foreach (var value in source.AttributeDecimalValues)
            //    {
            //        var attribValue = value;
            //        var lazyProxyCall = new Lazy<object>(() => attribValue.Value);
            //        items.AddOrUpdate(attribValue.ValueKey, lazyProxyCall, (x, y) => lazyProxyCall);
            //    }

            //    foreach (var attributeDateValue in source.AttributeDateValues)
            //    {
            //        var attribValue = attributeDateValue;
            //        var lazyProxyCall = new Lazy<object>(() => attribValue.Value);
            //        items.AddOrUpdate(attribValue.ValueKey, lazyProxyCall, (x, y) => lazyProxyCall);
            //    }

            //    foreach (var attributeLongStringValue in source.AttributeLongStringValues)
            //    {
            //        var attribValue = attributeLongStringValue;
            //        var lazyProxyCall = new Lazy<object>(() => attribValue.Value);
            //        items.AddOrUpdate(attribValue.ValueKey, lazyProxyCall, (x, y) => lazyProxyCall);
            //    }

            //    return items;
            //};
        }
Example #7
0
 public IEnumerable <TypedAttribute> MapAttributes(IEnumerable <Attribute> attributes, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
 {
     return(attributes.Select(x => MapAttribute(x, lookupHelper, masterMapper)).ToArray());
 }
        //public IEnumerable<AttributeGroup> MapAttributeGroups(IEnumerable<AttributeDefinitionGroup> attributeDefinitionGroups)
        //{
        //    // For every item in the input parameter, select the result of the method MapAttributeGroup
        //    return attributeDefinitionGroups.Select(MapAttributeGroup);
        //}

        public void MapTypedEntityForRevision(NodeVersion source, TypedEntity destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            Mandate.ParameterNotNull(source, "source");
            Mandate.ParameterNotNull(destination, "destination");

            Node enclosingNode = source.Node;

            destination.EntitySchema = MapAttributeSchemaDefinition(source.AttributeSchemaDefinition, lookupHelper, masterMapper);

            // When we map the attributes, if any of them belong to schemas with another alias than the schema of this NodeVersion, then
            // those attributes must be "inherited" and we need to advertise that in the output model along with a reference to that schema too
            var allInheritedAttributes = source.Attributes.Where(x => x.AttributeDefinition.AttributeSchemaDefinition.Alias != source.AttributeSchemaDefinition.Alias).ToArray();
            var allRealAttributes      = source.Attributes.Except(allInheritedAttributes);

            var mappedRealAttributes      = MapAttributes(allRealAttributes, lookupHelper, masterMapper);
            var mappedInheritedAttributes =
                allInheritedAttributes.Select(
                    x => new { Original = x, Mapped = MapAttribute(x, lookupHelper, masterMapper) }).ToArray();

            // For the inherited ones, remap the AttributeDefinition
            foreach (var inherited in mappedInheritedAttributes)
            {
                var otherSchema = MapAttributeSchemaDefinition(inherited.Original.AttributeDefinition.AttributeSchemaDefinition, lookupHelper, masterMapper);
                inherited.Mapped.AttributeDefinition = new InheritedAttributeDefinition(inherited.Mapped.AttributeDefinition, otherSchema);
            }

            var collectionShouldValidateAgainstSchema = !allInheritedAttributes.Any();

            destination.Attributes.Reset(mappedRealAttributes.Concat(mappedInheritedAttributes.Select(x => x.Mapped)), collectionShouldValidateAgainstSchema);

            // Since this manual mapping stuff doesn't have a scope for avoiding remaps of the same object instance,
            // we need to go through and ensure we're using one group instance, so we'll use the one from the Schema
            foreach (var attribute in destination.Attributes)
            {
                var groupFromSchema = destination.EntitySchema.AttributeGroups.FirstOrDefault(x => x.Id == attribute.AttributeDefinition.AttributeGroup.Id);
                if (groupFromSchema != null)
                {
                    attribute.AttributeDefinition.AttributeGroup = groupFromSchema;
                }
            }

            destination.Id = new HiveId(enclosingNode.Id);

            destination.UtcCreated       = enclosingNode.DateCreated;
            destination.UtcModified      = source.DateCreated;
            destination.UtcStatusChanged = GetLatestStatusDate(source, lookupHelper, masterMapper);

            MapRelations(source.Node, destination, lookupHelper, masterMapper);
        }
        public void MapRevision(NodeVersion source, IRevision <TypedEntity> destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            if (destination.Item == null)
            {
                var casted = destination as Revision <TypedEntity>;
                if (casted != null)
                {
                    casted.Item = MapTypedEntityForRevision(source, lookupHelper, masterMapper);
                }
            }
            else
            {
                MapTypedEntityForRevision(source, destination.Item, lookupHelper, masterMapper);
            }

            var latestStatus = GetLatestNodeVersionStatus(source, lookupHelper, masterMapper);

            var utcStatusChanged = latestStatus == null ? DateTimeOffset.MinValue : latestStatus.Date;
            var statusType       = latestStatus == null
                                 ? new RevisionStatusType("unknown", "Unknown / Not specified")
                                 : MapEntityStatusType(latestStatus.NodeVersionStatusType, lookupHelper, masterMapper);

            var metaData = new RevisionData()
            {
                Id               = (HiveId)source.Id,
                StatusType       = statusType,
                UtcCreated       = source.NodeVersionStatuses.First().Date,
                UtcModified      = utcStatusChanged,
                UtcStatusChanged = utcStatusChanged
            };

            destination.Item.UtcModified      = source.DateCreated;
            destination.Item.UtcStatusChanged = utcStatusChanged;
            destination.MetaData = metaData;
        }
        //public void MapAttributeGroup(AttributeGroup destination, AttributeDefinitionGroup source)
        //{
        //    destination.Alias = source.Alias;
        //    destination.Id = source.Id;
        //    destination.Name = source.Name;
        //    destination.UtcCreated = source.DateCreated;
        //}

        //public AttributeGroup MapAttributeGroup(AttributeDefinitionGroup attributeGroup)
        //{
        //    // TODO:
        //    // - Attributes and AttributeDefinitions navigator on the stack model will be tricky to track changes
        //    // - Add Ordinal to Rdbms model
        //    var mapped = new AttributeGroup();
        //    MapAttributeGroup(mapped, attributeGroup);
        //    return mapped;
        //}

        public void MapAttributeSchemaDefinition(AttributeSchemaDefinition source, EntitySchema destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            destination.Alias      = source.Alias;
            destination.Id         = (HiveId)source.Id;
            destination.Name       = source.Name;
            destination.UtcCreated = source.Node.DateCreated;
            destination.SchemaType = source.SchemaType;

            if (!string.IsNullOrEmpty(source.XmlConfiguration))
            {
                destination.XmlConfiguration = XDocument.Parse(source.XmlConfiguration); // else the constructor will initialize it
            }
            destination.AttributeGroups.Clear();
            destination.AttributeDefinitions.Clear();
            //destination.AttributeTypes.Clear();

            foreach (var attributeDefinitionGroup in source.AttributeDefinitionGroups)
            {
                var mappedGroup = MapAttributeGroupDefinition(attributeDefinitionGroup, lookupHelper, masterMapper);
                destination.AttributeGroups.Add(mappedGroup);
            }

            //create a local cache of AttributeTypes to pass to the mappers so that we can
            //ensure that the same AttributeType based on the alias is the same used across all
            //AttributeDefinitions.
            var attributeTypeCache = new List <Model.Attribution.MetaData.AttributeType>();

            foreach (var attributeDefinition in source.AttributeDefinitions)
            {
                var localAttribCopy = attributeDefinition;
                var newDef          = MapAttributeDefinition(localAttribCopy, lookupHelper, masterMapper, attributeTypeCache);
                newDef.AttributeGroup = destination.AttributeGroups.SingleOrDefault(x => x.Alias == localAttribCopy.AttributeDefinitionGroup.Alias);
                if (newDef.AttributeGroup == null)
                {
                    throw new InvalidOperationException(
                              "Could not find group with alias {0} for mapping".InvariantFormat(
                                  localAttribCopy.AttributeDefinitionGroup.Alias));
                }
                destination.AttributeDefinitions.Add(newDef);
            }

            MapRelations(source.Node, destination, lookupHelper, masterMapper);
        }
        public EntitySchema MapAttributeSchemaDefinition(AttributeSchemaDefinition attributeSchemaDefinition, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            //TODO
            //- Map AttributeGroupDefinitions - how to track changes?
            //- Add DateModified to Rdbms model
            var mapped = new EntitySchema();

            MapAttributeSchemaDefinition(attributeSchemaDefinition, mapped, lookupHelper, masterMapper);
            return(mapped);
        }
 public void MapEntityStatusType(NodeVersionStatusType source, RevisionStatusType destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
 {
     destination.Id       = (HiveId)source.Id;
     destination.Alias    = source.Alias;
     destination.Name     = source.Name;
     destination.IsSystem = source.IsSystem;
 }
        public AttributeGroup MapAttributeGroupDefinition(AttributeDefinitionGroup attributeDefinitionGroup, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            // TODO:
            // - Attributes and AttributeDefinitions navigator on the stack model will be tricky to track changes
            // - Add Ordinal to Rdbms model
            var mapped = new AttributeGroup();

            MapAttributeGroupDefinition(attributeDefinitionGroup, mapped, lookupHelper, masterMapper);
            return(mapped);
        }
        public void MapAttributeGroupDefinition(AttributeDefinitionGroup source, AttributeGroup destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            destination.Alias      = source.Alias;
            destination.Id         = (HiveId)source.Id;
            destination.Name       = source.Name;
            destination.UtcCreated = source.Node.DateCreated;
            destination.Ordinal    = source.Ordinal;

            //destination.AttributeDefinitions.Clear();

            //foreach (var attributeDefinition in source.AttributeDefinitions)
            //{
            //    destination.AttributeDefinitions.Add(MapAttributeDefinition(attributeDefinition));
            //}
        }
 public void MapLocaleToLanguage(Locale source, LanguageInfo destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
 {
     destination.Alias = source.Alias;
     destination.Name  = source.Name;
     destination.Key   = source.LanguageIso; // TODO: Refactor LanguageInfo to just use Alias
     destination.InferCultureFromKey();
     // TODO: Lookup Fallbacks using a delegate to the Localization system
 }
        public TypedEntity MapTypedEntityForRevision(NodeVersion node, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            var mapped = new TypedEntity();

            MapTypedEntityForRevision(node, mapped, lookupHelper, masterMapper);
            return(mapped);
        }
Example #17
0
        public void MapAttributeTypeDefinition(AttributeType source, Model.Attribution.MetaData.AttributeType destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            destination.Alias                    = source.Alias;
            destination.Id                       = (HiveId)source.Id;
            destination.Description              = source.Description;
            destination.Name                     = source.Name;
            destination.RenderTypeProvider       = source.RenderTypeProvider;
            destination.RenderTypeProviderConfig = source.XmlConfiguration;

            if (!string.IsNullOrEmpty(source.PersistenceTypeProvider))
            {
                // TODO: Use TypeFinder, but requires TypeFinder to be moved into Framework. Otherwise, add caching
                var reverseSerializationType = Type.GetType(source.PersistenceTypeProvider, false, false);
                if (reverseSerializationType != null)
                {
                    var obj = Activator.CreateInstance(reverseSerializationType) as IAttributeSerializationDefinition;
                    destination.SerializationType = obj;
                }
                else
                {
                    throw new TypeLoadException(string.Format("Cannot load type '{0}' which is specified for this AttributeType in the database; either the Assembly has not been loaded into the AppDomain or it's been renamed since this item was last saved.", source.PersistenceTypeProvider));
                }
            }
        }
 private void MapRelations <T>(T source, IRelatableEntity destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
     where T : Node
 {
     /* Temp: do nothing */
     return;
 }
Example #19
0
        public TypedAttribute MapAttribute(Attribute attribute, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            //TODO:
            //- Remove Dates
            //- Add Ordinal to Rdbms for sorting within a tab
            var mapped = new TypedAttribute();

            MapAttribute(attribute, mapped, lookupHelper, masterMapper);
            return(mapped);
        }
        private void OldMapRelations <T>(T source, IRelatableEntity destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
            where T : Node
        {
            //destination.Relations.Clear();
            //destination.Relations.LazyLookAhead = (axis) =>
            //{
            //    switch (axis)
            //    {
            //        case HierarchyScope.Children:
            //        case HierarchyScope.Descendents:
            //        case HierarchyScope.DescendentsOrSelf:
            //            return CheckCountOutgoingRelations(source, destination, lookupHelper, masterMapper);
            //        case HierarchyScope.AllOrNone:
            //            return
            //                CheckCountIncomingRelations(source, destination, lookupHelper, masterMapper) +
            //                CheckCountOutgoingRelations(source, destination, lookupHelper, masterMapper);
            //        case HierarchyScope.Ancestors:
            //        case HierarchyScope.AncestorsOrSelf:
            //            return CheckCountIncomingRelations(source, destination, lookupHelper, masterMapper);
            //    }
            //    return 0;
            //};

            //destination.Relations.LazyLoadFactory = (relatableEntitySource, axis) =>
            //{
            //    switch (axis)
            //    {
            //        case HierarchyScope.Children:
            //        case HierarchyScope.Descendents:
            //        case HierarchyScope.DescendentsOrSelf:
            //            return PopulateOutgoingRelations(source, destination, relatableEntitySource, lookupHelper, masterMapper);
            //        case HierarchyScope.AllOrNone:
            //            return PopulateIncomingRelations(source, destination, relatableEntitySource, lookupHelper, masterMapper)
            //                .Concat(PopulateOutgoingRelations(source, destination, relatableEntitySource, lookupHelper, masterMapper));
            //        case HierarchyScope.Ancestors:
            //        case HierarchyScope.AncestorsOrSelf:
            //            return PopulateIncomingRelations(source, destination, relatableEntitySource, lookupHelper, masterMapper);
            //    }
            //    return Enumerable.Empty<Relation>();
            //};
        }
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:System.Object" /> class.
 /// </summary>
 public FakeTypeMapperCollection(AbstractMappingEngine[] dynamicTypeMaps)
     : base(new List<Lazy<AbstractMappingEngine, TypeMapperMetadata>>())
 {
     Array.ForEach(dynamicTypeMaps, x => Add(new Lazy<AbstractMappingEngine, TypeMapperMetadata>(() => x, new TypeMapperMetadata(true))));
 }
        public LanguageInfo MapLocaleToLanguage(Locale source, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            var output = new LanguageInfo();

            MapLocaleToLanguage(source, output, lookupHelper, masterMapper);
            return(output);
        }