forked from ArtOfCode-/ChatMessenger
/
App.xaml.cs
83 lines (73 loc) · 2.16 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using EPQMessenger.Windows;
using EPQMessenger.Workers;
[assembly:CLSCompliant(true)]
namespace EPQMessenger
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public OperationMode OperatingMode { get; private set; }
public static bool StopAllThreads { get; set; }
public static Logger LogDevice { get; private set; }
[STAThread]
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
StopAllThreads = false;
LogDevice = new Logger();
this.ParseCommandLineArgs();
if (OperatingMode == OperationMode.Server)
{
ServerWindow window = new ServerWindow();
window.Show();
window.Closed += (sender, ea) =>
{
Environment.Exit(0);
};
}
else if (OperatingMode == OperationMode.Client)
{
ClientWindow window = new ClientWindow();
window.Show();
window.Closed += (sender, ea) =>
{
Environment.Exit(0);
};
}
}
private void ParseCommandLineArgs()
{
string[] args = Environment.GetCommandLineArgs();
if (args.Contains("-s") || args.Contains("--server"))
{
this.SetOperationMode(OperationMode.Server);
}
else
{
this.SetOperationMode(OperationMode.Client);
}
if (args.Contains("-d") || args.Contains("--disable-logging"))
{
LogDevice.IsEnabled = false;
}
else
{
LogDevice.IsEnabled = true;
}
}
private void SetOperationMode(OperationMode mode)
{
OperatingMode = mode;
}
}
}