public void CamelizeTest() { var jsp = new JsonParser() { CamelizeProperties = true }; var res = jsp.Parse(Properties.Resources.json_camelize); Assert.AreEqual("JP", res.UserName); Assert.AreEqual(100.0, res.FollowerCount); Assert.AreEqual("no_way", res.Something); Assert.AreEqual("ok", res["Don'tDoIt"]); }
static void Main(string[] args) { //Encoder tests Console.WriteLine("Encoder tests"); string text = System.IO.File.ReadAllText("config/0.txt"); var jsonParser = new JsonParser() { CamelizeProperties = false }; dynamic config = jsonParser.Parse(System.IO.File.ReadAllText("config\\0.txt")); ReceiverSlice.Encoder enc = new ReceiverSlice.Encoder("111111.2#33", config); Console.Write("Build INFO command: "); }
public void Parse2Test() { var jsp = new JsonParser(); dynamic res = jsp.Parse(Properties.Resources.json_example2); Assert.AreEqual("file", res.menu.id); Assert.AreEqual("File", res.menu.value); Assert.AreEqual("New", res.menu.popup.menuitems[0].value); Assert.AreEqual("Open", res.menu.popup.menuitems[1].value); Assert.AreEqual("Close", res.menu.popup.menuitems[2].value); Assert.AreEqual("CreateNewDoc()", res.menu.popup.menuitems[0].onclick); Assert.AreEqual("OpenDoc()", res.menu.popup.menuitems[1].onclick); Assert.AreEqual("CloseDoc()", res.menu.popup.menuitems[2].onclick); }
static void testDecoder(Decoder decoder) { var jsonParser = new JsonParser() { CamelizeProperties = false }; dynamic config = jsonParser.Parse(System.IO.File.ReadAllText("config.txt")); Console.WriteLine("-----------------Decoder Test-----------------"); //printDecodedMessage(decoder.Decode(new UnparsedMessage("*450052.0#16[0099],2012-10-02 21:14:45,STS,DC=0,PC=0,LV=0.0,BV=3.2,BU=3.6,I=5.3,T=23.9,DU=0.0,RU=0.0,STORAGE,OK,#E3", null, null, null, null, config))); //printDecodedMessage(decoder.Decode(new UnparsedMessage("*450052.0#16[0014],INVALID,#07", null, null, null, null, config))); //printDecodedMessage(decoder.Decode(new UnparsedMessage("*450052.0#16[0009],OK,#9A", null, null, null, null, config))); //printDecodedMessage(decoder.Decode(new UnparsedMessage("450052,000,2012-10-02 21:19:19,STS,DC=0,PC=0,LV=0.0,BV=3.2,BU=3.6,I=2.7,T=23.7,DU=0.0,RU=0.0,XYZ=-0.06:-0.22:0.94,#8C", null, null, null, null, config))); //printDecodedMessage(decoder.Decode(new UnparsedMessage("450052,001,2012-10-02 21:20:01,A69-9001,30444,#B3", null, null, null, null, config))); //printDecodedMessage(decoder.Decode(new UnparsedMessage("450052,032,2012-10-02 21:40:42,A69-1303,48823,#C5", null, null, null, null, config))); //printDecodedMessage(decoder.Decode(new UnparsedMessage("450052,039,2012-10-02 21:42:17,A69-9001,30,444,#CA", null, null, null, null, config))); //printDecodedMessage(decoder.Decode(new UnparsedMessage("*450052.0#16[0099],VR2C-69:450052,'VEMCO',MAP-113 [ 1105 1303 9001/9002 1420 1430 1601 1602 ],FW=0.0.25,HW=3,OK,#57", null, null, null, null, config))); //printDecodedMessage(decoder.Decode(new UnparsedMessage("*450052.0#16[0125],2012-10-02 21:47:06,STS,DC=108,PC=1199,LV=0.0,BV=3.2,BU=3.6,I=5.3,T=23.1,DU=0.0,RU=0.1,XYZ=-0.06:-0.22:0.94,STOPPED,OK,#89", null, null, null, null, config))); //printDecodedMessage(decoder.Decode(new UnparsedMessage("*450052.0#16[0053],232,SI=60,BL=U,BI=1,MA=U,FMT=SER SEQ UTC CS,OK,#8A", null, null, null, null, config))); }
public void CamelizeTest() { GetJsonFile("json_camelize.json", (j) => { _json = j; _finished = true; }); EnqueueConditional(() => _finished); EnqueueCallback(() => { var jsp = new JsonParser() { CamelizeProperties = true }; dynamic res = jsp.Parse(_json); Assert.AreEqual("JP", res.UserName); Assert.AreEqual(100.0, res.FollowerCount); Assert.AreEqual("no_way", res.Something); Assert.AreEqual("ok", res["Don'tDoIt"]); }); EnqueueTestComplete(); }
public void Parse1Test() { var jsp = new JsonParser(); dynamic res = jsp.Parse(Properties.Resources.json_example1); Assert.AreEqual(res.glossary.title, "example glossary"); Assert.AreEqual(res.glossary.GlossDiv.title, "S"); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.ID, "SGML"); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.SortAs, "SGML"); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.GlossTerm, "Standard Generalized Markup Language"); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.Abbrev, "ISO 8879:1986"); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.GlossDef.para, "A meta-markup language, used to create markup languages such as DocBook."); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso[0], "GML"); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso[1], "XML"); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.GlossSee, "markup"); }
static void Main(string[] args) { var jsonParser = new JsonParser() { CamelizeProperties = false }; dynamic config = jsonParser.Parse(System.IO.File.ReadAllText("config.txt")); Dispatcher dispatcher = new Dispatcher(); Database database = new Database(dispatcher, config); Decoder decoder = new Decoder(dispatcher); Receiver receiver = new Receiver("450052", "VR2C-69", dispatcher); Encoder encoder = new Encoder("*450052.0#16,", config); ConsoleLogger consoleLogger = new ConsoleLogger(dispatcher); dispatcher.addModule(database); dispatcher.addModule(decoder); dispatcher.addModule(consoleLogger); dispatcher.run(); testUnparsedMessages(dispatcher, receiver, config); //testEncoder(encoder); //testDecoder(decoder); //testDatabase(database); }
public void Parse1Test() { GetJsonFile("json_example1.json", (j) => { _json = j; _finished = true; }); EnqueueConditional(() => _finished); EnqueueCallback(() => { var jsp = new JsonParser(); dynamic res = jsp.Parse(_json); Assert.AreEqual(res.glossary.title, "example glossary"); Assert.AreEqual(res.glossary.GlossDiv.title, "S"); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.ID, "SGML"); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.SortAs, "SGML"); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.GlossTerm, "Standard Generalized Markup Language"); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.Abbrev, "ISO 8879:1986"); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.GlossDef.para, "A meta-markup language, used to create markup languages such as DocBook."); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso[0], "GML"); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso[1], "XML"); Assert.AreEqual(res.glossary.GlossDiv.GlossList.GlossEntry.GlossSee, "markup"); }); EnqueueTestComplete(); }
/// <summary> /// The constructor for the Database module. /// </summary> /// <param name="dispatcher">The Dispatcher this object will receive messages from.</param> public Database(Dispatcher dispatcher) : base(dispatcher) { var jsonParser = new JsonParser() { CamelizeProperties = false }; this.config = jsonParser.Parse(System.IO.File.ReadAllText(DATABASE_CONFIG_FILE)); if (config.database.use == "true") { host = config.database.host; db = config.database.name; user = config.database.user; pass = config.database.pass; } connectionString = "Server=" + host + ";Database=" + db + ";Uid=" + user + ";Pwd=" + pass + ";"; updateSensorCalibrations(config); insertions = new List<string>(); try { logWriter = new System.IO.StreamWriter(config.log_file, false); } catch (Exception e) { } }
public void Parse5Test() { GetJsonFile("json_example5.json", (j) => { _json = j; _finished = true; }); EnqueueConditional(() => _finished); EnqueueCallback(() => { var jsp = new JsonParser(); dynamic res = jsp.Parse(_json); Assert.AreEqual(8, res.Count); Assert.AreEqual("Open", res[0].id); Assert.AreEqual("OpenNew", res[1].id); Assert.AreEqual("Open New", res[1]["true"]); Assert.AreEqual(null, res[2]); Assert.AreEqual(false, res[3].id); Assert.AreEqual(true, res[4].label); Assert.AreEqual(true, res[5]); Assert.AreEqual("Mute", res[6].id); Assert.AreEqual(null, res[7]); }); EnqueueTestComplete(); }
public void Parse3Test() { var jsp = new JsonParser(); dynamic res = jsp.Parse(Properties.Resources.json_example3); Assert.AreEqual("on", res.widget.debug); Assert.AreEqual("Sample Konfabulator Widget", res.widget.window.title); Assert.AreEqual(500.0, res.widget.window.width); Assert.AreEqual(600, res.widget.window.height); }
public void SpecialCharsParseStringsTest() { GetJsonFile("json_strings.json", (j) => { _json = j; _finished = true; }); EnqueueConditional(() => _finished); EnqueueCallback(() => { var jsp = new JsonParser(); dynamic obj = jsp.Parse(_json); Assert.AreEqual("you are a \"silly\" person.", obj.a); Assert.AreEqual("my name is 'JP'", obj.b); Assert.AreEqual("testing a new \n line.", obj.c); }); EnqueueTestComplete(); }
public void SimpleUnicodeParseTest() { GetJsonFile("json_unicode.json", (j) => { _json = j; _finished = true; }); EnqueueConditional(() => _finished); EnqueueCallback(() => { var jsp = new JsonParser(); dynamic res = jsp.Parse(_json); Assert.AreEqual("÷", res.div); Assert.AreEqual("Σ", res.sigma); Assert.AreEqual("လ", res.inf); }); EnqueueTestComplete(); }
public void SimpleUnicodeParseTest() { var jsp = new JsonParser(); var res = jsp.Parse(Properties.Resources.json_unicode); Assert.AreEqual("÷", res.div); Assert.AreEqual("Σ", res.sigma); Assert.AreEqual("လ", res.inf); }
public void SpecialCharsParseStringsTest() { var json = Properties.Resources.json_strings; var jsp = new JsonParser(); dynamic obj = jsp.Parse(json); Assert.AreEqual("you are a \"silly\" person.", obj.a); Assert.AreEqual("my name is 'JP'", obj.b); Assert.AreEqual("testing a new \n line.", obj.c); }
public void SimpleNumbersParseTest() { var jsp = new JsonParser(); //dynamic n = jsp.Parse("[\"1.0\"]"); Assert.AreEqual(1.0, jsp.Parse("1.0")); Assert.AreEqual(-1.0, jsp.Parse("-1.0")); Assert.AreEqual(1.0, jsp.Parse("1")); Assert.AreEqual(-1.0, jsp.Parse("-1")); Assert.AreEqual(4.5e10, jsp.Parse("4.5e10")); Assert.AreEqual(-4.5e10, jsp.Parse("-4.5e10")); Assert.AreEqual(99.0e-10, jsp.Parse("99.0e-10")); Assert.AreEqual(-1.343424e-10, jsp.Parse("-1.343424e-10")); Assert.AreEqual(4.5e10, jsp.Parse("4.5E10")); Assert.AreEqual(-4.5e10, jsp.Parse("-4.5E10")); Assert.AreEqual(99.0e-10, jsp.Parse("99.0E-10")); Assert.AreEqual(4.5e10, jsp.Parse("4.5e+10")); Assert.AreEqual(-4.5e10, jsp.Parse("-4.5e+10")); }
/// <summary> /// Called by the constructor to determine whether a VEMCO receiver is attached (vs another kind of /// serial device), what the firmware is and which configuration file should be used. /// </summary> /// <remarks> /// Because one of the goals of this method is to determine the firmware (and corresponding configuration file), /// for the most part we must try both "default" commands and all those available in the configuration files. /// One assumption here is that future changes to protocol's INFO and discovery methods will not interfere with /// the operation of prior receivers. And although we can take some care to provide as much flexibility for /// changes in the protocol, there are clearly some limits. For example, we cannot anticipate a change to /// a binary format. /// /// The init() method first attempts to "discover" the connected receiver. Generally a receiver will not respond /// to commands that are not prefaced by the serial number, etc. Since we do not have the serial number prior to /// running this method, we must use the VEMCO's broadcast and discover commands. /// /// Next the method issues INFO commands in order to scrape out the firmware version. We assume here that the /// manufacturer's protocol will remain stable within a firmware version. Also note that so long as the protocol /// itself does not change, there is no need for additional configuration files. /// /// Assuming that these two tasks are completed without bailing, then init() command completes and returns /// control to the constructor. /// </remarks> /// <exception cref="ReceiverExceptions">Thrown when either the discovery /// or info phase is not able to acquire the needed information</exception> public void init() { Dictionary<Double, List<dynamic>> discoveryMethods = new Dictionary<Double, List<dynamic>>(); Dictionary<Double, String> infoMethods = new Dictionary<Double, String>(); String discoveryReturns = ""; var jsonParser = new JsonParser() { CamelizeProperties = false }; foreach (string filename in System.IO.Directory.GetFiles(VR2C_COMMAND_FOLDER)) { dynamic config = jsonParser.Parse(System.IO.File.ReadAllText(filename)); var dc = config.discovery_commands; var fwver = config.firmware_version; try { infoMethods.Add(fwver, (string)config.encoder["INFO"]); } catch(Exception e) { ReceiverExceptions re = new ReceiverExceptions(this, "INFO command not found in " + "configuration file: " + filename + ". This is normally not fatal on its own but " + "indicates a serious problem with the format/content of the config file.", false,e); dispatcher.enqueueEvent(new RealTimeEvents.ExcepReceiver(re.fatal, re.ToString(), this, this.portName, null, null, null)); } try { discoveryMethods.Add(((int)fwver), dc); } catch (Exception e) { ReceiverExceptions re = new ReceiverExceptions(this, "Discovery commands not found in " + "configuration file: " + filename + ". This is normally not fatal on its own but " + "indicates a serious problem with the format/content of the config file.", false, e); dispatcher.enqueueEvent(new RealTimeEvents.ExcepReceiver(re.fatal, re.text, this, this.portName, null, null, null)); } } List<dynamic> default_discovery = new List<dynamic>(); default_discovery.Add("*BROADC.A#ST,QUIT"); default_discovery.Add("*BROADC.A#ST,DISCOVERY"); default_discovery.Add("*DISCOV.E#RY,DISCOVERY"); discoveryMethods.Add(-1, default_discovery); int discovery_attempts = 0; serialPort.ReadExisting(); while (serialPort.BytesToRead <= 0 && discovery_attempts < 5) { write_wait = (discovery_attempts + 1) * 100; foreach (List<dynamic> l in discoveryMethods.Values) { foreach(var command in l) { _write(command); } } discovery_attempts++; } if (discovery_attempts >= 5) { ReceiverExceptions re = new ReceiverExceptions(this, "Not able to discover VEMCO receiver attached on this port.", true); dispatcher.enqueueEvent(new RealTimeEvents.ExcepReceiver(re,re.fatal, this, this.portName, null,null, null)); serialPort.Close(); throw re; } while (serialPort.BytesToRead > 0) { discoveryReturns = serialPort.ReadExisting(); } string commandPreamble = discoveryReturns.Substring(0, 12) + ","; this.VEMCO_SerialNumber = discoveryReturns.Substring(1,6); dispatcher.enqueueEvent(new RealTimeEvents.NoteReceiver("command preamble: " + discoveryReturns.Substring(0,12) + ",", this, this.portName, this.VEMCO_SerialNumber, null, null)); dispatcher.enqueueEvent(new RealTimeEvents.NoteReceiver("read: " + discoveryReturns, this, this.portName, this.VEMCO_SerialNumber, null, null)); infoMethods.Add(-1, commandPreamble + "INFO"); int info_attempts = 0; serialPort.ReadExisting(); Boolean gotINFO = false; String infoReturns = ""; int read_attempts = 0; while (!gotINFO && read_attempts < 5) { info_attempts = 0; serialPort.ReadExisting(); while (serialPort.BytesToRead <= 0 && info_attempts < 5) { foreach (String infoc in infoMethods.Values) { dispatcher.enqueueEvent(new RealTimeEvents.NoteReceiver("(receiver note) attempting INFO command with " + infoc, this, this.portName, this.VEMCO_SerialNumber, null, null)); _write(infoc); Thread.Sleep(500); } info_attempts++; } while (serialPort.BytesToRead > 0 && !(infoReturns.Contains(crlf[0]) || infoReturns.Contains(crlf[1]))) { infoReturns = serialPort.ReadExisting(); foreach (string filename in System.IO.Directory.GetFiles(VR2C_COMMAND_FOLDER)) { dynamic config = jsonParser.Parse(System.IO.File.ReadAllText(filename)); if (Regex.IsMatch(infoReturns, config.decoder.sentences["info_response"].format)) { gotINFO = true; } } } read_attempts++; } if (read_attempts >= 5) { ReceiverExceptions re = new ReceiverExceptions(this, "(FATAL) Not able to get INFO from the VEMCO receiver attached on this port.", true); dispatcher.enqueueEvent(new RealTimeEvents.ExcepReceiver(re, re.fatal, this, this.portName, this.VEMCO_SerialNumber, null, null)); serialPort.Close(); throw re; } int RECEIVER_FW_VERSION = -1; if (infoReturns != "") { int fw_start = infoReturns.IndexOf("FW="); int fw_end = infoReturns.IndexOf(",", fw_start); string fw_ver = infoReturns.Substring((fw_start + 3), (fw_end - fw_start - 3)); int fw_ver_firstperiod = fw_ver.IndexOf("."); int fw_ver_secondperiod = fw_ver.IndexOf(".", fw_ver_firstperiod + 1); string major = fw_ver.Substring(0, fw_ver_firstperiod); string minor = fw_ver.Substring(fw_ver_firstperiod + 1, (fw_ver_secondperiod - fw_ver_firstperiod - 1)); string release = fw_ver.Substring(fw_ver_secondperiod + 1, (fw_ver.Length - fw_ver_secondperiod - 1)); RECEIVER_FW_VERSION = (Int32.Parse(major) * 10000) + (Int32.Parse(minor) * 100) + (Int32.Parse(release)); } dispatcher.enqueueEvent(new RealTimeEvents.NoteReceiver("Detected firmware version: " + RECEIVER_FW_VERSION, this, this.portName, this.VEMCO_SerialNumber, this.VEMCO_Model, null)); if (RECEIVER_FW_VERSION >= 0) { int fw_use = -1; foreach (string filename in System.IO.Directory.GetFiles(VR2C_COMMAND_FOLDER)) { string text = System.IO.File.ReadAllText(filename); dynamic config = jsonParser.Parse(System.IO.File.ReadAllText(filename)); if (config.firmware_version >= fw_use && config.firmware_version <= RECEIVER_FW_VERSION) { fw_use = (Int32)config.firmware_version; encoder = new Encoder(commandPreamble, config); } } if (fw_use < 0 || encoder == null) { ReceiverExceptions re = new ReceiverExceptions(this, "(FATAL) Unable to parse out FW version from return from INFO command.", true); dispatcher.enqueueEvent(new RealTimeEvents.ExcepReceiver(re, re.fatal, this, this.portName, this.VEMCO_SerialNumber, null, null)); serialPort.Close(); throw re; } } else { ReceiverExceptions re = new ReceiverExceptions(this, "(FATAL) Unable to parse out FW version from return from INFO command.", true); dispatcher.enqueueEvent(new RealTimeEvents.ExcepReceiver(re,re.fatal, this, this.portName, this.VEMCO_SerialNumber, null, null)); serialPort.Close(); throw re; } Match matches = Regex.Match(infoReturns, encoder.encoderConfig.decoder.words["receiver_model"]); VEMCO_Model = matches.Groups[1].ToString(); dispatcher.enqueueEvent(new RealTimeEvents.NoteReceiver("(receiver note) Successfully configured encoder with fw version = " + encoder.encoderConfig.firmware_version, this, this.portName, this.VEMCO_SerialNumber, this.VEMCO_Model, this.encoder.encoderConfig)); }
public void SimpleArrayParseTest() { var jsp = new JsonParser(); dynamic arr = jsp.Parse("[\"a\", \"b\", \"c\"]"); Assert.AreEqual(3, arr.Count); Assert.AreEqual("a", arr[0]); Assert.AreEqual("b", arr[1]); Assert.AreEqual("c", arr[2]); arr = jsp.Parse("[\"a\"]"); Assert.AreEqual(1, arr.Count); Assert.AreEqual("a", arr[0]); arr = jsp.Parse(" \t\n[\"a \", \"b\", \t\"c\"]\t"); Assert.AreEqual(3, arr.Count); Assert.AreEqual("a ", arr[0]); Assert.AreEqual("b", arr[1]); arr = jsp.Parse("\t\n\r [ \r\n\t\t ] \n\t"); Assert.AreEqual(0, arr.Count); }
public void SimpleBooleanNullParseTest() { var jsp = new JsonParser(); Assert.IsTrue(jsp.Parse("true")); Assert.IsFalse(jsp.Parse("false")); Assert.IsNull(jsp.Parse("null")); }
public void Parse3Test() { GetJsonFile("json_example3.json", (j) => { _json = j; _finished = true; }); EnqueueConditional(() => _finished); EnqueueCallback(() => { var jsp = new JsonParser(); dynamic res = jsp.Parse(_json); Assert.AreEqual("on", res.widget.debug); Assert.AreEqual("Sample Konfabulator Widget", res.widget.window.title); Assert.AreEqual(500.0, res.widget.window.width); Assert.AreEqual(600, res.widget.window.height); }); EnqueueTestComplete(); }
public void Parse4Test() { var jsp = new JsonParser(); dynamic res = jsp.Parse(Properties.Resources.json_example4); Assert.AreEqual("org.cofax.cds.CDSServlet", res["web-app"].servlet[0]["servlet-class"]); Assert.AreEqual("*****@*****.**", res["web-app"].servlet[0]["init-param"]["configGlossary:adminEmail"]); Assert.AreEqual(500.0, res["web-app"].servlet[0]["init-param"].maxUrlLength); Assert.AreEqual("/WEB-INF/tlds/cofax.tld", res["web-app"].taglib["taglib-location"]); }
public void Parse2Test() { GetJsonFile("json_example2.json", (j) => { _json = j; _finished = true; }); EnqueueConditional(() => _finished); EnqueueCallback(() => { var jsp = new JsonParser(); dynamic res = jsp.Parse(_json); Assert.AreEqual("file", res.menu.id); Assert.AreEqual("File", res.menu.value); Assert.AreEqual("New", res.menu.popup.menuitems[0].value); Assert.AreEqual("Open", res.menu.popup.menuitems[1].value); Assert.AreEqual("Close", res.menu.popup.menuitems[2].value); Assert.AreEqual("CreateNewDoc()", res.menu.popup.menuitems[0].onclick); Assert.AreEqual("OpenDoc()", res.menu.popup.menuitems[1].onclick); Assert.AreEqual("CloseDoc()", res.menu.popup.menuitems[2].onclick); }); EnqueueTestComplete(); }
public void Parse4Test() { GetJsonFile("json_example4.json", (j) => { _json = j; _finished = true; }); EnqueueConditional(() => _finished); EnqueueCallback(() => { var jsp = new JsonParser(); dynamic res = jsp.Parse(_json); Assert.AreEqual("org.cofax.cds.CDSServlet", res["web-app"].servlet[0]["servlet-class"]); Assert.AreEqual("*****@*****.**", res["web-app"].servlet[0]["init-param"]["configGlossary:adminEmail"]); Assert.AreEqual(500.0, res["web-app"].servlet[0]["init-param"].maxUrlLength); Assert.AreEqual("/WEB-INF/tlds/cofax.tld", res["web-app"].taglib["taglib-location"]); }); EnqueueTestComplete(); }
public void SimpleObjectParseTest() { var jsp = new JsonParser(); dynamic obj = jsp.Parse("{\"name\": \"JP\"}"); Assert.AreEqual("JP", obj.name); obj = jsp.Parse("{\"name\":\"Jon Paul\"}"); Assert.AreEqual("Jon Paul", obj.name); obj = jsp.Parse("{\"msg\":\"My name is \\\"JP\\\" ok?\"}"); Assert.AreEqual("My name is \"JP\" ok?", obj.msg); Assert.IsFalse(obj.IsEmpty); obj = jsp.Parse(" { \r\n }\t"); Assert.IsTrue(obj.IsEmpty); }
public void Parse5Test() { var jsp = new JsonParser(); dynamic res = jsp.Parse(Properties.Resources.json_example5); Assert.AreEqual(8, res.Count); Assert.AreEqual("Open", res[0].id); Assert.AreEqual("OpenNew", res[1].id); Assert.AreEqual("Open New", res[1]["true"]); Assert.AreEqual(null, res[2]); Assert.AreEqual(false, res[3].id); Assert.AreEqual(true, res[4].label); Assert.AreEqual(true, res[5]); Assert.AreEqual("Mute", res[6].id); Assert.AreEqual(null, res[7]); }
/// <summary> /// Called by the constructor to determine whether a VEMCO receiver is attached (vs another kind of /// serial device), what the firmware is and which configuration file should be used. /// </summary> /// <remarks> /// Because one of the goals of this method is to determine the firmware (and corresponding configuration file), /// for the most part we must try both "default" commands and all those available in the configuration files. /// One assumption here is that future changes to protocol's INFO and discovery methods will not interfere with /// the operation of prior receivers. And although we can take some care to provide as much flexibility for /// changes in the protocol, there are clearly some limits. For example, we cannot anticipate a change to /// a binary format. /// /// The init() method first attempts to "discover" the connected receiver. Generally a receiver will not respond /// to commands that are not prefaced by the serial number, etc. Since we do not have the serial number prior to /// running this method, we must use the VEMCO's broadcast and discover commands. /// /// Next the method issues INFO commands in order to scrape out the firmware version. We assume here that the /// manufacturer's protocol will remain stable within a firmware version. Also note that so long as the protocol /// itself does not change, there is no need for additional configuration files. /// /// Assuming that these two tasks are completed without bailing, then init() command completes and returns /// control to the constructor. /// </remarks> /// <exception cref="ReceiverExceptions">Thrown when either the discovery /// or info phase is not able to acquire the needed information</exception> public void init() { Dictionary<Int32, List<dynamic>> discoveryMethods = new Dictionary<Int32, List<dynamic>>(); Dictionary<Int32, String> infoMethods = new Dictionary<Int32, String>(); String discoveryReturns = ""; var jsonParser = new JsonParser() { CamelizeProperties = false }; //foreach (string filename in System.IO.Directory.GetFiles(VR2C_COMMAND_FOLDER)) //{ // dynamic config = jsonParser.Parse(System.IO.File.ReadAllText(filename)); // var dc = config.discovery_commands; // var fwver = config.firmware_version; // try // { // infoMethods.Add(fwver, (string)config.encoder["INFO"]); // } // catch(Exception e) // { // ReceiverExceptions re = new ReceiverExceptions(this, "INFO command not found in " + // "configuration file: " + filename + ". This is normally not fatal on its own but " + // "indicates a serious problem with the format/content of the config file.", // false,e); // dispatcher.enqueueEvent(new ExcepReceiver(re.fatal, re.ToString(), // this, this.portName, null, null, null)); // } // try // { // discoveryMethods.Add(((int)fwver), dc); // } // catch (Exception e) // { // ReceiverExceptions re = new ReceiverExceptions(this, "Discovery commands not found in " + // "configuration file: " + filename + ". This is normally not fatal on its own but " + // "indicates a serious problem with the format/content of the config file.", // false, e); // dispatcher.enqueueEvent(new ExcepReceiver(re.fatal, re.text, // this, this.portName, null, null, null)); // } //} List<dynamic> default_discovery = new List<dynamic>(); default_discovery.Add("*BROADC.A#ST,QUIT"); default_discovery.Add("*BROADC.A#ST,DISCOVERY"); default_discovery.Add("*DISCOV.E#RY,DISCOVERY"); discoveryMethods.Add(-1, default_discovery); int discovery_attempts = 0; //serialPort.ReadExisting(); //while (serialPort.BytesToRead <= 0 && discovery_attempts < 5) //{ // write_wait = (discovery_attempts + 1) * 100; // foreach (List<dynamic> l in discoveryMethods.Values) // { // foreach(var command in l) { // _write(command); // } // } // discovery_attempts++; //} //if (discovery_attempts >= 5) //{ // ReceiverExceptions re = new ReceiverExceptions(this, "Not able to discover VEMCO receiver attached on this port.", true); // dispatcher.enqueueEvent(new ExcepReceiver(re,re.fatal, // this, this.portName, null,null, null)); // serialPort.Close(); // throw re; //} //while (serialPort.BytesToRead > 0) //{ // discoveryReturns = serialPort.ReadExisting(); //} //string commandPreamble = discoveryReturns.Substring(0, 12) + ","; //this.VEMCO_SerialNumber = discoveryReturns.Substring(1,6); //dispatcher.enqueueEvent(new NoteReceiver("command preamble: " + discoveryReturns.Substring(0,12) + ",", // this, this.portName, this.VEMCO_SerialNumber, null, null)); //dispatcher.enqueueEvent(new NoteReceiver("read: " + discoveryReturns, // this, this.portName, this.VEMCO_SerialNumber, null, null)); //infoMethods.Add(-1, commandPreamble + "INFO"); //int info_attempts = 0; //serialPort.ReadExisting(); //Boolean gotINFO = false; //String infoReturns = ""; //int read_attempts = 0; //while (!gotINFO && read_attempts < 5) //{ // info_attempts = 0; // serialPort.ReadExisting(); // while (serialPort.BytesToRead <= 0 && info_attempts < 5) // { // foreach (String infoc in infoMethods.Values) // { // dispatcher.enqueueEvent(new NoteReceiver("(receiver note) attempting INFO command with " + infoc, // this, this.portName, this.VEMCO_SerialNumber, null, null)); // _write(infoc); // Thread.Sleep(500); // } // info_attempts++; // } // while (serialPort.BytesToRead > 0) // { // infoReturns = serialPort.ReadExisting(); // foreach (string filename in System.IO.Directory.GetFiles(VR2C_COMMAND_FOLDER)) // { // List<String> wordExpansions = new List<String>(); // dynamic config = jsonParser.Parse(System.IO.File.ReadAllText(filename)); // foreach (Object o in config.decoder.sentences["info_response"].word_order) // { // wordExpansions.Add(config.decoder.words[((String)o)]); // } // if (Regex.IsMatch(infoReturns, String.Format(config.decoder.sentences["info_response"].format, wordExpansions.ToArray<String>()))) // { // gotINFO = true; // } // } // } // read_attempts++; //} //if (read_attempts >= 5) //{ // ReceiverExceptions re = new ReceiverExceptions(this, "(FATAL) Not able to get INFO from the VEMCO receiver attached on this port.", true); // dispatcher.enqueueEvent(new ExcepReceiver(re, re.fatal, // this, this.portName, this.VEMCO_SerialNumber, null, null)); // serialPort.Close(); // throw re; //} //int RECEIVER_FW_VERSION = -1; //if (infoReturns != "") //{ // //!!! Need a method to read the model. // this.VEMCO_Model = null; // int fw_start = infoReturns.IndexOf("FW="); // int fw_end = infoReturns.IndexOf(",", fw_start); // string fw_ver = infoReturns.Substring((fw_start + 3), (fw_end - fw_start - 3)); // int fw_ver_firstperiod = fw_ver.IndexOf("."); // int fw_ver_secondperiod = fw_ver.IndexOf(".", fw_ver_firstperiod + 1); // string major = fw_ver.Substring(0, fw_ver_firstperiod); // string minor = fw_ver.Substring(fw_ver_firstperiod + 1, (fw_ver_secondperiod - fw_ver_firstperiod - 1)); // string release = fw_ver.Substring(fw_ver_secondperiod + 1, (fw_ver.Length - fw_ver_secondperiod - 1)); // RECEIVER_FW_VERSION = (Int32.Parse(major) * 10000) + (Int32.Parse(minor) * 100) + (Int32.Parse(release)); //} //dispatcher.enqueueEvent(new NoteReceiver("Detected firmware version: " + RECEIVER_FW_VERSION, // this, this.portName, this.VEMCO_SerialNumber, this.VEMCO_Model, null)); //if (RECEIVER_FW_VERSION >= 0) //{ // int fw_use = -1; // foreach (string filename in System.IO.Directory.GetFiles(VR2C_COMMAND_FOLDER)) // { // string text = System.IO.File.ReadAllText(filename); // dynamic config = jsonParser.Parse(System.IO.File.ReadAllText(filename)); // if (config.firmware_version >= fw_use && config.firmware_version <= RECEIVER_FW_VERSION) // { // fw_use = (Int32)config.firmware_version; // encoder = new Encoder(commandPreamble, config); // } // } // if (fw_use < 0 || encoder == null) // { // ReceiverExceptions re = new ReceiverExceptions(this, "(FATAL) Unable to parse out FW version from return from INFO command.", true); // dispatcher.enqueueEvent(new ExcepReceiver(re, re.fatal, // this, this.portName, this.VEMCO_SerialNumber, null, null)); // serialPort.Close(); // throw re; // } //} //else //{ // ReceiverExceptions re = new ReceiverExceptions(this, "(FATAL) Unable to parse out FW version from return from INFO command.", true); // dispatcher.enqueueEvent(new ExcepReceiver(re,re.fatal, // this, this.portName, this.VEMCO_SerialNumber, null, null)); // serialPort.Close(); // throw re; //} //dispatcher.enqueueEvent(new NoteReceiver("(receiver note) Successfully configured encoder with fw version = " + encoder.encoderConfig.firmware_version, // this, this.portName, this.VEMCO_SerialNumber, this.VEMCO_Model, this.encoder.encoderConfig)); }