private static (ImmutableDictionary <GrainType, GrainProperties>, ImmutableDictionary <GrainType, Type>) CreateGrainManifest(
            GrainClassOptions grainClassOptions,
            IEnumerable <IGrainPropertiesProvider> grainMetadataProviders,
            IApplicationPartManager applicationPartManager,
            GrainTypeResolver grainTypeProvider)
        {
            var feature       = applicationPartManager.CreateAndPopulateFeature <GrainClassFeature>();
            var propertiesMap = ImmutableDictionary.CreateBuilder <GrainType, GrainProperties>();
            var typeMap       = ImmutableDictionary.CreateBuilder <GrainType, Type>();

            foreach (var value in feature.Classes)
            {
                var grainClass = value.ClassType;
                if (grainClassOptions.ExcludedGrainTypes.Contains(grainClass.FullName))
                {
                    // Explicitly excluded.
                    continue;
                }

                var grainType  = grainTypeProvider.GetGrainType(grainClass);
                var properties = new Dictionary <string, string>();
                foreach (var provider in grainMetadataProviders)
                {
                    provider.Populate(grainClass, grainType, properties);
                }

                var result = new GrainProperties(properties.ToImmutableDictionary());
                if (propertiesMap.ContainsKey(grainType))
                {
                    throw new InvalidOperationException($"An entry with the key {grainType} is already present."
                                                        + $"\nExisting: {propertiesMap[grainType].ToDetailedString()}\nTrying to add: {result.ToDetailedString()}"
                                                        + "\nConsider using the [GrainType(\"name\")] attribute to give these classes unique names.");
                }

                propertiesMap.Add(grainType, result);
                typeMap.Add(grainType, grainClass);
            }

            return(propertiesMap.ToImmutable(), typeMap.ToImmutable());
        }
Beispiel #2
0
        private static Dictionary <string, GrainTypeData> CreateGrainTypeMap(GrainClassFeature grainClassFeature, GrainClassOptions grainClassOptions)
        {
            var result = new Dictionary <string, GrainTypeData>();

            var excluded = grainClassOptions.ExcludedGrainTypes;

            foreach (var grainClassMetadata in grainClassFeature.Classes)
            {
                var grainType = grainClassMetadata.ClassType;
                var className = TypeUtils.GetFullName(grainType);

                if (excluded != null && excluded.Contains(className))
                {
                    continue;
                }

                var typeData = grainType.GetTypeInfo().IsGenericTypeDefinition ?
                               new GenericGrainTypeData(grainType) :
                               new GrainTypeData(grainType);
                result[className] = typeData;
            }

            return(result);
        }