Пример #1
0
        private void ServeRoot()
        {
            byte[] buffer = Encoding.UTF8.GetBytes(TemplateProcessor.Process(Environment.CurrentDirectory + "\\HTTP\\templates\\index.template", new Dictionary <string, Func <string> >()
            {
                { "URI", () => { return(Context.Request.Url.LocalPath); } }
            }));


            Context.Response.ContentLength64 = buffer.Length;
            WriteData(buffer, buffer.Length);
            Context.Response.OutputStream.Close();
        }
Пример #2
0
        private void Serve404()
        {
            //byte[] buffer = Encoding.UTF8.GetBytes("<html><head><title>CashCam Camera</title></head><body>404 file not found</body></html>");
            byte[] buffer = Encoding.UTF8.GetBytes(TemplateProcessor.Process(Environment.CurrentDirectory + "\\HTTP\\templates\\404.template", new Dictionary <string, Func <string> >()
            {
                { "URI", () => { return(Context.Request.Url.LocalPath); } }
            }));

            Context.Response.StatusCode      = 404;
            Context.Response.ContentLength64 = buffer.Length;
            WriteData(buffer, buffer.Length);
            Context.Response.OutputStream.Close();
        }
Пример #3
0
        private void ServeStream()
        {
            try
            {
                if (!chunkEnabled)
                {
                    chunkEnabled = true;

                    //Camera 0

                    if (Program.CameraManager.GetGamera(0) != null && Program.CameraManager.GetGamera(0).StreamEnabled())
                    {
                        Context.Response.ContentType = "application/ogg";
                        Context.Response.SendChunked = true;
                        Context.Response.KeepAlive   = true;
                        Program.CameraManager.GetGamera(0)
                        .StreamTask.Repeater.AddStream(
                            new OGGStream.StreamClient(Context.Response.OutputStream, (data, offset, length) => {
                            try { Context.Response.OutputStream.Write(data, offset, length); return(true); } catch { } return(false);
                        }));
                    }
                    else
                    {
                        byte[] buffer = Encoding.UTF8.GetBytes(TemplateProcessor.Process(Environment.CurrentDirectory + "\\HTTP\\templates\\noStrean.template", new Dictionary <string, Func <string> >()
                        {
                            { "URI", () => { return(Context.Request.Url.LocalPath); } },
                            { "CameraID", () => { return("0"); } }
                        }));

                        Context.Response.StatusCode      = 404;
                        Context.Response.ContentLength64 = buffer.Length;
                        WriteData(buffer, buffer.Length);
                        Context.Response.OutputStream.Close();
                    }
                }
            }
            finally
            {
            }
        }
Пример #4
0
        public static string GetPage(HttpListenerContext context)
        {
            string ACTION = "";
            int    id;

            if (context.Request.QueryString.Count != 0)
            {
                foreach (string key in context.Request.QueryString.AllKeys)
                {
                    switch (key)
                    {
                    case "stops":
                        if (int.TryParse(context.Request.QueryString[key], out id))
                        {
                            if (Console.GetOnOff(string.Format(Variables.V_camera_stream_enabled, id)).Value)
                            {
                                ConsoleResponse cr = Console.SetValue(string.Format(Variables.V_camera_stream_enabled, id), "false");
                                if (cr.State == ConsoleCommandState.Sucess)
                                {
                                    ACTION += "Sucess! Camera " + id + " disabled.<br/>";
                                }
                                else
                                {
                                    ACTION += "Failure while disabling camera " + id + ": " + cr.Value + "<br/>";
                                }
                            }
                        }

                        break;

                    case "starts":
                        if (int.TryParse(context.Request.QueryString[key], out id))
                        {
                            if (!Console.GetOnOff(string.Format(Variables.V_camera_stream_enabled, id)).Value)
                            {
                                ConsoleResponse cr = Console.SetValue(string.Format(Variables.V_camera_stream_enabled, id), "true");
                                if (cr.State == ConsoleCommandState.Sucess)
                                {
                                    ACTION += "Sucess! Camera " + id + " enabled.<br/>";
                                }
                                else
                                {
                                    ACTION += "Failure while enabling camera " + id + ": " + cr.Value + "<br/>";
                                }
                            }
                        }
                        break;
                    }
                }
            }

            string camerafor = "";

            // Count is protected from having non numurical values so if this fails look elsewhere
            int count = int.Parse(Console.GetValue(Variables.V_camera_count).Value);

            for (int i = 0; i < count; i++)
            {
                camerafor += TemplateProcessor.Process(Environment.CurrentDirectory + "\\HTTP\\templates\\control.camerafor.template", new Dictionary <string, Func <string> >()
                {
                    { "URI", () => { return(context.Request.Url.LocalPath); } },
                    { "STATUS", () => { return(Console.GetValue(string.Format(Variables.V_camera_stream_enabled, i)).Value); } },
                    { "ID", () => { return(i.ToString()); } },
                });
            }


            return(TemplateProcessor.Process(Environment.CurrentDirectory + "\\HTTP\\templates\\control.template", new Dictionary <string, Func <string> >()
            {
                { "URI", () => { return context.Request.Url.LocalPath; } },
                { "ACTION", () => { return ACTION; } },
                { "control.camerafor.template", () => { return camerafor; } },
            }));
        }