Пример #1
0
        public void Evaluate(int SpreadMax)
        {
            SpreadMax = FInput.IsAnyInvalid() || FIndex.IsAnyInvalid()? 0 : FIndex.CombineWith(FIndex);

            if (SpreadMax == 0)
            {
                FOutput.FlushNil();
                return;
            }
            else
            {
                if (!FIndex.IsChanged && !FInput.IsChanged)
                {
                    return;
                }
            }

            FOutput.SliceCount = SpreadMax;

            for (int i = 0; i < SpreadMax; i++)
            {
                FOutput[i].AssignFrom(FInput[FIndex[i]]);
            }
            FOutput.Flush();
        }
Пример #2
0
#pragma warning restore

        public void Evaluate(int SpreadMax)
        {
            if ((!FInput.IsChanged && !FRemove.IsChanged))
            {
                return;
            }

            if ((FRemove.IsAnyInvalid() || FInput.IsAnyInvalid()))
            {
                if (FOutput.SliceCount > 0)
                {
                    FOutput.FlushResult(FInput);
                    return;
                }
                else
                {
                    return;
                }
            }

            SpreadMax          = FInput.SliceCount;
            FOutput.SliceCount = SpreadMax;

            for (int i = 0; i < SpreadMax; i++)
            {
                var remains = from msg in FInput[i]
                              where !FRemove.Contains(msg)
                              select msg;

                FOutput[0].SliceCount = 0;
                FOutput[0].AssignFrom(remains);
            }
            FOutput.Flush();
        }
        public override void Evaluate(int SpreadMax)
        {
            if (Default != null && !FInput.IsChanged)
            {
                return;
            }

            if (FInput.IsAnyInvalid())
            {
                if (Default == null)
                {
                    NewDefault();
                }

                FOutput.SliceCount = 1;

                Default.Topic = FTopic[0];
                FOutput[0]    = Default;
                FOutput.Flush();
            }
            else
            {
                FOutput.FlushResult(FInput);
            }
        }
Пример #4
0
        public override void Evaluate(int SpreadMax)
        {
            // graceful fallback when being fed bad data
            if (FNew.IsAnyInvalid() || FTopic.IsAnyInvalid() || FSpreadCount.IsAnyInvalid())
            {
                FOutput.FlushNil();
                return;
            }

            if (!FNew.Any() && !ForceNewDefaults)
            {
                FOutput.FlushNil();
                return;
            }

            SpreadMax          = FFormularSelection.SliceCount; // numbers of supported Formulars
            FOutput.SliceCount = SpreadMax;

            var counter = 0;

            for (int i = 0; i < SpreadMax; i++)
            {
                var             formularName = FFormularSelection[i].Name;
                MessageFormular formular;
                try
                {
                    formular = RetrieveRegisteredFormular(formularName);
                } catch (RegistryException)
                {
                    formular = null;
                }

                if (formular == null || formular.IsDynamic)
                {
                    formular = new MessageFormular(formularName, ""); // empty fallback, in case not available or dynamic
                }
                FOutput[i].SliceCount = 0;

                var count = FSpreadCount[i];
                for (int j = 0; j < count; j++)
                {
                    if (FNew[counter] || ForceNewDefaults)
                    {
                        Message message = new Message(formular);
                        message.Topic = FTopic[counter];
                        FOutput[i].Add(message);
                    }
                    counter++;
                }
            }
            FOutput.Flush();

            ForceNewDefaults = false;
        }
Пример #5
0
        public void Evaluate(int SpreadMax)
        {
            if (MessageEnumerator == null)
            {
                return;
            }

            if (!FReset.IsAnyInvalid() && FReset[0])
            {
                MessageEnumerator.Reset();
            }

            if (FRead.IsAnyInvalid() || !FRead[0])
            {
                return;
            }

            FEndOfStream[0] = false;


            FOutput.SliceCount = 0;
            var maxCount = FCount[0];

            for (int i = 0; i < maxCount; i++)
            {
                try
                {
                    MessageEnumerator.MoveNext();
                    var message = MessageEnumerator.Current.ToObject <Message>();
                    FOutput.Add(message);
                }
                catch (Exception e)
                {
                    MessageEnumerator.Reset();
                    FEndOfStream[0] = true;

                    FLogger.Log(LogType.Debug, e.ToString());
                }
            }
            FOutput.Flush();

            FError[0] = "";
        }
Пример #6
0
        public void Evaluate(int SpreadMax)
        {
            if ((!FInput.IsChanged))
            {
                return;
            }

            if (FInput.IsAnyInvalid())
            {
                FOutput.FlushNil();
                return;
            }

            var remains = from msg in FInput
                          where msg != null
                          where !msg.IsEmpty
                          select msg;

            FOutput.FlushResult(remains);
        }
