Ejemplo n.º 1
0
            /// <summary>
            /// Creates the intrinsic definitions.
            /// </summary>
            private void InitializeBuiltinDefinitions(CheckpointingQueryEngine queryEngine)
            {
#pragma warning disable IDE0079 // Remove unnecessary suppression.
#pragma warning disable CA2000  // Dispose objects before losing scope. (Entities are owned by the registry.)

                // Subscribe implementation for Subscribable and ReliableObservable.
                _other.TryAdd(QueryEngineConstants.SubscribeUri, new OtherDefinitionEntity(new Uri(QueryEngineConstants.SubscribeUri), (Expression <Func <ISubscribable <T>, IObserver <T>, ISubscription> >)((o, v) => o.SubscribeRoot(v)), null));
                _other.TryAdd(QueryEngineConstants.ReliableSubscribeUri, new OtherDefinitionEntity(new Uri(QueryEngineConstants.ReliableSubscribeUri), (Expression <Func <IReliableObservable <T>, IReliableObserver <T>, IReliableSubscription> >)((o, v) => o.Subscribe(v)), null));

                // NB: All of the *Id definitions are legacy, prior to standardizing on `rx://builtin/identity`. They've been kept to ensure existing
                //     expressions can continue to bind and recover. They're harmless.

                // Conversions from Observable to Subscribable and from Subscribable to Subscribable (identity).
                _observables.TryAdd(QueryEngineConstants.ObservableId, new ObservableDefinitionEntity(new Uri(QueryEngineConstants.ObservableId), (Expression <Func <IObservable <T>, ISubscribable <T> > >)((source) => source.ToSubscribable()), null));
                _observables.TryAdd(QueryEngineConstants.SubscribableId, new ObservableDefinitionEntity(new Uri(QueryEngineConstants.SubscribableId), (Expression <Func <ISubscribable <T>, ISubscribable <T> > >)((source) => source), null));
                _observables.TryAdd(QueryEngineConstants.QbservableId, new ObservableDefinitionEntity(new Uri(QueryEngineConstants.QbservableId), (Expression <Func <ISubscribable <T>, ISubscribable <T> > >)((source) => source), null)); // TODO: consider eliminating the identities from the expression

                // Conversion from Observer to Observer (identity).
                _observers.TryAdd(QueryEngineConstants.ObserverId, new ObserverDefinitionEntity(new Uri(QueryEngineConstants.ObserverId), (Expression <Func <IObserver <T>, IObserver <T> > >)(observer => observer), null));

                // Subject factories for input and output edges.
                _subjectFactories.TryAdd(QueryEngineConstants.InputUri, new StreamFactoryDefinitionEntity(new Uri(QueryEngineConstants.InputUri), (Expression <Func <EdgeDescription, IReliableMultiSubject <T, T> > >)((edge) => new InputEdge <T>(edge, queryEngine._serviceResolver, queryEngine._reliableService)), null));
                _subjectFactories.TryAdd(QueryEngineConstants.OutputUri, new StreamFactoryDefinitionEntity(new Uri(QueryEngineConstants.OutputUri), (Expression <Func <EdgeDescription, IReliableMultiSubject <T, T> > >)((edge) => new OutputEdge <T>(edge, queryEngine._serviceResolver, queryEngine._reliableService)), null));
                _subjectFactories.TryAdd(QueryEngineConstants.BridgeUri, new StreamFactoryDefinitionEntity(new Uri(QueryEngineConstants.BridgeUri), (Expression <Func <Expression, IReliableMultiSubject <T, T> > >)((expr) => new Bridge <T>(queryEngine.Options.ExpressionPolicy.InMemoryCache.Create(expr))), null));
                _subjectFactories.TryAdd(QueryEngineConstants.InnerSubjectUri, new StreamFactoryDefinitionEntity(new Uri(QueryEngineConstants.InnerSubjectUri), (Expression <Func <IReliableMultiSubject <T, T> > >)(() => new InnerSubject <T>()), null));
                _subjectFactories.TryAdd(QueryEngineConstants.InnerSubjectRefCountUri, new StreamFactoryDefinitionEntity(new Uri(QueryEngineConstants.InnerSubjectRefCountUri), (Expression <Func <Uri, Uri, IReliableMultiSubject <T, T> > >)((refCountUri, collectorUri) => new RefCountSubject <T>(refCountUri, collectorUri)), null));

                // Built-in subscription factory for observable.Subscribe(observer)
                _subscriptionFactories.TryAdd(QueryEngineConstants.SubscribeUri, new SubscriptionFactoryDefinitionEntity(new Uri(QueryEngineConstants.SubscribeUri), (Expression <Func <ISubscribable <T>, IObserver <T>, ISubscription> >)((o, v) => o.SubscribeRoot(v)), null));
                _subscriptionFactories.TryAdd(QueryEngineConstants.ReliableSubscribeUri, new SubscriptionFactoryDefinitionEntity(new Uri(QueryEngineConstants.ReliableSubscribeUri), (Expression <Func <IReliableObservable <T>, IReliableObserver <T>, IReliableSubscription> >)((o, v) => o.Subscribe(v)), null));

#pragma warning restore CA2000
#pragma warning restore IDE0079
            }
                public TemplateMigrationTask(CheckpointingQueryEngine queryEngine, QueryEngineRegistryTemplatizer templatizer, Regex keyRegex, int quota, TraceSource traceSource)
                {
                    Debug.Assert(quota > 0);

                    _queryEngine    = queryEngine;
                    _templatizer    = templatizer;
                    _quota          = quota;
                    _remainingQuota = quota;
                    _traceSource    = traceSource;
                    _enumerator     = new RegistryKeyEnumerable(queryEngine._registry).Where(e => keyRegex.IsMatch(e.Uri.ToCanonicalString())).GetEnumerator();
                }
Ejemplo n.º 3
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);
            }
 public GarbageCollector(CheckpointingQueryEngine queryEngine, Action <ReactiveEntity> remove)
 {
     _queryEngine         = queryEngine;
     _remove              = remove;
     _collectibleEntities = new ConcurrentQueue <ReactiveEntity>();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Invokes the specified event but ignores (but logs) any exceptions thrown by the exception handler.
        /// </summary>
        /// <typeparam name="TEventArgs">The type of the event arguments.</typeparam>
        /// <param name="handler">The event to invoke.</param>
        /// <param name="sender">The sender raising the event.</param>
        /// <param name="args">The arguments passed to the event handler(s).</param>
        /// <param name="method">The name of the caller, used for logging purposes in case of failure.</param>
        public static void InvokeSafe <TEventArgs>(this EventHandler <TEventArgs> handler, CheckpointingQueryEngine sender, TEventArgs args, [CallerMemberName] string method = null)
        {
#pragma warning disable IDE0079 // Remove unnecessary suppression.
#pragma warning disable CA1031  // Do not catch general exception types. (Goal of Safe variant.)

            try
            {
                handler(sender, args);
            }
            catch (Exception ex)
            {
                sender.TraceSource.FailSafe_Exception(method, ex);
            }

#pragma warning restore CA1031
#pragma warning restore IDE0079
        }