Example #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);
        }
Example #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);
        }
Example #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));
        }
Example #4
0
 public static CompositeDataMap Wrap(ApplicationSchemaDefinition compositeApplication, DataMap compositeDataMap)
 {
     return(new CompositeDataMap(compositeApplication, compositeDataMap, Enumerable.Empty <Component>()));
 }
Example #5
0
 public static string Id(this DataMap dataMap, IApplicationIdentifier application)
 {
     return(dataMap.Value(application.IdFieldName));
 }
Example #6
0
 public static T Id <T>(this DataMap dataMap, IApplicationIdentifier application)
 {
     return(dataMap.Value <T>(application.IdFieldName));
 }