Пример #1
0
 public FactoryInstance GetFactoryInstance()
 {
     if (this._factoryInstance == null)
     {
         IFlexFactory factory    = this.Service.GetMessageBroker().GetFactory(this.FactoryId);
         Hashtable    properties = this._settings.Properties;
         this._factoryInstance = factory.CreateFactoryInstance(this.Id, properties);
     }
     return(this._factoryInstance);
 }
Пример #2
0
        /// <summary>
        /// Returns the FactoryInstance used by the Destination to create object instances.
        /// </summary>
        /// <returns></returns>
        public FactoryInstance GetFactoryInstance()
        {
            if (_factoryInstance != null)
            {
                return(_factoryInstance);
            }

            MessageBroker messageBroker = this.Service.GetMessageBroker();
            IFlexFactory  factory       = messageBroker.GetFactory(this.FactoryId);

            _factoryInstance = factory.CreateFactoryInstance(this.Id, _destinationDefinition.Properties);
            return(_factoryInstance);
        }
Пример #3
0
        /// <summary>
        /// Returns the FactoryInstance used by the Destination to create object instances.
        /// </summary>
        /// <returns></returns>
        public FactoryInstance GetFactoryInstance()
        {
            if (_factoryInstance != null)
            {
                return(_factoryInstance);
            }

            MessageBroker messageBroker = this.Service.GetMessageBroker();
            IFlexFactory  factory       = messageBroker.GetFactory(this.FactoryId);
            Hashtable     properties    = _settings.Properties;

            _factoryInstance = factory.CreateFactoryInstance(this.Id, properties);
            return(_factoryInstance);
        }
Пример #4
0
        /// <summary>
        /// This method supports the AMFCore infrastructure and is not intended to be used directly from your code.
        /// </summary>
        public void Init()
        {
            _messageBroker = new MessageBroker(this);

            _serviceConfigSettings = ServiceConfigSettings.Load();
            foreach (ChannelSettings channelSettings in _serviceConfigSettings.ChannelsSettings)
            {
                Type type = ObjectFactory.Locate(channelSettings.Class);
                if (type != null)
                {
                    IEndpoint endpoint = ObjectFactory.CreateInstance(type, new object[] { _messageBroker, channelSettings }) as IEndpoint;
                    if (endpoint != null)
                    {
                        _messageBroker.AddEndpoint(endpoint);
                    }
                }
            }
            foreach (FactorySettings factorySettings in _serviceConfigSettings.FactoriesSettings)
            {
                Type type = ObjectFactory.Locate(factorySettings.ClassId);
                if (type != null)
                {
                    IFlexFactory flexFactory = ObjectFactory.CreateInstance(type, new object[0]) as IFlexFactory;
                    if (flexFactory != null)
                    {
                        _messageBroker.AddFactory(factorySettings.Id, flexFactory);
                    }
                }
            }
            //Add the dotnet Factory
            _messageBroker.AddFactory("dotnet", new DotNetFactory());

            foreach (ServiceSettings serviceSettings in _serviceConfigSettings.ServiceSettings)
            {
                Type type = ObjectFactory.Locate(serviceSettings.Class);//current assembly only
                if (type != null)
                {
                    IService service = ObjectFactory.CreateInstance(type, new object[] { _messageBroker, serviceSettings }) as IService;
                    if (service != null)
                    {
                        _messageBroker.AddService(service);
                    }
                }
            }
        }
Пример #5
0
		/// <summary>
        /// Initializes a new instance of the FactoryInstance class.
		/// </summary>
		/// <param name="factory">The IFlexFactory this FactoryInstance is created from.</param>
		/// <param name="id">The Destination's id.</param>
		/// <param name="properties">The configuration properties for this destination.</param>
        public FactoryInstance(IFlexFactory factory, string id, DestinationProperties properties)
		{
			_factory = factory;
			_id = id;
			_properties = properties;
		}
Пример #6
0
 internal void AddFactory(string id, IFlexFactory factory)
 {
     this._factories.Add(id, factory);
 }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the DotNetFactoryInstance class.
 /// </summary>
 /// <param name="flexFactory">The IFlexFactory this FactoryInstance is created from.</param>
 /// <param name="id">The Destination identity.</param>
 /// <param name="properties">The configuration properties for this destination.</param>
 public DotNetFactoryInstance(IFlexFactory flexFactory, string id, DestinationProperties properties)
     : base(flexFactory, id, properties)
 {
 }
Пример #8
0
        /// <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);
            }
        }
Пример #9
0
		internal void AddFactory(string id, IFlexFactory factory)
		{
			_factories.Add(id, factory);
		}
