示例#1
0
文件: PipelineManager.cs 项目: rpj/rg
        // [1] Use TaskCreationOptions.LongRunning here not because the consituent operations are
        // coarse-grained (they aren't and could in fact benefit from parallelization in future iterations),
        // but because this hint informs the scheduler not to schedule the task on the local queue
        // which - given that this method is called from an HTTP-request-handling thread - would
        // schedule it on the same work queue that future HTTP requests would be serviced from.
        // Further information here: https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.taskscheduler?view=netframework-4.8#long-running-tasks
        public object Queue(PipelineBase pipeline,
                            PipelineRequestTracker?initiator,
                            bool trackAfterCompletion = false)
        {
            _pipelinesMutex.WaitOne();
            if (_pipelines.ContainsKey(pipeline.Id))
            {
                return(null);
            }

            if (pipeline.Status < PipelineBase.PipelineStatus.Pending)
            {
                return(null);
            }

            var tracker = new PipelineTracker()
            {
                Pipeline     = pipeline,
                Initiator    = initiator,
                Created      = DateTime.UtcNow,
                LastAccessed = null,
                QueueToken   = Guid.NewGuid().ToString(),
                OriginalCompletionHandler = pipeline.CompletionHandler,
                TrackAfterCompletion      = trackAfterCompletion
            };

            pipeline.CompletionHandler = OnPipelineStateChance;
            tracker.Task = Task.Factory.StartNew(pipeline.Execute, TaskCreationOptions.LongRunning /* [1] */);

            _pipelines[pipeline.Id] = tracker;
            _pipelinesMutex.ReleaseMutex();

            return(_pipelines[pipeline.Id].QueueToken);
        }
示例#2
0
        static Task SendMessage(this IBehaviorContext context, Type messageType, object message, SendOptions options)
        {
            var settings = context.Builder.Build <ReadOnlySettings>();
            var pipeline = new PipelineBase <IOutgoingSendContext>(context.Builder, settings, settings.Get <PipelineConfiguration>().MainPipeline);

            var outgoingContext = new OutgoingSendContext(
                new OutgoingLogicalMessage(messageType, message),
                options,
                context);

            return(pipeline.Invoke(outgoingContext));
        }
示例#3
0
        public static Task Unsubscribe(IBehaviorContext context, Type eventType, UnsubscribeOptions options)
        {
            var settings = context.Builder.Build <ReadOnlySettings>();
            var pipeline = new PipelineBase <IUnsubscribeContext>(context.Builder, settings, settings.Get <PipelineConfiguration>().MainPipeline);

            var subscribeContext = new UnsubscribeContext(
                context,
                eventType,
                options);

            return(pipeline.Invoke(subscribeContext));
        }
示例#4
0
        TransportReceiver BuildPipelineInstance(PipelineModifications modifications, string name, PushSettings pushSettings, PushRuntimeSettings runtimeSettings)
        {
            var pipelineInstance = new PipelineBase <ITransportReceiveContext>(builder, settings, modifications);
            var receiver         = new TransportReceiver(
                name,
                builder,
                builder.Build <IPushMessages>(),
                pushSettings,
                pipelineInstance,
                runtimeSettings);

            return(receiver);
        }
示例#5
0
        public static Task Reply(IBehaviorContext context, object message, ReplyOptions options)
        {
            var settings = context.Builder.Build <ReadOnlySettings>();
            var pipeline = new PipelineBase <IOutgoingReplyContext>(
                context.Builder,
                settings,
                settings.Get <PipelineConfiguration>().MainPipeline);

            var outgoingContext = new OutgoingReplyContext(
                new OutgoingLogicalMessage(message),
                options,
                context);

            return(pipeline.Invoke(outgoingContext));
        }
示例#6
0
 internal PowerShellStopper(ExecutionContext context, PowerShell powerShell)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     this.powerShell = powerShell != null ? powerShell : throw new ArgumentNullException(nameof(powerShell));
     if (context.CurrentCommandProcessor == null || context.CurrentCommandProcessor.CommandRuntime == null || (context.CurrentCommandProcessor.CommandRuntime.PipelineProcessor == null || context.CurrentCommandProcessor.CommandRuntime.PipelineProcessor.LocalPipeline == null))
     {
         return;
     }
     this.eventHandler           = new EventHandler <PipelineStateEventArgs>(this.LocalPipeline_StateChanged);
     this.pipeline               = (PipelineBase)context.CurrentCommandProcessor.CommandRuntime.PipelineProcessor.LocalPipeline;
     this.pipeline.StateChanged += this.eventHandler;
 }
        public async Task <object> GetResult(PipelineBase pi)
        {
            object x = "";

            await Task.Factory.StartNew(async() =>
            {
                await pi.ExecutePipeline();
                x = pi.GetResult();
                do
                {
                    await Task.Delay(200);
                } while (x == null);
                return(Task.FromResult(x));
            });

            return(Task.FromResult(x));
        }
