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);
                }
            }
Пример #2
0
 /// <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,
     });
Пример #3
0
            public bool TryLookupObserver(IReactiveMetadata metadata, string key, out ObserverDefinitionEntity entity)
            {
                if (metadata.Observers.TryGetValue(new Uri(key), out IReactiveObserverDefinition observerDefinition))
                {
                    var expression = _metadataRewrites.GetValue(
                        observerDefinition.Expression,
                        e => _queryEngine.RewriteQuotedReactiveToSubscribable(e));
                    entity = new ObserverDefinitionEntity(observerDefinition.Uri, expression, observerDefinition.State);
                    return(true);
                }

                // Will result in a stream being created if a definition exists
                // in the remote metadata store. This path should only succeed
                // when hit by the definition inlining binder.
                if (TryCreateStreamFromMetadata(metadata, key, out var subject))
                {
                    entity = ObserverDefinitionEntity.FromSubject(subject);
                    return(true);
                }

                entity = null;
                return(false);
            }
Пример #4
0
            public BuiltinEntitiesRegistry(CheckpointingQueryEngine queryEngine, IReactiveMetadata metadata)
            {
                Debug.Assert(queryEngine != null);
                Debug.Assert(metadata != null);

                _queryEngine = queryEngine;
                _subjects    = new ReactiveEntityCollection <string, SubjectEntity>(StringComparer.Ordinal);

                var localObservables            = new ReactiveEntityCollection <string, ObservableDefinitionEntity>(StringComparer.Ordinal);
                var localObservablesAndSubjects = new ChainedLookupReactiveEntityCollection <string, ObservableDefinitionEntity, SubjectEntity>(localObservables, _subjects, s => ObservableDefinitionEntity.FromSubject(s));

                _observables = new ExternalLookupReactiveEntityCollection <ObservableDefinitionEntity>(localObservablesAndSubjects, TryLookupObservable, metadata);

                var localObservers            = new ReactiveEntityCollection <string, ObserverDefinitionEntity>(StringComparer.Ordinal);
                var localObserversAndSubjects = new ChainedLookupReactiveEntityCollection <string, ObserverDefinitionEntity, SubjectEntity>(localObservers, _subjects, s => ObserverDefinitionEntity.FromSubject(s));

                _observers = new ExternalLookupReactiveEntityCollection <ObserverDefinitionEntity>(localObserversAndSubjects, TryLookupObserver, metadata);

                var localSubjectFactories = new ReactiveEntityCollection <string, StreamFactoryDefinitionEntity>(StringComparer.Ordinal);

                _subjectFactories = new ExternalLookupReactiveEntityCollection <StreamFactoryDefinitionEntity>(localSubjectFactories, TryLookupStreamFactory, metadata);

                var localSubscriptionFactories = new ReactiveEntityCollection <string, SubscriptionFactoryDefinitionEntity>(StringComparer.Ordinal);

                _subscriptionFactories = new ExternalLookupReactiveEntityCollection <SubscriptionFactoryDefinitionEntity>(localSubscriptionFactories, TryLookupSubscriptionFactory, metadata);

                _other     = new ReactiveEntityCollection <string, DefinitionEntity>(StringComparer.Ordinal);
                _templates = new InvertedLookupReactiveEntityCollection <string, DefinitionEntity>(StringComparer.Ordinal, InvertedDefinitionEntityComparer.Default);

                _subscriptions         = new ReactiveEntityCollection <string, SubscriptionEntity>(StringComparer.Ordinal);
                _reliableSubscriptions = new ReactiveEntityCollection <string, ReliableSubscriptionEntity>(StringComparer.Ordinal);

                _metadataRewrites = new ConditionalWeakTable <Expression, Expression>();

                InitializeBuiltinDefinitions(queryEngine);
            }
Пример #5
0
        public QueryEngineRegistry(IQueryEngineRegistry parent)
        {
            Debug.Assert(parent != null);

            _parent = parent;

            _localSubjects = new ReactiveEntityCollection <string, SubjectEntity>(StringComparer.Ordinal);
            Subjects       = new ChainedLookupReactiveEntityCollection <string, SubjectEntity>(_localSubjects, _parent.Subjects);

            _localObservables = new ReactiveEntityCollection <string, ObservableDefinitionEntity>(StringComparer.Ordinal);
            var localObservablesAndSubjects = new ChainedLookupReactiveEntityCollection <string, ObservableDefinitionEntity, SubjectEntity>(_localObservables, _localSubjects, s => ObservableDefinitionEntity.FromSubject(s));

            Observables = new ChainedLookupReactiveEntityCollection <string, ObservableDefinitionEntity>(localObservablesAndSubjects, _parent.Observables);

            _localObservers = new ReactiveEntityCollection <string, ObserverDefinitionEntity>(StringComparer.Ordinal);
            var localObserversAndSubjects = new ChainedLookupReactiveEntityCollection <string, ObserverDefinitionEntity, SubjectEntity>(_localObservers, _localSubjects, s => ObserverDefinitionEntity.FromSubject(s));

            Observers = new ChainedLookupReactiveEntityCollection <string, ObserverDefinitionEntity>(localObserversAndSubjects, _parent.Observers);

            _localSubjectFactories = new ReactiveEntityCollection <string, StreamFactoryDefinitionEntity>(StringComparer.Ordinal);
            SubjectFactories       = new ChainedLookupReactiveEntityCollection <string, StreamFactoryDefinitionEntity>(_localSubjectFactories, _parent.SubjectFactories);

            _localSubscriptionFactories = new ReactiveEntityCollection <string, SubscriptionFactoryDefinitionEntity>(StringComparer.Ordinal);
            SubscriptionFactories       = new ChainedLookupReactiveEntityCollection <string, SubscriptionFactoryDefinitionEntity>(_localSubscriptionFactories, _parent.SubscriptionFactories);

            _localSubscriptions = new ReactiveEntityCollection <string, SubscriptionEntity>(StringComparer.Ordinal);
            Subscriptions       = new ChainedLookupReactiveEntityCollection <string, SubscriptionEntity>(_localSubscriptions, _parent.Subscriptions);

            _localOther = new ReactiveEntityCollection <string, DefinitionEntity>(StringComparer.Ordinal);
            Other       = new ChainedLookupReactiveEntityCollection <string, DefinitionEntity>(_localOther, _parent.Other);

            _localReliableSubscriptions = new ReactiveEntityCollection <string, ReliableSubscriptionEntity>(StringComparer.Ordinal);
            ReliableSubscriptions       = new ChainedLookupReactiveEntityCollection <string, ReliableSubscriptionEntity>(_localReliableSubscriptions, _parent.ReliableSubscriptions);

            _localTemplates = new ReactiveEntityCollection <string, DefinitionEntity>(StringComparer.Ordinal);
            var chainedTemplates = new ChainedLookupReactiveEntityCollection <string, DefinitionEntity>(_localTemplates, _parent.Templates);

            Templates = new InvertedLookupReactiveEntityCollection <string, DefinitionEntity>(chainedTemplates, InvertedDefinitionEntityComparer.Default);
        }