예제 #1
0
        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());
        }
예제 #2
0
        private static (ImmutableDictionary <GrainType, GrainProperties>, ImmutableDictionary <GrainType, Type>) CreateGrainManifest(
            IEnumerable <IGrainPropertiesProvider> grainMetadataProviders,
            IOptions <GrainTypeOptions> grainTypeOptions,
            GrainTypeResolver grainTypeProvider)
        {
            var propertiesMap = ImmutableDictionary.CreateBuilder <GrainType, GrainProperties>();
            var typeMap       = ImmutableDictionary.CreateBuilder <GrainType, Type>();

            foreach (var grainClass in grainTypeOptions.Value.Classes)
            {
                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());
        }