Exemple #1
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,
     });
                /// <summary>
                /// Predicate defining whether the subscription state should be included in the checkpoint.
                /// </summary>
                /// <param name="entity">The entity.</param>
                /// <returns>
                /// True if should be included.
                /// </returns>
                protected override bool ShouldSaveSubscriptionState(SubscriptionEntity entity)
                {
                    Debug.Assert(entity != null, "Entity should not be null.");

                    var instance = entity.Instance;

                    if (instance != null)
                    {
                        return(SubscriptionStateVisitor.HasStateChanged(instance));
                    }

                    return(false);
                }
                /// <summary>
                /// Saves subscription runtime state.
                /// </summary>
                /// <param name="entity">The entity to save.</param>
                /// <param name="stream">The stream to save to.</param>
                protected virtual void SaveSubscriptionState(SubscriptionEntity entity, Stream stream)
                {
                    Debug.Assert(entity != null, "Entity should not be null.");
                    Debug.Assert(stream != null, "Stream should not be null.");

                    var instance = entity.Instance;

                    if (instance != null)
                    {
                        var policy = _engine.Parent._serializationPolicy;

                        using (entity.Measure(EntityMetric.SaveState))
                        {
                            using var operatorStateWriter = new OperatorStateWriterFactory(stream, policy);

                            operatorStateWriter.WriteHeader();

                            SubscriptionStateVisitor.SaveState(instance, operatorStateWriter);
                        }
                    }
                }
            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);
                }
            }
 /// <summary>
 /// Predicate defining whether the subscription state should be included in the checkpoint.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns>
 /// True if should be included.
 /// </returns>
 protected override bool ShouldSaveSubscriptionState(SubscriptionEntity entity) => true;
 /// <summary>
 /// Predicate defining whether the subscription state should be included in the checkpoint.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns>True if should be included.</returns>
 protected abstract bool ShouldSaveSubscriptionState(SubscriptionEntity entity);