/// <summary> /// Gets the grain properties for the provided type. /// </summary> public bool TryGetGrainProperties(GrainType grainType, out GrainProperties properties) { var clusterManifest = _clusterManifestProvider.Current; if (clusterManifest is null) { properties = default; return(false); } GrainType lookupKey; if (GenericGrainType.TryParse(grainType, out var generic)) { lookupKey = generic.GetUnconstructedGrainType().GrainType; } else { lookupKey = grainType; } foreach (var manifest in clusterManifest.AllGrainManifests) { if (manifest.Grains.TryGetValue(lookupKey, out properties)) { return(true); } } properties = default; return(false); }
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()); }
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()); }
/// <summary> /// Gets the grain properties for the provided type. /// </summary> public GrainProperties GetGrainProperties(GrainType grainType) { if (!TryGetGrainProperties(grainType, out var result)) { //ThrowNotFoundException(grainType); result = new GrainProperties(ImmutableDictionary <string, string> .Empty); } return(result); }
/// <summary> /// Gets the grain properties for the provided type. /// </summary> public bool TryGetGrainProperties(GrainType grainType, out GrainProperties properties) { var clusterManifest = _clusterManifestProvider.Current; foreach (var entry in clusterManifest.Silos) { var manifest = entry.Value; if (manifest.Grains.TryGetValue(grainType, out properties)) { return(true); } } properties = default; return(false); }