/*, AddStateDelegate delAS, GetStateTypeDelegate delGST, AddNodeDelegate delAN, GetIPAddressDelegate delGIA, AddMessageToTableDelegate delAMTT, GetMessageDelegate delGM)*/ /* private AddStateDelegate addStateDelegate; private GetStateTypeDelegate getStateTypeDelegate; private AddNodeDelegate addNodeDelegate; private GetIPAddressDelegate getIPAddressDelegate; private AddMessageToTableDelegate addMessageToTableDelegate; private GetMessageDelegate getMessageDelegate;*/ public HTTPServer(MainView mv, AddToLogFunctionDelegate delATLF, Data dat) { // Creates new HTTP listener object listener = new HttpListener(); listener.Prefixes.Add("http://*:6372/"); mainViewForm = mv; dataObject = dat; addToLogDelegate = delATLF; /*addStateDelegate = delAS; getStateTypeDelegate = delGST; addNodeDelegate = delAN; getIPAddressDelegate = delGIA; addMessageToTableDelegate = delAMTT; getMessageDelegate = delGM;*/ }
private void testFunction() { Data data = new Data(); data.AddNode(1, 1, "192.168.1.1", "LEDBlinky"); // data.AddState(0, "0", 0, 0); int ti = data.AddState(1, "LED", 0, 0); Console.WriteLine("addstate success = " + ti.ToString()); MessageObject testobj = new MessageObject(); testobj.nodeid = 1; testobj.statetype1 = "1"; testobj.state = "on"; data.AddMessageToTable(testobj); MessageObject[] obj = data.GetMessage(1); string t = obj[0].Json(data); Console.WriteLine(t); }
public string Json(Data data) { //Returns a Json jsonInfomation jsonout = new jsonInfomation(); jsonout.nodeid = nodeid; //state 1 lookup try { jsonout.statetype1 = data.GetStateType(statetype1); } catch { } try { jsonout.statetype2 = data.GetStateType(statetype2); } catch { } try { jsonout.statetype3 = data.GetStateType(statetype3); } catch { } try {jsonout.statetype4 = data.GetStateType(statetype4);} catch { } try { jsonout.statetype5 = data.GetStateType(statetype5);} catch { } try { jsonout.statetype6 = data.GetStateType(statetype6); } catch { } jsonout.state = state; string output = JsonConvert.SerializeObject(jsonout, Formatting.Indented); return output; }