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 override void Evaluate(int SpreadMax) { if (FInput.IsAnyInvalid()) { FOutput.FlushNil(); return; // if no input, no further calculation. } bool doFlush = false; // any of the update slices is true -> update the plugin. var anyUpdate = FUpdate.Any(); // Flush upstream changes through the plugin if (FInput.IsChanged) { FOutput.SliceCount = 0; FOutput.AssignFrom(FInput); doFlush = true; } else if (!anyUpdate) { return; } var keyCount = FKey.SliceCount; var ValueSpread = FValue.ToISpread(); bool newData = ValueSpread.IsChanged; // changed pin newData |= !FAutoSense[0]; // assume newData, if AutoSense is off. if (anyUpdate && newData) { SpreadMax = FInput.SliceCount; doFlush = true; for (int i = 0; i < SpreadMax; i++) { Message message = FInput[i]; var keyIndex = 0; foreach (var key in FKey) { var fieldIndex = i * keyCount + keyIndex; keyIndex++; if (!FUpdate[fieldIndex]) { continue; } if (!message.Fields.Contains(key)) { message[key] = BinFactory.New(TargetDynamicType); } var value = ValueSpread[fieldIndex] as ISpread; if (value.SliceCount > 0) { if (message[key].GetInnerType().IsAssignableFrom(TargetDynamicType)) { // check if any relevant change occurred if (!message[key].Equals(value as IEnumerable)) { message.AssignFrom(key, value); } } else { var casted = from slice in value as IEnumerable <object> let targetType = message[key].GetInnerType() select Convert.ChangeType(slice, targetType); if (!message[key].Equals(casted)) { message.AssignFrom(key, casted); } } } else { message[key].Clear(); } } } } if (doFlush) { FOutput.Flush(); } }
public override void Evaluate(int SpreadMax) { if (!FInput.IsChanged && !FConfig.IsChanged && !FKey.IsChanged && !FAvoidNil.IsChanged) { return; } SpreadMax = FInput.IsAnyInvalid() ? 0 : FInput.SliceCount; if (SpreadMax == 0) { if (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 } } FOutput.FlushResult(FInput); var keyCount = FKey.SliceCount; FBinSize.SliceCount = SpreadMax; var input = FValue.ToISpread(); input.SliceCount = SpreadMax * keyCount; for (int i = 0; i < SpreadMax; i++) { Message message = FInput[i]; var count = 0; var index = 0; foreach (var key in FKey) { var type = TargetDynamicType; var output = (input[i * keyCount + index] as ISpread); output.SliceCount = 0; if (!message.Fields.Contains(key)) { if (!FAvoidNil.IsAnyInvalid() && FAvoidNil[0]) { output.SliceCount = 1; output[0] = TypeIdentity.Instance.NewDefault(type); } } else { var inputBin = message[key]; if (type.IsAssignableFrom(inputBin.GetInnerType())) { output.SliceCount = inputBin.Count; for (int j = 0; j < inputBin.Count; j++) { output[j] = inputBin[j]; } } else // will throw Exception, if Conversion is not possible { output.SliceCount = inputBin.Count; for (int j = 0; j < inputBin.Count; j++) { output[j] = Convert.ChangeType(inputBin[j], type, CultureInfo.InvariantCulture); } } } count += output.SliceCount; index++; } FBinSize[i] = count; } input.Flush(); FBinSize.Flush(); }
public override void Evaluate(int SpreadMax) { InitDX11Graph(); if (FInput.IsAnyInvalid()) { FOutput.FlushNil(); return; // if no input, no further calculation. } bool doFlush = false; // any of the update slices is true -> update the plugin. var anyUpdate = FUpdate.Any(); // Flush upstream changes through the plugin if (FInput.IsChanged) { FOutput.SliceCount = 0; FOutput.AssignFrom(FInput); doFlush = true; } else if (!anyUpdate) { return; } var dataSpread = FValue.ToISpread(); bool newData = dataSpread.IsChanged; // changed pin newData |= FForce[0]; // assume newData, if AutoSense is off. if (anyUpdate && newData) { // Update and Force not included in spreading. SpreadMax = dataSpread.SliceCount.CombineWith(FKey).CombineWith(FInput); if (FUpdate.IsAnyInvalid() || FForce.IsAnyInvalid()) { SpreadMax = 0; } FIterations[0] = SpreadMax; doFlush = true; var fieldIndex = 0; for (int i = 0; i < SpreadMax; i++) // iterate spreaded (except update, which gets cut short) { Message message = FInput[i]; for (int j = 0; j < FKey[i].SliceCount; j++, fieldIndex++) // iterate all relevant fields for each message { if (!FUpdate[fieldIndex]) { continue; // update is per-field } var key = FKey[i][j]; var spread = dataSpread[fieldIndex] as ISpread; LazyInsert(message, key, spread); } } } if (doFlush) { FOutput.Flush(); } }