コード例 #1
0
        public void Setup()
        {
            AggregateRoot   = new TAggregateRoot();
            Repository      = new FakeRepository(AggregateRoot);
            CaughtException = new ThereWasNoExceptionButOneWasExpectedException();
            foreach (var @event in Given())
            {
                AggregateRoot.ApplyEvent(@event);
            }

            CommandHandler = BuildCommandHandler();
            SetupDependencies();
            try
            {
                CommandHandler.Consume(When());
                if (Repository.SavedAggregate == null)
                {
                    PublishedEvents = AggregateRoot.GetUncommittedEvents();
                }
                else
                {
                    PublishedEvents = Repository.SavedAggregate.GetUncommittedEvents();
                }
            }
            catch (Exception exception)
            {
                CaughtException = exception;
            }
            finally
            {
                Finally();
            }
        }
コード例 #2
0
        private void ConfigureStartSettings()
        {
            var devNull = new DelegatingConsumer <T>(@event => { });

            _backlogConsumer       = devNull;
            _undeliverableConsumer = devNull;
        }
コード例 #3
0
        public void Subscribe <T>(Consumes <T> consumer, Func <T, bool> topic)
        {
            var subscription = GetSubscriptionSubject <T>();
            var observable   = Box <T>(subscription).Where(topic).AsObservable();

            observable.Subscribe(@event => consumer.Handle(@event), exception => { }, () => { });
        }
コード例 #4
0
        private Consumes <TMessage> .Selected BuildConsumer()
        {
            TComponent component = _builder.GetInstance <TComponent>();

            Consumes <TMessage> .Selected consumer = component.TranslateTo <Consumes <TMessage> .Selected>();

            return(consumer);
        }
コード例 #5
0
 public static void TryConsume <T>(this Consumes <T> consumer, T message) where T : Message
 {
     if (consumer == null)
     {
         return;
     }
     consumer.Handle(message);
 }
コード例 #6
0
        public void Subscribe <T>(Consumes <T> consumer)
        {
            var subscription   = GetSubscriptionSubject <T>();
            var observable     = Box <T>(subscription).AsObservable();
            var unsubscription = _unsubscriptions.GetOrAdd(typeof(T), t => new CancellationTokenSource());

            observable.Subscribe(@event => consumer.Handle(@event), exception => { }, () => { }, unsubscription.Token);
        }
コード例 #7
0
 public NarrowingConsumer(Consumes <TProduces> inner)
 {
     if (inner == null)
     {
         throw new ArgumentNullException("inner");
     }
     _inner = inner;
 }
コード例 #8
0
 public static Action <T> AsAction <T>(this Consumes <T> consumer) where T : Message
 {
     if (consumer == null)
     {
         throw new ArgumentNullException("consumer");
     }
     return(consumer.Handle);
 }
コード例 #9
0
 public BackgroundProducer(BlockingCollection <T> source)
 {
     Buffer = source;
     MaxDegreeOfParallelism = 1;
     _uptime         = new Stopwatch();
     _cancel         = new CancellationTokenSource();
     _empty          = new SemaphoreSlim(1);
     RetryPolicy     = new RetryPolicy();
     RateLimitPolicy = new RateLimitPolicy();
     _consumer       = new CollectionConsumer <T>();
 }
コード例 #10
0
        public void Subscribe <TDerivedMessage>(Consumes <TDerivedMessage> handler) where TDerivedMessage : TBaseMessage
        {
            Multiplexor <TBaseMessage> handlers;

            if (!_subscriptions.TryGetValue(typeof(TDerivedMessage), out handlers))
            {
                handlers = new Multiplexor <TBaseMessage>();
                _subscriptions.Add(typeof(TDerivedMessage), handlers);
            }
            handlers.AttachConsumer(new NarrowingConsumer <TBaseMessage, TDerivedMessage>(handler));
        }
コード例 #11
0
        public ThreadBoundary(Consumes <T> consumer, int sleepMilliseconds)
        {
            _consumer          = consumer;
            _sleepMilliseconds = sleepMilliseconds;
            var t = new Thread(Run)
            {
                IsBackground = true
            };

            t.Start();
        }
