restored network browser

This commit is contained in:
Luke Pulverenti 2013-09-06 16:25:03 -04:00
parent e4dfbb6f55
commit 0d59941539
5 changed files with 115 additions and 13 deletions

View File

@ -55,6 +55,15 @@ namespace MediaBrowser.Api
{
}
/// <summary>
/// Class GetNetworkComputers
/// </summary>
[Route("/Environment/NetworkDevices", "GET")]
[Api(Description = "Gets a list of devices on the network")]
public class GetNetworkDevices : IReturn<List<FileSystemEntryInfo>>
{
}
/// <summary>
/// Class EnvironmentService
/// </summary>
@ -138,6 +147,32 @@ namespace MediaBrowser.Api
});
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetNetworkDevices request)
{
var result = GetNetworkDevices().OrderBy(i => i.Path).ToList();
return ToOptimizedResult(result);
}
/// <summary>
/// Gets the network computers.
/// </summary>
/// <returns>IEnumerable{FileSystemEntryInfo}.</returns>
private IEnumerable<FileSystemEntryInfo> GetNetworkDevices()
{
return _networkManager.GetNetworkDevices().Select(c => new FileSystemEntryInfo
{
Name = c,
Path = NetworkPrefix + c,
Type = FileSystemEntryType.NetworkComputer
});
}
/// <summary>
/// Gets the name.
/// </summary>

View File

@ -224,6 +224,67 @@ namespace MediaBrowser.Common.Implementations.NetworkManagement
return hosts[0];
}
/// <summary>
/// Uses the DllImport : NetServerEnum with all its required parameters
/// (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/netserverenum.asp
/// for full details or method signature) to retrieve a list of domain SV_TYPE_WORKSTATION
/// and SV_TYPE_SERVER PC's
/// </summary>
/// <returns>Arraylist that represents all the SV_TYPE_WORKSTATION and SV_TYPE_SERVER
/// PC's in the Domain</returns>
public IEnumerable<string> GetNetworkDevices()
{
//local fields
const int MAX_PREFERRED_LENGTH = -1;
var SV_TYPE_WORKSTATION = 1;
var SV_TYPE_SERVER = 2;
var buffer = IntPtr.Zero;
var tmpBuffer = IntPtr.Zero;
var entriesRead = 0;
var totalEntries = 0;
var resHandle = 0;
var sizeofINFO = Marshal.SizeOf(typeof(_SERVER_INFO_100));
try
{
//call the DllImport : NetServerEnum with all its required parameters
//see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/netserverenum.asp
//for full details of method signature
var ret = NativeMethods.NetServerEnum(null, 100, ref buffer, MAX_PREFERRED_LENGTH, out entriesRead, out totalEntries, SV_TYPE_WORKSTATION | SV_TYPE_SERVER, null, out resHandle);
//if the returned with a NERR_Success (C++ term), =0 for C#
if (ret == 0)
{
//loop through all SV_TYPE_WORKSTATION and SV_TYPE_SERVER PC's
for (var i = 0; i < totalEntries; i++)
{
//get pointer to, Pointer to the buffer that received the data from
//the call to NetServerEnum. Must ensure to use correct size of
//STRUCTURE to ensure correct location in memory is pointed to
tmpBuffer = new IntPtr((int)buffer + (i * sizeofINFO));
//Have now got a pointer to the list of SV_TYPE_WORKSTATION and
//SV_TYPE_SERVER PC's, which is unmanaged memory
//Needs to Marshal data from an unmanaged block of memory to a
//managed object, again using STRUCTURE to ensure the correct data
//is marshalled
var svrInfo = (_SERVER_INFO_100)Marshal.PtrToStructure(tmpBuffer, typeof(_SERVER_INFO_100));
//add the PC names to the ArrayList
if (!string.IsNullOrEmpty(svrInfo.sv100_name))
{
yield return svrInfo.sv100_name;
}
}
}
}
finally
{
//The NetApiBufferFree function frees
//the memory that the NetApiBufferAllocate function allocates
NativeMethods.NetApiBufferFree(buffer);
}
}
}
}

View File

@ -29,19 +29,11 @@ namespace MediaBrowser.Common.Net
/// <param name="path">The path.</param>
/// <returns>IEnumerable{NetworkShare}.</returns>
IEnumerable<NetworkShare> GetNetworkShares(string path);
}
/// <summary>
/// Enum NetworkProtocol
/// </summary>
public enum NetworkProtocol
{
/// <summary>
/// The TCP
/// Gets available devices within the domain
/// </summary>
Tcp,
/// <summary>
/// The UDP
/// </summary>
Udp
/// <returns>PC's in the Domain</returns>
IEnumerable<string> GetNetworkDevices();
}
}

View File

@ -496,6 +496,20 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
});
};
/**
* Gets a list of network devices from the server
*/
self.getNetworkDevices = function () {
var url = self.getUrl("Environment/NetworkDevices");
return self.ajax({
type: "GET",
url: url,
dataType: "json"
});
};
/**
* Cancels a package installation
*/

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.169" targetFramework="net45" />
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.170" targetFramework="net45" />
<package id="ServiceStack.Common" version="3.9.58" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.58" targetFramework="net45" />
</packages>