private void InitializeServer()
{
// Find the persisted server entity
var entity = _dataAccess.ServerFind(this.ServerId);
this.AutoStart = entity.AutoStart;
this.RemoteServerHostName = entity.RemoteServerHostName;
this.ListeningPort = entity.Port;
this.UseSsl = entity.UseSsl;
this.UseHttpsForIncommingConnections = entity.UseHttpsForIncommingConnections;
this.RecordingBehavior = entity.DisableStumpsWhenRecording
? RecordingBehavior.DisableStumps
: RecordingBehavior.LeaveStumpsUnchanged;
if (!string.IsNullOrWhiteSpace(this.RemoteServerHostName))
{
var pattern = this.UseSsl
? StumpsServerInstance.SecureUriFormat
: StumpsServerInstance.InsecureUriFormat;
var uriString = string.Format(CultureInfo.InvariantCulture, pattern, this.RemoteServerHostName);
var uri = new Uri(uriString);
_server = _serverFactory.CreateServer(this.ListeningPort, uri);
_server.UseHttpsForIncommingConnections = this.UseHttpsForIncommingConnections;
}
else
{
// TODO: Choose which method to use for the fallback when no remote server is available.
_server = _serverFactory.CreateServer(this.ListeningPort, FallbackResponse.Http503ServiceUnavailable);
}
_server.RequestFinished += (o, e) =>
{
if (this.RecordTraffic)
{
this.Recordings.Add(e.Context);
}
};
}