Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit 8ae0474

Browse files
[Touch.Server] Included option to skip log file header
Included option to skip log file header
2 parents a145cac + c1ddbf3 commit 8ae0474

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.vs/
12
.DS_Store
23
*.pidb
34
*.userprefs

Touch.Server/Main.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ public void Initialize ()
7272
Console.WriteLine ("Touch.Unit Simple Server listening on: {0}:{1}", Address, Port);
7373
}
7474

75-
public int Start ()
75+
public int Start (bool skipheader = false)
7676
{
7777
bool processed;
7878

7979
try {
8080

8181
do {
8282
using (TcpClient client = server.AcceptTcpClient ()) {
83-
processed = Processing (client);
83+
processed = Processing (client, skipheader);
8484
}
8585
} while (!AutoExit || !processed);
8686
}
@@ -99,20 +99,22 @@ public int Start ()
9999
return 0;
100100
}
101101

102-
public bool Processing (TcpClient client)
102+
public bool Processing (TcpClient client, bool skipHeader = false)
103103
{
104104
string logfile = Path.Combine (LogPath, LogFile ?? DateTime.UtcNow.Ticks.ToString () + ".log");
105105
string remote = client.Client.RemoteEndPoint.ToString ();
106106
Console.WriteLine ("Connection from {0} saving logs to {1}", remote, logfile);
107107
connected.Set ();
108108

109109
using (FileStream fs = File.OpenWrite (logfile)) {
110-
// a few extra bits of data only available from this side
111-
string header = String.Format ("[Local Date/Time:\t{1}]{0}[Remote Address:\t{2}]{0}",
112-
Environment.NewLine, DateTime.Now, remote);
113-
byte[] array = Encoding.UTF8.GetBytes (header);
114-
fs.Write (array, 0, array.Length);
115-
fs.Flush ();
110+
if (!skipHeader) {
111+
// a few extra bits of data only available from this side
112+
string header = String.Format("[Local Date/Time:\t{1}]{0}[Remote Address:\t{2}]{0}",
113+
Environment.NewLine, DateTime.Now, remote);
114+
byte[] array = Encoding.UTF8.GetBytes(header);
115+
fs.Write (array, 0, array.Length);
116+
fs.Flush ();
117+
}
116118
// now simply copy what we receive
117119
int i;
118120
int total = 0;
@@ -153,6 +155,7 @@ public static int Main (string[] args)
153155
string launchdev = null;
154156
string launchsim = null;
155157
bool autoexit = false;
158+
bool skipheader = false;
156159
string device_name = String.Empty;
157160
string device_type = String.Empty;
158161
TimeSpan? timeout = null;
@@ -169,6 +172,7 @@ public static int Main (string[] args)
169172
{ "launchdev=", "Run the specified app on a device (specify using bundle identifier)", v => launchdev = v },
170173
{ "launchsim=", "Run the specified app on the simulator (specify using path to *.app directory)", v => launchsim = v },
171174
{ "autoexit", "Exit the server once a test run has completed (default: false)", v => autoexit = true },
175+
{ "skipheader", "Exclude the header from the logfile (default: false)", v => skipheader = true },
172176
{ "devname=", "Specify the device to connect to", v => device_name = v},
173177
{ "device=", "Specifies the device type to launch the simulator", v => device_type = v },
174178
{ "timeout=", "Specifies a timeout (in minutes), after which the simulator app will be killed (ignored for device runs)", v => timeout = TimeSpan.FromMinutes (double.Parse (v)) },
@@ -346,7 +350,7 @@ public static int Main (string[] args)
346350
});
347351
}
348352

349-
var result = listener.Start ();
353+
var result = listener.Start (skipheader);
350354
if (proc != null && !proc.WaitForExit (30000 /* wait another 30 seconds for mtouch to finish as well */))
351355
Console.WriteLine ("mtouch didn't complete within 30s of the simulator app exiting. Touch.Server will exit anyway.");
352356
// Wait up to 2 seconds to receive the last of the error/output data. This will only be received *after*

0 commit comments

Comments
 (0)