コード例 #1
0
		/// <summary>
		/// Start the message broker.
		/// </summary>
		public void Start()
		{
			RegisterMessageBroker();

            //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.
            _globalScope = new GlobalScope();
            _globalScope.Name = "default";
            ScopeResolver scopeResolver = new ScopeResolver(_globalScope);
            FluorineFx.Messaging.Api.IClientRegistry clientRegistry = _clientManager;
            ServiceInvoker serviceInvoker = new ServiceInvoker();
            ScopeContext context = new ScopeContext("/", clientRegistry, scopeResolver, serviceInvoker, null);
            CoreHandler handler = new CoreHandler();
            _globalScope.Context = context;
            _globalScope.Handler = handler;
            _globalScope.Register();

			StartServices();
			StartEndpoints();
		}
コード例 #2
0
ファイル: RtmpEndpoint.cs プロジェクト: Boreeas/LoLNotes
		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);
			}
		}