113 lines
3.5 KiB
C#
113 lines
3.5 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using rPiNVR.Models;
|
|
using System.Diagnostics;
|
|
using System.Diagnostics.Metrics;
|
|
using System.IO;
|
|
|
|
namespace rPiNVR.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly ILogger<HomeController> _logger;
|
|
private List<Camera> _avail;
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
{
|
|
_logger = logger;
|
|
string[] lines = System.IO.File.ReadAllLines("available.list");
|
|
_avail = new List<Camera>();
|
|
_avail.Add(new Camera(9999, "Empty"));
|
|
foreach (var line in lines)
|
|
{
|
|
string[] cameraDetails = line.Split(',');
|
|
_avail.Add(new Camera(int.Parse(cameraDetails[0]), cameraDetails[1]));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
public IActionResult Index()
|
|
{
|
|
/*AvailableCameras avail = new AvailableCameras();
|
|
ViewData["available"] = avail.Cameras*/
|
|
ViewData["available"] = _avail;
|
|
List<int> cams = new List<int>();
|
|
using (StreamReader file = new StreamReader("cam.list"))
|
|
{
|
|
string ln;
|
|
while ((ln = file.ReadLine()) != null)
|
|
{
|
|
int cam;
|
|
bool b = int.TryParse(ln, out cam);
|
|
if (!b)
|
|
{
|
|
_logger.LogError("Invalid file format of cam.list", file);
|
|
break;
|
|
}
|
|
|
|
cams.Add(cam);
|
|
|
|
}
|
|
file.Close();
|
|
}
|
|
return View(cams);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Index(List<int> cams)
|
|
{
|
|
/*AvailableCameras avail = new AvailableCameras();
|
|
ViewData["available"] = avail.Cameras;*/
|
|
ViewData["available"] = _avail;
|
|
|
|
using (StreamWriter file = new StreamWriter("cam.list"))
|
|
{
|
|
foreach (int cam in cams)
|
|
{
|
|
file.WriteLine(cam);
|
|
}
|
|
file.Flush();
|
|
file.Close();
|
|
}
|
|
|
|
using (StreamWriter file = new StreamWriter("cam.cfg"))
|
|
{
|
|
int numCols = 1;
|
|
int numRows = 1;
|
|
if (cams.Count > 1)
|
|
{
|
|
numCols = cams.Count / 2;
|
|
numRows = 2;
|
|
}
|
|
|
|
file.WriteLine($"NUM_COLS={numCols}");
|
|
file.WriteLine($"NUM_ROWS={numRows}");
|
|
|
|
file.Flush();
|
|
file.Close();
|
|
}
|
|
|
|
ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "/bin/bash", Arguments = "rtspnvr.sh start", };
|
|
Process proc = new Process() { StartInfo = startInfo, };
|
|
proc.Start();
|
|
|
|
return View(cams);
|
|
}
|
|
|
|
public IActionResult StopCameras()
|
|
{
|
|
ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "/bin/bash", Arguments = "rtspnvr.sh stop", };
|
|
Process proc = new Process() { StartInfo = startInfo, };
|
|
proc.Start();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
}
|
|
} |