/// <summary> /// Creates an invalid instance of the given reactive entity kind with the given URI. /// </summary> /// <param name="uri">The URI.</param> /// <param name="kind">The reactive entity kind.</param> /// <returns> /// The invalid instance, or null if an unexpected kind is provided. /// </returns> public static ReactiveEntity CreateInvalidInstance(Uri uri, ReactiveEntityKind kind) { return(kind switch { ReactiveEntityKind.Observable => ObservableDefinitionEntity.CreateInvalidInstance(uri), ReactiveEntityKind.Observer => ObserverDefinitionEntity.CreateInvalidInstance(uri), ReactiveEntityKind.Stream => SubjectEntity.CreateInvalidInstance(uri), ReactiveEntityKind.StreamFactory => StreamFactoryDefinitionEntity.CreateInvalidInstance(uri), ReactiveEntityKind.Subscription => SubscriptionEntity.CreateInvalidInstance(uri), ReactiveEntityKind.ReliableSubscription => ReliableSubscriptionEntity.CreateInvalidInstance(uri), ReactiveEntityKind.Template or ReactiveEntityKind.Other => OtherDefinitionEntity.CreateInvalidInstance(uri), _ => null, });
public bool TryLookupStreamFactory(IReactiveMetadata metadata, string key, out StreamFactoryDefinitionEntity entity) { if (metadata.StreamFactories.TryGetValue(new Uri(key), out IReactiveStreamFactoryDefinition streamFactoryDefinition)) { var expression = _metadataRewrites.GetValue( streamFactoryDefinition.Expression, e => _queryEngine.RewriteQuotedReactiveToSubscribable(e)); entity = new StreamFactoryDefinitionEntity(streamFactoryDefinition.Uri, expression, streamFactoryDefinition.State); return(true); } entity = null; return(false); }
private void AddEntityPlaceholder(ReactiveEntityKind kind, string key) { var uri = new Uri(key); #pragma warning disable IDE0079 // Remove unnecessary suppression. #pragma warning disable CA2000 // Dispose objects before losing scope. (Entities are owned by the registry.) var added = kind switch { ReactiveEntityKind.Observable => Registry.Observables.TryAdd(key, ObservableDefinitionEntity.CreateInvalidInstance(uri)), ReactiveEntityKind.Observer => Registry.Observers.TryAdd(key, ObserverDefinitionEntity.CreateInvalidInstance(uri)), ReactiveEntityKind.Stream => Registry.Subjects.TryAdd(key, SubjectEntity.CreateInvalidInstance(uri)), ReactiveEntityKind.StreamFactory => Registry.SubjectFactories.TryAdd(key, StreamFactoryDefinitionEntity.CreateInvalidInstance(uri)), ReactiveEntityKind.SubscriptionFactory => Registry.SubscriptionFactories.TryAdd(key, SubscriptionFactoryDefinitionEntity.CreateInvalidInstance(uri)), ReactiveEntityKind.Subscription => Registry.Subscriptions.TryAdd(key, SubscriptionEntity.CreateInvalidInstance(uri)), ReactiveEntityKind.ReliableSubscription => Registry.ReliableSubscriptions.TryAdd(key, ReliableSubscriptionEntity.CreateInvalidInstance(uri)), ReactiveEntityKind.Other => Registry.Other.TryAdd(key, OtherDefinitionEntity.CreateInvalidInstance(uri)), ReactiveEntityKind.Template => Registry.Templates.TryAdd(key, OtherDefinitionEntity.CreateInvalidInstance(uri)), _ => throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Cannot create an invalid entity '{0}' of type '{1}'.", key, kind)), }; #pragma warning restore CA2000 #pragma warning restore IDE0079 if (added) { Parent.TraceSource.Registry_AddEntityPlaceholder(Parent.Uri, kind.ToString(), key); } }