adding discovery menu
This commit is contained in:
140
MainForm.cs
140
MainForm.cs
@@ -2,7 +2,11 @@ using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Windows.Forms;
|
||||
using Tmds.MDns;
|
||||
using static robospot_camera_finder.MainForm;
|
||||
|
||||
namespace robospot_camera_finder
|
||||
{
|
||||
@@ -17,51 +21,27 @@ namespace robospot_camera_finder
|
||||
|
||||
private static string browse_scope = "_rtsp._tcp";
|
||||
|
||||
bool is_browsing = false;
|
||||
|
||||
public class Camera
|
||||
{
|
||||
private IPAddress ip;
|
||||
private string name;
|
||||
private string location;
|
||||
private string serial;
|
||||
|
||||
public Camera(string name, IPAddress ip, string location, string serial)
|
||||
public Camera(string name, string ip, string location, string serial)
|
||||
{
|
||||
this.name = name;
|
||||
this.ip = ip;
|
||||
this.location = location;
|
||||
this.serial = serial;
|
||||
camera_name = name;
|
||||
camera_ip = ip;
|
||||
camera_location = location;
|
||||
camera_serial = serial;
|
||||
}
|
||||
|
||||
public string camera_name
|
||||
{
|
||||
get
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
public Camera() { }
|
||||
|
||||
public IPAddress camera_ip
|
||||
{
|
||||
get
|
||||
{
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
public string camera_name { get; set; }
|
||||
|
||||
public string camera_location
|
||||
{
|
||||
get
|
||||
{
|
||||
return location;
|
||||
}
|
||||
}
|
||||
public string camera_serial
|
||||
{
|
||||
get
|
||||
{
|
||||
return serial;
|
||||
}
|
||||
}
|
||||
public string camera_ip { get; set; }
|
||||
|
||||
public string camera_location { get; set; }
|
||||
|
||||
public string camera_serial { get; set; }
|
||||
}
|
||||
|
||||
public MainForm()
|
||||
@@ -127,6 +107,8 @@ namespace robospot_camera_finder
|
||||
if (!browser.IsBrowsing)
|
||||
{
|
||||
browser.StartBrowse(browse_scope);
|
||||
is_browsing = true;
|
||||
toolStripStatusDisco.Text = "Discovery : Started";
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -134,6 +116,8 @@ namespace robospot_camera_finder
|
||||
if (browser.IsBrowsing)
|
||||
{
|
||||
browser.StopBrowse();
|
||||
is_browsing = false;
|
||||
toolStripStatusDisco.Text = "Discovery : Stopped";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,25 +150,31 @@ namespace robospot_camera_finder
|
||||
serial = serial_line.Substring("SerialNumber=".Length).Trim();
|
||||
}
|
||||
|
||||
Camera new_camera = new Camera("Camera " + cam_addr.ToString() + " - " + location + " - " + serial, cam_addr, location, serial);
|
||||
Camera new_camera = new Camera("Camera " + cam_addr + " - " + location + " - " + serial, cam_addr.ToString(), location, serial);
|
||||
|
||||
if (all_cameras.Count == 0)
|
||||
{
|
||||
all_cameras.Add(new_camera);
|
||||
} else
|
||||
{
|
||||
for (int i = 0; i < all_cameras.Count; i++)
|
||||
{
|
||||
if (all_cameras[i].camera_serial == new_camera.camera_serial)
|
||||
{
|
||||
all_cameras[i] = new_camera;
|
||||
}
|
||||
else
|
||||
{
|
||||
all_cameras.Add(new_camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
add_camera(new_camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void add_camera(Camera new_camera)
|
||||
{
|
||||
if (all_cameras.Count == 0)
|
||||
{
|
||||
all_cameras.Add(new_camera);
|
||||
}
|
||||
else
|
||||
{
|
||||
Camera find_cam = all_cameras.FirstOrDefault(cam => cam.camera_serial == new_camera.camera_serial);
|
||||
|
||||
if (find_cam != null)
|
||||
{
|
||||
int i = all_cameras.IndexOf(find_cam);
|
||||
all_cameras[i] = new_camera;
|
||||
}
|
||||
else
|
||||
{
|
||||
all_cameras.Add(new_camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,7 +187,7 @@ namespace robospot_camera_finder
|
||||
{
|
||||
foreach (var camera in all_cameras)
|
||||
{
|
||||
if (cam_ip == camera.camera_ip)
|
||||
if (cam_ip.ToString() == camera.camera_ip)
|
||||
{
|
||||
all_cameras.Remove(camera);
|
||||
return;
|
||||
@@ -244,5 +234,41 @@ namespace robospot_camera_finder
|
||||
browse(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
string json = "";
|
||||
OpenFileDialog openFile = new OpenFileDialog();
|
||||
openFile.Filter = "json file (*.json)|*.json";
|
||||
openFile.RestoreDirectory = true;
|
||||
|
||||
if (openFile.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
json = File.ReadAllText(openFile.FileName);
|
||||
|
||||
List<Camera> cameras_in_file = JsonSerializer.Deserialize<List<Camera>>(json);
|
||||
|
||||
foreach (Camera new_camera in cameras_in_file)
|
||||
{
|
||||
add_camera(new_camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
string json = JsonSerializer.Serialize<BindingList<Camera>>(all_cameras, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
SaveFileDialog saveFile = new SaveFileDialog();
|
||||
saveFile.Filter = "json file (*.json)|*.json";
|
||||
saveFile.RestoreDirectory = true;
|
||||
|
||||
if (saveFile.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
File.WriteAllText(saveFile.FileName, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user