SetHeader() public méthode

public SetHeader ( string name, string value ) : void
name string
value string
Résultat void
        private int OnSettings(HttpReqResp req)
        {
            try
            {
                var screenshotterCheck = (Database.GetInstanceSettings().WindowsContextTrackerEnabled ? "checked=\"checked\" " : "");
                var miniSurveysCheck   = (Database.GetInstanceSettings().MiniSurveysEnabled ? "checked=\"checked\"" : "");
                var idleCheck          = (Database.GetInstanceSettings().IdleEnabled ? "checked=\"checked\"" : "");
                var miniSurveyInterval = Database.GetInstanceSettings().MiniSurveyInterval;

                var html = "<form method=\"post\" action=\"setsettings\"><table border=\"0\" >" +
                           "<tr><td><label for=\"idle\">Mini-Surveys enabled</label>:</td><td><input type=\"checkbox\" name=\"miniSurveysCheck\" id=\"miniSurveysCheck\" " + miniSurveysCheck + "/></td><td></td></tr>" +
                           "<tr><td><label for=\"history\">Mini-Survey Interval</label>:</td><td><input type=\"text\" size=\"4\" type=\"number\" min=\"1\" maxlength=\"5\" name=\"miniSurveyInterval\" id=\"miniSurveyInterval\" value=\"" + miniSurveyInterval + "\" /></td><td>In minutes (e.g. '60', the tracker will ask you once an hour to fill out the mini-survey).</td></tr>" +
                           "<tr><td><label for=\"idle\">Windows Context Tracker enabled</label>:</td><td><input type=\"checkbox\" name=\"screenshotterCheck\" id=\"screenshotterCheck\" " + screenshotterCheck + "/></td><td>Hint: The tracker regularly takes screenshots that will later be automatically analyced using OCR techniques by the researchers.</td></tr>" +
                           "<tr><td><label for=\"idle\">IDLE enabled</label>:</td><td><input type=\"checkbox\" name=\"idleCheck\" id=\"idleCheck\" " + idleCheck + "/></td><td>Hint: Disable it when you regularly leave your PC on for hours without using it.</td></tr>" +
                           "<tr><td colspan='3'>&nbsp;</td></tr>" +
                           "<tr><td><input type=\"submit\" value=\"save\" /></td><td colspan='2' style=\"color: red;\">Hint: please restart the monitoring tool after enabling/disabling one of the trackers (via Task Manager).</td></tr>" +
                           "</table></form>";

                var title = Settings.SettingsTitle;

                html = ((string)_resourceManager.GetObject("personalanalytics_html"))
                       .Replace("{content}", html)
                       //.Replace("{menu}", Menu)
                       .Replace("{title}", title);
                req.Write(html);
                req.SetHeader("Content-Type", "text/html; charset=utf-8");
            }
            catch (Exception e)
            {
                req.Write(e.ToString());
                req.SetHeader("Content-Type", "text/html; charset=utf-8");
            }
            return(200);
        }
        private int OnStats(HttpReqResp req)
        {
            try
            {
                var html = string.Empty;
                var date = VisHelper.GetVisualizationDateFromUrlParameters(req);
                //var visType = VisHelper.GetVisualizationTypesFromUrlParameters(req);

                // log request
                Database.GetInstance().LogInfo(string.Format("The participant opened the retrospection/visualization for '{0}'.", date));

                // prepare charts
                var contextTimelineChart = new ContextTimelineChart(date);
                var productivityGauge    = new ProductivityGaugeChart(date);
                var activityPie          = new ActivityPieChart(date);


                // organize & draw charts
                html += "<style type='text/css'>";
                html += "td { border: 3px solid #B0B0B0; }";
                html += "</style>";

                html += "<table cellpadding='20' style='margin-left: auto; margin-right: auto;'>"; // border-color: #F1F1F1;  vertical-align: top; horizontal-align: center;'
                html += "<tr><td style='vertical-align:top;'>" + productivityGauge.GetHtml() + "</td><td style='vertical-align:top;' rowspan='2'>" + contextTimelineChart.GetHtml() + "</td></tr>";
                html += "<tr><td style='vertical-align:top;'>" + activityPie.GetHtml() + "</td></tr>";
                html += "</table>";

                var title = Dict.RetrospectionPageTitle + " for the " + date.Date.ToShortDateString();
                if (RemoteDataHandler.VisualizeWithRemoteData())
                {
                    title += " (visualizing local and remote data)";
                }
                //title += "<a href=\"settings\">" + Settings.SettingsTitle + "</a>";

                html = ((string)_resourceManager.GetObject("personalanalytics_html"))
                       .Replace("{content}", html)
                       //.Replace("{menu}", Menu)
                       .Replace("{title}", title);
                req.Write(html);
                req.SetHeader("Content-Type", "text/html; charset=utf-8");
            }
            catch (Exception e)
            {
                req.Write(e.ToString());
                req.SetHeader("Content-Type", "text/html; charset=utf-8");
            }
            return(200);
        }
        private static int OnSetSettings(HttpReqResp reqresp)
        {
            //TrackerManager.GetInstance().EnableDisableUserEfficiencyTracker(reqresp["miniSurveysCheck"] == "on");
            Database.GetInstanceSettings().MiniSurveysEnabled = (reqresp["miniSurveysCheck"] == "on");
            //TrackerManager.GetInstance().EnableDisableWindowsContextTracker(reqresp["screenshotterCheck"] == "on");
            Database.GetInstanceSettings().WindowsContextTrackerEnabled = (reqresp["screenshotterCheck"] == "on");

            Database.GetInstanceSettings().IdleEnabled = (reqresp["idleCheck"] == "on");

            int miniSurveyInterval;
            var res = int.TryParse(reqresp["miniSurveyInterval"], out miniSurveyInterval);

            if (res && miniSurveyInterval > 0)
            {
                Database.GetInstanceSettings().MiniSurveyInterval = miniSurveyInterval;
            }
            else
            {
                Database.GetInstanceSettings().MiniSurveyInterval = Settings.MiniSurveyIntervalDefaultValue;
            }

            reqresp.SetHeader("Location", "settings");

            return(301);
        }
 private int OnStylesheets(HttpReqResp req)
 {
     try
     {
         req.Write((byte[])_resourceManager.GetObject(req.Script.Replace('.', '_')));
         req.SetHeader("Content-Type", req.Script.EndsWith(".png") ? "image/png" : "text/css");
     }
     catch { }
     return(200);
 }
        private void HandlerThread(object obj)
        {
            if (_clientCount > 9)
            {
                return;
            }
            _clientCount++;
            var    client = (TcpClient)obj;
            Stream stream = client.GetStream();

            try
            {
                var reader = new StreamReader(stream);
                var line   = reader.ReadLine();
                if (line == null)
                {
                    line = string.Empty;
                }
                else
                {
                    line = line.Split(' ')[1].Substring(1);
                }
                var token         = (line.IndexOf('?') == -1 ? line : line.Substring(0, line.IndexOf('?')));
                var query         = (line.IndexOf('?') == -1 ? string.Empty : line.Substring(line.IndexOf('?') + 1));
                var host          = "";
                var contentLength = 0;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.StartsWith("Host:"))
                    {
                        host = line.Substring(5).Trim().Split(':')[0];
                    }
                    if (line.StartsWith("Content-Length:"))
                    {
                        contentLength = int.Parse(line.Substring(15).Trim());
                    }
                    else if (line == "")
                    {
                        if (contentLength != 0)
                        {
                            var buffer = new char[contentLength];
                            reader.Read(buffer, 0, contentLength);
                            query += (query == string.Empty ? "" : "&") + new string(buffer);
                        }
                        break;
                    }
                }

                var reqResp = new HttpReqResp(host, token, query);
                reqResp.SetHeader("Cache-Control", "no-cache");
                var statusCode = (_handlers.ContainsKey(token) ? _handlers[token](reqResp) : 404);
                WriteString("HTTP/1.1 " + statusCode + " " + _statusCodes[statusCode] + "\r\n", stream);
                WriteString("Server: aHTTP 1.1\r\n", stream);
                reqResp.SetHeader("Content-Length", reqResp.Response.Length.ToString());
                for (var i = 0; i < reqResp.Headers.Count; i++)
                {
                    WriteString(reqResp.Headers.GetKey(i) + ": " + reqResp.Headers.Get(i) + "\r\n", stream);
                }
                WriteString("\r\n", stream);
                try { stream.Write(reqResp.Response.GetBuffer(), 0, (int)reqResp.Response.Length); }
                catch { }
            }
            catch { }
            stream.Flush();
            stream.Close();
            client.Close();
            _clientCount--;
        }
 private int OnResource(HttpReqResp req)
 {
     try
     {
         req.Write((byte[])_resourceManager.GetObject(req.Script.Replace('.', '_')));
         req.SetHeader("Content-Type", req.Script.EndsWith(".png") ? "image/png" : "text/javascript");
     }
     catch { }
     return 200;
 }
        private static int OnSetSettings(HttpReqResp reqresp)
        {
            //TrackerManager.GetInstance().EnableDisableUserEfficiencyTracker(reqresp["miniSurveysCheck"] == "on");
            Database.GetInstanceSettings().MiniSurveysEnabled = (reqresp["miniSurveysCheck"] == "on");
            //TrackerManager.GetInstance().EnableDisableWindowsContextTracker(reqresp["screenshotterCheck"] == "on");
            Database.GetInstanceSettings().WindowsContextTrackerEnabled = (reqresp["screenshotterCheck"] == "on");

            Database.GetInstanceSettings().IdleEnabled = (reqresp["idleCheck"] == "on");

            int miniSurveyInterval;
            var res = int.TryParse(reqresp["miniSurveyInterval"], out miniSurveyInterval);

            if (res && miniSurveyInterval > 0)
            {
                Database.GetInstanceSettings().MiniSurveyInterval = miniSurveyInterval;
            }
            else
            {
                Database.GetInstanceSettings().MiniSurveyInterval = Settings.MiniSurveyIntervalDefaultValue;
            }

            reqresp.SetHeader("Location", "settings");

            return 301;
        }
        private int OnStats(HttpReqResp req)
        {
            try
            {
                var html = string.Empty;
                var date = VisHelper.GetVisualizationDateFromUrlParameters(req);
                //var visType = VisHelper.GetVisualizationTypesFromUrlParameters(req);

                // log request
                Database.GetInstance().LogInfo(string.Format("The participant opened the retrospection/visualization for '{0}'.", date));

                // prepare charts
                var contextTimelineChart = new ContextTimelineChart(date);
                var productivityGauge = new ProductivityGaugeChart(date);
                var activityPie = new ActivityPieChart(date);

                // organize & draw charts
                html += "<style type='text/css'>";
                html += "td { border: 3px solid #B0B0B0; }";
                html += "</style>";

                html += "<table cellpadding='20' style='margin-left: auto; margin-right: auto;'>"; // border-color: #F1F1F1;  vertical-align: top; horizontal-align: center;'
                html += "<tr><td style='vertical-align:top;'>" + productivityGauge.GetHtml() + "</td><td style='vertical-align:top;' rowspan='2'>" + contextTimelineChart.GetHtml() + "</td></tr>";
                html += "<tr><td style='vertical-align:top;'>" + activityPie.GetHtml() + "</td></tr>";
                html += "</table>";

                var title = Dict.RetrospectionPageTitle + " for the " + date.Date.ToShortDateString();
                if (RemoteDataHandler.VisualizeWithRemoteData()) title += " (visualizing local and remote data)";
                //title += "<a href=\"settings\">" + Settings.SettingsTitle + "</a>";

                html = ((string) _resourceManager.GetObject("personalanalytics_html"))
                    .Replace("{content}", html)
                    //.Replace("{menu}", Menu)
                    .Replace("{title}", title);
                req.Write(html);
                req.SetHeader("Content-Type", "text/html; charset=utf-8");
            }
            catch (Exception e)
            {
                req.Write(e.ToString());
                req.SetHeader("Content-Type", "text/html; charset=utf-8");
            }
            return 200;
        }
        private int OnSettings(HttpReqResp req)
        {
            try
            {
                var screenshotterCheck = (Database.GetInstanceSettings().WindowsContextTrackerEnabled ? "checked=\"checked\" " : "");
                var miniSurveysCheck = (Database.GetInstanceSettings().MiniSurveysEnabled ? "checked=\"checked\"" : "");
                var idleCheck = (Database.GetInstanceSettings().IdleEnabled ? "checked=\"checked\"" : "");
                var miniSurveyInterval = Database.GetInstanceSettings().MiniSurveyInterval;

                var html = "<form method=\"post\" action=\"setsettings\"><table border=\"0\" >" +
                    "<tr><td><label for=\"idle\">Mini-Surveys enabled</label>:</td><td><input type=\"checkbox\" name=\"miniSurveysCheck\" id=\"miniSurveysCheck\" " + miniSurveysCheck + "/></td><td></td></tr>" +
                    "<tr><td><label for=\"history\">Mini-Survey Interval</label>:</td><td><input type=\"text\" size=\"4\" type=\"number\" min=\"1\" maxlength=\"5\" name=\"miniSurveyInterval\" id=\"miniSurveyInterval\" value=\"" + miniSurveyInterval + "\" /></td><td>In minutes (e.g. '60', the tracker will ask you once an hour to fill out the mini-survey).</td></tr>" +
                    "<tr><td><label for=\"idle\">Windows Context Tracker enabled</label>:</td><td><input type=\"checkbox\" name=\"screenshotterCheck\" id=\"screenshotterCheck\" " + screenshotterCheck + "/></td><td>Hint: The tracker regularly takes screenshots that will later be automatically analyced using OCR techniques by the researchers.</td></tr>" +
                    "<tr><td><label for=\"idle\">IDLE enabled</label>:</td><td><input type=\"checkbox\" name=\"idleCheck\" id=\"idleCheck\" " + idleCheck + "/></td><td>Hint: Disable it when you regularly leave your PC on for hours without using it.</td></tr>" +
                    "<tr><td colspan='3'>&nbsp;</td></tr>" +
                    "<tr><td><input type=\"submit\" value=\"save\" /></td><td colspan='2' style=\"color: red;\">Hint: please restart the monitoring tool after enabling/disabling one of the trackers (via Task Manager).</td></tr>" +
                    "</table></form>";

                var title = Settings.SettingsTitle;

                html = ((string)_resourceManager.GetObject("personalanalytics_html"))
                    .Replace("{content}", html)
                    //.Replace("{menu}", Menu)
                    .Replace("{title}", title);
                req.Write(html);
                req.SetHeader("Content-Type", "text/html; charset=utf-8");
            }
            catch (Exception e)
            {
                req.Write(e.ToString());
                req.SetHeader("Content-Type", "text/html; charset=utf-8");
            }
            return 200;
        }
        private void HandlerThread(object obj)
        {
            if (_clientCount > 9)
                return;
            _clientCount++;
            var client = (TcpClient)obj;
            Stream stream = client.GetStream();
            try
            {
                var reader = new StreamReader(stream);
                var line = reader.ReadLine();
                if (line == null) line = string.Empty;
                else line = line.Split(' ')[1].Substring(1);
                var token = (line.IndexOf('?') == -1 ? line : line.Substring(0, line.IndexOf('?')));
                var query = (line.IndexOf('?') == -1 ? string.Empty : line.Substring(line.IndexOf('?') + 1));
                var host = "";
                var contentLength = 0;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.StartsWith("Host:"))
                        host = line.Substring(5).Trim().Split(':')[0];
                    if (line.StartsWith("Content-Length:"))
                        contentLength = int.Parse(line.Substring(15).Trim());
                    else if (line == "")
                    {
                        if (contentLength != 0)
                        {
                            var buffer = new char[contentLength];
                            reader.Read(buffer, 0, contentLength);
                            query += (query == string.Empty ? "" : "&") + new string(buffer);
                        }
                        break;
                    }
                }

                var reqResp = new HttpReqResp(host, token, query);
                reqResp.SetHeader("Cache-Control", "no-cache");
                var statusCode = (_handlers.ContainsKey(token) ? _handlers[token](reqResp) : 404);
                WriteString("HTTP/1.1 " + statusCode + " " + _statusCodes[statusCode] + "\r\n", stream);
                WriteString("Server: aHTTP 1.1\r\n", stream);
                reqResp.SetHeader("Content-Length", reqResp.Response.Length.ToString());
                for (var i = 0; i < reqResp.Headers.Count; i++)
                    WriteString(reqResp.Headers.GetKey(i) + ": " + reqResp.Headers.Get(i) + "\r\n", stream);
                WriteString("\r\n", stream);
                try { stream.Write(reqResp.Response.GetBuffer(), 0, (int)reqResp.Response.Length); }
                catch { }
            }
            catch { }
            stream.Flush();
            stream.Close();
            client.Close();
            _clientCount--;
        }