Exemplo n.º 1
0
        public Broker(string metadataDir = null, IRegistryProvider registryProvider = null)
        {
            _workingDir = Directory.GetCurrentDirectory();
            var binDir    = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var studioDir = Path.Combine(binDir, "studio");

            Log.Info("Studio dir: {0}", studioDir);
            metadataDir = Path.GetFullPath(metadataDir ?? Path.Combine(_workingDir, "metadata"));
            Log.Info("Metadata dir: {0}", metadataDir);
            var metadataFile = Path.Combine(metadataDir, "interop.json");

            _transportServers = new[]
            {
                TransportServerFactory.Instance.Create(
                    PipeTransmissionServerFactory.Instance.Create(_workingDir), DefaultTransportSerializationProvider),
                TransportServerFactory.Instance.Create(
                    WebSocketTransmissionServerFactory.Instance.Create(
                        _workingDir,
                        new Dictionary <string, string> {
                    { "/metadata/interop", metadataFile }, { "/studio", studioDir }
                }),
                    DefaultTransportSerializationProvider)
            };
            _connectionListener  = new ServerConnectionListener(_transportServers);
            registryProvider     = registryProvider ?? JsonRegistryProvider.Initialize(Path.Combine(metadataDir, "interop.json"));
            _appLifecycleManager = AppLifecycleManagerFactory.Instance.Create(metadataDir);
            _brokerProcessor     = BrokerProcessorFactory.Instance.Create(
                _connectionListener.In,
                registryProvider,
                DefaultProtocolSerializationProvider,
                _appLifecycleManager);
            OnStop(_connectionListener.Stop);
        }
Exemplo n.º 2
0
        public Broker(BrokerOptions options, IRegistryProvider registryProvider = null)
        {
            _features = EnvironmentHelper.GetBrokerFeatures();
            Log.Info($"Broker features: {_features}");
            var trustedLauncherId = EnvironmentHelper.GetLauncherAppInstanceId();

            Log.Info($"App launcher application instance id: {trustedLauncherId}");
            if (_features.HasFlag(BrokerFeatures.CheckAppInstanceId) && trustedLauncherId == null)
            {
                throw new BrokerException($"{EnvironmentHelper.LauncherId} must be defined if {BrokerFeatures.CheckAppInstanceId} set.");
            }
            _workingDir = Directory.GetCurrentDirectory();
            var binDir    = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var studioDir = Path.Combine(binDir, "studio");

            Log.Info("Studio dir: {0}", studioDir);
            var metadataDir = Path.GetFullPath(options.MetadataDir ?? Path.Combine(_workingDir, "metadata"));

            Log.Info("Metadata dir: {0}", metadataDir);
            var metadataFile = Path.Combine(metadataDir, "interop.json");
            IReadOnlyDictionary <string, string> staticFileMapping = new Dictionary <string, string>
            {
                { "/metadata/interop", metadataFile },
                { "/studio", studioDir }
            };
            var webSocketTransmissionServerOptions = new WebSocketTransmissionServerOptions(_workingDir, options.Port, staticFileMapping);
            var transportServers = new List <ITransportServer>
            {
                TransportServerFactory.Instance.Create(
                    TransportType.Pipe,
                    PipeTransmissionServerFactory.Instance.Create(_workingDir),
                    DefaultTransportSerializationProvider),
                TransportServerFactory.Instance.Create(
                    TransportType.Ws,
                    WebSocketTransmissionServerFactory.Instance.Create(webSocketTransmissionServerOptions),
                    DefaultTransportSerializationProvider),
            };

            if (_features.HasFlag(BrokerFeatures.UseWSS))
            {
                var certificate = GetCertificate();
                if (certificate != null)
                {
                    var wssTransmissionServerOptions = new WebSocketTransmissionServerOptions(_workingDir, options.WssPort, staticFileMapping);
                    var sslProtocols = EnvironmentHelper.GetSslProtocols();
                    Log.Info($"{EnvironmentHelper.SslProtocols}={sslProtocols}");
                    transportServers.Add(TransportServerFactory.Instance.Create(
                                             TransportType.Wss,
                                             WebSocketTransmissionServerFactory.Instance.CreateSecure(wssTransmissionServerOptions, certificate, sslProtocols),
                                             DefaultTransportSerializationProvider));
                }
            }
            _transportServers   = transportServers;
            _connectionListener = new ServerConnectionListener(_transportServers);
            registryProvider    = registryProvider ?? new JsonRegistryProvider(Path.Combine(metadataDir, "interop.json"));
            _interopContext     = InteropContextFactory.Instance.Create(trustedLauncherId ?? default, metadataDir, registryProvider);
            _brokerProcessor    = BrokerProcessorFactory.Instance.Create(
                _connectionListener.In,
                DefaultProtocolSerializationProvider,
                _interopContext,
                _features);
            OnStop(_connectionListener.Stop);
        }