Пример #7
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FIndex.IsChanged)
            {
                Indices.Clear();
                foreach (var id in FIndex)
                {
                    int track = (int)id.x;
                    if (!Indices.ContainsKey(track))
                    {
                        Indices[track] = new HashSet <int>();
                    }
                    Indices[track].Add((int)id.y);
                }
            }

            if (FInput.IsAnyInvalid() || FIndex.IsAnyInvalid())
            {
                if (FOutput.SliceCount > 0)
                {
                    FOutput.SliceCount = 0;
                    FOutput.Flush();
                }
                return;
            }

            FOutput.SliceCount = 0;

            var search = from message in FInput
                         let track = (message["TrackId"] as Bin <int>).First
                                     where Indices.ContainsKey(track)
                                     let clip = (message["ClipId"] as Bin <int>).First
                                                where Indices[track].Contains(clip)
                                                select message;

            FOutput.AssignFrom(search);

            FOutput.Flush();
        }
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FInput.IsAnyInvalid())
            {
                if (FOutput.SliceCount > 0)
                {
                    FOutput.SliceCount = 0;
                    FOutput.Flush();
                }
                return;
            }

            FOutput.SliceCount = 0;

            FOutput.AssignFrom(
                from message in FInput
                let bin = message["Foo"] as Bin <string>
                          where bin.First == "bar"
                          select message
                );

            FOutput.Flush();
        }
Пример #9
0
        public override void Evaluate(int SpreadMax)
        {
            // graceful fallback when being fed bad data
            if (FNew.IsAnyInvalid() || FTopic.IsAnyInvalid() || FSpreadCount.IsAnyInvalid())
            {
                FOutput.FlushNil();
                return;
            }

            if (!FNew.Any() && !ForceNewDefaults)
            {
                FOutput.FlushNil();
                return;
            }

            SpreadMax          = FFormularSelection.SliceCount; // numbers of supported Formulars
            FOutput.SliceCount = SpreadMax;

            var counter = 0;

            for (int i = 0; i < SpreadMax; i++)
            {
                var formularName = FFormularSelection[i].Name;
                var formular     = MessageFormularRegistry.Context[formularName];

                FOutput[i].SliceCount = 0;
                if (formular == null)
                {
                    continue;
                }

                var count = FSpreadCount[i];
                for (int j = 0; j < count; j++)
                {
                    if (FNew[counter] || ForceNewDefaults)
                    {
                        Message message = new Message();
                        message.Topic = FTopic[counter];
                        foreach (var field in formular.FieldNames)
                        {
                            int binsize = formular[field].DefaultSize;
                            binsize = binsize > 0 ? binsize : 1;
                            var type = formular[field].Type;

                            message[field] = BinFactory.New(type, binsize);

                            for (int slice = 0; slice < binsize; slice++)
                            {
                                message[field].Add(TypeIdentity.Instance.NewDefault(type));
                            }
                        }

                        FOutput[i].Add(message);
                    }
                    counter++;
                }
            }
            FOutput.Flush();

            ForceNewDefaults = false;
        }
