public void Start(HttpServer server, SimpleJsonListener json, SimpleTemplate templateDemo) { _ws = server; _json = json; _templateDemo = templateDemo; _ws.AddPath("/demoLED.html", ProcessDemoLED); _LEDControl.LoadString(_ws.HttpRootManager.ReadToByte(_privatePath + "/templateLED.html")); _LEDControl["ledOn"] = new TemplateAction() { Pattern = "LEDON" }; _LEDControl["ledOff"] = new TemplateAction() { Pattern = "LEDOFF" }; _templateDemo["maualLed"] = new TemplateAction() { Pattern = "MANUALLED", Data = "Off" }; _ws.HttpRootManager.AddExtensionTemplateData("shtml", "manualLed", new TemplateAction() { Pattern = "MANUALLED", Data = "Off" }); _json.AddData("MaualLed", "Off"); //_ports._debug = true; }
public void Start(HttpServer server, SimpleTemplate template) { _ws = server; _templateDemo = template; _ws.AddPath("/template.html", VrniTemplate); _templateDemo.LoadString(_ws.HttpRootManager.ReadToByte(_privatePath + "/templateDemo.html")); _templateDemo["userName"] = new TemplateAction() { Pattern = "USERNAME" }; }
public void Start(HttpServer server) { _ws = server; _ws.AddPath("/demoTemperature.html", ProcessTemperature); _temperatureTemplate.LoadString(_ws.HttpRootManager.ReadToByte(_privatePath + "/templateTermometer.html")); _temperatureTemplate["temperature"] = new TemplateAction() { Pattern = "TEMP" }; _termometer.HighPrecision = true; }
public void Start(HttpServer server, SimpleJsonListener json, SimpleTemplate templateDemo) { _ws = server; _json = json; _templateDemo = templateDemo; _ws.AddPath("/demoTimer.html", ProcessTimer); _timerControl.LoadString(_ws.HttpRootManager.ReadToByte(_privatePath + "/templateTimer.html")); _timerControl["timerOn"] = new TemplateAction() { Pattern = "TIMERON" }; _timerControl["timerOff"] = new TemplateAction() { Pattern = "TIMEROFF" }; _templateDemo["led"] = new TemplateAction() { Pattern = "LED", Data = "Off" }; _templateDemo["timer"] = new TemplateAction() { Pattern = "TIMER", Data = "Off" }; _json.AddData("Timer", "Off"); _json.AddData("Led", "Off"); _ws.HttpRootManager.AddExtensionTemplateData("shtml", "led", new TemplateAction() { Pattern = "LED", Data = "Off" }); _ws.HttpRootManager.AddExtensionTemplateData("shtml", "timer", new TemplateAction() { Pattern = "TIMER", Data = "Off" }); _ws.AddTimer("TestTimer", 10000, TimerEvent); //_ports._debug = true; }
public void Start(HttpServer server) { _ws = server; _ws.AddPath("/demoCookieSet.html", ProcessCookieSet); _ws.AddPath("/demoCookieRead.html", ProcessCookieRead); _ws.AddPath("/demoCookieRemove.html", ProcessCookieRemove); _cookieTemplate.LoadString(_ws.HttpRootManager.ReadToByte(_privatePath + "/templateCookieRead.html")); _cookieTemplate["cookie"] = new TemplateAction() { Pattern = "COOKIE" }; _cookieSetTemplate.LoadString(_ws.HttpRootManager.ReadToByte(_privatePath + "/templateCookieSet.html")); _cookieSetTemplate["cookie"] = new TemplateAction() { Pattern = "COOKIE" }; }
public void Start(HttpServer server) { _ws = server; _ws.AddPath("/demoSessionSet.html", ProcessSessionSet); _ws.AddPath("/demoSessionRead.html", ProcessSessionRead); _ws.AddPath("/demoSessionRemove.html", ProcessSessionRemove); _sessionTemplate.LoadString(_ws.HttpRootManager.ReadToByte(_privatePath + "/templateSessionRead.html")); _sessionTemplate["session"] = new TemplateAction() { Pattern = "SESSION" }; _sessionSetTemplate.LoadString(_ws.HttpRootManager.ReadToByte(_privatePath + "/templateSessionSet.html")); _sessionSetTemplate["session"] = new TemplateAction() { Pattern = "SESSION" }; }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <param name="response"></param> public void Listen(HttpRequest request, HttpResponse response) { try { // Ali je pot v registriranem listenerju in kliči listener ter return ; if (IsRegisteredExtension(request.RequestPath.ToLower())) { string[] _tmp = request.RequestPath.ToLower().Split(new char[] { '.' }); if (_tmp.Length > 0) { ProcessExtensionListener(request, response, _tmp[_tmp.Length - 1]); return; } else { throw new InvalidDataException("Cannot determine extension from " + request.RequestPath); } } if (request.RequestPath.EndsWith("/")) { // Preverimo, ali je v folderju index file. foreach (string file in _serverRootFile) { if (Containes(_serverRootFolder + request.RequestPath + file)) { response.Write(ReadToByte(_serverRootFolder + request.RequestPath + file), _server.GetMimeType.GetMimeFromFile(request.RequestPath + file)); return; } } // Ni index fajla, izpišemo folder. /* * 1) Skopiramo vse poti v začasno datoteko * 2) vse poti, ki ustrezajo ustrezni mapi, skopiramo in pripravimo za izpis * 3) če ne najdemo, je treba izpisat 404. */ List <string> _ustreznePoti = new List <string>(); foreach (string _pot in GetNames()) { if (_pot.ToLower().Contains((_serverRootFolder + request.RequestPath).ToLower().Replace('/', '.'))) { // Dodamo samo pravilne url-je za trenutno mapo, brez polne poti in v pravilni obliki. int cut = _pot.ToLower().Split(new string[] { _serverRootFolder.ToLower() + request.RequestPath.ToLower().Replace('/', '.') }, StringSplitOptions.None)[1].Length; string _tmpPath = _pot.Replace('.', '/'); int Place = _tmpPath.LastIndexOf("/"); _tmpPath = _tmpPath.Remove(Place, 1).Insert(Place, "."); if (!_tmpPath.Substring(_tmpPath.Length - cut).Contains("/")) { _ustreznePoti.Add(_tmpPath.Substring(_tmpPath.Length - cut)); } } } if (_ustreznePoti.Count > 0) { SimpleTemplate _template = new SimpleTemplate(); _template.LoadString(ReadToByte("SystemHtml/templateFolderListing.html")); _template.SafeMode = false; StringBuilder rezultat = new StringBuilder(); foreach (string _pot in _ustreznePoti) { rezultat.Append("<a href=\"" + _pot + "\">" + _pot + "</a><br>\n"); } _template["path"] = new TemplateAction() { Pattern = "PATH", Data = request.RequestPath }; _template["content"] = new TemplateAction() { Pattern = "CONTENT", Data = rezultat.ToString() }; _template.ProcessAction(); response.Write(_template.GetByte(), "text/html"); return; } else { ReturnErrorMessage(request, response, "404"); return; } } else { /* * Ni folder, izpišemo zahtevano datoteko. */ if (Containes(_serverRootFolder + request.RequestPath)) { response.Write(ReadToByte(_serverRootFolder + request.RequestPath), _server.GetMimeType.GetMimeFromFile(request.RequestPath)); return; } else { ReturnErrorMessage(request, response, "404"); return; } } } catch (Exception e) { Debug.WriteLine(e); response.Write(e); } }