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

149 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Linq;
namespace BS.SharedLauncher.Information
{
public static class SessionInformation
{
private static Connection connection;
private static Login login;
private static Session session;
public static string GetDebugConnection(int i)
{
if (i == 1)
{
// Download Server
return "http://localhost:3778";
//return "https://localhost:44367/";
//return "https://app5.bewoplaner.de";
}
if (i == 2)
{
// Core Server
return "http://localhost:3777/Host/";
//return "https://localhost:44308/Host/";
//return "https://app5.bewoplaner.de";
}
throw new Exception();
}
public static Connection Connection
{
get
{
if (connection is null)
{
connection = new Connection();
Loaded = true;
}
return connection;
}
}
public static Session Session
{
get
{
if (session is null)
{
session = new Session();
Loaded = true;
}
return session;
}
}
public static Login Login
{
get
{
if (login is null)
{
login = new Login();
Loaded = true;
}
return login;
}
}
public static bool Loaded { get; set; }
static SessionInformation()
{
Loaded = false;
}
public static void Load(List<string> connection, List<string> login, List<string> session)
{
Init(
BS.SharedLauncher.Information.Connection.Parse(connection),
BS.SharedLauncher.Information.Login.Parse(login),
BS.SharedLauncher.Information.Session.Parse(session));
}
public static void Init(Connection pconnection, Login plogin, Session psession)
{
//if (Loaded)
// throw new Exception(SessionInformation.ToString());
connection = pconnection;
login = plogin;
session = psession;
Loaded = true;
}
public static bool LoadPipe(string pipe)
{
try
{
using (PipeStream pipeClient = new AnonymousPipeClientStream(PipeDirection.In, pipe))
{
using (StreamReader sr = new StreamReader(pipeClient))
{
string temp;
List<string> result = new List<string>();
var signal = new string[] { "C-137", "C-131" };
// Warte auf Start
do
{
temp = sr.ReadLine();
}
while (!temp.StartsWith(signal[0]));
var connection = (from x in Enumerable.Range(0, Connection.Length) select sr.ReadLine()).ToList();
var login = (from x in Enumerable.Range(0, Login.Length) select sr.ReadLine()).ToList();
var session = (from x in Enumerable.Range(0, Session.Length) select sr.ReadLine()).ToList();
do
{
temp = sr.ReadLine();
}
while (!temp.StartsWith(signal[1]));
Load(connection, login, session);
}
}
return true;
}
catch (Exception ex)
{
return false;
}
}
public static string ToString()
{
return $"c:{string.Join(",", connection.ToList())} l:{string.Join(",", login.ToList())} s:{string.Join(",", session.ToList())}";
}
}
}