private void ProcessTemperature(HttpRequest request, HttpResponse response)
        {
            try
            {
                byte[]        _temp = _termometer.TemperatureRead();
                StringBuilder temp  = new StringBuilder();
                if (_temp[0] > 125)  // Termometer gre do 125, če je več, potem pomeni da je negativna temperatura. (Thermometer reads up to 125C, everything above it is negative)
                {
                    temp.Append((_temp[0] - 256).ToString());
                }
                else
                {
                    temp.Append(_temp[0].ToString());
                }
                temp.Append(".");
                temp.Append(_temp[1].ToString());

                _temperatureTemplate["temperature"].Data = temp.ToString();
                _temperatureTemplate.ProcessAction();
                response.Write(_temperatureTemplate.GetByte(), _ws.GetMimeType.GetMimeFromFile("/templateTermometer.html"));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                response.Write(e);
            }
        }
示例#2
0
        private void ProcessCookieSet(HttpRequest request, HttpResponse response)
        {
            try
            {
                if (request.Parameters.ContainsKey("niz"))
                {
                    response.AddCookie(new HttpCookie("DemoCookie", request.Parameters["niz"], (DateTime.Now).AddHours(1)));

                    response.Write(_ws.HttpRootManager.ReadToByte(_privatePath + "/cookieSetPotrdi.html"), _ws.GetMimeType.GetMimeFromFile("/cookieSetPotrdi.html"));
                }
                else
                {
                    if (request.ContainsCookie("DemoCookie"))
                    {
                        _cookieSetTemplate["cookie"].Data = request.Cookies["DemoCookie"].Value;
                    }
                    else
                    {
                        _cookieSetTemplate["cookie"].Data = string.Empty;
                    }
                    _cookieSetTemplate.ProcessAction();
                    response.Write(_cookieSetTemplate.GetByte(), _ws.GetMimeType.GetMimeFromFile("/teplateCookieSet.html"));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                response.Write(e);
            }
        }
示例#3
0
 private void ProcessSessionSet(HttpRequest request, HttpResponse response)
 {
     try
     {
         if (request.Parameters.ContainsKey("niz"))
         {
             string niz = (request.GetSession()["Demo"] = request.Parameters["niz"]) as string;
             response.Write(_ws.HttpRootManager.ReadToByte(_privatePath + "/sessionSetPotrdi.html"), _ws.GetMimeType.GetMimeFromFile("/sessionSetPotrdi.html"));
         }
         else
         {
             Session _session = request.GetSession(false);
             if (_session != null)
             {
                 _sessionSetTemplate["session"].Data = (string)_session["Demo"];
             }
             else
             {
                 _sessionSetTemplate["session"].Data = string.Empty;
             }
             _sessionSetTemplate.ProcessAction();
             response.Write(_sessionSetTemplate.GetByte(), _ws.GetMimeType.GetMimeFromFile("/teplateSessionSet.html"));
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         response.Write(e);
     }
 }
示例#4
0
 private void VrniTemplate(HttpRequest request, HttpResponse response)
 {
     _templateDemo["userName"].Data = request.AuthenticatedUser;
     _templateDemo.ProcessAction();
     byte[] rezultat = _templateDemo.GetByte();
     response.Write(rezultat, _ws.GetMimeType.GetMimeFromFile(_privatePath + "/templateDemo.html"));
 }
示例#5
0
        private void ProcessDemoLED(HttpRequest request, HttpResponse response)
        {
            try
            {
                if (request.Parameters.ContainsKey("state"))
                {
                    if (request.Parameters["state"].Equals("On", StringComparison.OrdinalIgnoreCase))
                    {
                        stateLed = "On";
                        _json.UpdateData("MaualLed", "On");
                        _templateDemo["maualLed"].Data = "On";
                        _ws.HttpRootManager.UpdateExtensionTemplateData("shtml", "manualLed", new TemplateAction()
                        {
                            Pattern = "MANUALLED", Data = "On"
                        });
                        //pin2.Write(GpioPinValue.High);
                        _ports.WritePin(PortNumber.PORT_TWO, true);
                    }
                    else if (request.Parameters["state"].Equals("Off", StringComparison.OrdinalIgnoreCase))
                    {
                        stateLed = "Off";
                        _json.UpdateData("MaualLed", "Off");
                        _templateDemo["maualLed"].Data = "Off";
                        _ws.HttpRootManager.UpdateExtensionTemplateData("shtml", "manualLed", new TemplateAction()
                        {
                            Pattern = "MANUALLED", Data = "Off"
                        });
                        //pin2.Write(GpioPinValue.Low);
                        _ports.WritePin(PortNumber.PORT_TWO, false);
                    }
                    Debug.WriteLineIf(_debug, "State changed to: " + stateLed);
                }

                if (stateLed.Equals("on", StringComparison.OrdinalIgnoreCase))
                {
                    _LEDControl["ledOn"].Data  = "checked";
                    _LEDControl["ledOff"].Data = string.Empty;
                }
                else
                {
                    _LEDControl["ledOn"].Data  = string.Empty;
                    _LEDControl["ledOff"].Data = "checked";
                }

                _LEDControl.ProcessAction();
                response.Write(_LEDControl.GetByte(), _ws.GetMimeType.GetMimeFromFile("/templateLED.html"));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                response.Write(e);
            }
        }
示例#6
0
        private void ProcessTimer(HttpRequest request, HttpResponse response)
        {
            try
            {
                if (request.Parameters.ContainsKey("state"))
                {
                    if (request.Parameters["state"].Equals("On", StringComparison.OrdinalIgnoreCase))
                    {
                        enableBlink = true;
                        Debug.WriteLineIf(_debug, "Timer state changed to: On");
                    }
                    else if (request.Parameters["state"].Equals("Off", StringComparison.OrdinalIgnoreCase))
                    {
                        enableBlink = false;
                        Debug.WriteLineIf(_debug, "Timer state changed to: Off");
                    }
                }

                if (enableBlink)
                {
                    _timerControl["timerOn"].Data  = "checked";
                    _timerControl["timerOff"].Data = string.Empty;
                    _json.UpdateData("Timer", "On");
                    _templateDemo["timer"].Data = "On";
                    _ws.HttpRootManager.UpdateExtensionTemplateData("shtml", "timer", new TemplateAction()
                    {
                        Pattern = "TIMER", Data = "On"
                    });
                }
                else
                {
                    _timerControl["timerOn"].Data  = string.Empty;
                    _timerControl["timerOff"].Data = "checked";
                    _json.UpdateData("Timer", "Off");
                    _templateDemo["timer"].Data = "Off";
                    _ws.HttpRootManager.UpdateExtensionTemplateData("shtml", "timer", new TemplateAction()
                    {
                        Pattern = "TIMER", Data = "Off"
                    });
                }

                _timerControl.ProcessAction();
                response.Write(_timerControl.GetByte(), _ws.GetMimeType.GetMimeFromFile("/templateTimer.html"));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                response.Write(e);
            }
        }
示例#7
0
 private void ProcessCookieRead(HttpRequest request, HttpResponse response)
 {
     try
     {
         if (request.ContainsCookie("DemoCookie"))
         {
             _cookieTemplate["cookie"].Data = request.Cookies["DemoCookie"].Value;
         }
         else
         {
             _cookieTemplate["cookie"].Data = "no data.";
         }
         _cookieTemplate.ProcessAction();
         response.Write(_cookieTemplate.GetByte(), _ws.GetMimeType.GetMimeFromFile("/teplateCookieRead.html"));
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         response.Write(e);
     }
 }
示例#8
0
 private void ProcessSessionRead(HttpRequest request, HttpResponse response)
 {
     try
     {
         Session _session = request.GetSession(false);
         //string niz = (request.GetSession(false)?["Demo"]) as string;
         if (_session != null)
         {
             _sessionTemplate["session"].Data = (string)_session["Demo"];
         }
         else
         {
             _sessionTemplate["session"].Data = "no data.";
         }
         _sessionTemplate.ProcessAction();
         response.Write(_sessionTemplate.GetByte(), _ws.GetMimeType.GetMimeFromFile("/teplateSessionRead.html"));
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         response.Write(e);
     }
 }
        /// <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);
            }
        }