-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cross platform support (Windows / Linux / OS X) by @krippz
Merge pull request #11 from krippz/crossplat
- Loading branch information
Showing
32 changed files
with
5,774 additions
and
1,896 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Mongo2Go.Helper | ||
{ | ||
public interface IMongoBinaryLocator | ||
{ | ||
string Directory { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace Mongo2Go.Helper | ||
{ | ||
|
||
public class MongoBinaryLocator : IMongoBinaryLocator | ||
{ | ||
private string nugetPrefix = System.IO.Path.Combine ("packages", "Mongo2Go*"); | ||
private string searchPattern = ""; | ||
private string binFolder = string.Empty; | ||
|
||
public MongoBinaryLocator (string binSearchPattern) | ||
{ | ||
if (string.IsNullOrEmpty (binSearchPattern)) { | ||
throw new ArgumentException ("Missing the search pattern for finding the mongoDb binaries.", "binSearchPattern"); | ||
} | ||
|
||
searchPattern = binSearchPattern; | ||
} | ||
|
||
public string Directory { | ||
get { | ||
if (string.IsNullOrEmpty (binFolder)){ | ||
return binFolder = ResolveBinariesDirectory (); | ||
} else { | ||
return binFolder; | ||
} | ||
} | ||
} | ||
|
||
private string ResolveBinariesDirectory () | ||
{ | ||
// 1st: path when installed via nuget | ||
// 2nd: path when started from solution | ||
string binariesFolder = FolderSearch.CurrentExecutingDirectory ().FindFolderUpwards (System.IO.Path.Combine (nugetPrefix, searchPattern)) ?? | ||
FolderSearch.CurrentExecutingDirectory ().FindFolderUpwards (searchPattern); | ||
|
||
if (binariesFolder == null) { | ||
throw new MonogDbBinariesNotFoundException (string.Format ( | ||
"Could not find Mongo binaries using {0}. We walk up the directories {1} levels from {2}", | ||
searchPattern, | ||
FolderSearch.MaxLevelOfRecursion, | ||
FolderSearch.CurrentExecutingDirectory ())); | ||
} | ||
return binariesFolder; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.NetworkInformation; | ||
using System.Net.Sockets; | ||
|
||
namespace Mongo2Go.Helper | ||
{ | ||
public class PortWatcherFactory | ||
{ | ||
public static IPortWatcher CreatePortWatcher() | ||
{ | ||
IPortWatcher portwatcher = null; | ||
|
||
switch (Environment.OSVersion.Platform) | ||
{ | ||
case PlatformID.Unix: | ||
portwatcher = new UnixPortWatcher (); | ||
break; | ||
|
||
default: | ||
portwatcher = new PortWatcher (); | ||
break; | ||
} | ||
|
||
return portwatcher; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Net; | ||
using System.Net.Sockets; | ||
|
||
namespace Mongo2Go.Helper | ||
{ | ||
|
||
public class UnixPortWatcher : IPortWatcher | ||
{ | ||
public int FindOpenPort (int startPort) | ||
{ | ||
int port = startPort; | ||
do { | ||
if (IsPortAvailable (port)) { | ||
break; | ||
} | ||
|
||
if (port == MongoDbDefaults.TestStartPort + 100) { | ||
throw new NoFreePortFoundException (); | ||
} | ||
|
||
++port; | ||
|
||
} while (true); | ||
|
||
return port; | ||
} | ||
|
||
public bool IsPortAvailable (int portNumber) | ||
{ | ||
bool result = false; | ||
|
||
TcpListener tcpListener = new TcpListener (IPAddress.Loopback, portNumber); | ||
try { | ||
tcpListener.Start (); | ||
} catch (SocketException) { | ||
result = false; | ||
|
||
} finally | ||
{ | ||
tcpListener.Stop (); | ||
result = true; | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.