예제 #1
0
        public void Add(Type dataSetType)
        {
            var descriptor = new DataSetDescriptor(dataSetType);

            _datasetsByName.Add(descriptor.Name, descriptor);
            DatasetsByType.Add(descriptor.Type, descriptor);
        }
예제 #2
0
        private async Task <IEnumerable <string> > Execute(DataSetDescriptor descriptor)
        {
            var messages = new List <string>();
            var dataSet  = _dataSetResolver(descriptor.Type);

            //determine dependencies
            foreach (var dependency in descriptor.Dependencies)
            {
                var dependencySetDescriptor = DatasetsByType[dependency];
                messages.AddRange(await Execute(dependencySetDescriptor));
            }

            foreach (var property in descriptor.Properties)
            {
                if (Properties.ContainsKey(descriptor.Type.FullName))
                {
                    var name = property.MemberInfo.Name;
                    if (Properties[descriptor.Type.FullName].ContainsKey(name) && Properties[descriptor.Type.FullName][name] != null)
                    {
                        var value = Convert.ChangeType(Properties[descriptor.Type.FullName][name], property.MemberInfo.PropertyType);
                        property.MemberInfo.SetValue(dataSet, value);
                    }
                }

                if (!new DataSetPropertyRequiredSpecification(property)
                    .IsSatisfiedBy(Properties.ContainsKey(descriptor.Type.FullName) ? Properties[descriptor.Type.FullName] : null))
                {
                    throw new DataSetPropertyValidationException($"The property {property.Property.Name} must have a value");
                }
            }

            foreach (var e in DescriptorExtensions)
            {
                e.Apply(dataSet, descriptor.ExtensionObjects[e.GetType()]);
            }

            messages.Add(await dataSet.Execute());
            return(messages);
        }