Пример #10
0
        public override void Start()
        {
            try
            {
                if (log.IsInfoEnabled)
                {
                    log.Info(__Res.GetString(__Res.RtmpEndpoint_Start));
                }

                //Each Application has its own Scope hierarchy and the root scope is WebScope.
                //There's a global scope that aims to provide common resource sharing across Applications namely GlobalScope.
                //The GlobalScope is the parent of all WebScopes.
                //Other scopes in between are all instances of Scope. Each scope takes a name.
                //The GlobalScope is named "default".
                //The WebScope is named per Application context name.
                //The Scope is named per path name.
                IGlobalScope globalScope = GetMessageBroker().GlobalScope;
                string       baseDirectory;
                if (FluorineContext.Current != null)
                {
                    baseDirectory = Path.Combine(FluorineContext.Current.ApplicationBaseDirectory, "apps");
                }
                else
                {
                    baseDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "apps");
                }
                if (Directory.Exists(baseDirectory))
                {
                    foreach (string appDirectory in Directory.GetDirectories(baseDirectory))
                    {
                        DirectoryInfo            directoryInfo = new DirectoryInfo(appDirectory);
                        string                   appName       = directoryInfo.Name;
                        string                   appConfigFile = Path.Combine(appDirectory, "app.config");
                        ApplicationConfiguration configuration = ApplicationConfiguration.Load(appConfigFile);
                        WebScope                 scope         = new WebScope(this, globalScope, configuration);

                        // Create context for the WebScope and initialize
                        ScopeContext scopeContext = new ScopeContext("/" + appName, globalScope.Context.ClientRegistry, globalScope.Context.ScopeResolver, globalScope.Context.ServiceInvoker, null);
                        // Store context in scope
                        scope.Context = scopeContext;
                        // ApplicationAdapter
                        IFlexFactory    factory         = GetMessageBroker().GetFactory(configuration.ApplicationHandler.Factory);
                        FactoryInstance factoryInstance = factory.CreateFactoryInstance(this.Id, null);
                        if (factoryInstance == null)
                        {
                            string msg = string.Format("Missing factory {0}", configuration.ApplicationHandler.Factory);
                            log.Fatal(msg);
                            throw new NotSupportedException(msg);
                        }
                        factoryInstance.Source = configuration.ApplicationHandler.Type;
                        object        applicationHandlerInstance = factoryInstance.Lookup();
                        IScopeHandler scopeHandler = applicationHandlerInstance as IScopeHandler;
                        if (scopeHandler == null)
                        {
                            log.Error(__Res.GetString(__Res.Type_InitError, configuration.ApplicationHandler.Type));
                            throw new TypeInitializationException(configuration.ApplicationHandler.Type, null);
                        }
                        scope.Handler = scopeHandler;
                        // Make available as "/<directoryName>" and allow access from all hosts
                        scope.SetContextPath("/" + appName);
                        // Register WebScope in server
                        scope.Register();
                    }
                }
                _rtmpServer = new RtmpServer(this);

                UriBase uri = this.ChannelDefinition.GetUri();
                if (uri.Protocol == "http" || uri.Protocol == "https")
                {
                    log.Info(string.Format("Rtmp endpoint was not started, specified protocol: {0}", uri.Protocol));
                    return;
                }
                int port = 1935;
                if (uri.Port != null && uri.Port != string.Empty)
                {
                    try
                    {
                        port = System.Convert.ToInt32(uri.Port);
                    }
                    catch (FormatException ex)
                    {
                        log.Error("Invalid port", ex);
                        return;
                    }
                }
                if (log.IsInfoEnabled)
                {
                    log.Info(__Res.GetString(__Res.RtmpEndpoint_Starting, port.ToString()));
                }

                IPEndPoint ipEndPoint;
                if (this.ChannelDefinition.Properties.BindAddress != null)
                {
                    IPAddress ipAddress = IPAddress.Parse(this.ChannelDefinition.Properties.BindAddress);
                    ipEndPoint = new IPEndPoint(ipAddress, port);
                }
                else
                {
                    ipEndPoint = new IPEndPoint(IPAddress.Any, port);
                }
                _rtmpServer.AddListener(ipEndPoint);
                _rtmpServer.OnError += new ErrorHandler(OnError);
                _rtmpServer.Start();

                if (log.IsInfoEnabled)
                {
                    log.Info(__Res.GetString(__Res.RtmpEndpoint_Started));
                }
            }
            catch (Exception ex)
            {
                if (log.IsFatalEnabled)
                {
                    log.Fatal("RtmpEndpoint failed", ex);
                }
            }
        }
Пример #11
0
 /// <summary>
 /// Initializes a new instance of the DotNetFactoryInstance class.
 /// </summary>
 /// <param name="flexFactory"></param>
 /// <param name="id"></param>
 /// <param name="properties"></param>
 public DotNetFactoryInstance(IFlexFactory flexFactory, string id, Hashtable properties)
     : base(flexFactory, id, properties)
 {
 }
