public void TestSimpleCompositeParsers() { string configXml = @"/Resources/composites.xml"; MessageFactory <IsoMessage> mfact = Config(configXml); IsoMessage m = mfact.ParseMessage("01000040000000000000016one 03two12345.".GetSbytes(), 0); Assert.NotNull(m); CompositeField f = (CompositeField)m.GetObjectValue(10); Assert.NotNull(f); Assert.Equal(4, f.Values.Count); Assert.Equal("one ", f.GetObjectValue(0)); Assert.Equal("two", f.GetObjectValue(1)); Assert.Equal("12345", f.GetObjectValue(2)); Assert.Equal(".", f.GetObjectValue(3)); m = mfact.ParseMessage("01000040000000000000018ALPHA05LLVAR12345X".GetSbytes(), 0); Assert.NotNull(m); Assert.True(m.HasField(10)); f = (CompositeField)m.GetObjectValue(10); Assert.NotNull(f.GetField(0)); Assert.NotNull(f.GetField(1)); Assert.NotNull(f.GetField(2)); Assert.NotNull(f.GetField(3)); Assert.Null(f.GetField(4)); Assert.Equal("ALPHA", f.GetObjectValue(0)); Assert.Equal("LLVAR", f.GetObjectValue(1)); Assert.Equal("12345", f.GetObjectValue(2)); Assert.Equal("X", f.GetObjectValue(3)); }
private static FieldParseInfo GetParser <T>(XmlElement f, MessageFactory <T> mfact) where T : IsoMessage { var itype = Enumm.Parse <IsoType>(f.GetAttribute("type")); var length = 0; if (f.GetAttribute("length").Length > 0) { length = int.Parse(f.GetAttribute("length")); } Debug.Assert(itype != null, "itype != null"); var fpi = FieldParseInfo.GetInstance(itype.Value, length, mfact.Encoding); var subs = f.GetElementsByTagName("field"); if (subs != null && subs.Count > 0) { var combo = new CompositeField(); for (var i = 0; i < subs.Count; i++) { var sf = (XmlElement)subs.Item(i); Debug.Assert(sf != null, "sf != null"); if (sf.ParentNode == f) { combo.AddParser(GetParser(sf, mfact)); } } fpi.Decoder = combo; } return(fpi); }
public FieldObject Terminate() { MapField result = new MapField(); if (this.isProjectingACollection) { foreach (FieldObject key in this.groupState.groupedStates.Keys) { List <FieldObject> projectFields = new List <FieldObject>(); this.container.ResetTableCache(this.groupState.groupedStates[key]); this.aggregateOp.ResetState(); for (int i = 0; i < this.groupState.groupedStates[key].Count; i++) { RawRecord aggregateTraversalRecord = this.aggregateOp.Next(); FieldObject projectResult = aggregateTraversalRecord?.RetriveData(0); if (projectResult == null) { throw new GraphViewException("The property does not exist for some of the elements having been grouped."); } projectFields.Add(projectResult); } Dictionary <string, FieldObject> compositeFieldObjects = new Dictionary <string, FieldObject>(); compositeFieldObjects.Add(DocumentDBKeywords.KW_TABLE_DEFAULT_COLUMN_NAME, new CollectionField(projectFields)); result[key] = new CompositeField(compositeFieldObjects, DocumentDBKeywords.KW_TABLE_DEFAULT_COLUMN_NAME); } } else { foreach (KeyValuePair <FieldObject, List <RawRecord> > pair in this.groupState.groupedStates) { FieldObject key = pair.Key; this.aggregateOp.ResetState(); this.container.ResetTableCache(pair.Value); RawRecord aggregateTraversalRecord = null; FieldObject aggregateResult = null; while (this.aggregateOp.State() && (aggregateTraversalRecord = this.aggregateOp.Next()) != null) { aggregateResult = aggregateTraversalRecord.RetriveData(0) ?? aggregateResult; } if (aggregateResult == null) { continue; } result[key] = aggregateResult; } } return(result); }
public void TwoSphereCompositeFieldTests(float x, float y, float z, float expectedResult) { var field = new CompositeField { new SphereField { Radius = 10, Falloff = 10, Center = new Vector3(0, 0, 0) }, new SphereField { Radius = 10, Falloff = 10, Center = new Vector3(20, 0, 0) } }; var actualResult = field.GetValue(new Vector3(x, y, z)); Assert.AreEqual(expectedResult, actualResult, 0.00001); }
public void TestDecodeBinaryWithOffset() { CompositeField dec = new CompositeField() .AddParser(new LlvarParseInfo()) .AddParser(new NumericParseInfo(5)) .AddParser(new AlphaParseInfo(1)); int offset = 5; CompositeField f = (CompositeField)dec.DecodeBinaryField(binaryData, offset, binaryData.Length - offset); Assert.NotNull(f); Assert.Equal(3, f.Values.Count); Assert.Equal("Two", f.Values[0].Value); Assert.Equal(999L, f.Values[1].Value); Assert.Equal("X", f.Values[2].Value); }
public void TestEncodeText() { CompositeField f = new CompositeField(); f.AddValue(new IsoValue(IsoType.ALPHA, "One", 5)); f.Values[0].Encoding = Encoding.UTF8; Assert.Equal("One ", f.EncodeField(f)); f.AddValue("Two", null, IsoType.LLVAR, 0); f.Values[1].Encoding = Encoding.UTF8; Assert.Equal("One 03Two", f.EncodeField(f)); f.AddValue(999, null, IsoType.NUMERIC, 5); f.Values[2].Encoding = Encoding.UTF8; Assert.Equal("One 03Two00999", f.EncodeField(f)); f.AddValue("X", null, IsoType.ALPHA, 1); Assert.Equal(textData, f.EncodeField(f)); }
public void TestDecodeText() { CompositeField dec = new CompositeField() .AddParser(new AlphaParseInfo(5)) .AddParser(new LlvarParseInfo()) .AddParser(new NumericParseInfo(5)) .AddParser(new AlphaParseInfo(1)); CompositeField f = (CompositeField)dec.DecodeField(textData); Assert.NotNull(f); Assert.Equal(4, f.Values.Count); Assert.Equal("One ", f.Values[0].Value); Assert.Equal("Two", f.Values[1].Value); Assert.Equal("00999", f.Values[2].Value); Assert.Equal("X", f.Values[3].Value); }
private void cmdOK_Click(object sender, EventArgs e) { using (var transaction = _store.TransactionManager.BeginTransaction(Guid.NewGuid().ToString())) { _composite.Fields.Clear(); foreach (Field column in lstMembers.CheckedItems) { var newField = new CompositeField(_model.Partition); newField.FieldId = column.Id; _composite.Fields.Add(newField); } transaction.Commit(); } this.DialogResult = DialogResult.OK; this.Close(); }
public void TestDecodeBinary() { CompositeField dec = new CompositeField() .AddParser(new AlphaParseInfo(5)) .AddParser(new LlvarParseInfo()) .AddParser(new NumericParseInfo(5)) .AddParser(new AlphaParseInfo(1)); CompositeField f = (CompositeField)dec.DecodeBinaryField(binaryData, 0, binaryData.Length); Assert.NotNull(f); Assert.Equal(4, f.Values.Count); Assert.Equal("One ", f.Values[0].Value); Assert.Equal("Two", f.Values[1].Value); Assert.Equal(999L, f.Values[2].Value); Assert.Equal("X", f.Values[3].Value); }
public void TestEncodeBinary() { CompositeField f = new CompositeField() .AddValue(new IsoValue(IsoType.ALPHA, "One", 5)); Assert.Equal(new sbyte[] { (sbyte)'O', (sbyte)'n', (sbyte)'e', 32, 32 }, f.EncodeBinaryField(f)); f.AddValue(new IsoValue(IsoType.LLVAR, "Two")); Assert.Equal( new sbyte[] { (sbyte)'O', (sbyte)'n', (sbyte)'e', (sbyte)' ', (sbyte)' ', 3, (sbyte)'T', (sbyte)'w', (sbyte)'o' }, f.EncodeBinaryField(f)); f.AddValue(new IsoValue(IsoType.NUMERIC, 999L, 5)); f.AddValue(new IsoValue(IsoType.ALPHA, "X", 1)); Assert.Equal(binaryData, f.EncodeBinaryField(f)); }
public void TestSimpleCompositeTemplate() { string configXml = @"/Resources/composites.xml"; MessageFactory <IsoMessage> mfact = Config(configXml); IsoMessage m = mfact.NewMessage(0x100); //Simple composite Assert.NotNull(m); Assert.False(m.HasField(1)); Assert.False(m.HasField(2)); Assert.False(m.HasField(3)); Assert.False(m.HasField(4)); CompositeField f = (CompositeField)m.GetObjectValue(10); Assert.NotNull(f); Assert.Equal(f.GetObjectValue(0), "abcde"); Assert.Equal(f.GetObjectValue(1), "llvar"); Assert.Equal(f.GetObjectValue(2), "12345"); Assert.Equal(f.GetObjectValue(3), "X"); Assert.False(m.HasField(4)); }
public void TestExtendCompositeWithSameField() { string configXml = @"/Resources/issue47.xml"; MessageFactory <IsoMessage> mfact = Config(configXml); string m200 = "02001000000000000004000000100000013ABCDEFGHIJKLM"; IsoMessage isoMessage = mfact.ParseMessage(m200.GetSbytes(), 0); // check field num 4 IsoValue field4 = isoMessage.GetField(4); Assert.Equal(IsoType.AMOUNT, field4.Type); Assert.Equal(IsoType.AMOUNT.Length(), field4.Length); // check nested field num 4 from composite field 62 CompositeField compositeField62 = (CompositeField)isoMessage.GetField(62).Value; IsoValue nestedField4 = compositeField62.GetField(0); // first in list Assert.Equal(IsoType.ALPHA, nestedField4.Type); Assert.Equal(13, nestedField4.Length); }
private void NestedCompositeTemplate(int type, int fnum) { string configXml = @"/Resources/composites.xml"; MessageFactory <IsoMessage> mfact = Config(configXml); IsoMessage m = mfact.NewMessage(type); Assert.NotNull(m); Assert.False(m.HasField(1)); Assert.False(m.HasField(2)); Assert.False(m.HasField(3)); Assert.False(m.HasField(4)); CompositeField f = (CompositeField)m.GetObjectValue(fnum); Assert.Equal(f.GetObjectValue(0), "fghij"); Assert.Equal(f.GetObjectValue(2), "67890"); Assert.Equal(f.GetObjectValue(3), "Y"); f = (CompositeField)f.GetObjectValue(1); Assert.Equal(f.GetObjectValue(0), "KL"); Assert.Equal(f.GetObjectValue(1), "mn"); f = (CompositeField)f.GetObjectValue(2); Assert.Equal(f.GetObjectValue(0), "123"); Assert.Equal(f.GetObjectValue(1), "45"); }
public void TestNestedCompositeParser() { string configXml = @"/Resources/composites.xml"; MessageFactory <IsoMessage> mfact = Config(configXml); IsoMessage m = mfact.ParseMessage("01010040000000000000019ALPHA11F1F205F03F4X".GetSbytes(), 0); Assert.NotNull(m); Assert.True(m.HasField(10)); CompositeField f = (CompositeField)m.GetObjectValue(10); Assert.NotNull(f.GetField(0)); Assert.NotNull(f.GetField(1)); Assert.NotNull(f.GetField(2)); Assert.Null(f.GetField(3)); Assert.Equal("ALPHA", f.GetObjectValue(0)); Assert.Equal("X", f.GetObjectValue(2)); f = (CompositeField)f.GetObjectValue(1); Assert.Equal("F1", f.GetObjectValue(0)); Assert.Equal("F2", f.GetObjectValue(1)); f = (CompositeField)f.GetObjectValue(2); Assert.Equal("F03", f.GetObjectValue(0)); Assert.Equal("F4", f.GetObjectValue(1)); }
private static void ConstructTree(TreeField root, int index, PathField pathField) { if (index >= pathField.Path.Count) { return; } PathStepField pathStepField = pathField.Path[index++] as PathStepField; Debug.Assert(pathStepField != null, "pathStepField != null"); CompositeField compose1PathStep = pathStepField.StepFieldObject as CompositeField; Debug.Assert(compose1PathStep != null, "compose1PathStep != null"); FieldObject nodeObject = compose1PathStep[compose1PathStep.DefaultProjectionKey]; TreeField child; if (!root.Children.TryGetValue(nodeObject, out child)) { child = new TreeField(nodeObject); root.Children[nodeObject] = child; } ConstructTree(child, index, pathField); }
public override FieldObject Evaluate(RawRecord record) { FieldObject checkObject = record[this.checkFieldIndex]; if (checkObject == null) { return(new StringField("false", JsonDataType.Boolean)); } CollectionField arrayObject = record[this.arrayFieldIndex] as CollectionField; if (arrayObject != null) { foreach (FieldObject fieldObject in arrayObject.Collection) { if (fieldObject is CompositeField) { CompositeField compose1Field = fieldObject as CompositeField; if (checkObject.Equals(compose1Field[compose1Field.DefaultProjectionKey])) { return(new StringField("true", JsonDataType.Boolean)); } } else if (checkObject.Equals(fieldObject)) { return(new StringField("true", JsonDataType.Boolean)); } } return(new StringField("false", JsonDataType.Boolean)); } return(checkObject.Equals(record[this.arrayFieldIndex]) ? new StringField("true", JsonDataType.Boolean) : new StringField("false", JsonDataType.Boolean)); }
/// <summary> /// /// </summary> /// <typeparam name="TField1"></typeparam> /// <typeparam name="TField2"></typeparam> /// <param name="name"></param> /// <param name="field1"></param> /// <param name="field2"></param> /// <param name="unique"></param> private void CreateIndex <TField1, TField2>(string name, IField <TRecord, TField1> field1, IField <TRecord, TField2> field2, bool unique) { this.table.ValidateField(field1); this.table.ValidateField(field2); if (field1 == field2) { throw new ArgumentException(Properties.Resources.ErrorCompositeFields); } CompositeField <TField1, TField2> field = new CompositeField <TField1, TField2>(field1, field2); IFieldIndex <Composite <TField1, TField2> > index; if (unique) { index = new UniqueIndex <Composite <TField1, TField2> >(this.table, name, field); } else { index = new RangeIndex <Composite <TField1, TField2> >(this.table, name, field); } List <IIndex <TRecord> > list1 = this.table.Indexes[field1.Order]; if (list1 == null) { list1 = new List <IIndex <TRecord> >(); this.table.Indexes[field1.Order] = list1; } List <IIndex <TRecord> > list2 = this.table.Indexes[field2.Order]; if (list2 == null) { list2 = new List <IIndex <TRecord> >(); this.table.Indexes[field2.Order] = list2; } list1.Add(index); list2.Add(index); }
/// <summary> /// Creates an IsoValue from the XML definition in a message template. /// If it's for a toplevel field and the message factory has a codec for this field, /// that codec is assigned to that field. For nested fields, a CompositeField is /// created and populated. /// </summary> /// <returns>The template field.</returns> /// <param name="f">xml element</param> /// <param name="mfact">message factory</param> /// <param name="toplevel">If set to <c>true</c> toplevel.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> private static IsoValue GetTemplateField <T>(XmlElement f, MessageFactory <T> mfact, bool toplevel) where T : IsoMessage { var num = int.Parse(f.GetAttribute("num")); var typedef = f.GetAttribute("type"); if ("exclude".Equals(typedef)) { return(null); } var length = 0; if (f.GetAttribute("length").Length > 0) { length = int.Parse(f.GetAttribute("length")); } var itype = Enumm.Parse <IsoType>(typedef); var subs = f.GetElementsByTagName("field"); if (subs.Count > 0) { var cf = new CompositeField(); for (var j = 0; j < subs.Count; j++) { var sub = (XmlElement)subs.Item(j); if (sub != null && sub.ParentNode != f) { continue; } var sv = GetTemplateField( sub, mfact, false); if (sv == null) { continue; } sv.Encoding = mfact.Encoding; cf.AddValue(sv); } Debug.Assert(itype != null, nameof(itype) + " != null"); return(itype.Value.NeedsLength() ? new IsoValue( itype.Value, cf, length, cf) : new IsoValue( itype.Value, cf, cf)); } var v = f.ChildNodes.Count == 0 ? string.Empty : f.ChildNodes.Item(0)?.Value; var customField = toplevel ? mfact.GetCustomField(num) : null; if (customField != null) { Debug.Assert( itype != null, "itype != null"); return(itype.Value.NeedsLength() ? new IsoValue( itype.Value, customField.DecodeField(v), length, customField) : new IsoValue( itype.Value, customField.DecodeField(v), customField)); } Debug.Assert( itype != null, "itype != null"); return(itype.Value.NeedsLength() ? new IsoValue( itype.Value, v, length) : new IsoValue( itype.Value, v)); }
private static void LoadEntityComposites(string folder, Entity entity) { XmlDocument document = null; var fileName = Path.Combine(folder, entity.Name + ".composites.xml"); if (!File.Exists(fileName)) return; try { document = new XmlDocument(); document.Load(fileName); } catch (Exception ex) { //Do Nothing MessageBox.Show("The file '" + fileName + "' is not valid and could not be loaded!", "Load Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } foreach (XmlNode n in document.DocumentElement) { var newComposite = new Composite(entity.Partition); entity.Composites.Add(newComposite); newComposite.Summary = XmlHelper.GetNodeValue(document.DocumentElement, "summary", newComposite.Summary); newComposite.CodeFacade = XmlHelper.GetAttributeValue(n, "codefacade", newComposite.CodeFacade); newComposite.IsGenerated = XmlHelper.GetAttributeValue(n, "isgenerated", newComposite.IsGenerated); newComposite.Name = XmlHelper.GetAttributeValue(n, "name", newComposite.Name); var columnsNode = n.SelectSingleNode("columnset"); if (columnsNode != null) { foreach (XmlNode m in columnsNode.ChildNodes) { var newField = new CompositeField(entity.Partition); newComposite.Fields.Add(newField); newField.FieldId = XmlHelper.GetAttributeValue(m, "fieldid", newField.FieldId); } } } }
public override RawRecord Next() { if (!this.State()) { return(null); } RawRecord r = null; while (this.inputOp.State() && (r = this.inputOp.Next()) != null) { FieldObject groupByKey = groupByKeyFunction.Evaluate(r); if (groupByKey == null) { throw new GraphViewException("The provided property name or traversal does not map to a value for some elements."); } if (!this.groupedStates.ContainsKey(groupByKey)) { this.groupedStates.Add(groupByKey, new List <RawRecord>()); } this.groupedStates[groupByKey].Add(r); } MapField result = new MapField(this.groupedStates.Count); if (this.isProjectingACollection) { foreach (FieldObject key in groupedStates.Keys) { List <FieldObject> projectFields = new List <FieldObject>(); this.container.ResetTableCache(groupedStates[key]); this.aggregateOp.ResetState(); for (int i = 0; i < groupedStates[key].Count; i++) { RawRecord aggregateTraversalRecord = this.aggregateOp.Next(); FieldObject projectResult = aggregateTraversalRecord?.RetriveData(0); if (projectResult == null) { throw new GraphViewException("The property does not exist for some of the elements having been grouped."); } projectFields.Add(projectResult); } Dictionary <string, FieldObject> compositeFieldObjects = new Dictionary <string, FieldObject>(); compositeFieldObjects.Add(DocumentDBKeywords.KW_TABLE_DEFAULT_COLUMN_NAME, new CollectionField(projectFields)); result[key] = new CompositeField(compositeFieldObjects, DocumentDBKeywords.KW_TABLE_DEFAULT_COLUMN_NAME); } } else { foreach (KeyValuePair <FieldObject, List <RawRecord> > pair in this.groupedStates) { FieldObject key = pair.Key; this.aggregateOp.ResetState(); this.container.ResetTableCache(pair.Value); RawRecord aggregateTraversalRecord = null; FieldObject aggregateResult = null; while (this.aggregateOp.State() && (aggregateTraversalRecord = this.aggregateOp.Next()) != null) { aggregateResult = aggregateTraversalRecord.RetriveData(0) ?? aggregateResult; } if (aggregateResult == null) { continue; } result[key] = aggregateResult; } } RawRecord resultRecord = new RawRecord(); for (int i = 0; i < this.carryOnCount; i++) { resultRecord.Append((FieldObject)null); } resultRecord.Append(result); this.Close(); return(resultRecord); }