public void SetFirstInvalidObject() { Bin bin = BinFactory.New(1, 2, 3); bin.First = 1.0; }
public void InsertInvalidObject() { Bin bin = BinFactory.New(1, 2, 3); bin[0] = "a"; }
public void RangeBinIndexBelow() { Bin bin = BinFactory.New(1, 2, 3); bin[-1] = 4; }
public void RangeBinIndex() { Bin bin = BinFactory.New(1, 2, 3); bin[9] = 4; }
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 object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { Type type; try { type = objectType.GetGenericArguments()[0]; } catch (Exception) { type = typeof(string); } Bin bin = BinFactory.New(type); //IEnumerable jArray = null; if (reader.TokenType == JsonToken.StartArray) { var jArray = JArray.Load(reader); foreach (var jO in jArray.Children()) { if (jO is JValue) { var o = (jO as JValue).Value; if (type == typeof(Stream)) { var raw = GenerateStreamFromString(o as string); bin.Add(raw); } else { bin.Add(Convert.ChangeType(o, type)); } } if (jO is JObject) { var o = (jO as JObject).ToObject(type); bin.Add(o); } } } else { if (typeof(Stream).IsAssignableFrom(type)) { var o = serializer.Deserialize(reader, typeof(string)) as string; bin.Add(GenerateStreamFromString(o)); } else { try { var o = serializer.Deserialize(reader, type); bin.Add(o); } catch { // casting errors } } } return(bin); }