Files
BeWoPlaner/SharedLauncher/Information/ConnectionInformation.cs

247 lines
7.0 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 Tenant { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string ProxyName { get; set; }
public string ProxyPassword { get; set; }
public string ProxyUsername { get; set; }
public string IpAddress{ get; set; }
public string LauncherServerAddress { get; set; }
public string Servername { get; set; }
public string CoreServerAddress { get; set; }
public string ChatServerAddress { get; set; }
public string Version { get; set; }
public static Connection Parse(string[] data)
{
var connection = new Connection();
connection.Tenant = data[0];
connection.Username = data[1];
connection.Password = data[2];
connection.IpAddress = data[3];
connection.CoreServerAddress = data[4];
connection.ChatServerAddress = data[5];
connection.Version = data[6];
return connection;
}
public string[] ToArray()
{
return new string[] { "demo", "demo", "demo", IpAddress, ConnectionInformation.CoreServerAddressOrigin.ToString(), ChatServerAddress, Version };
}
//public static bool TryParse(string input, out Connection connection)
//{
// connection = new Connection();
// try
// {
// connection = Parse(input);
// return true;
// }
// catch (Exception)
// {
// return false;
// }
//}
//public static bool TryParse(string input, out Connection connection)
//{
// connection = new Connection();
// try
// {
// connection = Parse(input);
// return true;
// }
// catch (Exception)
// {
// return false;
// }
//}
public override string ToString()
{
return
$"te{Tenant}{trennzeichen}un{Username}{trennzeichen}pw{Password}{trennzeichen}ip{IpAddress}{trennzeichen}sn{Servername}{trennzeichen}cs{ChatServerAddress}{trennzeichen}vr{Version}";
}
}
public static class ConnectionInformation
{
private static Connection connection;
public static Connection Connection
{
get
{
if (connection is null)
connection = new Connection();
return connection;
}
}
public static string ProxyName
{
get { return Connection.ProxyName; }
set { Connection.ProxyName = value; }
}
public static string ProxyPassword
{
get { return Connection.ProxyPassword; }
set { Connection.ProxyPassword = value; }
}
public static string ProxyUsername
{
get { return Connection.ProxyUsername; }
set { Connection.ProxyUsername = value; }
}
public static string ChatServerAddress
{
get { return Connection.ChatServerAddress; }
set { Connection.ChatServerAddress = value; }
}
public static string CoreServerAddress
{
get { return Connection.CoreServerAddress; }
set { Connection.CoreServerAddress = value; }
}
public static string IpAddress
{
get { return Connection.IpAddress; }
set { Connection.IpAddress = value; }
}
public static string Password
{
get { return Connection.Password; }
set { Connection.Password = value; }
}
public static string ServerName
{
get { return Connection.Servername; }
set { Connection.Servername = value; }
}
public static string Tenant
{
get { return Connection.Tenant; }
set { Connection.Tenant = value; }
}
public static string Username
{
get { return Connection.Username; }
set { Connection.Username = value; }
}
public static string Version
{
get { return Connection.Version; }
set { Connection.Version = value; }
}
public static string LauncherServerAddress
{
get { return Connection.LauncherServerAddress; }
set
{
Connection.LauncherServerAddress = value;
//LauncherServiceFacade.UpdateServerAddresses(LauncherServerAddressOrigin.ToString());
}
}
public static Uri LauncherServerAddressOrigin
{
get
{
String url = Connection.LauncherServerAddress?.ToLower();
#if DEBUG
//url = String.Format("http://localhost:3778");
return new Uri("https://app5.bewoplaner.de/launcher");
//url = String.Format("app1.bewoplaner.de/service");
#endif
if (url.IndexOf("localhost") < 0)
{
if (int.TryParse(url, out int i))
url = "app" + url;
if (url.IndexOf('.') < 0)
{
url += ".bewoplaner.de";
}
if (url.IndexOf("/service") < 0)
{
url += "/service";
}
return new Uri(string.Format("https://{0}", url));
}
return new Uri(url);
}
}
public static Uri CoreServerAddressOrigin
{
get
{
String url = Connection.CoreServerAddress?.ToLower();
#if DEBUG
url = String.Format("http://localhost:3777/Host");
//return new Uri("https://app4.bewoplaner.de/servicesbd");
//url = String.Format("app1.bewoplaner.de/service");
#endif
if (url.IndexOf("localhost") < 0)
{
if (Int32.TryParse(url, out int i))
url = "app" + url;
if (url.IndexOf('.') < 0)
{
url += ".bewoplaner.de";
}
//if (url.IndexOf("/service45") < 0)
//{
// url += "/service45";
//}
if (url.IndexOf("/servicesbd") < 0)
{
url += "/servicesbd";
}
return new Uri(string.Format("https://{0}", url));
}
return new Uri(url);
}
}
}
}