コード例 #1
0
        public void Evaluate(int spreadMax)
        {
            Synchronizing?.Invoke(this, EventArgs.Empty);

            var buildResult = FBuildResult;

            if (buildResult.Error != null)
            {
                // This way the vvvv plugin node stays red
                PluginHost.LastRuntimeError = buildResult.Error;
                return;
            }
            else if (!string.IsNullOrEmpty(buildResult.SymbolError))
            {
                PluginHost.LastRuntimeError = buildResult.SymbolError;
            }

            var runtimeHost = FRuntimeHost;

            if (runtimeHost.Mode == RunMode.Paused || runtimeHost.Mode == RunMode.Stopped)
            {
                if (FMessages.Errors.Any())
                {
                    PluginHost.LastRuntimeError = FMessages.Errors.FirstOrDefault().What;
                }
                return;
            }

            var x = Clocks.FrameClock.Time; // hack. make sure that somebody is interested in time. otherwise HDEFrameClock observable will not trigger.

            try
            {
                RuntimeGraph.HandleException(NodeId);

                spreadMax = StreamUtils.GetSpreadMax(FInStreams);

                // Prepare internal state
                if (FInstances.Length != spreadMax)
                {
                    var instanceType = buildResult.InstanceType;
                    if (instanceType != null)
                    {
                        FInstances.Resize(spreadMax, () => buildResult.Factory.CreateInstance(instanceType, FInstanceId), value => Dispose(value));
                    }
                    else
                    {
                        FInstances.Resize(spreadMax, () => null, value => Dispose(value));
                    }
                }

                buildResult.EvaluateAction(spreadMax, FInstances, FInStreams, FOutStreams);
            }
            catch (RuntimeException exception)
            {
                // Collect the exception messages
                foreach (var p in exception.ExtractElementMessages(runtimeHost.Compilation.Compilation))
                {
                    FMessages.Add(p.Key.TracingId, MessageSeverity.Error, p.Value);
                }
                // Let others know about it
                runtimeHost.RaiseOnException(exception);
                // And finally tell vvvv about it
                throw exception.Original;
            }
            finally
            {
                Flushing?.Invoke(this, EventArgs.Empty);
            }
        }