Пример #10
0
        public override void Evaluate(int SpreadMax)
        {
            InitDX11Graph();

            #region early break
            if (
                !FInput.IsChanged &&
                !FConfig.IsChanged &&
                !FKey.IsChanged &&
                !FAvoidNil.ToISpread().IsChanged &&
                !FAvoidNilEnable.IsChanged &&
                !FSwapDim.IsChanged
                )
            {
                return;
            }

            SpreadMax = FInput.IsAnyInvalid() ? 0 : FInput.SliceCount;
            if (SpreadMax == 0)
            {
                if (!FAvoidNilEnable.IsAnyInvalid() && FAvoidNilEnable[0])
                {
                    var force = FAvoidNil.ToISpread().IsChanged || FAvoidNilEnable.IsChanged;
                    if (force || FOutput.SliceCount > 0) // zero inputs -> zero outputs.
                    {
                        FOutput.FlushNil();

                        // set a default
                        FBinSize.SliceCount = 1;
                        FBinSize[0]         = 1;
                        FBinSize.Flush();
                        FValue.ToISpread().SliceCount = 1;

                        var output  = (FValue.ToISpread())[0] as ISpread;
                        var dummies = GetDefaults(FAvoidNil.ToISpread(), 0).ToList();
                        output.SliceCount = dummies.Count;
                        for (int j = 0; j < dummies.Count; j++)
                        {
                            output[j] = dummies[j];
                        }

                        FValue.ToISpread().Flush();
                        return;
                    }
                    else
                    {
                        return;  // already defaulted
                    }
                }
                else
                {
                    var force = !FAvoidNilEnable.IsAnyInvalid() && !FAvoidNilEnable[0] && FAvoidNilEnable.IsChanged;
                    if (force || FOutput.SliceCount > 0) // zero inputs -> zero outputs.
                    {
                        FOutput.FlushNil();
                        FBinSize.SliceCount = 1;
                        FBinSize[0]         = 0;
                        FBinSize.Flush();
                        FValue.ToISpread().FlushNil();
                        return;
                    }
                    else
                    {
                        return;  // already zero'ed
                    }
                }
            }
            #endregion early break

            FOutput.FlushResult(FInput);

            var keyCount = FKey.SliceCount;
            FBinSize.SliceCount = SpreadMax;

            var binnedOutput = FValue.ToISpread();
            binnedOutput.SliceCount = SpreadMax * keyCount;

            if (!FSwapDim.IsAnyInvalid() && FSwapDim[0]) // fields first
            {
                for (int i = 0; i < keyCount; i++)
                {
                    var fieldName = FKey[i];
                    var count     = 0;
                    var index     = 0;
                    foreach (var message in FInput)
                    {
                        var output = (binnedOutput[i * keyCount + index] as ISpread);
                        SetData(message, index, fieldName, output);
                        count += output.SliceCount;
                        index++;
                    }
                    FBinSize[i] = count;
                }
            }
            else // messages first
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    Message message = FInput[i];
                    var     count   = 0;
                    var     index   = 0;
                    foreach (var fieldName in FKey)
                    {
                        var output = (binnedOutput[i * keyCount + index] as ISpread);
                        SetData(message, index, fieldName, output);
                        count += output.SliceCount;
                        index++;
                    }
                    FBinSize[i] = count;
                }
            }

            binnedOutput.Flush();
            FBinSize.Flush();
        }
        public void Evaluate(int SpreadMax)
        {
            if (FConfiguration.IsAnyInvalid() || FName.IsAnyInvalid())
            {
                return;
            }

            ForceUpdate |= !FUpdate.IsAnyInvalid() && FUpdate[0];
            var change = ForceUpdate || FInherits.IsChanged || FName.IsChanged || FConfiguration.IsChanged;


            if (!ForceUpdate && !change)
            {
                if (_lastException != null)
                {
                    FError.FlushItem(_lastException.ToString());
                    throw _lastException;
                }
            }

            // untoggle exception.
            if (_lastException != null)
            {
                var tmp = _lastException;
                FError.FlushItem(_lastException.ToString());
                _lastException = null; // assume innocence
                throw tmp;
            }

            if (!change && !ForceUpdate)
            {
                return;
            }

            FOutput.SliceCount = SpreadMax = FName.SliceCount;

            var id  = this.PluginHost.GetNodePath(false);
            var reg = MessageFormularRegistry.Context;

            for (int i = 0; i < SpreadMax; i++)
            {
                if (string.IsNullOrWhiteSpace(FName[i]))
                {
                    _lastException = new ParseFormularException("A Formular cannot have an empty Name.");
                    return;
                }

                var config = string.Join(", ", FConfiguration[i]).Split(',');

                var fields = new List <FormularFieldDescriptor>();
                foreach (var def in config)
                {
                    FormularFieldDescriptor field;
                    try
                    {
                        field = new FormularFieldDescriptor(def.Trim(), true);
                    }
                    catch (ParseFormularException e)
                    {
                        _lastException = e;
                        return;
                    }

                    var match = (
                        from f in fields
                        where f.Name == field.Name
                        select f
                        ).FirstOrDefault();

                    if (match != null)
                    {
                        _lastException = new DuplicateFieldException("Cannot add \"" + def + "\" in Formular for [" + FName[i] + "]. Field with the same name already defined.", match, field);
                        return;
                    }
                    else
                    {
                        fields.Add(field);
                    }
                }


                var formular = new MessageFormular(FName[i], fields);

                if (!FInherits.IsAnyInvalid())
                {
                    // flatten
                    var allFields = (
                        from form in FInherits
                        from field in form.FieldDescriptors
                        select field
                        ).Distinct();

                    foreach (var field in allFields)
                    {
                        if (!formular.CanAppend(field))
                        {
                            var duplicate = formular[field.Name];
                            _lastException = new DuplicateFieldException("Cannot add new Field \"" + field.ToString() + "\" to Formular [" + formular.Name + "]. Field is already defined as \"" + duplicate.ToString() + "\".", field, duplicate);
                            return;
                        }
                        else
                        {
                            try
                            {
                                formular.Append(field, true);
                            }
                            catch (DuplicateFieldException e)
                            {
                                _lastException = e;
                                return;
                            }
                        }
                    }
                }

                // only register, when update has been hit!
                if (ForceUpdate)
                {
                    try
                    {
                        var defined = reg.Define(id, formular); // will raise Change events to inform all formularable nodes
                        if (defined)
                        {
                            FOutput[i] = formular;
                        }
                    }
                    catch (RegistryException e)
                    {
                        _lastException = e;
                        return;
                    }
                }