protected override void StartApplication(ApplicationConfiguration configuration)
{
base.StartApplication(configuration);
lock (m_lock)
{
try
{
// create the datastore for the instance.
m_serverInternal = new ServerInternalData(
ServerProperties,
configuration,
MessageContext,
CertificateValidator,
InstanceCertificate);
// create the manager responsible for providing localized string resources.
ResourceManager resourceManager = CreateResourceManager(m_serverInternal, configuration);
// create the manager responsible for incoming requests.
RequestManager requestManager = CreateRequestManager(m_serverInternal, configuration);
// create the master node manager.
MasterNodeManager masterNodeManager = CreateMasterNodeManager(m_serverInternal, configuration);
// add the node manager to the datastore.
m_serverInternal.SetNodeManager(masterNodeManager);
// put the node manager into a state that allows it to be used by other objects.
masterNodeManager.Startup();
// create the manager responsible for handling events.
EventManager eventManager = CreateEventManager(m_serverInternal, configuration);
// creates the server object.
m_serverInternal.CreateServerObject(
eventManager,
resourceManager,
requestManager);
// do any additional processing now that the node manager is up and running.
OnNodeManagerStarted(m_serverInternal);
// create the manager responsible for aggregates.
m_serverInternal.AggregateManager = CreateAggregateManager(m_serverInternal, configuration);
// start the session manager.
SessionManager sessionManager = CreateSessionManager(m_serverInternal, configuration);
sessionManager.Startup();
// start the subscription manager.
SubscriptionManager subscriptionManager = CreateSubscriptionManager(m_serverInternal, configuration);
subscriptionManager.Startup();
// add the session manager to the datastore.
m_serverInternal.SetSessionManager(sessionManager, subscriptionManager);
ServerError = null;
// setup registration information.
lock (m_registrationLock)
{
m_bindingFactory = BindingFactory.Create(configuration, MessageContext);
m_maxRegistrationInterval = configuration.ServerConfiguration.MaxRegistrationInterval;
ApplicationDescription serverDescription = ServerDescription;
m_registrationInfo = new RegisteredServer();
m_registrationInfo.ServerUri = serverDescription.ApplicationUri;
m_registrationInfo.ServerNames.Add(serverDescription.ApplicationName);
m_registrationInfo.ProductUri = serverDescription.ProductUri;
m_registrationInfo.ServerType = serverDescription.ApplicationType;
m_registrationInfo.GatewayServerUri = null;
m_registrationInfo.IsOnline = true;
m_registrationInfo.SemaphoreFilePath = null;
// add all discovery urls.
string computerName = System.Net.Dns.GetHostName();
for (int ii = 0; ii < BaseAddresses.Count; ii++)
{
UriBuilder uri = new UriBuilder(BaseAddresses[ii].DiscoveryUrl);
if (String.Compare(uri.Host, "localhost", StringComparison.OrdinalIgnoreCase) == 0)
{
uri.Host = computerName;
}
m_registrationInfo.DiscoveryUrls.Add(uri.ToString());
}
// build list of registration endpoints.
m_registrationEndpoints = new ConfiguredEndpointCollection(configuration);
EndpointDescription endpoint = configuration.ServerConfiguration.RegistrationEndpoint;
if (endpoint == null)
{
endpoint = new EndpointDescription();
endpoint.EndpointUrl = Utils.Format(Utils.DiscoveryUrls[0], "localhost");
endpoint.SecurityLevel = 0;
endpoint.SecurityMode = MessageSecurityMode.SignAndEncrypt;
endpoint.SecurityPolicyUri = SecurityPolicies.Basic128Rsa15;
endpoint.Server.ApplicationType = ApplicationType.DiscoveryServer;
}
m_registrationEndpoints.Add(endpoint);
m_minRegistrationInterval = 1000;
m_lastRegistrationInterval = m_minRegistrationInterval;
// start registration timer.
if (m_registrationTimer != null)
{
m_registrationTimer.Dispose();
m_registrationTimer = null;
}
if (m_maxRegistrationInterval > 0)
{
m_registrationTimer = new Timer(OnRegisterServer, this, m_minRegistrationInterval, Timeout.Infinite);
}
}
// set the server status as running.
SetServerState(ServerState.Running);
// all initialization is complete.
OnServerStarted(m_serverInternal);
// monitor the configuration file.
if (!String.IsNullOrEmpty(configuration.SourceFilePath))
{
m_configurationWatcher = new ConfigurationWatcher(configuration);
m_configurationWatcher.Changed += new EventHandler<ConfigurationWatcherEventArgs>(this.OnConfigurationChanged);
}
}
catch (Exception e)
{
Utils.Trace(e, "Unexpected error starting application");
m_serverInternal = null;
ServiceResult error = ServiceResult.Create(e, StatusCodes.BadInternalError, "Unexpected error starting application");
ServerError = error;
throw new ServiceResultException(error);
}
}
}