コード例 #12
0
 public GcMetricsProducer(
     Options options,
     Consumes <GcEventParser.Events.Info> gcInfo,
     Consumes <GcEventParser.Events.Verbose> gcVerbose,
     Consumes <RuntimeEventParser.Events.CountersV3_0> runtimeCounters)
 {
     _options         = options;
     _gcInfo          = gcInfo;
     _gcVerbose       = gcVerbose;
     _runtimeCounters = runtimeCounters;
 }
コード例 #13
0
        public IEnumerable <Action <TMessage> > Enumerate(TMessage message)
        {
            Consumes <TMessage> .All consumer = BuildConsumer();

            try
            {
                yield return(consumer.Consume);
            }
            finally
            {
                Release(consumer);
            }
        }
コード例 #14
0
        private Consumes <TMessage> .All BuildConsumer()
        {
            TComponent component = _builder.GetInstance <TComponent>();

            if (component == null)
            {
                throw new ConfigurationException(string.Format("Unable to resolve type '{0}' from container: ", typeof(TComponent)));
            }

            Consumes <TMessage> .All consumer = component.TranslateTo <Consumes <TMessage> .All>();

            return(consumer);
        }
コード例 #15
0
 public virtual void SetUp()
 {
     consumer = GivenConsumer();
     try {
         published = When();
         if (published != null)
         {
             consumer.Handle(published);
         }
     }
     catch (Exception Ex) {
         caught = Ex;
     }
 }
コード例 #16
0
ファイル: Program.cs プロジェクト: terjew/AdventOfCode2019
        public Reaction(string definition)
        {
            var parts  = definition.Split(" => ");
            var inputs = parts[0].Split(", ");
            var output = parts[1];

            foreach (var input in inputs)
            {
                Consumes.Add(new ReactionComponent(input));
            }

            Produces = new ReactionComponent(output);
            Produces.Chemical.SetSynthesis(this);
        }
コード例 #17
0
 public DelegatingConsumer(Action <T> @delegate, Consumes <T> forwardTo)
 {
     _delegate = @event =>
     {
         try
         {
             @delegate(@event);
             return(forwardTo.Handle(@event));
         }
         catch (Exception)
         {
             return(false);
         }
     };
 }
コード例 #18
0
        public IEnumerable <Action <TMessage> > Enumerate(TMessage message)
        {
            Consumes <TMessage> .Selected consumer = BuildConsumer();

            try
            {
                if (consumer.Accept(message) == false)
                {
                    yield break;
                }

                yield return(consumer.Consume);
            }
            finally
            {
                Release(consumer);
            }
        }
コード例 #19
0
 /// <summary>
 /// Scour with declarative principle
 /// </summary>
 /// <param name="enumerable"></param>
 protected override void ScourCore(IEnumerable <EventBusBaseAttribute> enumerable)
 {
     foreach (var item in enumerable.Where(t => t.GetType() != typeof(EventBusAssemblyScourAttribute)))
     {
         if (item is EventBusEventAttribute)
         {
             Events.Add(item.EventType);
         }
         else if (item is EventBusCommandAttribute)
         {
             Commands.Add(item.EventType);
         }
         else if (item is EventBusConsumerAttribute)
         {
             Consumes.Add(item.EventType);
         }
     }
 }
コード例 #20
0
        protected virtual UnsubscribeAction ConnectWorker <TComponent, TMessage>(ISubscriberContext context, Consumes <Distributed <TMessage> > .Selected consumer)
            where TComponent : Consumes <Distributed <TMessage> > .Selected
            where TMessage : class
        {
            var sink = new WorkerMessageSink <Distributed <TMessage> >(message =>
            {
                // rock it
                return(consumer.Accept(message) ? (Action <Distributed <TMessage> >)consumer.Consume : null);
            });

            return(context.Pipeline.ConnectToRouter(sink, () => context.SubscribedTo <Distributed <TMessage> >()));
        }
コード例 #21
0
 public void AttachConsumer(Consumes <T> consumer)
 {
     _consumer = consumer;
 }
