public override Dictionary<String, Option> match(Dictionary<String, Option> variables, TransactionalStreamReader input, out List<Option> fields) { input.startTransaction(); Dictionary<String, Option> myEnv = variables; fields = new List<Option>(); foreach (Rule rule in rules) { List<Option> newFields; myEnv = rule.match(myEnv, input, out newFields); if (myEnv == null) break; if (newFields != null) fields.AddRange(newFields); } if (myEnv == null) { input.cancelTransaction(); if (failSilently) return variables; else return null; } else { if (this.name != null) myEnv[name] = new OptionArray(name, input.getTransactionData()); input.commitTransaction(); return myEnv; } }
public void cancelTransactionTest() { Stream stream = new MemoryStream(); TransactionalStreamReader target = new TransactionalStreamReader(stream); // Przygotuj dane testowe stream.WriteByte(9); stream.WriteByte(20); stream.WriteByte(31); stream.WriteByte(42); stream.Seek(0, SeekOrigin.Begin); target.startTransaction(); Assert.AreEqual(target.ReadByte(), 9); Assert.AreEqual(target.ReadByte(), 20); target.cancelTransaction(); target.startTransaction(); Assert.AreEqual(target.ReadByte(), 9); Assert.AreEqual(target.ReadByte(), 20); Assert.AreEqual(target.ReadByte(), 31); Assert.AreEqual(target.ReadByte(), 42); target.cancelTransaction(); Assert.AreEqual(stream.ReadByte(), -1); // Cały strumien został zjedzony }
public override bool match(TransactionalStreamReader s) { // First, read whatever is in the stream int newValue = 0; s.startTransaction(); for (int i = 0; i < Size; i++) { newValue |= s.ReadByte() << (8*i); } if (MinValue > newValue || newValue > MaxValue) { s.cancelTransaction(); return false; } if (myValue == null) { Value = newValue; s.commitTransaction(); return true; } else // myValue != null if (myValue == newValue) { s.commitTransaction(); return true; } else { s.cancelTransaction(); return false; } }
public override bool match(TransactionalStreamReader s) { // FIXME: wczytywanie vs. dopasowanie tablic s.startTransaction(); foreach (Option o in OptionsArray) if (!o.match(s)) { s.cancelTransaction(); return false; } s.commitTransaction(); return true; }
public Dictionary<string, Option> matchIncoming(Dictionary<string, Option> env, TransactionalStreamReader transStream, List<Message> excluded, out List<Option> fields) { List<Message> oldExcluded = excludedSoFar; excludedSoFar = excluded; Dictionary<String, Option> nextEnv = null; fields = new List<Option>(); foreach (Message msg in requestMsgs) { if (!excluded.Contains(msg)) { List<Option> newFields; Message oldCurrentMsg = currentMessage; currentMessage = msg; transStream.startTransaction(); nextEnv = msg.match(env, transStream, out newFields); currentMessage = oldCurrentMsg; if (nextEnv == null) transStream.cancelTransaction(); else { if (newFields != null) fields.AddRange(newFields); transStream.commitTransaction(); break; } } } excludedSoFar = oldExcluded; return nextEnv; }