| 30 |
using System; |
using System; |
| 31 |
using System.Collections.Generic; |
using System.Collections.Generic; |
| 32 |
using System.IO; |
using System.IO; |
| 33 |
|
using System.Net; |
| 34 |
using System.Reflection; |
using System.Reflection; |
| 35 |
|
using System.Security.Cryptography.X509Certificates; |
| 36 |
|
using System.ServiceProcess; |
| 37 |
using ExtensionLoader; |
using ExtensionLoader; |
| 38 |
using ExtensionLoader.Config; |
using ExtensionLoader.Config; |
| 39 |
using OpenMetaverse; |
using HttpServer; |
| 40 |
|
|
| 41 |
namespace AssetServer |
namespace AssetServer |
| 42 |
{ |
{ |
| 43 |
public class AssetServer |
public class AssetServer : ServiceBase |
| 44 |
{ |
{ |
| 45 |
public const string CONFIG_FILE = "AssetServer.ini"; |
public const string CONFIG_FILE = "AssetServer.ini"; |
| 46 |
|
|
| 47 |
public HttpServer HttpServer; |
public WebServer HttpServer; |
| 48 |
public IniConfigSource ConfigFile; |
public IniConfigSource ConfigFile; |
| 49 |
|
|
| 50 |
public IStorageProvider StorageProvider; |
public IStorageProvider StorageProvider; |
| 55 |
|
|
| 56 |
public AssetServer() |
public AssetServer() |
| 57 |
{ |
{ |
| 58 |
|
this.ServiceName = "CableBeachAssetServer"; |
| 59 |
|
|
| 60 |
} |
} |
| 61 |
|
|
| 62 |
public bool Start() |
public bool Start() |
| 63 |
{ |
{ |
| 64 |
List<string> extensionList = null; |
List<string> extensionList = null; |
| 65 |
List<string> listenPrefixes = null; |
int port = 0; |
| 66 |
|
X509Certificate2 serverCert = null; |
| 67 |
|
|
| 68 |
try { ConfigFile = new IniConfigSource(CONFIG_FILE); } |
try { ConfigFile = new IniConfigSource(CONFIG_FILE); } |
| 69 |
catch (Exception) |
catch (Exception) |
| 76 |
{ |
{ |
| 77 |
IConfig extensionConfig = ConfigFile.Configs["Config"]; |
IConfig extensionConfig = ConfigFile.Configs["Config"]; |
| 78 |
|
|
| 79 |
// Load the addresses to listen at |
// Load the port number to listen on |
| 80 |
string[] prefixes = extensionConfig.GetString("ListenAddress").Split(','); |
port = extensionConfig.GetInt("ListenPort"); |
| 81 |
listenPrefixes = new List<string>(prefixes.Length); |
|
| 82 |
foreach (string prefix in prefixes) |
// Load the server certificate file |
| 83 |
listenPrefixes.Add(prefix.Trim()); |
string certFile = extensionConfig.GetString("SSLCertFile"); |
| 84 |
|
if (!String.IsNullOrEmpty(certFile)) |
| 85 |
|
serverCert = new X509Certificate2(certFile); |
| 86 |
} |
} |
| 87 |
catch (Exception) |
catch (Exception) |
| 88 |
{ |
{ |
| 136 |
|
|
| 137 |
try |
try |
| 138 |
{ |
{ |
| 139 |
InitHttpServer(listenPrefixes); |
InitHttpServer(port, serverCert); |
| 140 |
} |
} |
| 141 |
catch (Exception ex) |
catch (Exception ex) |
| 142 |
{ |
{ |
| 155 |
return true; |
return true; |
| 156 |
} |
} |
| 157 |
|
|
| 158 |
public void Stop() |
public void Shutdown() |
| 159 |
{ |
{ |
| 160 |
foreach (IExtension<AssetServer> extension in ExtensionLoader<AssetServer>.Extensions) |
foreach (IExtension<AssetServer> extension in ExtensionLoader<AssetServer>.Extensions) |
| 161 |
{ |
{ |
| 169 |
HttpServer.Stop(); |
HttpServer.Stop(); |
| 170 |
} |
} |
| 171 |
|
|
| 172 |
void InitHttpServer(List<string> listenPrefixes) |
void InitHttpServer(int port, X509Certificate serverCert) |
| 173 |
{ |
{ |
| 174 |
HttpServer = new HttpServer(listenPrefixes); |
if (serverCert != null) |
| 175 |
|
HttpServer = new WebServer(IPAddress.Any, port, serverCert, null, false); |
| 176 |
|
else |
| 177 |
|
HttpServer = new WebServer(IPAddress.Any, port); |
| 178 |
|
|
| 179 |
HttpServer.Start(); |
HttpServer.Start(); |
| 180 |
|
|
| 181 |
System.Text.StringBuilder output = new System.Text.StringBuilder("Asset server is listening at: "); |
Logger.Log.Info("Asset server is listening on port " + port); |
|
for (int i = 0; i < listenPrefixes.Count; i++) |
|
|
{ |
|
|
output.Append(listenPrefixes[i]); |
|
|
if (i != listenPrefixes.Count - 1) output.Append(", "); |
|
| 182 |
} |
} |
| 183 |
|
|
| 184 |
Logger.Log.Info(output.ToString()); |
#region ServiceBase Overrides |
| 185 |
|
|
| 186 |
|
protected override void OnStart(string[] args) |
| 187 |
|
{ |
| 188 |
|
Start(); |
| 189 |
|
} |
| 190 |
|
protected override void OnStop() |
| 191 |
|
{ |
| 192 |
|
Shutdown(); |
| 193 |
} |
} |
| 194 |
|
|
| 195 |
|
#endregion |
| 196 |
} |
} |
| 197 |
} |
} |