コード例 #22
0
        //public List<Security> security { get; set; }

        public void Serialize(JsonWriter writer)
        {
            writer.WritePropertyName(Id);

            writer.WriteStartObject();

            if (Tags != null && Tags.Any())
            {
                writer.WritePropertyName("tags");
                writer.WriteStartArray();
                foreach (string tag in Tags)
                {
                    writer.WriteValue(tag);
                }
                writer.WriteEndArray();
            }

            if (!string.IsNullOrWhiteSpace(Summary))
            {
                writer.WritePropertyName("summary");
                writer.WriteValue(Summary);
            }

            if (!string.IsNullOrWhiteSpace(Description))
            {
                writer.WritePropertyName("description");
                writer.WriteValue(Description);
            }

            if (ExternalDocs != null)
            {
                writer.WritePropertyName("externalDocs");
                ExternalDocs.Serialize(writer);
            }

            if (!string.IsNullOrWhiteSpace(OperationId))
            {
                writer.WritePropertyName("operationId");
                writer.WriteValue(OperationId);
            }

            if (Consumes != null && Consumes.Any())
            {
                writer.WritePropertyName("consumes");
                writer.WriteStartArray();
                foreach (string cons in Consumes)
                {
                    writer.WriteValue(cons);
                }
                writer.WriteEndArray();
            }

            if (Produces != null && Produces.Any())
            {
                writer.WritePropertyName("produces");
                writer.WriteStartArray();
                foreach (string prod in Produces)
                {
                    writer.WriteValue(prod);
                }
                writer.WriteEndArray();
            }

            if (Parameters != null && Parameters.Any())
            {
                writer.WritePropertyName("parameters");
                writer.WriteStartArray();
                foreach (ParameterBase p in Parameters)
                {
                    p.Serialize(writer);
                }
                writer.WriteEndArray();
            }

            if (Responses != null && Responses.Any())
            {
                writer.WritePropertyName("responses");
                writer.WriteStartObject();
                foreach (Response r in Responses)
                {
                    r.Serialize(writer);
                }
                writer.WriteEndObject();
            }

            if (Schemes != null && Schemes.Any())
            {
                writer.WritePropertyName("schemes");
                writer.WriteStartArray();
                foreach (string sch in Schemes)
                {
                    writer.WriteValue(sch);
                }
                writer.WriteEndArray();
            }
            if (Deprecated)
            {
                writer.WritePropertyName("deprecated");
                writer.WriteValue(Deprecated);
            }

            writer.WriteEndObject();
        }
コード例 #23
0
 public void AttachConsumer(Consumes <TProduces> consumer)
 {
     _inner = consumer;
 }
コード例 #24
0
 public void AttachConsumer(Consumes <T> consumer)
 {
     multiplexor.AttachConsumer(consumer);
 }
コード例 #25
0
 public static IConsumeContext <T> MessageContext <T>(this Consumes <T> .All instance)
     where T : class
 {
     return(ContextStorage.MessageContext <T>());
 }
コード例 #26
0
        /// <summary>
        /// Compare a modified document node (this) to a previous one and look for breaking as well as non-breaking changes.
        /// </summary>
        /// <param name="context">The modified document context.</param>
        /// <param name="previous">The original document model.</param>
        /// <returns>A list of messages from the comparison.</returns>
        public override IEnumerable <ComparisonMessage> Compare(
            ComparisonContext <ServiceDefinition> context,
            Operation previous
            )
        {
            var priorOperation = previous;

            var currentRoot  = context.CurrentRoot;
            var previousRoot = context.PreviousRoot;

            if (priorOperation == null)
            {
                throw new ArgumentException("previous");
            }

            base.Compare(context, previous);

            if (OperationId != priorOperation.OperationId)
            {
                context.LogBreakingChange(ComparisonMessages.ModifiedOperationId, priorOperation.OperationId, OperationId);
            }
            Extensions.TryGetValue("x-ms-long-running-operation", out var currentLongrunningOperationValue);
            priorOperation.Extensions.TryGetValue("x-ms-long-running-operation", out var priorLongrunningOperationValue);

            currentLongrunningOperationValue = currentLongrunningOperationValue == null ? false : currentLongrunningOperationValue;
            priorLongrunningOperationValue   = priorLongrunningOperationValue == null ? false : priorLongrunningOperationValue;
            if (!currentLongrunningOperationValue.Equals(priorLongrunningOperationValue))
            {
                context.LogBreakingChange(ComparisonMessages.XmsLongRunningOperationChanged);
            }

            CheckParameters(context, priorOperation);

            // Check that all the request body formats that were accepted still are.

            context.PushProperty("consumes");
            foreach (var format in priorOperation.Consumes)
            {
                if (!Consumes.Contains(format))
                {
                    context.LogBreakingChange(ComparisonMessages.RequestBodyFormatNoLongerSupported, format);
                }
            }
            context.Pop();

            // Check that all the response body formats were also supported by the old version.

            context.PushProperty("produces");
            foreach (var format in Produces)
            {
                if (!priorOperation.Produces.Contains(format))
                {
                    context.LogBreakingChange(ComparisonMessages.ResponseBodyFormatNowSupported, format);
                }
            }
            context.Pop();

            if (Responses != null && priorOperation.Responses != null)
            {
                context.PushProperty("responses");
                foreach (var response in Responses)
                {
                    var oldResponse = priorOperation.FindResponse(response.Key, priorOperation.Responses);

                    context.PushProperty(response.Key);

                    if (oldResponse == null)
                    {
                        context.LogBreakingChange(ComparisonMessages.AddingResponseCode, response.Key);
                    }
                    else
                    {
                        response.Value.Compare(context, oldResponse);
                    }

                    context.Pop();
                }

                foreach (var response in priorOperation.Responses)
                {
                    var newResponse = this.FindResponse(response.Key, this.Responses);

                    if (newResponse == null)
                    {
                        context.PushProperty(response.Key);
                        context.LogBreakingChange(ComparisonMessages.RemovedResponseCode, response.Key);
                        context.Pop();
                    }
                }
                context.Pop();
            }

            return(context.Messages);
        }
コード例 #27
0
 public JitMetricsProducer(Consumes <JitEventParser.Events.Verbose> jitVerbose, Consumes <RuntimeEventParser.Events.CountersV5_0> runtimeCounters)
 {
     _jitVerbose      = jitVerbose;
     _runtimeCounters = runtimeCounters;
 }
コード例 #28
0
        /// <summary>
        /// Compare a modified document node (this) to a previous one and look for breaking as well as non-breaking changes.
        /// </summary>
        /// <param name="context">The modified document context.</param>
        /// <param name="previous">The original document model.</param>
        /// <returns>A list of messages from the comparison.</returns>
        public override IEnumerable <ComparisonMessage> Compare(ComparisonContext context, SwaggerBase previous)
        {
            if (previous == null)
            {
                throw new ArgumentNullException("previous");
            }

            context.CurrentRoot  = this;
            context.PreviousRoot = previous;

            base.Compare(context, previous);

            var previousDefinition = previous as ServiceDefinition;

            if (previousDefinition == null)
            {
                throw new ArgumentException("Comparing a service definition with something else.");
            }

            if (Info != null && previousDefinition.Info != null)
            {
                context.PushProperty("info");
                context.PushProperty("version");

                CompareVersions(context, Info.Version, previousDefinition.Info.Version);

                context.Pop();
                context.Pop();
            }

            if (context.Strict)
            {
                // There was no version change between the documents. This is not an error, but noteworthy.
                context.LogInfo(ComparisonMessages.NoVersionChange);
            }

            // Check that all the protocols of the old version are supported by the new version.

            context.PushProperty("schemes");
            foreach (var scheme in previousDefinition.Schemes)
            {
                if (!Schemes.Contains(scheme))
                {
                    context.LogBreakingChange(ComparisonMessages.ProtocolNoLongerSupported, scheme);
                }
            }
            context.Pop();

            // Check that all the request body formats that were accepted still are.

            context.PushProperty("consumes");
            foreach (var format in previousDefinition.Consumes)
            {
                if (!Consumes.Contains(format))
                {
                    context.LogBreakingChange(ComparisonMessages.RequestBodyFormatNoLongerSupported, format);
                }
            }
            context.Pop();

            // Check that all the response body formats were also supported by the old version.

            context.PushProperty("produces");
            foreach (var format in Produces)
            {
                if (!previousDefinition.Produces.Contains(format))
                {
                    context.LogBreakingChange(ComparisonMessages.ResponseBodyFormatNowSupported, format);
                }
            }
            context.Pop();

            // Check that no paths were removed, and compare the paths that are still there.

            var newPaths = RemovePathVariables(Paths);

            context.PushProperty("paths");
            foreach (var path in previousDefinition.Paths.Keys)
            {
                var p = Regex.Replace(path, @"\{\w*\}", @"{}");

                context.PushProperty(path);

                Dictionary <string, Operation> operations = null;
                if (!newPaths.TryGetValue(p, out operations))
                {
                    context.LogBreakingChange(ComparisonMessages.RemovedPath, path);
                }
                else
                {
                    Dictionary <string, Operation> previousOperations = previousDefinition.Paths[path];
                    foreach (var previousOperation in previousOperations)
                    {
                        Operation newOperation = null;
                        if (!operations.TryGetValue(previousOperation.Key, out newOperation))
                        {
                            context.LogBreakingChange(ComparisonMessages.RemovedOperation, previousOperation.Value.OperationId);
                        }
                    }

                    foreach (var operation in operations)
                    {
                        Operation previousOperation = null;
                        if (previousDefinition.Paths[path].TryGetValue(operation.Key, out previousOperation))
                        {
                            context.PushProperty(operation.Key);
                            operation.Value.Compare(context, previousOperation);
                            context.Pop();
                        }
                    }
                }
                context.Pop();
            }
            context.Pop();

            newPaths = RemovePathVariables(CustomPaths);

            context.PushProperty("x-ms-paths");
            foreach (var path in previousDefinition.CustomPaths.Keys)
            {
                var p = Regex.Replace(path, @"\{\w*\}", @"{}");

                context.PushProperty(path);

                Dictionary <string, Operation> operations = null;
                if (!newPaths.TryGetValue(p, out operations))
                {
                    context.LogBreakingChange(ComparisonMessages.RemovedPath, path);
                }
                else
                {
                    Dictionary <string, Operation> previousOperations = previousDefinition.CustomPaths[path];
                    foreach (var previousOperation in previousOperations)
                    {
                        Operation newOperation = null;
                        if (!operations.TryGetValue(previousOperation.Key, out newOperation))
                        {
                            context.LogBreakingChange(ComparisonMessages.RemovedOperation, previousOperation.Value.OperationId);
                        }
                    }

                    foreach (var operation in operations)
                    {
                        Operation previousOperation = null;
                        if (previousDefinition.CustomPaths[path].TryGetValue(operation.Key, out previousOperation))
                        {
                            context.PushProperty(operation.Key);
                            operation.Value.Compare(context, previousOperation);
                            context.Pop();
                        }
                    }
                }
                context.Pop();
            }
            context.Pop();

            ReferenceTrackSchemas(this);
            ReferenceTrackSchemas(previousDefinition);

            context.PushProperty("parameters");
            foreach (var def in previousDefinition.Parameters.Keys)
            {
                SwaggerParameter parameter = null;
                if (!Parameters.TryGetValue(def, out parameter))
                {
                    context.LogBreakingChange(ComparisonMessages.RemovedClientParameter, def);
                }
                else
                {
                    context.PushProperty(def);
                    parameter.Compare(context, previousDefinition.Parameters[def]);
                    context.Pop();
                }
            }
            context.Pop();

            context.PushProperty("responses");
            foreach (var def in previousDefinition.Responses.Keys)
            {
                OperationResponse response = null;
                if (!Responses.TryGetValue(def, out response))
                {
                    context.LogBreakingChange(ComparisonMessages.RemovedDefinition, def);
                }
                else
                {
                    context.PushProperty(def);
                    response.Compare(context, previousDefinition.Responses[def]);
                    context.Pop();
                }
            }
            context.Pop();

            context.PushProperty("definitions");
            foreach (var def in previousDefinition.Definitions.Keys)
            {
                Schema schema    = null;
                Schema oldSchema = previousDefinition.Definitions[def];

                if (!Definitions.TryGetValue(def, out schema))
                {
                    if (oldSchema.IsReferenced)
                    {
                        // It's only an error if the definition is referenced in the old service.
                        context.LogBreakingChange(ComparisonMessages.RemovedDefinition, def);
                    }
                }
                else if (schema.IsReferenced && oldSchema.IsReferenced)
                {
                    context.PushProperty(def);
                    schema.Compare(context, previousDefinition.Definitions[def]);
                    context.Pop();
                }
            }
            context.Pop();

            context.Pop();

            return(context.Messages);
        }
 public ContentionMetricsProducer(Consumes <ContentionEventParser.Events.Info> contentionInfo, Consumes <RuntimeEventParser.Events.Counters> runtimeCounters)
 {
     _contentionInfo  = contentionInfo;
     _runtimeCounters = runtimeCounters;
 }
コード例 #30
0
 public virtual void Attach(Consumes <T> consumer)
 {
     Background.Attach(consumer);
 }