Skip to content

Commit 3a70717

Browse files
Merge remote-tracking branch 'origin/master' into LOC_3186_mac_support
2 parents 486cd62 + 534031c commit 3a70717

File tree

7 files changed

+180
-28
lines changed

7 files changed

+180
-28
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,27 @@ jobs:
3333
run: dotnet test BrowserStackLocalIntegrationTests --no-build -p:Configuration=Release
3434
- name: Pack NuGet Package
3535
run: msbuild BrowserStackLocal -t:pack -p:Configuration=Release
36+
- name: Setup nuget
37+
uses: nuget/setup-nuget@v1
38+
with:
39+
nuget-api-key: ${{ secrets.NUGET_API_KEY }}
40+
nuget-version: '5.x'
41+
- name: Create PFX certificate
42+
id: createPfx
43+
shell: pwsh
44+
env:
45+
PFX_CONTENT: ${{ secrets.BASE64_PFX_CONTENT }}
46+
run: |
47+
$pfxPath = Join-Path -Path $env:RUNNER_TEMP -ChildPath "cert.pfx";
48+
$encodedBytes = [System.Convert]::FromBase64String($env:PFX_CONTENT);
49+
Set-Content $pfxPath -Value $encodedBytes -AsByteStream;
50+
Write-Output "::set-output name=PFX_PATH::$pfxPath";
51+
- name: Sign Nuget Package
52+
run: nuget sign .\BrowserStackLocal\bin\Release\*.nupkg -certificatePath "${{ steps.createPfx.outputs.PFX_PATH }}" -certificatePassword "${{secrets.CERT_PASSWORD}}" -Timestamper "http://timestamp.comodoca.com"
3653
- name: Save artifact
3754
uses: actions/upload-artifact@v2
3855
with:
3956
name: BrowserStackLocal.nupkg
4057
path: .\BrowserStackLocal\BrowserStackLocal\bin\Release\*.nupkg
58+
- name: Push package to Nuget Repository
59+
run: nuget push **\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.23107.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrowserStackLocal", "BrowserStackLocal\BrowserStackLocal.csproj", "{F58E1C9A-5910-4DA8-B531-9F4A6B0AE8C8}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrowserStackLocal Unit Tests", "BrowserStackLocal Unit Tests\BrowserStackLocal Unit Tests.csproj", "{FF1ABB6F-4A2C-48F4-B4DB-47DAD566D2F9}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrowserStackLocalIntegrationTests", "BrowserStackLocalIntegrationTests\BrowserStackLocalIntegrationTests.csproj", "{01FFB287-C79A-4476-AEDB-EE8DE80EB3B3}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Release|Any CPU = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{F58E1C9A-5910-4DA8-B531-9F4A6B0AE8C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{F58E1C9A-5910-4DA8-B531-9F4A6B0AE8C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{F58E1C9A-5910-4DA8-B531-9F4A6B0AE8C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{F58E1C9A-5910-4DA8-B531-9F4A6B0AE8C8}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{FF1ABB6F-4A2C-48F4-B4DB-47DAD566D2F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{FF1ABB6F-4A2C-48F4-B4DB-47DAD566D2F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{FF1ABB6F-4A2C-48F4-B4DB-47DAD566D2F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{FF1ABB6F-4A2C-48F4-B4DB-47DAD566D2F9}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{01FFB287-C79A-4476-AEDB-EE8DE80EB3B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{01FFB287-C79A-4476-AEDB-EE8DE80EB3B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{01FFB287-C79A-4476-AEDB-EE8DE80EB3B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{01FFB287-C79A-4476-AEDB-EE8DE80EB3B3}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
EndGlobal

BrowserStackLocal/BrowserStackLocal.sln

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.23107.0
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.1.32414.318
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrowserStackLocal", "BrowserStackLocal\BrowserStackLocal.csproj", "{F58E1C9A-5910-4DA8-B531-9F4A6B0AE8C8}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrowserStackLocal", "BrowserStackLocal\BrowserStackLocal.csproj", "{F58E1C9A-5910-4DA8-B531-9F4A6B0AE8C8}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrowserStackLocal Unit Tests", "BrowserStackLocal Unit Tests\BrowserStackLocal Unit Tests.csproj", "{FF1ABB6F-4A2C-48F4-B4DB-47DAD566D2F9}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrowserStackLocal Unit Tests", "BrowserStackLocal Unit Tests\BrowserStackLocal Unit Tests.csproj", "{FF1ABB6F-4A2C-48F4-B4DB-47DAD566D2F9}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrowserStackLocalIntegrationTests", "BrowserStackLocalIntegrationTests\BrowserStackLocalIntegrationTests.csproj", "{01FFB287-C79A-4476-AEDB-EE8DE80EB3B3}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrowserStackLocalIntegrationTests", "BrowserStackLocalIntegrationTests\BrowserStackLocalIntegrationTests.csproj", "{01FFB287-C79A-4476-AEDB-EE8DE80EB3B3}"
11+
ProjectSection(ProjectDependencies) = postProject
12+
{F58E1C9A-5910-4DA8-B531-9F4A6B0AE8C8} = {F58E1C9A-5910-4DA8-B531-9F4A6B0AE8C8}
13+
EndProjectSection
1114
EndProject
1215
Global
1316
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -31,4 +34,7 @@ Global
3134
GlobalSection(SolutionProperties) = preSolution
3235
HideSolutionNode = FALSE
3336
EndGlobalSection
37+
GlobalSection(ExtensibilityGlobals) = postSolution
38+
SolutionGuid = {3019DB30-CCF5-4543-B787-FCBBD97B21C8}
39+
EndGlobalSection
3440
EndGlobal

BrowserStackLocal/BrowserStackLocal/BrowserStackLocal.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
<Title>BrowserStackLocalTitle>
88
<Product>BrowserStackLocalProduct>
99
<Description>C# Bindings for BrowserStack LocalDescription>
10-
<Version>2.0.0.0Version>
11-
<FileVersion>2.0.0.0FileVersion>
10+
<Version>2.1.0Version>
11+
<AssemblyVersion>2.1.0AssemblyVersion>
12+
<FileVersion>2.1.0FileVersion>
1213
<Authors>BrowserStackAuthors>
1314
<Company>BrowserStackCompany>
1415
<Copyright>Copyright © 2016Copyright>

BrowserStackLocal/BrowserStackLocal/BrowserStackTunnel.cs

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public class BrowserStackTunnel : IDisposable
2626
Directory.GetCurrentDirectory(),
2727
Path.GetTempPath() };
2828

29-
int basePathsIndex = -1;
29+
public int basePathsIndex = -1;
3030
protected string binaryAbsolute = "";
3131
protected string binaryArguments = "";
32-
32+
3333
protected StringBuilder output;
3434
public LocalState localState;
3535
protected string logFilePath = "";
@@ -147,7 +147,7 @@ public virtual void Run(string accessKey, string folder, string logFilePath, str
147147
{
148148
File.WriteAllText(logFilePath, string.Empty);
149149
}
150-
RunProcess(arguments, processType);
150+
RunProcess(arguments, processType);
151151
}
152152

153153
private void RunProcess(string arguments, string processType)
@@ -172,14 +172,40 @@ private void RunProcess(string arguments, string processType)
172172
if (e.Data != null)
173173
{
174174
JObject binaryOutput = null;
175-
try {
175+
try
176+
{
176177
binaryOutput = JObject.Parse(e.Data);
177-
} catch (Exception) {
178+
}
179+
catch (Exception)
180+
{
181+
SetTunnelState(LocalState.Error);
178182
throw new Exception($"Error while parsing JSON {e.Data}");
179183
}
180-
if(binaryOutput.GetValue("state") != null && !binaryOutput.GetValue("state").ToString().ToLower().Equals("connected"))
184+
185+
JToken connectionState = binaryOutput.GetValue("state");
186+
if (connectionState != null)
187+
{
188+
if (connectionState.ToString().ToLower().Equals("connected"))
189+
{
190+
SetTunnelState(LocalState.Connected);
191+
}
192+
else if (connectionState.ToString().ToLower().Equals("disconnected"))
193+
{
194+
SetTunnelState(LocalState.Disconnected);
195+
}
196+
else
197+
{
198+
SetTunnelState(LocalState.Error);
199+
throw new Exception("Error while executing BrowserStackLocal " + processType + " " + e.Data);
200+
}
201+
}
202+
else
181203
{
182-
throw new Exception("Eror while executing BrowserStackLocal " + processType + " " + e.Data);
204+
JToken message = binaryOutput.GetValue("message");
205+
if (message != null && message.Type == JTokenType.String && message.ToString() == "BrowserStackLocal stopped successfully")
206+
{
207+
SetTunnelState(LocalState.Disconnected);
208+
}
183209
}
184210
}
185211
});
@@ -196,13 +222,19 @@ private void RunProcess(string arguments, string processType)
196222
process.BeginOutputReadLine();
197223
process.BeginErrorReadLine();
198224

199-
TunnelStateChanged(LocalState.Idle, LocalState.Connecting);
200-
AppDomain.CurrentDomain.ProcessExit += new EventHandler((s, e) => Kill());
225+
SetTunnelState(LocalState.Connecting);
226+
AppDomain.CurrentDomain.ProcessExit += new EventHandler((s, e) =>
227+
{
228+
Kill();
229+
});
201230

202231
process.WaitForExit();
203232
}
204233

205-
private void TunnelStateChanged(LocalState prevState, LocalState state) { }
234+
private void SetTunnelState(LocalState newState)
235+
{
236+
localState = newState;
237+
}
206238

207239
public bool IsConnected()
208240
{
@@ -216,13 +248,13 @@ public void Kill()
216248
process.Close();
217249
process.Kill();
218250
process = null;
219-
localState = LocalState.Disconnected;
251+
SetTunnelState(LocalState.Disconnected);
220252
}
221253
}
222254

223255
public void Dispose()
224256
{
225-
if(process != null)
257+
if (process != null)
226258
{
227259
Kill();
228260
}

BrowserStackLocal/BrowserStackLocal/Local.cs

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Text.RegularExpressions;
5+
using System.Reflection;
56

67
namespace BrowserStack
78
{
@@ -12,6 +13,8 @@ public class Local
1213
private string customLogPath = "";
1314
private string argumentString = "";
1415
private string customBinaryPath = "";
16+
private string bindingVersion = "";
17+
1518
protected BrowserStackTunnel tunnel = null;
1619
private static KeyValuePair<string, string> emptyStringPair = new KeyValuePair<string, string>();
1720

@@ -63,7 +66,11 @@ private void addArgs(string key, string value)
6366
{
6467

6568
}
66-
else
69+
else if (key.Equals("source"))
70+
{
71+
72+
}
73+
else
6774
{
6875
result = valueCommands.Find(pair => pair.Key == key);
6976
if (!result.Equals(emptyStringPair))
@@ -92,13 +99,56 @@ private void addArgs(string key, string value)
9299
}
93100
}
94101
}
95-
102+
103+
public static string GetVersionString(string pVersionString)
104+
{
105+
string tVersion = "Unknown";
106+
string[] aVersion;
107+
108+
if (string.IsNullOrEmpty(pVersionString)) { return tVersion; }
109+
aVersion = pVersionString.Split('.');
110+
if (aVersion.Length > 0) { tVersion = aVersion[0]; }
111+
if (aVersion.Length > 1) { tVersion += "." + aVersion[1]; }
112+
if (aVersion.Length > 2) { tVersion += "." + aVersion[2].PadLeft(4, '0'); }
113+
if (aVersion.Length > 3) { tVersion += "." + aVersion[3].PadLeft(4, '0'); }
114+
115+
return tVersion;
116+
}
117+
public static Assembly GetAssemblyEmbedded(string pAssemblyDisplayName)
118+
{
119+
Assembly tMyAssembly = null;
120+
121+
if (string.IsNullOrEmpty(pAssemblyDisplayName)) { return tMyAssembly; }
122+
try
123+
{
124+
tMyAssembly = Assembly.Load(pAssemblyDisplayName);
125+
}
126+
catch (Exception ex)
127+
{
128+
string m = ex.Message;
129+
Console.Error.WriteLine(m);
130+
}
131+
return tMyAssembly;
132+
}
133+
public static string GetVersionStringFromAssemblyEmbedded(string pAssemblyDisplayName)
134+
{
135+
string tVersion = "Unknown";
136+
Assembly tMyAssembly = null;
137+
138+
tMyAssembly = GetAssemblyEmbedded(pAssemblyDisplayName);
139+
if (tMyAssembly == null) { return tVersion; }
140+
tVersion = GetVersionString(tMyAssembly.GetName().Version.ToString());
141+
return tVersion;
142+
}
143+
96144
public Local()
97145
{
98-
tunnel = new BrowserStackTunnel();
146+
bindingVersion = GetVersionStringFromAssemblyEmbedded("BrowserStackLocal");
147+
tunnel = new BrowserStackTunnel();
99148
}
100149
public void start(List<KeyValuePair<string, string>> options)
101150
{
151+
tunnel.basePathsIndex = -1;
102152
foreach (KeyValuePair<string, string> pair in options)
103153
{
104154
string key = pair.Key;
@@ -111,7 +161,7 @@ public void start(List> options)
111161
accessKey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY");
112162
if (accessKey == null || accessKey.Trim().Length == 0)
113163
{
114-
throw new Exception("BROWSERSTACK_ACCESS_KEY cannot be empty. "+
164+
throw new Exception("BROWSERSTACK_ACCESS_KEY cannot be empty. " +
115165
"Specify one by adding key to options or adding to the environment variable BROWSERSTACK_ACCESS_KEY.");
116166
}
117167
Regex.Replace(this.accessKey, @"\s+", "");
@@ -123,20 +173,30 @@ public void start(List> options)
123173
}
124174

125175
argumentString += "-logFile \"" + customLogPath + "\" ";
176+
argumentString += "--source \"c-sharp:" + bindingVersion + "\" ";
126177
tunnel.addBinaryPath(customBinaryPath);
127178
tunnel.addBinaryArguments(argumentString);
128-
while (true) {
179+
while (true)
180+
{
129181
bool except = false;
130-
try {
182+
try
183+
{
131184
tunnel.Run(accessKey, folder, customLogPath, "start");
132-
} catch (Exception)
185+
}
186+
catch (System.ComponentModel.Win32Exception)
133187
{
134188
except = true;
135189
}
190+
catch (Exception e)
191+
{
192+
except = true;
193+
Console.WriteLine(e.ToString());
194+
}
136195
if (except)
137196
{
138197
tunnel.fallbackPaths();
139-
} else
198+
}
199+
else
140200
{
141201
break;
142202
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# browserstack-local-csharp
22

3-
[![Build Status](https://travis-ci.org/browserstack/browserstack-local-csharp.svg?branch=master)](https://travis-ci.org/browserstack/browserstack-local-csharp)
3+
[![.NET package CI](https://github.com/browserstack/browserstack-local-csharp/actions/workflows/ci.yml/badge.svg)](https://github.com/browserstack/browserstack-local-csharp/actions/workflows/ci.yml)
44

55
C# bindings for BrowserStack Local.
66

0 commit comments

Comments
 (0)