Ejemplo n.º 1
0
        private static ImmutableDictionary <GrainType, GrainProperties> CreateGrainManifest(
            IEnumerable <IGrainPropertiesProvider> grainMetadataProviders,
            IApplicationPartManager applicationPartManager,
            GrainTypeResolver grainTypeProvider)
        {
            var feature = applicationPartManager.CreateAndPopulateFeature <GrainClassFeature>();
            var builder = ImmutableDictionary.CreateBuilder <GrainType, GrainProperties>();

            foreach (var value in feature.Classes)
            {
                var grainClass = value.ClassType;
                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 (builder.ContainsKey(grainType))
                {
                    throw new InvalidOperationException($"An entry with the key {grainType} is already present."
                                                        + $"\nExisting: {builder[grainType].ToDetailedString()}\nTrying to add: {result.ToDetailedString()}"
                                                        + "\nConsider using the [GrainType(\"name\")] attribute to give these classes unique names.");
                }

                builder.Add(grainType, result);
            }

            return(builder.ToImmutable());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 3
0
        public SiloManifestProvider(
            IEnumerable <IGrainPropertiesProvider> grainPropertiesProviders,
            IEnumerable <IGrainInterfacePropertiesProvider> grainInterfacePropertiesProviders,
            IApplicationPartManager applicationPartManager,
            GrainTypeResolver typeProvider,
            GrainInterfaceIdResolver interfaceIdProvider)
        {
            var grains     = CreateGrainManifest(grainPropertiesProviders, applicationPartManager, typeProvider);
            var interfaces = CreateInterfaceManifest(grainInterfacePropertiesProviders, applicationPartManager, interfaceIdProvider);

            this.SiloManifest = new SiloManifest(grains, interfaces);
        }
Ejemplo n.º 4
0
        public SiloManifestProvider(
            IEnumerable <IGrainPropertiesProvider> grainPropertiesProviders,
            IEnumerable <IGrainInterfacePropertiesProvider> grainInterfacePropertiesProviders,
            IOptions <GrainTypeOptions> grainTypeOptions,
            GrainTypeResolver typeProvider,
            GrainInterfaceTypeResolver interfaceIdProvider,
            TypeConverter typeConverter)
        {
            var(grainProperties, grainTypes) = CreateGrainManifest(grainPropertiesProviders, grainTypeOptions, typeProvider);
            var interfaces = CreateInterfaceManifest(grainInterfacePropertiesProviders, grainTypeOptions, interfaceIdProvider);

            this.SiloManifest = new GrainManifest(grainProperties, interfaces);
            this.GrainTypeMap = new GrainClassMap(typeConverter, grainTypes);
        }