Пример #12
0
        public void Init(string configPath, bool serviceBrowserAvailable)
        {
            Type type;

            this._messageBroker         = new FluorineFx.Messaging.MessageBroker(this);
            this._serviceConfigSettings = FluorineFx.Messaging.Config.ServiceConfigSettings.Load(configPath, "services-config.xml");
            foreach (ChannelSettings settings in this._serviceConfigSettings.ChannelsSettings)
            {
                type = ObjectFactory.Locate(settings.Class);
                if (type != null)
                {
                    IEndpoint endpoint = ObjectFactory.CreateInstance(type, new object[] { this._messageBroker, settings }) as IEndpoint;
                    if (endpoint != null)
                    {
                        this._messageBroker.AddEndpoint(endpoint);
                    }
                }
                else
                {
                    log.Error(__Res.GetString("Type_InitError", new object[] { settings.Class }));
                }
                ChannelSettings channelSettings = new ChannelSettings("__@fluorinertmpt", null);
                IEndpoint       endpoint2       = new RtmptEndpoint(this._messageBroker, channelSettings);
                this._messageBroker.AddEndpoint(endpoint2);
            }
            foreach (FactorySettings settings3 in this._serviceConfigSettings.FactoriesSettings)
            {
                type = ObjectFactory.Locate(settings3.ClassId);
                if (type != null)
                {
                    IFlexFactory factory = ObjectFactory.CreateInstance(type, new object[0]) as IFlexFactory;
                    if (factory != null)
                    {
                        this._messageBroker.AddFactory(settings3.Id, factory);
                    }
                }
                else
                {
                    log.Error(__Res.GetString("Type_InitError", new object[] { settings3.ClassId }));
                }
            }
            this._messageBroker.AddFactory("dotnet", new DotNetFactory());
            if (serviceBrowserAvailable && (this._serviceConfigSettings.ServiceSettings["remoting-service"] != null))
            {
                ServiceSettings serviceSettings = this._serviceConfigSettings.ServiceSettings["remoting-service"];
                AdapterSettings adapterSettings = this._serviceConfigSettings.ServiceSettings["remoting-service"].AdapterSettings["dotnet"];
                this.InstallServiceBrowserDestinations(serviceSettings, adapterSettings);
            }
            foreach (ServiceSettings settings6 in this._serviceConfigSettings.ServiceSettings)
            {
                type = ObjectFactory.Locate(settings6.Class);
                if (type != null)
                {
                    IService service = ObjectFactory.CreateInstance(type, new object[] { this._messageBroker, settings6 }) as IService;
                    if (service != null)
                    {
                        this._messageBroker.AddService(service);
                    }
                }
                else
                {
                    log.Error(__Res.GetString("Type_InitError", new object[] { settings6.Class }));
                }
            }
            if ((this._serviceConfigSettings.SecuritySettings != null) && ((this._serviceConfigSettings.SecuritySettings.LoginCommands != null) && (this._serviceConfigSettings.SecuritySettings.LoginCommands.Count > 0)))
            {
                string loginCommand = this._serviceConfigSettings.SecuritySettings.LoginCommands.GetLoginCommand("asp.net");
                type = ObjectFactory.Locate(loginCommand);
                if (type != null)
                {
                    ILoginCommand command = ObjectFactory.CreateInstance(type, new object[0]) as ILoginCommand;
                    this._messageBroker.LoginCommand = command;
                }
                else
                {
                    log.Error(__Res.GetString("Type_InitError", new object[] { loginCommand }));
                }
            }
            this.InitAuthenticationService();
            try
            {
                if ((FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings != null) && FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.Enable)
                {
                    IResource resource = FluorineContext.Current.GetResource(FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.PolicyFile);
                    if (!resource.Exists)
                    {
                        throw new FileNotFoundException("Policy file not found", FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.PolicyFile);
                    }
                    log.Info(__Res.GetString("Silverlight_StartPS", new object[] { resource.File.FullName }));
                    this._policyServer = new PolicyServer(resource.File.FullName);
                }
            }
            catch (Exception exception)
            {
                log.Error(__Res.GetString("Silverlight_PSError"), exception);
            }
        }
Пример #13
0
        /// <summary>
        /// Initializes a new instance of the DotNetFactoryInstance class.
        /// </summary>
        /// <param name="flexFactory">The IFlexFactory this FactoryInstance is created from.</param>
        /// <param name="id">The Destination identity.</param>
        /// <param name="properties">The configuration properties for this destination.</param>
        public DotNetFactoryInstance(IFlexFactory flexFactory, string id, DestinationProperties properties)
            : base(flexFactory, id, properties)
		{
		}
Пример #14
0
 /// <summary>
 /// Initializes a new instance of the FactoryInstance class.
 /// </summary>
 /// <param name="factory">The IFlexFactory this FactoryInstance is created from.</param>
 /// <param name="id">The Destination's id.</param>
 /// <param name="properties">The configuration properties for this destination.</param>
 public FactoryInstance(IFlexFactory factory, string id, DestinationProperties properties)
 {
     _factory    = factory;
     _id         = id;
     _properties = properties;
 }
Пример #15
0
 /// <summary>
 /// Initializes a new instance of the FactoryInstance class.
 /// </summary>
 /// <param name="factory">The IFlexFactory this FactoryInstance is created from.</param>
 /// <param name="id">The Destination's id.</param>
 /// <param name="properties">The configuration properties for this destination.</param>
 public FactoryInstance(IFlexFactory factory, string id, Hashtable properties)
 {
     _factory    = factory;
     _id         = id;
     _properties = properties;
 }