Merge pull request 'take gateway from localhost' (#8) from fix_Take_gateway_from_localhost into master

Reviewed-on: #8
This commit is contained in:
Laurențiu Constantin 2024-06-17 14:59:12 +00:00
commit 5291e2cb5b

View File

@ -376,6 +376,40 @@ namespace MotoTrbo_GW
}
private void FetchAudioSettings()
{
DBsettingsManager dbSettings = new DBsettingsManager(DBServer, DBSchema, DBUser, DBPass, DBPort);
string tmpSamplaRate = dbSettings.getSettingValue(0, "sampleRate");
if (!string.IsNullOrEmpty(tmpSamplaRate))
sampleRate = int.Parse(tmpSamplaRate);
else
{
SafeMobileLib.Utils.WriteLine("Invalid sample rate", ConsoleColor.Red);
}
string tmpBitDepth = dbSettings.getSettingValue(0, "bitDepth");
if (!string.IsNullOrEmpty(tmpSamplaRate))
{
bitdepth = int.Parse(tmpBitDepth);
bitdepthInBytes = bitdepth / 8;
}
else
{
SafeMobileLib.Utils.WriteLine("Invalid bit depth", ConsoleColor.Red);
}
string tmpBufferMilliseconds = dbSettings.getSettingValue(0, "bufferMilliseconds");
if (!string.IsNullOrEmpty(tmpBufferMilliseconds))
recordedBufferMiliseconds = int.Parse(tmpBufferMilliseconds);
else
{
SafeMobileLib.Utils.WriteLine("Invalid bufferMilliseconds", ConsoleColor.Red);
}
}
private void ContinueConstructor()
{
@ -394,45 +428,78 @@ namespace MotoTrbo_GW
"Update required...", MessageBoxButtons.YesNo, RadMessageIcon.Exclamation);
if (dr == DialogResult.Yes)
{
CheckForUpdate(true);
Application.Exit();
}
else
Application.Exit();
Application.Exit();
}
else
{
//new code
List <Gateway> listGW = new List<Gateway>();
try
{
if (!string.IsNullOrEmpty(DBServer))
{
listGW = getGWidFromDB(DBServer);
}
if (listGW.Count == 0)
{
DBServer = "127.0.0.1";
listGW = getGWidFromDB(DBServer);
}
}
catch (Exception ex)
{
SafeMobileLib.Utils.WriteLine("Ex on find automat the gateway ID:" + ex.ToString());
}
try
{
if (listGW.Count == 0)
{
FeedbackRadMessageBox.ShowError("Gateway IP not present in DB\n\r Please go to Administrative module and register this GW with IP:!!!" + DBServer, "IP missing");
System.Environment.Exit(0);
return;
}
else
{
GWID = ((Gateway)listGW[0]).Id;
source = new IniConfigSource(Main.CFG_FILE);
source.Configs["Gateway"].Set("id", GWID);
// source.Configs["NAI"].Set("peerID", ((Gateway)listGW[0]).Peer_id);
source.Save();
SafeMobileLib.Utils.WriteLine("Gateway ID is " + GWID, ConsoleColor.Cyan);
//SafeMobileLib.Utils.WriteLine("ID:" + GWID + " saved to config file.");
btGWID.Text = GWID.ToString();
}
}
catch (Exception ex)
{
SafeMobileLib.Utils.WriteLine("DB error!!!");
SafeMobileLib.Utils.WriteLine(ex.ToString());
FeedbackRadMessageBox.ShowError("DB error.\n\rPlease turn down the firewall or add an exception for the Datebase in the firewall and try again!!!\n\r DB ip:" + DBServer,
"DB error");
System.Environment.Exit(0);
//System.Windows.Forms.Application.Exit();
return;
}
//end of new code
// Get Audio settings
DBsettingsManager dbSettings = new DBsettingsManager(DBServer, DBSchema, DBUser, DBPass, DBPort);
string tmpSamplaRate = dbSettings.getSettingValue(0, "sampleRate");
if (!string.IsNullOrEmpty(tmpSamplaRate))
sampleRate = int.Parse(tmpSamplaRate);
else
{
SafeMobileLib.Utils.WriteLine("Invalid sample rate", ConsoleColor.Red);
}
string tmpBitDepth = dbSettings.getSettingValue(0, "bitDepth");
if (!string.IsNullOrEmpty(tmpSamplaRate))
{
bitdepth = int.Parse(tmpBitDepth);
bitdepthInBytes = bitdepth / 8;
}
else
{
SafeMobileLib.Utils.WriteLine("Invalid bit depth", ConsoleColor.Red);
}
string tmpBufferMilliseconds = dbSettings.getSettingValue(0, "bufferMilliseconds");
if (!string.IsNullOrEmpty(tmpBufferMilliseconds))
recordedBufferMiliseconds = int.Parse(tmpBufferMilliseconds);
else
{
SafeMobileLib.Utils.WriteLine("Invalid bufferMilliseconds", ConsoleColor.Red);
}
FetchAudioSettings();
//int asio driver object
@ -469,91 +536,7 @@ namespace MotoTrbo_GW
}
}
}
//old code
/*if (GWID == -1)
{
int id = getGWidFromDB(YourIPaddress);
if (id == -1)
{
RadMessageBox.Show("Gateway IP not present in DB\n\r Please go to Administrative module and register this GW with IP:!!!" + YourIPaddress, "IP missing", MessageBoxButtons.OK, RadMessageIcon.Error);
System.Environment.Exit(0);
}
else
{
GWID = id;
source = new IniConfigSource(Main.CFG_FILE);
source.Configs["Gateway"].Set("id", id);
source.Save();
SafeMobileLib.Utils.WriteLine("ID:" + id +" saved to config file.");
}
}*/
//new code
List <Gateway> listGW = new List<Gateway>();
try
{
listGW = getGWidFromDB(YourIPaddress);
if (listGW.Count == 0)
{
if (DBServer.Contains("127.0.0.1") || (DBServer.ToUpper().Contains("LOCALHOST")))
listGW = getGWidFromDB("127.0.0.1");
}
else
{
if (GWID != -1)
{
Boolean find = false;
foreach (Gateway obj in listGW)
if (obj.Id == GWID) { find = true; break; }
if ((!find) && (DBServer.Contains("127.0.0.1") || (DBServer.ToUpper().Contains("LOCALHOST"))))
listGW = getGWidFromDB("127.0.0.1");
}
}
}
catch (Exception ex)
{
SafeMobileLib.Utils.WriteLine("Ex on find automat the gateway ID:" + ex.ToString());
}
try
{
if (listGW.Count == 0)
{
FeedbackRadMessageBox.ShowError("Gateway IP not present in DB\n\r Please go to Administrative module and register this GW with IP:!!!" + YourIPaddress, "IP missing");
System.Environment.Exit(0);
return;
}
else
{
GWID = ((Gateway)listGW[0]).Id;
source = new IniConfigSource(Main.CFG_FILE);
source.Configs["Gateway"].Set("id", GWID);
// source.Configs["NAI"].Set("peerID", ((Gateway)listGW[0]).Peer_id);
source.Save();
SafeMobileLib.Utils.WriteLine("Gateway ID is " + GWID, ConsoleColor.Cyan);
//SafeMobileLib.Utils.WriteLine("ID:" + GWID + " saved to config file.");
btGWID.Text = GWID.ToString();
}
}
catch (Exception ex)
{
SafeMobileLib.Utils.WriteLine("DB error!!!");
SafeMobileLib.Utils.WriteLine(ex.ToString());
FeedbackRadMessageBox.ShowError("DB error.\n\rPlease turn down the firewall or add an exception for the Datebase in the firewall and try again!!!\n\r DB ip:" + YourIPaddress,
"DB error");
System.Environment.Exit(0);
//System.Windows.Forms.Application.Exit();
return;
}
//end of new code
/*try
{
@ -1274,7 +1257,7 @@ because base station {radioGwID} failed to send PTT", ConsoleColor.Red);
IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(Main.ApplicationServer), registrationPort);
client.Connect(serverEndPoint);
NetworkStream clientStream = client.GetStream();
YourIPaddress = (client.Client.LocalEndPoint.ToString().Split(':'))[0];
YourIPaddress = (client.Client.LocalEndPoint.ToString().Split(":".ToCharArray()))[0];
Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;