Files
BeWoPlaner/SharedLauncher/Information/Connection.cs
Rene Evertz 03f8d4af5d Project Files
+ Loader Exceptions reduziert
2024-05-24 14:16:08 +02:00

124 lines
3.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BS.SharedLauncher.Information
{
public class Connection
{
private const char trennzeichen = '\t';
public string ProxyName { get; set; }
public string ProxyPassword { get; set; }
public string ProxyUsername { get; set; }
public string IpAddress { get; set; }
public string DownloadServerAddress { get; set; }
public string Servername { get; set; }
public string CoreServerAddress { get; set; }
public string ChatServerAddress { get; set; }
public int Length => ToList().Count;
public static Connection Parse(List<string> data)
{
var connection = new Connection();
var c = 0;
connection.ProxyName = data[c++];
connection.ProxyPassword = data[c++];
connection.ProxyUsername = data[c++];
connection.IpAddress = data[c++];
connection.DownloadServerAddress = data[c++];
connection.Servername = data[c++];
connection.CoreServerAddress = data[c++];
connection.ChatServerAddress = data[c++];
return connection;
}
public List<string> ToList()
{
return new List<string> { ProxyName, ProxyPassword, ProxyUsername,
IpAddress, DownloadServerAddress, Servername,
CoreServerAddress, ChatServerAddress};
}
public string DownloadServerAddressExact
{
get
{
String url = DownloadServerAddress?.ToLower();
// Localhost
if (url.IndexOf("localhost") >= 0)
return new Uri(url).ToString();
// Just Number
if (int.TryParse(url, out int i))
url = "app" + url;
// Kein Https
if (url.IndexOf("https://") < 0)
url = "https://" + url;
// Kein Punkt
if (url.IndexOf('.') < 0)
url += ".bewoplaner.de";
// Kein Slash
if (url.IndexOf("/download") < 0)
url += "/download";
return new Uri(url).ToString();
}
}
public string CoreServerAddressExact
{
get
{
try
{
String url = CoreServerAddress?.ToLower();
if (string.IsNullOrEmpty(url))
return null;
// Localhost
if (url.IndexOf("localhost") >= 0)
return new Uri(url).ToString();
// Just Number
if (int.TryParse(url, out int i))
url = "app" + url;
// Kein Https
if (url.IndexOf("https://") < 0)
url = "https://" + url;
// Kein Punkt
if (url.IndexOf('.') < 0)
url += ".bewoplaner.de";
// Kein Slash
if (url.IndexOf("/service") < 0)
url += "/service";
return new Uri(url).ToString();
}
catch(Exception e)
{
return null;
}
}
}
}
}