/// <summary> /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code. /// </summary> /// <param name="configFolderPaths">Possible configuration file locations.</param> /// <param name="serviceBrowserAvailable">Indicates whether the service browser is avaliable.</param> public void Init(string[] configFolderPaths, bool serviceBrowserAvailable) { _messageBroker = new MessageBroker(this); string servicesConfigFile = null; for (int i = 0; i < configFolderPaths.Length; i++) { servicesConfigFile = Path.Combine(configFolderPaths[i], "services-config.xml"); if (log.IsDebugEnabled) log.Debug(__Res.GetString(__Res.MessageServer_TryingServiceConfig, servicesConfigFile)); if (File.Exists(servicesConfigFile)) break; } if (servicesConfigFile != null && File.Exists(servicesConfigFile)) { if (log.IsDebugEnabled) log.Debug(__Res.GetString(__Res.MessageServer_LoadingServiceConfig, servicesConfigFile)); _servicesConfiguration = ServicesConfiguration.Load(servicesConfigFile); } else { if (log.IsDebugEnabled) log.Debug(__Res.GetString(__Res.MessageServer_LoadingConfigDefault)); _servicesConfiguration = ServicesConfiguration.CreateDefault(); } foreach (ChannelDefinition channelDefinition in _servicesConfiguration.Channels) { Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(channelDefinition.Endpoint.Class)); if (type != null) { IEndpoint endpoint = ObjectFactory.CreateInstance(type, new object[] { _messageBroker, channelDefinition }) as IEndpoint; if (endpoint != null) _messageBroker.AddEndpoint(endpoint); } else log.Error(__Res.GetString(__Res.Type_InitError, channelDefinition.Class)); } ChannelDefinition rtmptChannelDefinition = new ChannelDefinition(); rtmptChannelDefinition.Id = RtmptEndpoint.FluorineRtmptEndpointId; IEndpoint rtmptEndpoint = new RtmptEndpoint(_messageBroker, rtmptChannelDefinition); _messageBroker.AddEndpoint(rtmptEndpoint); if (_servicesConfiguration.Factories != null) { foreach (Factory factory in _servicesConfiguration.Factories) { Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(factory.Class)); if (type != null) { IFlexFactory flexFactory = ObjectFactory.CreateInstance(type, new object[0]) as IFlexFactory; if (flexFactory != null) _messageBroker.AddFactory(factory.Id, flexFactory); } else log.Error(__Res.GetString(__Res.Type_InitError, factory.Class)); } } //Add the dotnet Factory _messageBroker.AddFactory(DotNetFactory.Id, new DotNetFactory()); if (serviceBrowserAvailable) { ServiceDefinition serviceConfiguration = _servicesConfiguration.GetServiceByClass("flex.messaging.services.RemotingService"); if (serviceConfiguration != null) { AdapterDefinition adapter = serviceConfiguration.GetAdapterByClass(typeof(Remoting.RemotingAdapter).FullName); if (adapter != null) InstallServiceBrowserDestinations(serviceConfiguration, adapter); else { adapter = serviceConfiguration.GetDefaultAdapter(); if (adapter != null) InstallServiceBrowserDestinations(serviceConfiguration, adapter); } } } if (_servicesConfiguration.Services.ServiceDefinitions != null) { foreach (ServiceDefinition serviceDefinition in _servicesConfiguration.Services.ServiceDefinitions) { Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(serviceDefinition.Class));//current assembly only if (type != null) { IService service = ObjectFactory.CreateInstance(type, new object[] { _messageBroker, serviceDefinition }) as IService; if (service != null) _messageBroker.AddService(service); } else log.Error(__Res.GetString(__Res.Type_InitError, serviceDefinition.Class)); } } if (_servicesConfiguration.Services.Includes != null) { foreach (ServiceInclude include in _servicesConfiguration.Services.Includes) { ServiceDefinition serviceDefinition = include.ServiceDefinition; Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(serviceDefinition.Class));//current assembly only if (type != null) { IService service = ObjectFactory.CreateInstance(type, new object[] { _messageBroker, serviceDefinition }) as IService; if (service != null) _messageBroker.AddService(service); } else log.Error(__Res.GetString(__Res.Type_InitError, serviceDefinition.Class)); } } if (_servicesConfiguration.Security != null) { if (_servicesConfiguration.Security.LoginCommands != null && _servicesConfiguration.Security.LoginCommands.Length > 0) { LoginCommand loginCommand = _servicesConfiguration.Security.GetLoginCommand(LoginCommand.FluorineLoginCommand); if (loginCommand != null) { Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(loginCommand.Class)); if (type != null) { ILoginCommand loginCommandObj = ObjectFactory.CreateInstance(type, new object[] { }) as ILoginCommand; _messageBroker.LoginManager.LoginCommand = loginCommandObj; _messageBroker.LoginManager.IsPerClientAuthentication = loginCommand.IsPerClientAuthentication; } else log.Error(__Res.GetString(__Res.Type_InitError, loginCommand.Class)); } else log.Error(__Res.GetString(__Res.Type_InitError, "<<LoginCommand class>>")); } } InitAuthenticationService(); try { if (FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings != null && FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.Enable) { IResource resource; if (FluorineContext.Current != null) resource = FluorineContext.Current.GetResource(FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.PolicyFile); else resource = new FileSystemResource(FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.PolicyFile); if (resource.Exists) { log.Info(__Res.GetString(__Res.Silverlight_StartPS, resource.File.FullName)); _policyServer = new PolicyServer(resource.File.FullName); } else throw new FileNotFoundException("Policy file not found", FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.PolicyFile); } } catch (Exception ex) { log.Error(__Res.GetString(__Res.Silverlight_PSError), ex); } }
public RtmptServer(RtmptEndpoint endpoint) { _connections = new SynchronizedHashtable(); _endpoint = endpoint; _rtmpHandler = new RtmpHandler(endpoint); }