aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/App.xaml.cs
blob: 82c2b0e4dd32d857021f2689b9f35b3a46ccd73b (plain)
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
using Newtonsoft.Json;
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows;
using ZetaIpc.Runtime.Client;

namespace Tango.FSE.LogViewer.UI
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private static Mutex mutex = new Mutex(true, "{8F6F0AC4-B9A1-45fd-A8CF-TANGLOGVIEWR}");

        public const int FILE_ASSPCIATION_PORT = 8989;

        protected override void OnStartup(StartupEventArgs e)
        {
            if (e.Args != null && e.Args.Length > 0)
            {
                if (mutex.WaitOne(TimeSpan.Zero, true))
                {
                    //This is the first instance. Do nothing...
                    mutex.ReleaseMutex();
                }
                else
                {
                    var ipcClient = new IpcClient();
                    ipcClient.Initialize(FILE_ASSPCIATION_PORT);
                    ipcClient.Send(JsonConvert.SerializeObject(new ArgsObject() { Args = e.Args.ToList() }));
                    Thread.Sleep(1000);
                    Environment.Exit(0);
                    return;
                }
            }

            base.OnStartup(e);
        }
    }
}