示例#8
0
 internal PowerShellStopper(ExecutionContext context, PowerShell powerShell)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if (powerShell == null)
     {
         throw new ArgumentNullException("powerShell");
     }
     this.powerShell = powerShell;
     if (((context.CurrentCommandProcessor != null) && (context.CurrentCommandProcessor.CommandRuntime != null)) && ((context.CurrentCommandProcessor.CommandRuntime.PipelineProcessor != null) && (context.CurrentCommandProcessor.CommandRuntime.PipelineProcessor.LocalPipeline != null)))
     {
         this.eventHandler           = new EventHandler <PipelineStateEventArgs>(this.LocalPipeline_StateChanged);
         this.pipeline               = context.CurrentCommandProcessor.CommandRuntime.PipelineProcessor.LocalPipeline;
         this.pipeline.StateChanged += this.eventHandler;
     }
 }
示例#9
0
文件: PipelineManager.cs 项目: rpj/rg
        private void OnPipelineStateChance(PipelineBase p)
        {
            var tracker = LockingGetter <PipelineTracker>(p.Id, null);

            tracker.Completed = DateTime.UtcNow;

            if (tracker?.OriginalCompletionHandler != null)
            {
                tracker.OriginalCompletionHandler(p);
            }

            lock (this)
            {
                _lifetimeStats.Count          += p.RecordCount;
                _lifetimeStats.GenerationTime += p.Elapsed;
                if (!_lifetimeStats.ResultFreq.ContainsKey(p.Status.ToString()))
                {
                    _lifetimeStats.ResultFreq[p.Status.ToString()] = 0;
                }
                p.Specifications.ForEach(s => {
                    if (!_lifetimeStats.SpecFreq.ContainsKey(s))
                    {
                        _lifetimeStats.SpecFreq[s] = 0;
                    }
                    _lifetimeStats.SpecFreq[s]++;
                });
                p.Artifacts.ForEach(a => {
                    if (!_lifetimeStats.OutputFreq.ContainsKey(a.Type))
                    {
                        _lifetimeStats.OutputFreq[a.Type] = 0;
                    }
                    _lifetimeStats.OutputFreq[a.Type]++;
                });
                _lifetimeStats.ResultFreq[p.Status.ToString()]++;
                _lifetimeStats.Jobs++;
            }

            if (!tracker.TrackAfterCompletion)
            {
                Remove(p.Id);
            }
        }
示例#10
0
        public static void TestDrawLine()
        {
            PipelineBase <AppdataBasic, V2FBasic> pipeline = new PipelineBase <AppdataBasic, V2FBasic>();
            CharRenderBuffer <float> charBuffer            = new CharRenderBuffer <float>(pipeline.RenderTarget);

            RenderEntity entity = new RenderEntity(new Transform(Vector3.Zero),
                                                   new Model(
                                                       vertices: new Vector3[] { new Vector3(-.5f, .5f, -.5f), new Vector3(-.5f, -.5f, -.5f), new Vector3(.5f, -.5f, -.5f), new Vector3(.5f, .5f, -.5f),
                                                                                 new Vector3(-.5f, .5f, .5f), new Vector3(-.5f, -.5f, .5f), new Vector3(.5f, -.5f, .5f), new Vector3(.5f, .5f, .5f) },
                                                       primitives: new IPrimitive[] { new LinePrimitive(0, 1), new LinePrimitive(1, 2), new LinePrimitive(2, 3), new LinePrimitive(3, 0),
                                                                                      new LinePrimitive(4, 5), new LinePrimitive(5, 6), new LinePrimitive(6, 7), new LinePrimitive(7, 4),
                                                                                      new LinePrimitive(0, 4), new LinePrimitive(1, 5), new LinePrimitive(2, 6), new LinePrimitive(3, 7) },
                                                       uvs: null,
                                                       normals: null
                                                       ), null);
            ICamera camera = new Camera_Orthographic(width: 3.5f, height: 3.5f, near: -2.5f, far: 2.5f,
                                                     new Transform(
                                                         pos: Vector3.Zero,
                                                         rotation: new Vector3(0, JMath.PI_HALF * .35f, -JMath.PI_HALF * 1.5f)));

            RenderEntity[] entitiesApply = new RenderEntity[] { entity };

            float framerate     = 25f;
            float time          = 10f;
            int   totalFrame    = (int)(framerate * time);
            float angleStep     = JMath.PI_TWO / totalFrame;
            int   frameInterval = (int)(1000f / framerate);

            for (int i = 0; i < totalFrame; i++)
            {
                pipeline.Draw(entitiesApply, camera);
                CRenderer.Render(charBuffer);
                entity.Transform.Rotation.X += angleStep;
                entity.Transform.Rotation.Z += angleStep;
                Thread.Sleep(frameInterval);
            }
        }
示例#11
0
 public PipelineStep(PipelineBase <T1> previous, Func <T1, T2> func)
 {
     this.previous = previous;
     this.func     = func;
 }
示例#12
0
 public OrderMaintainingPipelineParallelStep(PipelineBase <T1> previous, Func <T1, T2> func)
 {
     this.previous = previous;
     this.func     = func;
 }
示例#13
0
 public PipelineBlockingStep(PipelineBase <T> previous)
 {
     this.previous = previous;
 }
示例#14
0
 public AnimationPipeline(PipelineBase TimeReference)
 {
     Reference = TimeReference;
 }