private static void Requery() { #if persistentIds #if ORACLE string seq = /* "\"" + schemaName + "\".*/ \"" + sequenceName + "\""; string sql = "select " + seq + ".Nextval from dual"; OracleConnection conn = new OracleConnection(connectionString); OracleCommand cmd = new OracleCommand(sql, conn); conn.Open(); OracleDataReader reader = cmd.ExecuteReader(); if (!reader.Read()) throw new Exception("Can't read oracle sequence " + seq); currentId = reader.GetInt32(0); conn.Close(); upperLimit = currentId + increment; #endif #if FIREBIRD //SET GENERATOR "NDOGenerator" TO 0; PersistenceManager pm = PmFactory.NewPersistenceManager(); IQuery q = new NDOQuery<SequenceValue), "SELECT GEN_ID(\"NDOGenerator\", " + increment.ToString() + ") AS \"Value\" FROM RDB$DATABASE;", false, QueryLanguage.Sql); SequenceValue sv = (SequenceValue) q.ExecuteSingle(); currentId = sv.Value; upperLimit = sv.Value + increment; #endif #else currentId = 1; upperLimit = 0x7fffffff; #endif }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: public java.util.List<?> mapSequence(SequenceValue value) public override IList <object> MapSequence(SequenceValue value) { IList <object> list = new List <object>(value.Length()); value.forEach(v => list.Add(v.map(this))); return(list); }
public virtual async Task NextAsync(StateEntry stateEntry, IProperty property, CancellationToken cancellationToken = default(CancellationToken)) { Check.NotNull(stateEntry, "stateEntry"); Check.NotNull(property, "property"); var newValue = GetNextValue(); // If the chosen value is outside of the current block then we need a new block. // It is possible that other threads will use all of the new block before this thread // gets a chance to use the new new value, so use a while here to do it all again. while (newValue.Current >= newValue.Max) { // Once inside the lock check to see if another thread already got a new block, in which // case just get a value out of the new block instead of requesting one. using (await _lock.LockAsync(cancellationToken).WithCurrentCulture()) { if (newValue.Max == _currentValue.Max) { var newCurrent = await GetNewCurrentValueAsync(stateEntry, property, cancellationToken); newValue = new SequenceValue(newCurrent, newCurrent + _blockSize); _currentValue = newValue; } else { newValue = GetNextValue(); } } } stateEntry[property] = Convert.ChangeType(newValue.Current, property.PropertyType); }
public virtual async Task <object> NextAsync(StateEntry stateEntry, IProperty property, CancellationToken cancellationToken = default(CancellationToken)) { Check.NotNull(stateEntry, "stateEntry"); Check.NotNull(property, "property"); var newValue = GetNextValue(); // If the chosen value is outside of the current block then we need a new block. // It is possible that other threads will use all of the new block before this thread // gets a chance to use the new new value, so use a while here to do it all again. while (newValue.Current >= newValue.Max) { // Once inside the lock check to see if another thread already got a new block, in which // case just get a value out of the new block instead of requesting one. using (await _lock.LockAsync(cancellationToken)) { if (newValue.Max == _currentValue.Max) { var commandInfo = PrepareCommand(stateEntry.Configuration); var newCurrent = (long)await _executor.ExecuteScalarAsync(commandInfo.Item1.DbConnection, commandInfo.Item1.DbTransaction, commandInfo.Item2, cancellationToken).ConfigureAwait(false); newValue = new SequenceValue(newCurrent, newCurrent + _blockSize); _currentValue = newValue; } else { newValue = GetNextValue(); } } } return(Convert.ChangeType(newValue.Current, property.PropertyType)); }
protected override int VisitSequenceValue(ThemedValueFormatterState state, SequenceValue sequence) { if (sequence == null) { throw new ArgumentNullException(nameof(sequence)); } var count = 0; using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write('['); var delim = string.Empty; for (var index = 0; index < sequence.Elements.Count; ++index) { if (delim.Length != 0) { using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write(delim); } delim = ", "; Visit(state, sequence.Elements[index]); } using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write(']'); return(count); }
public static object _Internal_All(object items, object predicate) { var pred = predicate as Func <object, object>; if (pred == null) { return(Undefined.Value); } SequenceValue arr = items as SequenceValue; if (arr != null) { return(arr.Elements.All(e => true.Equals(pred(Representation.Represent(e))))); } var structure = items as StructureValue; if (structure != null) { return(structure.Properties.All(e => true.Equals(pred(Representation.Represent(e.Value))))); } return(Undefined.Value); }
/// <summary> /// Visit a <see cref="SequenceValue"/> value. /// </summary> /// <param name="state">Operation state.</param> /// <param name="sequence">The value to visit.</param> /// <returns>The result of visiting <paramref name="sequence"/>.</returns> protected override LogEventPropertyValue VisitSequenceValue(TState state, SequenceValue sequence) { if (sequence == null) { throw new ArgumentNullException(nameof(sequence)); } for (var i = 0; i < sequence.Elements.Count; ++i) { var original = sequence.Elements[i]; if (!ReferenceEquals(original, Visit(state, original))) { var contents = new LogEventPropertyValue[sequence.Elements.Count]; // There's no need to visit any earlier elements: they all evaluated to // a reference equal with the original so just fill in the array up until `i`. for (var j = 0; j < i; ++j) { contents[j] = sequence.Elements[j]; } for (var k = i; k < contents.Length; ++k) { contents[k] = Visit(state, sequence.Elements[k]); } return(new SequenceValue(contents)); } } return(sequence); }
public void StatePropagatesAndNestedStructuresAreRewritten() { var value = new SequenceValue(new[] { new StructureValue(new[] { new LogEventProperty("S", new ScalarValue("abcde")) }) }); var limiter = new LimitingRewriter(); var limited = limiter.LimitStringLength(value, 3); var seq = limited as SequenceValue; Assert.NotNull(seq); var str = seq !.Elements.Single() as StructureValue; Assert.NotNull(str); var prop = str !.Properties.Single(); Assert.Equal("S", prop.Name); var sca = prop.Value as ScalarValue; Assert.NotNull(sca); Assert.Equal("abc", sca !.Value); }
public void Test_Format_Sequence() { // arrange var name = "Scope"; var sequenceValue = "HTTP POST https://apigateway.mhdev.se/member-service/int/v2.0/members"; var scalar = new SequenceValue(new List <LogEventPropertyValue> { new ScalarValue(sequenceValue) }); var logEventProperty = new LogEventProperty(name, scalar); var structureValue = new StructureValue(new List <LogEventProperty> { logEventProperty }); var _formatter = new MhSensitivePropertyValueFormatter(); var logEvent = new LogEvent( new System.DateTimeOffset(), LogEventLevel.Information, null, new MessageTemplate("", new List <MessageTemplateToken>()), new List <LogEventProperty> { new LogEventProperty("BaseModel", structureValue) }); // act _formatter.Format(logEvent); var baseModel = logEvent.Properties["BaseModel"] as StructureValue; var result = baseModel.Properties[0]; // assert Assert.Equal(name, result.Name); Assert.NotNull(result.Value); }
public virtual GeneratedValue Next(IProperty property, DbContextService <DataStoreServices> dataStoreServices) { Check.NotNull(property, "property"); Check.NotNull(dataStoreServices, "dataStoreServices"); var newValue = GetNextValue(); // If the chosen value is outside of the current block then we need a new block. // It is possible that other threads will use all of the new block before this thread // gets a chance to use the new new value, so use a while here to do it all again. while (newValue.Current >= newValue.Max) { using (_lock.Lock()) { // Once inside the lock check to see if another thread already got a new block, in which // case just get a value out of the new block instead of requesting one. if (newValue.Max == _currentValue.Max) { var newCurrent = GetNewCurrentValue(property, dataStoreServices); newValue = new SequenceValue(newCurrent, newCurrent + _blockSize); _currentValue = newValue; } else { newValue = GetNextValue(); } } } return(new GeneratedValue(Convert.ChangeType(newValue.Current, property.PropertyType.UnwrapNullableType()))); }
private static object ToRawValue(LogEventPropertyValue logEventValue) { // Special-case a few types of LogEventPropertyValue that allow us to maintain better type fidelity. // For everything else take the default string rendering as the data. ScalarValue scalarValue = logEventValue as ScalarValue; if (scalarValue != null) { return(scalarValue.Value); } SequenceValue sequenceValue = logEventValue as SequenceValue; if (sequenceValue != null) { object[] arrayResult = sequenceValue.Elements.Select(e => ToRawScalar(e)).ToArray(); if (arrayResult.Length == sequenceValue.Elements.Count) { // All values extracted successfully, it is a flat array of scalars return(arrayResult); } } StructureValue structureValue = logEventValue as StructureValue; if (structureValue != null) { IDictionary <string, object> structureResult = new Dictionary <string, object>(structureValue.Properties.Count); foreach (var property in structureValue.Properties) { structureResult[property.Name] = ToRawScalar(property.Value); } if (structureResult.Count == structureValue.Properties.Count) { if (structureValue.TypeTag != null) { structureResult["$type"] = structureValue.TypeTag; } return(structureResult); } } DictionaryValue dictionaryValue = logEventValue as DictionaryValue; if (dictionaryValue != null) { IDictionary <string, object> dictionaryResult = dictionaryValue.Elements .Where(kvPair => kvPair.Key.Value is string) .ToDictionary(kvPair => (string)kvPair.Key.Value, kvPair => ToRawScalar(kvPair.Value)); if (dictionaryResult.Count == dictionaryValue.Elements.Count) { return(dictionaryResult); } } // Fall back to string rendering of the value return(logEventValue.ToString()); }
public override AnyValue MapSequence(SequenceValue value) { IList <AnyValue> list = new List <AnyValue>(value.Length()); value.forEach(v => list.Add(v.map(this))); return(VirtualValues.fromList(list)); }
public virtual async Task <object> NextAsync( IProperty property, DbContextService <DataStoreServices> dataStoreServices, CancellationToken cancellationToken = default(CancellationToken)) { Check.NotNull(property, "property"); Check.NotNull(dataStoreServices, "dataStoreServices"); var newValue = GetNextValue(); // If the chosen value is outside of the current block then we need a new block. // It is possible that other threads will use all of the new block before this thread // gets a chance to use the new new value, so use a while here to do it all again. while (newValue.Current >= newValue.Max) { // Once inside the lock check to see if another thread already got a new block, in which // case just get a value out of the new block instead of requesting one. using (await _lock.LockAsync(cancellationToken).WithCurrentCulture()) { if (newValue.Max == _currentValue.Max) { var newCurrent = await GetNewCurrentValueAsync(property, dataStoreServices, cancellationToken); newValue = new SequenceValue(newCurrent, newCurrent + BlockSize); _currentValue = newValue; } else { newValue = GetNextValue(); } } } return(Convert.ChangeType(newValue.Current, property.PropertyType.UnwrapNullableType())); }
public virtual object Next( DbContextConfiguration contextConfiguration, IProperty property) { Check.NotNull(contextConfiguration, "contextConfiguration"); Check.NotNull(property, "property"); var newValue = GetNextValue(); // If the chosen value is outside of the current block then we need a new block. // It is possible that other threads will use all of the new block before this thread // gets a chance to use the new new value, so use a while here to do it all again. while (newValue.Current >= newValue.Max) { using (_lock.Lock()) { // Once inside the lock check to see if another thread already got a new block, in which // case just get a value out of the new block instead of requesting one. if (newValue.Max == _currentValue.Max) { var commandInfo = PrepareCommand(contextConfiguration); var newCurrent = (long)_executor.ExecuteScalar(commandInfo.Item1, commandInfo.Item2); newValue = new SequenceValue(newCurrent, newCurrent + _blockSize); _currentValue = newValue; } else { newValue = GetNextValue(); } } } return(Convert.ChangeType(newValue.Current, property.PropertyType)); }
public virtual object Next(StateEntry entry, IProperty property) { Check.NotNull(entry, "entry"); Check.NotNull(property, "property"); var newValue = GetNextValue(); // If the chosen value is outside of the current block then we need a new block. // It is possible that other threads will use all of the new block before this thread // gets a chance to use the new new value, so use a while here to do it all again. while (newValue.Current >= newValue.Max) { using (_lock.Lock()) { // Once inside the lock check to see if another thread already got a new block, in which // case just get a value out of the new block instead of requesting one. if (newValue.Max == _currentValue.Max) { var commandInfo = PrepareCommand(entry.Configuration); var newCurrent = (long)_executor.ExecuteScalar(commandInfo.Item1.DbConnection, commandInfo.Item1.DbTransaction, commandInfo.Item2); newValue = new SequenceValue(newCurrent, newCurrent + _blockSize); _currentValue = newValue; } else { newValue = GetNextValue(); } } } return Convert.ChangeType(newValue.Current, property.PropertyType); }
private static object GetPropertyValue(LogEventPropertyValue propertyValue) { return(propertyValue switch { SequenceValue sequenceValue => sequenceValue.Elements.Select(RenderSequenceValue).ToArray(), ScalarValue scalarValue => scalarValue.Value, _ => propertyValue.ToString() });
public void SequencesOfSequencesAreFormatted() { var s = new SequenceValue(new[] { new SequenceValue(new[] { new ScalarValue("Hello") }) }); var f = Format(s); Assert.Equal("[[\"Hello\"]]", f); }
private static SequenceValue BasicAllocations() { var value = new SequenceValue(AllocationInstruction.GetSequence("Allocations")); value.Add(NewAllocation("general", 101.0, 15.0)); value.Add(NewAllocation("specific", 103.0, 10.0)); return(value); }
bool TryConvertEnumerable(object value, Destructuring destructuring, Type valueType, out LogEventPropertyValue result) { if (value is IEnumerable enumerable) { // Only dictionaries with 'scalar' keys are permitted, as // more complex keys may not serialize to unique values for // representation in sinks. This check strengthens the expectation // that resulting dictionary is representable in JSON as well // as richer formats (e.g. XML, .NET type-aware...). // Only actual dictionaries are supported, as arbitrary types // can implement multiple IDictionary interfaces and thus introduce // multiple different interpretations. if (TryGetDictionary(value, valueType, out var dictionary)) { result = new DictionaryValue(MapToDictionaryElements(dictionary, destructuring)); return true; IEnumerable<KeyValuePair<ScalarValue, LogEventPropertyValue>> MapToDictionaryElements(IDictionary dictionaryEntries, Destructuring destructure) { var count = 0; foreach (DictionaryEntry entry in dictionaryEntries) { if (++count > _maximumCollectionCount) { yield break; } var pair = new KeyValuePair<ScalarValue, LogEventPropertyValue>( (ScalarValue)_depthLimiter.CreatePropertyValue(entry.Key, destructure), _depthLimiter.CreatePropertyValue(entry.Value, destructure)); if (pair.Key.Value != null) yield return pair; } } } result = new SequenceValue(MapToSequenceElements(enumerable, destructuring)); return true; IEnumerable<LogEventPropertyValue> MapToSequenceElements(IEnumerable sequence, Destructuring destructure) { var count = 0; foreach (var element in sequence) { if (++count > _maximumCollectionCount) { yield break; } yield return _depthLimiter.CreatePropertyValue(element, destructure); } } } result = null; return false; }
//public Sequencer<T> Clone<T>(IObjectEntity<T> entity) where T : class //{ // var s = new Sequencer<T>(entity); // s.list = new List<SequenceValue>(this.list); // return s; //} Sequencer Order(string protortypeName, Sequence view) { SequenceValue compost = new SequenceValue { Name = protortypeName, Value = view }; list.Add(compost); return(this); }
static JToken ConvertSequenceValue(SequenceValue seq) { JArray arr = new JArray(); foreach (LogEventPropertyValue elem in seq.Elements) { arr.Add(ConvertPropertyValue(elem)); } return(arr); }
public void TestSimpleCreateTemplateDefinitionMessage() { Message templateDef = _scp11.CreateTemplateDefinitionMessage(ObjectMother.QuoteTemplate); Assert.AreEqual("Quote", templateDef.GetString("Name")); SequenceValue instructions = templateDef.GetSequence("Instructions"); Assert.AreEqual("bid", instructions[0].GetGroup(0).GetString("Name")); Assert.AreEqual("ask", templateDef.GetSequence("Instructions")[1].GetGroup(0).GetString("Name")); }
private static void WriteSequenceValue(string key, SequenceValue sequenceValue, IDictionary <string, string> properties) { int index = 0; foreach (var eventProperty in sequenceValue.Elements) { WriteValue(key + "." + index, eventProperty, properties); index++; } AppendProperty(properties, key + ".Count", index.ToString()); }
private IEnumerable <object> VisitSequenceValue(SequenceValue sequence) { var list = new List <object>(); foreach (var sequenceElement in sequence.Elements) { list.Add(this.Visit(sequenceElement)); } return(list); }
public void NonscalarPropertiesAreWrapped() { const string name = "Sequence"; var seq = new SequenceValue(Enumerable.Empty <LogEventPropertyValue>()); var lv = new SerilogLogValues(MessageTemplate.Empty, new Dictionary <string, LogEventPropertyValue> { [name] = seq }); var kvp = lv.Single(p => p.Key == name); var sv = Assert.IsType <SequenceValue>(kvp.Value); Assert.Equal(seq, sv); }
private int CompareSequenceAndNonSequence(SequenceValue v1, AnyValue v2) { bool isValue2 = v2 is Value; if (isValue2) { return(-1); } else { return(_virtualValueGroupComparator.Compare(VirtualValueGroup.LIST, (( VirtualValue )v2).ValueGroup())); } }
public void TestMultipleMessages() { var outStream = new MemoryStream(); var output = new MessageOutputStream(outStream); output.RegisterTemplate(ObjectMother.AllocInstrctnTemplateId, ObjectMother.AllocationInstruction); var allocations = new SequenceValue(ObjectMother.AllocationInstruction .GetSequence("Allocations")); allocations.Add(ObjectMother.NewAllocation("fortyFiveFund", 22.5, 75.0)); allocations.Add(ObjectMother.NewAllocation("fortyFund", 24.6, 25.0)); Message ai1 = ObjectMother.NewAllocInstrctn( "ltg0001", 1, 100.0, 23.4, ObjectMother.NewInstrument("CTYA", "200910"), allocations); allocations = new SequenceValue( ObjectMother.AllocationInstruction.GetSequence("Allocations")); allocations.Add(ObjectMother.NewAllocation("fortyFiveFund", 22.5, 75.0)); allocations.Add(ObjectMother.NewAllocation("fortyFund", 24.6, 25.0)); Message ai2 = ObjectMother.NewAllocInstrctn( "ltg0001", 1, 100.0, 23.4, ObjectMother.NewInstrument("CTYA", "200910"), allocations); allocations = new SequenceValue( ObjectMother.AllocationInstruction.GetSequence("Allocations")); allocations.Add(ObjectMother.NewAllocation("fortyFiveFund", 22.5, 75.0)); allocations.Add(ObjectMother.NewAllocation("fortyFund", 24.6, 25.0)); Message ai3 = ObjectMother.NewAllocInstrctn( "ltg0001", 1, 100.0, 23.4, ObjectMother.NewInstrument("CTYA", "200910"), allocations); output.WriteMessage(ai1); output.WriteMessage(ai2); output.WriteMessage(ai3); byte[] bytes = outStream.ToArray(); var input = new MessageInputStream(new MemoryStream(bytes)); input.RegisterTemplate(ObjectMother.AllocInstrctnTemplateId, ObjectMother.AllocationInstruction); Message message = input.ReadMessage(); Assert.AreEqual(ai1, message); message = input.ReadMessage(); Assert.AreEqual(ai2, message); Assert.AreEqual(ai3, input.ReadMessage()); }
public static bool TryResolveToEnumerable(object value, PropertyResolvingMode mode, NestParameterResolver nest, Type typeOfValue, int maxLoopCountForCollection, out MessagePropertyValue result) { if (value is IEnumerable __enumerable) { if (TryGetDictionary(value, typeOfValue, out var dictionary)) { result = new DictionaryValue(DictionaryElements()); return(true); IEnumerable <KeyValuePair <ScalarValue, MessagePropertyValue> > DictionaryElements() { var __index = 0; foreach (DictionaryEntry __item in dictionary) { if (++__index > maxLoopCountForCollection) { yield break; } if (nest.CreatePropertyValue(__item.Key, mode) is ScalarValue __key) { var __value = nest.CreatePropertyValue(__item.Value, mode); yield return(new KeyValuePair <ScalarValue, MessagePropertyValue>(__key, __value)); } } } } result = new SequenceValue(SequenceElements()); return(true); IEnumerable <MessagePropertyValue> SequenceElements() { var __index = 0; foreach (var __item in __enumerable) { if (++__index > maxLoopCountForCollection) { yield break; } yield return(nest.CreatePropertyValue(__item, mode)); } } } result = null; return(false); }
public void WhenNoRewritingTakesPlaceAllElementsAreUnchanged() { var value = new SequenceValue(new[] { new StructureValue(new[] { new LogEventProperty("S", new ScalarValue("abcde")) }) }); var limiter = new LimitingRewriter(); var unchanged = limiter.LimitStringLength(value, 10); Assert.Same(value, unchanged); }
public static Message NewAllocInstrctn(String id, int side, double quantity, double averagePrice, GroupValue instrument, SequenceValue allocations) { var allocInstrctn = new Message(AllocationInstruction); allocInstrctn.SetFieldValue(1, allocations); allocInstrctn.SetFieldValue(2, instrument); allocInstrctn.SetFieldValue(3, new StringValue(id)); allocInstrctn.SetFieldValue(4, new IntegerValue(side)); allocInstrctn.SetFieldValue(5, new DecimalValue(quantity)); allocInstrctn.SetFieldValue(6, new DecimalValue(averagePrice)); return(allocInstrctn); }
public void ASequencePropertySerializesAsArrayValue() { var name = Some.String(); var ints = new[]{ Some.Int(), Some.Int() }; var value = new SequenceValue(ints.Select(i => new ScalarValue(i))); var @event = Some.InformationEvent(); @event.AddOrUpdateProperty(new LogEventProperty(name, value)); var formatted = FormatJson(@event); var result = new List<int>(); foreach (var el in formatted.Properties[name]) result.Add((int)el); CollectionAssert.AreEqual(ints, result); }
public static Message Convert(Group group, Message groupMsg, ConversionContext context) { SetNameAndId(group, groupMsg); if (group.TypeReference != null && !FastConstants.AnyType.Equals(group.TypeReference)) { var typeRef = new GroupValue( (Group) SessionControlProtocol11 .TypeRef .GetField(new QName("TypeRef", SessionControlProtocol11.Namespace))); SetName(typeRef, group.TypeReference); groupMsg.SetFieldValue("TypeRef", typeRef); } var instructions = new SequenceValue( SessionControlProtocol11.TemplateDefinition.GetSequence("Instructions")); if (group.TypeReference != null && !FastConstants.AnyType.Equals(group.TypeReference)) { var typeRef = new GroupValue( (Group) SessionControlProtocol11 .TypeRef .GetField(new QName("TypeRef", SessionControlProtocol11.Namespace))); SetName(typeRef, group.TypeReference); groupMsg.SetFieldValue("TypeRef", typeRef); } Field[] fields = group.FieldDefinitions; for (int i = group is MessageTemplate ? 1 : 0; i < fields.Length; i++) { Field field = fields[i]; IFieldInstructionConverter converter = context.GetConverter(field); if (converter == null) throw new InvalidOperationException("No converter found for type " + field.GetType()); IFieldValue v = converter.Convert(field, context); instructions.Add(new[] {v}); } groupMsg.SetFieldValue("Instructions", instructions); return groupMsg; }
public void SequenceTest1() { var sequence = new Sequence(1, 0); var id = sequence.Next(); var key = new SequenceValue(); for (int i = 0; i < 100000; i++) { id = sequence.Next(); key = new SequenceValue { Value = id }; Assert.Equal(1, key.Type); // Assert.Equal((ushort)0, key.Reserved); } }
public static Message Convert(Group group, Message groupMsg, ConversionContext context) { SetNameAndId(group, groupMsg); var instructions = new SequenceValue(SessionControlProtocol_1_1.TEMPLATE_DEFINITION.GetSequence("Instructions")); int i = group is MessageTemplate?1:0; Field[] fields = group.FieldDefinitions; for (; i < fields.Length; i++) { Field field = fields[i]; FieldInstructionConverter converter = context.GetConverter(field); if (converter == null) throw new System.SystemException("No converter found for type " + field.GetType()); FieldValue value_Renamed = converter.Convert(field, context); instructions.Add(new[]{value_Renamed}); } groupMsg.SetFieldValue("Instructions", instructions); return groupMsg; }
public void TestEncode() { var firstName = new Scalar("First Name", FastType.I32, Operator.Copy, ScalarValue.Undefined, false); var lastName = new Scalar("Last Name", FastType.I32, Operator.Copy, ScalarValue.Undefined, false); var sequence1 = new Sequence("Contacts", new Field[] {firstName, lastName}, false); var sequenceValue = new SequenceValue(sequence1); sequenceValue.Add(new IFieldValue[] { new IntegerValue(1), new IntegerValue(2) }); sequenceValue.Add(new IFieldValue[] { new IntegerValue(3), new IntegerValue(4) }); byte[] actual = sequence1.Encode(sequenceValue, _template, _context, new BitVectorBuilder(1)); const string expected = "10000010 11100000 10000001 10000010 11100000 10000011 10000100"; TestUtil.AssertBitVectorEquals(expected, actual); }
public void TestDecode() { const string actual = "10000010 11100000 10000001 10000010 11100000 10000011 10000100"; Stream stream = ByteUtil.CreateByteStream(actual); var firstNumber = new Scalar("First Number", FastType.I32, Operator.Copy, ScalarValue.Undefined, false); var lastNumber = new Scalar("Second Number", FastType.I32, Operator.Copy, ScalarValue.Undefined, false); var sequence1 = new Sequence("Contants", new Field[] {firstNumber, lastNumber}, false); var sequenceValue = new SequenceValue(sequence1); sequenceValue.Add(new IFieldValue[] { new IntegerValue(1), new IntegerValue(2) }); sequenceValue.Add(new IFieldValue[] { new IntegerValue(3), new IntegerValue(4) }); IFieldValue result = sequence1.Decode(stream, _template, _context, BitVectorReader.InfiniteTrue); Assert.AreEqual(sequenceValue, result); }
public override FieldValue Decode(System.IO.Stream in_Renamed, Group decodeTemplate, Context context, BitVectorReader pmapReader) { var sequenceValue = new SequenceValue(this); FieldValue lengthValue = length.Decode(in_Renamed, decodeTemplate, context, pmapReader); if ((lengthValue == ScalarValue.NULL) || (lengthValue == null)) { return null; } int len = ((IntegerValue) lengthValue).value_Renamed; for (var i = 0; i < len; i++) sequenceValue.Add((GroupValue) group.Decode(in_Renamed, decodeTemplate, context, BitVectorReader.INFINITE_TRUE)); return sequenceValue; }
public static Message NewAllocInstrctn(String id, int side, double quantity, double averagePrice, GroupValue instrument, SequenceValue allocations) { var allocInstrctn = new Message(AllocationInstruction); allocInstrctn.SetFieldValue(1, allocations); allocInstrctn.SetFieldValue(2, instrument); allocInstrctn.SetFieldValue(3, new StringValue(id)); allocInstrctn.SetFieldValue(4, new IntegerValue(side)); allocInstrctn.SetFieldValue(5, new DecimalValue(quantity)); allocInstrctn.SetFieldValue(6, new DecimalValue(averagePrice)); return allocInstrctn; }
private static SequenceValue BasicAllocations() { var value = new SequenceValue(AllocationInstruction.GetSequence("Allocations")); value.Add(NewAllocation("general", 101.0, 15.0)); value.Add(NewAllocation("specific", 103.0, 10.0)); return value; }
public void TestComplexMessage() { var template = new MessageTemplate( "Company", new Field[] { new Scalar("Name", FastType.String, Operator.None, ScalarValue.Undefined, false), new Scalar("Id", FastType.U32, Operator.Increment, ScalarValue.Undefined, false), new Sequence( "Employees", new Field[] { new Scalar("First Name", FastType.String, Operator.Copy, ScalarValue.Undefined, false), new Scalar("Last Name", FastType.String, Operator.Copy, ScalarValue.Undefined, false) , new Scalar("Age", FastType.U32, Operator.Delta, ScalarValue.Undefined, false) }, false), new Group( "Tax Information", new Field[] { new Scalar("EIN", FastType.String, Operator.None, ScalarValue.Undefined, false) }, false) }); var aaaInsurance = new Message(template); aaaInsurance.SetFieldValue(1, new StringValue("AAA Insurance")); aaaInsurance.SetFieldValue(2, new IntegerValue(5)); var employees = new SequenceValue(template.GetSequence( "Employees")); employees.Add(new IFieldValue[] { new StringValue("John"), new StringValue("Doe"), new IntegerValue(45) }); employees.Add(new IFieldValue[] { new StringValue("Jane"), new StringValue("Doe"), new IntegerValue(48) }); aaaInsurance.SetFieldValue(3, employees); aaaInsurance.SetFieldValue(4, new GroupValue(template.GetGroup("Tax Information"), new IFieldValue[] {new StringValue("99-99999999")})); var outStream = new MemoryStream(); var output = new MessageOutputStream(outStream); output.RegisterTemplate(1, template); output.WriteMessage(aaaInsurance); var abcBuilding = new Message(template); abcBuilding.SetFieldValue(1, new StringValue("ABC Building")); abcBuilding.SetFieldValue(2, new IntegerValue(6)); employees = new SequenceValue(template.GetSequence("Employees")); employees.Add(new IFieldValue[] { new StringValue("Bob"), new StringValue("Builder"), new IntegerValue(3) }); employees.Add(new IFieldValue[] { new StringValue("Joe"), new StringValue("Rock"), new IntegerValue(59) }); abcBuilding.SetFieldValue(3, employees); abcBuilding.SetFieldValue(4, new GroupValue(template.GetGroup("Tax Information"), new IFieldValue[] {new StringValue("99-99999999")})); output.WriteMessage(abcBuilding); var input = new MessageInputStream(new MemoryStream(outStream.ToArray())); input.RegisterTemplate(1, template); GroupValue message = input.ReadMessage(); Assert.AreEqual(aaaInsurance, message); message = input.ReadMessage(); Assert.AreEqual(abcBuilding, message); }
public override IFieldValue Decode(Stream inStream, Group decodeTemplate, Context context, BitVectorReader pmapReader) { var sequenceValue = new SequenceValue(this); IFieldValue lengthValue = _length.Decode(inStream, decodeTemplate, context, pmapReader); if ((lengthValue == ScalarValue.Null) || (lengthValue == null)) { return null; } int len = ((IntegerValue) lengthValue).Value; for (int i = 0; i < len; i++) sequenceValue.Add( (GroupValue) _group.Decode(inStream, decodeTemplate, context, BitVectorReader.InfiniteTrue)); return sequenceValue; }