예제 #1
0
        public async Task <PropertyProviderData> GetProvider(IPropertyProvider provider, int providerID)
        {
            var plainProviderAttributes = await provider.GetAttributes();

            var plainProviderRelations = await provider.GetRelations();

            var plainProviderEvents = await provider.GetEvents();

            var attributes = await Task.WhenAll(plainProviderAttributes.Select(attr => GetAttachedAttribute(attr)));

            var relations = await Task.WhenAll(plainProviderRelations.Select(relation => GetAttachedRelation(relation)));

            var events = await Task.WhenAll(plainProviderEvents.Select(e => GetAttachedEvent(e)));

            var attributesDict = attributes.ToDictionary(
                k => k.Attribute.ID,
                v => v
                );
            var relationsDict = relations.ToDictionary(
                k => k.Relation.PropertyID,
                v => v
                );
            var eventsDict = events.ToDictionary(
                k => k.Property.PropertyID,
                v => v
                );

            return(new PropertyProviderData(attributesDict, relationsDict, eventsDict, providerID));
        }
예제 #2
0
        public async Task <bool> Validate()
        {
            var attributes = await provider.GetAttributes();

            var relations = await provider.GetRelations();

            var attributeValues = await GetAttributes();

            foreach (var attribute in attributes)
            {
                var required = await attribute.IsRequired();

                if (!required)
                {
                    continue;
                }

                if (attributeValues.TryGetValue(attribute.PropertyID, out var values) && values.Any())
                {
                    continue;
                }
                else
                {
                    return(false);
                }
            }

            var relationValues = await GetRelations();

            foreach (var relation in relations)
            {
                var required = await relation.IsRequired();

                if (!required)
                {
                    continue;
                }

                if (relationValues.TryGetValue(relation.PropertyID, out var values) && values.Any())
                {
                    continue;
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }