Ejemplo n.º 1
0
        /// <summary>
        /// This extension adds the inline command to the pipeline
        /// </summary>
        /// <typeparam name="E">The pipeline type.</typeparam>
        /// <param name="cpipe">The pipeline.</param>
        /// <param name="contract">The contract.</param>
        /// <param name="commandFunction">The command function.</param>
        /// <param name="referenceId">The reference identifier.</param>
        /// <param name="startupPriority">The startup priority.</param>
        /// <param name="channelResponse">The channel response.</param>
        /// <returns>Returns the pipeline.</returns>
        /// <exception cref="InvalidMessageContractException"></exception>
        /// <exception cref="InvalidPipelineChannelContractException"></exception>
        public static E AttachCommand <E>(this E cpipe, Type contract
                                          , Func <CommandMethodRequestContext, Task> commandFunction
                                          , string referenceId  = null
                                          , int startupPriority = 100
                                          , IPipelineChannelOutgoing <IPipeline> channelResponse = null
                                          )
            where E : IPipelineChannelIncoming <IPipeline>
        {
            string channelId, messageType, actionType;

            if (!ServiceMessageHelper.ExtractContractInfo(contract, out channelId, out messageType, out actionType))
            {
                throw new InvalidMessageContractException(contract);
            }

            if (channelId != cpipe.Channel.Id)
            {
                throw new InvalidPipelineChannelContractException(contract, channelId, cpipe.Channel.Id);
            }

            var command = new CommandMethodInline((channelId, messageType, actionType), commandFunction, referenceId);

            cpipe.Pipeline.AddCommand(command, startupPriority, null, cpipe, channelResponse);

            return(cpipe);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This extension method is used to add a command to the Microservice.
        /// </summary>
        /// <typeparam name="P">The pipeline type.</typeparam>
        /// <typeparam name="C">The command type.</typeparam>
        /// <param name="pipeline">The pipeline.</param>
        /// <param name="command">The command to add.</param>
        /// <param name="startupPriority">The optional start up priority. The default is 100.</param>
        /// <param name="assign">The command assignment action.</param>
        /// <param name="channelIncoming">The optional request channel.</param>
        /// <param name="channelResponse">The optional response channel.</param>
        /// <returns>Returns the pipeline.</returns>
        public static P AddCommand <P, C>(this P pipeline
                                          , C command
                                          , int startupPriority = 100
                                          , Action <C> assign   = null
                                          , IPipelineChannelIncoming <P> channelIncoming = null
                                          , IPipelineChannelOutgoing <P> channelResponse = null
                                          )
            where P : IPipeline
            where C : ICommand
        {
            command.StartupPriority = startupPriority;

            if (channelIncoming != null && command.ChannelIdAutoSet)
            {
                command.ChannelId = channelIncoming.Channel.Id;
            }

            if (channelResponse != null && command.ResponseChannelIdAutoSet)
            {
                command.ResponseChannelId = channelResponse.Channel.Id;
            }

            assign?.Invoke(command);
            pipeline.Service.Commands.Register(command);
            return(pipeline);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// This extension method is used to add a command to the Microservice.
 /// </summary>
 /// <typeparam name="P">The pipeline type.</typeparam>
 /// <typeparam name="C">The command type.</typeparam>
 /// <param name="pipeline">The pipeline.</param>
 /// <param name="startupPriority">The optional start up priority. The default is 100.</param>
 /// <param name="assign">The command assignment action.</param>
 /// <param name="channelIncoming">The optional request channel.</param>
 /// <param name="channelResponse">The optional response channel.</param>
 /// <returns>Returns the pipeline.</returns>
 public static P AddCommand <P, C>(this P pipeline
                                   , int startupPriority = 100
                                   , Action <C> assign   = null
                                   , IPipelineChannelIncoming <P> channelIncoming = null
                                   , IPipelineChannelOutgoing <P> channelResponse = null
                                   )
     where P : IPipeline
     where C : ICommand, new()
 {
     return(pipeline.AddCommand(new C(), startupPriority, assign, channelIncoming, channelResponse));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Attaches the command.
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <typeparam name="C"></typeparam>
        /// <param name="cpipe">The cpipe.</param>
        /// <param name="command">The command.</param>
        /// <param name="startupPriority">The startup priority.</param>
        /// <param name="assign">The assign.</param>
        /// <param name="channelResponse">The channel response.</param>
        /// <returns></returns>
        public static E AttachCommand <E, C>(this E cpipe
                                             , C command
                                             , int startupPriority = 100
                                             , Action <C> assign   = null
                                             , IPipelineChannelOutgoing <IPipeline> channelResponse = null
                                             )
            where E : IPipelineChannelIncoming <IPipeline>
            where C : ICommand
        {
            cpipe.Pipeline.AddCommand(command, startupPriority, assign, cpipe, channelResponse);

            return(cpipe);
        }
Ejemplo n.º 5
0
 public static P AddCommandUnity <P, I, C>(this P pipeline
                                           , Func <IEnvironmentConfiguration, C> creator
                                           , int startupPriority = 100
                                           , Action <C> assign   = null
                                           , IPipelineChannelIncoming <P> channelIncoming = null
                                           , IPipelineChannelOutgoing <P> channelResponse = null
                                           )
     where P : IPipelineWebApiUnity
     where C : I, ICommand
 {
     return(pipeline.AddCommandUnity <P, I, C>(creator(pipeline.Configuration)
                                               , startupPriority, assign, channelIncoming, channelResponse));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Attaches the command.
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <typeparam name="P"></typeparam>
        /// <typeparam name="C"></typeparam>
        /// <param name="cpipe">The cpipe.</param>
        /// <param name="creator">The creator.</param>
        /// <param name="startupPriority">The startup priority.</param>
        /// <param name="assign">The assign.</param>
        /// <param name="channelResponse">The channel response.</param>
        /// <returns></returns>
        public static E AttachCommand <E, P, C>(this E cpipe
                                                , Func <IEnvironmentConfiguration, C> creator
                                                , int startupPriority = 100
                                                , Action <C> assign   = null
                                                , IPipelineChannelOutgoing <IPipeline> channelResponse = null
                                                )
            where E : IPipelineChannelIncoming <IPipeline>
        //where P : IPipeline
            where C : ICommand
        {
            cpipe.Pipeline.AddCommand(creator, startupPriority, assign, cpipe, channelResponse);

            return(cpipe);
        }
Ejemplo n.º 7
0
        public static E AttachCommand <E>(this E cpipe
                                          , Func <TransmissionPayload, List <TransmissionPayload>, IPayloadSerializationContainer, Task> commandFunction
                                          , ServiceMessageHeader header
                                          , string referenceId  = null
                                          , int startupPriority = 100
                                          , IPipelineChannelOutgoing <IPipeline> channelResponse = null
                                          )
            where E : IPipelineChannelIncoming <IPipeline>
        {
            var command = new CommandInline(header, commandFunction, referenceId);

            cpipe.Pipeline.AddCommand(command, startupPriority, null, cpipe, channelResponse);

            return(cpipe);
        }
Ejemplo n.º 8
0
        public static P AddCommand <P>(this P pipeline
                                       , Func <TransmissionPayload, List <TransmissionPayload>, IPayloadSerializationContainer, Task> commandFunction
                                       , MessageFilterWrapper message
                                       , string referenceId  = null
                                       , int startupPriority = 100
                                       , IPipelineChannelIncoming <P> channelIncoming = null
                                       , IPipelineChannelOutgoing <P> channelResponse = null
                                       )
            where P : IPipeline
        {
            var command = new CommandInline(message, commandFunction, referenceId);

            pipeline.AddCommand(command, startupPriority, null, channelIncoming, channelResponse);

            return(pipeline);
        }
Ejemplo n.º 9
0
        public static P AddCommandUnity <P, I, C>(this P pipeline
                                                  , C command
                                                  , int startupPriority = 100
                                                  , Action <C> assign   = null
                                                  , IPipelineChannelIncoming <P> channelIncoming = null
                                                  , IPipelineChannelOutgoing <P> channelResponse = null
                                                  )
            where P : IPipelineWebApiUnity
            where C : I, ICommand
        {
            pipeline.AddCommand(command, startupPriority, assign, channelIncoming, channelResponse);

            pipeline.Unity.RegisterInstance <I>(command);

            return(pipeline);
        }
Ejemplo n.º 10
0
        protected virtual IPipeline Pipeline()
        {
            var pipeline = new MicroservicePipeline(GetType().Name);

            pipeline
            .AddDebugMemoryDataCollector(out mCollector)
            .AddPayloadSerializerDefaultJson()
            .AddChannelIncoming("internalIn", internalOnly: true)
            .AttachCommand(mCommand)
            .CallOut((c) => cpipeIn = c)
            .Revert()
            .AddChannelOutgoing("internalOut", internalOnly: true, autosetPartition01: false)
            .AttachPriorityPartition(0, 1)
            .CallOut((c) => cpipeOut = c)
            .Revert()
            .AddChannelIncoming("internalInit", internalOnly: true)
            .AttachCommandInitiator(out mCommandInit);

            return(pipeline);
        }
        public static IPipelineChannelOutgoing AttachTcpTlsSender(this IPipelineChannelOutgoing cpipe
                                                                  , string connectionName = null
                                                                  , IEnumerable <SenderPartitionConfig> priorityPartitions = null
                                                                  , string serviceBusConnection           = null
                                                                  , Action <TcpTlsChannelSender> onCreate = null)
        {
            throw new NotImplementedException();
            //var component = new AzureSBQueueSender();

            //component.ConfigureAzureMessaging(
            //      cpipe.Channel.Id
            //    , priorityPartitions ?? cpipe.Channel.Partitions.Cast<SenderPartitionConfig>()
            //    , null
            //    , connectionName ?? cpipe.Channel.Id
            //    , serviceBusConnection ?? cpipe.Pipeline.Configuration.ServiceBusConnection()
            //    );

            //onCreate?.Invoke(component);

            //cpipe.AttachSender(component, false);

            return(cpipe);
        }
Ejemplo n.º 12
0
        public void Pipeline1()
        {
            try
            {
                var pipeline = new MicroservicePipeline("TestPipeline");

                IPipelineChannelIncoming <MicroservicePipeline> cpipeIn     = null;
                IPipelineChannelOutgoing <MicroservicePipeline> cpipeOut    = null;
                PersistenceInternalService <Guid, Blah>         persistence = null;
                PersistenceBlahMemory    persistBlah = null;
                DebugMemoryDataCollector collector;

                int signalChange = 0;

                pipeline
                .AddDebugMemoryDataCollector(out collector)
                .AdjustPolicyTaskManager((t, c) =>
                {
                    t.ConcurrentRequestsMin = 1;
                    t.ConcurrentRequestsMax = 4;
                })
                .CallOut(ConfigureServiceRoot)
                .CallOut(CallOutDefault)
                .AddChannelIncoming("internalIn", internalOnly: true)
                .CallOut(ChannelInConfigure, (c) => true)
                .AttachCommand(new PersistenceBlahMemory(profile: "Blah"), assign: (p) => persistBlah    = p)
                .AttachCommand(new PersistenceInternalService <Guid, Blah>(), assign: (c) => persistence = c, channelResponse: cpipeOut)
                .CallOut((c) => cpipeIn = c)
                .Revert()
                .AddChannelOutgoing("internalOut", internalOnly: true)
                .CallOut(ChannelOutConfigure, (c) => false)
                .CallOut((c) => cpipeOut = c)
                .Revert();

                persistBlah.OnEntityChangeAction += ((o, e) => { signalChange++; });

                pipeline.Start();


                Guid cId  = Guid.NewGuid();
                var  blah = new Blah {
                    ContentId = cId, Message = "Hello", VersionId = Guid.NewGuid()
                };
                var result = persistence.Create(blah).Result;
                Assert.IsTrue(result.IsSuccess);

                var result2 = persistence.Read(cId).Result;
                Assert.IsTrue(result2.IsSuccess);

                blah.VersionId = Guid.NewGuid();
                var result3 = persistence.Update(blah).Result;
                Assert.IsTrue(result3.IsSuccess);

                var result4 = persistence.Delete(blah.ContentId).Result;
                Assert.IsTrue(result4.IsSuccess);


                Assert.IsTrue(signalChange == 3);

                Assert.IsTrue(calloutDefault.HasValue);
                Assert.IsTrue(calloutIn.HasValue);
                Assert.IsFalse(calloutOut.HasValue);

                pipeline.Stop();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Ejemplo n.º 13
0
 private void ChannelOutConfigure(IPipelineChannelOutgoing <MicroservicePipeline> inPipe)
 {
     calloutOut = true;
 }
Ejemplo n.º 14
0
        public void Pipeline2()
        {
            try
            {
                DebugMemoryDataCollector collector1, collector1a, collector2;
                CommandInitiator         init  = null;
                CommandInitiator         init2 = null;

                IPipelineChannelIncoming <MicroservicePipeline> cpipeIn  = null;
                IPipelineChannelOutgoing <MicroservicePipeline> cpipeOut = null;

                var fabric       = new ManualFabricBridge();
                var bridgeOut    = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.RoundRobin);
                var bridgeReturn = new ManualCommunicationBridgeAgent(fabric, CommunicationBridgeMode.Broadcast);

                //bridgeReturn.Agent.OnReceive += (o, e) => { if (e.Payload.Extent.Days == 42) init.ToString(); };
                //bridgeReturn.Agent.OnException += (o, e) => { if (e.Payload.Extent.Days == 42) init.ToString(); };

                var pClient  = new MicroservicePipeline("Client");
                var pClient2 = new MicroservicePipeline("Client2");
                var pServer  = new MicroservicePipeline("Server");

                pServer
                .AdjustPolicyTaskManagerForDebug()
                .AddDebugMemoryDataCollector(out collector2)
                .AddPayloadSerializerDefaultJson()
                .AddChannelIncoming("internalIn", internalOnly: false
                                    , autosetPartition01: false
                                    , assign: (p, c) => cpipeIn = p)
                .AttachPriorityPartition((0, 1.0M), (1, 0.9M))
                .AttachListener(bridgeOut.GetListener())
                .AttachMessagePriorityOverrideForResponse()
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(200, payload.Message);
                    return(Task.FromResult(0));
                }, ("franky", "johnny5"))
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(201, payload.Message);
                    return(Task.FromResult(0));
                }, ("franky", "johnny6"))
                .Revert()
                .AddChannelOutgoing("return")
                .AttachSender(bridgeReturn.GetSender())
                .Revert();
                ;

                pClient
                .AdjustPolicyTaskManagerForDebug()
                .AddDebugMemoryDataCollector(out collector1)
                .AddChannelIncoming("spooky", internalOnly: true)
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(200, payload.Message);
                    return(Task.FromResult(0));
                }, ("franky", "johnny5"))
                .Revert()
                .AddChannelIncoming("return")
                .AttachListener(bridgeReturn.GetListener())
                .AttachMessagePriorityOverrideForResponse()
                .AttachCommandInitiator(out init)
                .Revert()
                .AddChannelOutgoing("internalIn", internalOnly: false
                                    , autosetPartition01: false
                                    , assign: (p, c) => cpipeOut = p)
                .AttachPriorityPartition(0, 1)
                .AttachSender(bridgeOut.GetSender())
                .Revert()
                ;


                pClient2
                .AdjustPolicyTaskManagerForDebug()
                .AddDebugMemoryDataCollector(out collector1a)
                .AddChannelIncoming("spooky", internalOnly: true)
                .AttachCommand((CommandMethodRequestContext ctx) =>
                {
                    var payload = ctx.DtoGet <Blah>();
                    ctx.ResponseSet(200, payload.Message);
                    return(Task.FromResult(0));
                }, ("franky", "johnny5"))
                .Revert()
                .AddChannelIncoming("return")
                .AttachListener(bridgeReturn.GetListener())
                .AttachMessagePriorityOverrideForResponse()
                .AttachCommandInitiator(out init2)
                .Revert()
                .AddChannelOutgoing("internalIn", internalOnly: false
                                    , autosetPartition01: false)
                .AttachPriorityPartition(0, 1)
                .AttachSender(bridgeOut.GetSender())
                .Revert()
                ;

                pClient.Start();
                pClient2.Start();
                pServer.Start();

                init.OnRequestUnresolved  += Init_OnRequestUnresolved;
                init2.OnRequestUnresolved += Init_OnRequestUnresolved;

                var list = new List <Task <ResponseWrapper <string> > >();

                list.Add(init.Process <IPipelineTest2, Blah, string>(new Blah()
                {
                    Message = "hello1"
                }));
                list.Add(init.Process <Blah, string>("internalIn", "franky", "johnny5", new Blah()
                {
                    Message = "hello2"
                }));
                list.Add(init.Process <Blah, string>(("internalIn", "franky", "johnny5"), new Blah()
                {
                    Message = "hello3"
                }));
                list.Add(init.Process <Blah, string>(("internalIn", "franky", "johnny6"), new Blah()
                {
                    Message = "hello3"
                }));
                list.Add(init.Process <Blah, string>(("spooky", "franky", "johnny5"), new Blah()
                {
                    Message = "hellospooky"
                }));

                var result = Task.WhenAll(list).Result;

                result.ForEach((r) => Assert.IsTrue(r.ResponseCode == 200 || r.ResponseCode == 201));

                pClient.Stop();
                pClient2.Stop();
                pServer.Stop();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }