|
2 | 2 | using System.Diagnostics; |
3 | 3 | using System.IO.Pipes; |
4 | 4 | using System.Linq; |
| 5 | +using System.Runtime.Serialization.Json; |
5 | 6 | using System.Security.Cryptography; |
6 | 7 | using System.Text; |
7 | 8 | using System.Threading; |
@@ -51,7 +52,7 @@ public static bool LaunchOrReturn(Action<string[]> otherInstanceCallback, string |
51 | 52 | else |
52 | 53 | { |
53 | 54 | // We are not the first instance, send the named pipe message with our payload and stop loading |
54 | | - var namedPipeXmlPayload = new NamedPipeXmlPayload |
| 55 | + var namedPipeXmlPayload = new Payload |
55 | 56 | { |
56 | 57 | CommandLineArguments = Environment.GetCommandLineArgs().ToList() |
57 | 58 | }; |
@@ -87,16 +88,16 @@ private static bool IsApplicationFirstInstance() |
87 | 88 | /// Uses a named pipe to send the currently parsed options to an already running instance. |
88 | 89 | /// </summary> |
89 | 90 | /// <param name="namedPipePayload"></param> |
90 | | - private static void NamedPipeClientSendOptions(NamedPipeXmlPayload namedPipePayload) |
| 91 | + private static void NamedPipeClientSendOptions(Payload namedPipePayload) |
91 | 92 | { |
92 | 93 | try |
93 | 94 | { |
94 | 95 | using (var namedPipeClientStream = new NamedPipeClientStream(".", GetPipeName(), PipeDirection.Out)) |
95 | 96 | { |
96 | 97 | namedPipeClientStream.Connect(3000); // Maximum wait 3 seconds |
97 | 98 |
|
98 | | - var xmlSerializer = new XmlSerializer(typeof(NamedPipeXmlPayload)); |
99 | | - xmlSerializer.Serialize(namedPipeClientStream, namedPipePayload); |
| 99 | + var ser = new DataContractJsonSerializer(typeof(Payload)); |
| 100 | + ser.WriteObject(namedPipeClientStream, namedPipePayload); |
100 | 101 | } |
101 | 102 | } |
102 | 103 | catch (Exception) |
@@ -134,17 +135,17 @@ private static void NamedPipeServerConnectionCallback(IAsyncResult iAsyncResult) |
134 | 135 | // End waiting for the connection |
135 | 136 | _namedPipeServerStream.EndWaitForConnection(iAsyncResult); |
136 | 137 |
|
137 | | - var xmlSerializer = new XmlSerializer(typeof(NamedPipeXmlPayload)); |
138 | | - var namedPipeXmlPayload = (NamedPipeXmlPayload)xmlSerializer.Deserialize(_namedPipeServerStream); |
| 138 | + var ser = new DataContractJsonSerializer(typeof(Payload)); |
| 139 | + var payload = (Payload)ser.ReadObject(_namedPipeServerStream); |
139 | 140 |
|
140 | | - // namedPipeXmlPayload contains the data sent from the other instance |
| 141 | + // payload contains the data sent from the other instance |
141 | 142 | if (_syncContext != null) |
142 | 143 | { |
143 | | - _syncContext.Post(_ => _otherInstanceCallback(namedPipeXmlPayload.CommandLineArguments.ToArray()), null); |
| 144 | + _syncContext.Post(_ => _otherInstanceCallback(payload.CommandLineArguments.ToArray()), null); |
144 | 145 | } |
145 | 146 | else |
146 | 147 | { |
147 | | - _otherInstanceCallback(namedPipeXmlPayload.CommandLineArguments.ToArray()); |
| 148 | + _otherInstanceCallback(payload.CommandLineArguments.ToArray()); |
148 | 149 | } |
149 | 150 | } |
150 | 151 | catch (ObjectDisposedException) |
|
0 commit comments