Files
BeWoPlaner/SharedLauncher/Information/ConnectionInformation.cs

197 lines
5.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
{
public string Tenant { get; set; }
public string Username { get; set; }
public string Password { 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 static Connection Parse(string input)
{
var connection = new Connection();
var data = input.Split('?').Select(x => x.Length > 2 ? x.Substring(2) : string.Empty).ToArray();
connection.Tenant = data[0];
connection.Username = data[1];
connection.Password = data[2];
connection.IpAddress = data[3];
connection.Servername = data[4];
connection.ChatServerAddress = data[5];
return connection;
}
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}?un{Username}?pw{Password}?ip{IpAddress}?sn{Servername}?cs{ChatServerAddress}";
}
}
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 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 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://app4.bewoplaner.de/servicesbd");
//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("/servicesbd") < 0)
{
url += "/servicesbd";
}
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);
}
}
}
}