AnlageIP adresse kann nun im Menu geändert werden

This commit is contained in:
HuskyTeufel
2022-04-13 11:51:37 +02:00
parent 9ee596d1bb
commit a027973358
12 changed files with 378 additions and 20 deletions

View File

@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -18,7 +20,7 @@ namespace SanSystem.Einstellungen
try
{
result = getConfiguration(dataGridViewColumn.HeaderText);
result = (int)getConfiguration(dataGridViewColumn.HeaderText);
}
catch(Exception )
{

View File

@@ -11,7 +11,8 @@ namespace SanSystem.Einstellungen
{
abstract class Settings : IDisposable
{
protected Dictionary<string, int> configuration = new Dictionary<string, int>();
protected Dictionary<string, long> configuration = new Dictionary<string, long>();
const string pfad = "Settings";
@@ -30,15 +31,15 @@ namespace SanSystem.Einstellungen
else
{
string input = File.ReadAllText(modPath);
configuration = (Dictionary<string, int>)JsonConvert.DeserializeObject(input, typeof(Dictionary<string, int>));
configuration = (Dictionary<string, long>)JsonConvert.DeserializeObject(input, typeof(Dictionary<string, long>));
}
}
protected int getConfiguration(string keyName, int retry = 0)
protected long getConfiguration(string keyName, int retry = 0)
{
if (retry >= 3)
throw new Exception("Fehler, zuviele versuche");
int result = -1;
long result = -1;
if(!configuration.TryGetValue(keyName,out result))
{
configuration.Add(keyName, 20);
@@ -53,7 +54,7 @@ namespace SanSystem.Einstellungen
}
}
protected void setConfig(string keyName, int value)
protected void setConfig(string keyName, long value)
{
configuration[keyName] = value;
}

View File

@@ -0,0 +1,56 @@
using System;
namespace SanSystem.Einstellungen
{
class SoftwareConfiguration : Settings
{
long IPToLong(string addr)
{
System.Net.IPAddress ip;
if (System.Net.IPAddress.TryParse(addr, out ip))
return (((long)ip.GetAddressBytes()[0] << 24) | ((int)ip.GetAddressBytes()[1] << 16) | ((int)ip.GetAddressBytes()[2] << 8) | ip.GetAddressBytes()[3]);
else return 0;
}
string LongToIP(long addr)
{
System.Net.IPAddress tmpIp;
if (System.Net.IPAddress.TryParse(addr.ToString(), out tmpIp))
{
return tmpIp.ToString();
/*try
{
Byte[] bytes = tmpIp.GetAddressBytes();
long addrs = (long)BitConverter.ToInt32(bytes, 0);
return new System.Net.IPAddress(addrs).ToString();
}
*/
//catch (Exception e) { return e.Message; }
}
else return String.Empty;
}
internal void SetAnlageIP(string text)
{
setConfig("ANLAGEIP",IPToLong(text));
}
public SoftwareConfiguration() : base("SoftwareConfiguration")
{
}
public string GetAnlageIP()
{
long ip = getConfiguration("ANLAGEIP");
if (ip <= 0) throw new Exception("Something went wrong");
return LongToIP(ip);
}
public override void InitDevValues()
{
configuration.Add("ANLAGEIP", IPToLong("192.168.2.248"));
}
}
}