Exemplo n.º 1
0
        private CompositeDataMap(ApplicationSchemaDefinition application, DataMap composite, IEnumerable <Component> components)
        {
            if (application == null)
            {
                throw new ArgumentNullException("application");
            }
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (components == null)
            {
                throw new ArgumentNullException("components");
            }

            _application = application;
            _composite   = composite;
            _components  = components.ToDictionary(k => k.Application);
        }
Exemplo n.º 2
0
        public void AddComponent(ApplicationSchemaDefinition componentApplication, DataMap componentDataMap)
        {
            // Ensures the component's application is
            // indeed defined in the composite metadata.
            if (false == Application
                .Compositions
                .Any(c => componentApplication.Equals(c.To())))
            {
                throw new InvalidOperationException();
            }

            Component component;

            if (false == _components.TryGetValue(componentApplication, out component))
            {
                component = new Component(componentApplication, new List <DataMap>());
                _components[componentApplication] = component;
            }

            component.DataMaps.Insert(0, componentDataMap);
        }
Exemplo n.º 3
0
        public static async Task <CompositeDataMap> Expand(ApplicationSchemaDefinition compositeApplication, DataMap compositeDataMap)
        {
            var repository = new DataRepository();
            var components = new List <Component>();

            foreach (var composition in compositeApplication.Compositions)
            {
                var filters = new List <FilterExpression>();

                // Handles the composition criteria, which can
                // be either literals ("hardcoded") values or
                // based on the data map current state.
                foreach (var criterion in composition.EntityAssociation.Attributes)
                {
                    var value = string.IsNullOrEmpty(criterion.Literal)
                        ? compositeDataMap.Value(criterion.From)
                        : criterion.Literal;

                    filters.Add(new Exactly(criterion.To, value));
                }

                // Fetches all data maps ("components") that
                // satisfies the composition criteria.
                var componentApplication = composition.To();
                var componentDataMaps    = (await repository
                                            .LoadAsync(componentApplication, filters))
                                           .ToList();

                components.Add(new Component(componentApplication, componentDataMaps));
            }

            return(new CompositeDataMap(compositeApplication, compositeDataMap, components));
        }
Exemplo n.º 4
0
 public static CompositeDataMap Wrap(ApplicationSchemaDefinition compositeApplication, DataMap compositeDataMap)
 {
     return(new CompositeDataMap(compositeApplication, compositeDataMap, Enumerable.Empty <Component>()));
 }
Exemplo n.º 5
0
 public static string Id(this DataMap dataMap, IApplicationIdentifier application)
 {
     return(dataMap.Value(application.IdFieldName));
 }
Exemplo n.º 6
0
 public static T Id <T>(this DataMap dataMap, IApplicationIdentifier application)
 {
     return(dataMap.Value <T>(application.IdFieldName));
 }