Exemple #1
0
        /// <summary>
        /// 获取委托服务
        /// </summary>
        /// <returns>委托服务实例</returns>
        private DelegateServiceBase GetDelegateService()
        {
            if (_delegateService == null)
            {
                int?   fromActivityInstanceID = null;
                string fromActivityGUID       = string.Empty;
                string fromActivityName       = string.Empty;
                if (IsNotNodeMediatorStart(this) == true)
                {
                    fromActivityInstanceID = ActivityForwardContext.FromActivityInstance.ID;
                    fromActivityGUID       = ActivityForwardContext.FromActivityInstance.ActivityGUID;
                    fromActivityName       = ActivityForwardContext.FromActivityInstance.ActivityName;
                }

                var delegateContext = new DelegateContext
                {
                    AppInstanceID     = ActivityForwardContext.ProcessInstance.AppInstanceID,
                    ProcessGUID       = ActivityForwardContext.ProcessInstance.ProcessGUID,
                    ProcessInstanceID = ActivityForwardContext.ProcessInstance.ID,
                    ActivityGUID      = fromActivityGUID,
                    ActivityName      = fromActivityName
                };
                _delegateService = DelegateServiceFactory.CreateDelegateService(DelegateScopeTypeEnum.Activity,
                                                                                this.Session,
                                                                                delegateContext);
            }
            return(_delegateService);
        }
Exemple #2
0
        static DelegateServiceFactory GetDelegateServiceFactory()
        {
            var services = new DelegateServiceFactory();

            services.Register <IEchoService>(() => new EchoService());
            return(services);
        }
Exemple #3
0
        const string SslCertificateThumbprint = "6E5C6492129B75A4C83E1A23797AF6344092E5C2"; // For WebSockets. This is different to the internally configured thumbprint
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.ColoredConsole()
                         .MinimumLevel.Warning()
                         .CreateLogger();

            Console.Title = "Halibut Server";
            var certificate = new X509Certificate2("HalibutServer.pfx");

            var endPoint = new IPEndPoint(IPAddress.IPv6Any, 8433);

            var services = new DelegateServiceFactory();

            services.Register <ICalculatorService>(() => new CalculatorService());

            using (var server = new HalibutRuntime(services, certificate))
            {
                //Although this is the "Server" because it is the thing handling a request
                //in Octopus terms, this would be the Tentacle, being asked to do some work

                //Begin Listening Setup
                //server.Listen(endPoint);
                //server.Trust("2074529C99D93D5955FEECA859AEAC6092741205");
                //End Listening Setup

                //Begin Polling Setup
                //server.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:8433"), "2074529C99D93D5955FEECA859AEAC6092741205"));
                //End Polling Setup

                //Begin WebSocket Polling Setup

                server.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("wss://localhost:8433/Halibut"), SslCertificateThumbprint));
                //End WebSocket Polling Setup

                Console.WriteLine("Server listening on port 8433. Type 'exit' to quit, or 'cls' to clear...");
                while (true)
                {
                    var line = Console.ReadLine();
                    if (string.Equals("cls", line, StringComparison.OrdinalIgnoreCase))
                    {
                        Console.Clear();
                        continue;
                    }

                    if (string.Equals("q", line, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    if (string.Equals("exit", line, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    Console.WriteLine("Unknown command. Enter 'q' to quit.");
                }
            }
        }
Exemple #4
0
        public OctopusForm()
        {
            InitializeComponent();

            log = new Logger(logBox);
            var services = new DelegateServiceFactory();
            serverHalibutRuntime = new HalibutRuntime(services, new X509Certificate2("OctopusServer.pfx"));
        }
Exemple #5
0
        public OctopusForm()
        {
            InitializeComponent();

            log = new Logger(logBox);
            var services = new DelegateServiceFactory();

            serverHalibutRuntime = new HalibutRuntime(services, new X509Certificate2("OctopusServer.pfx"));
        }
Exemple #6
0
        static int RunServer()
        {
            var services = new DelegateServiceFactory();
            services.Register<ICalculatorService>(() => new CalculatorService());

            var server = new HalibutRuntime(services, ServerCertificate);
            server.Trust("2074529C99D93D5955FEECA859AEAC6092741205");
            var port = server.Listen();
            return port;
        }
Exemple #7
0
        public void StartServer()
        {
            var services = new DelegateServiceFactory();

            services.Register <ITestService>(() => new TestService());
            var DaServer = new HalibutRuntime(services, Configuration.ServerCertificate);

            DaServer.Listen(1337);
            DaServer.Trust(Configuration.ClientCertificate.Thumbprint);
        }
Exemple #8
0
        public TentacleForm()
        {
            InitializeComponent();

            log = new Logger(textBox1);

            var tentacleServices = new DelegateServiceFactory();
            tentacleServices.Register<IHealthCheckService>(() => new HealthCheck(log));

            tentacleHalibutRuntime = new HalibutRuntime(tentacleServices, new X509Certificate2("OctopusTentacle.pfx"));
        }
 public void SetUp()
 {
     var services = new DelegateServiceFactory();
     services.Register<IEchoService>(() => new EchoService());
     tentacle = new HalibutRuntime(services, Certificates.TentacleListening);
     var tentaclePort = tentacle.Listen();
     tentacle.Trust(Certificates.OctopusPublicThumbprint);
     endpoint = new ServiceEndPoint("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);
     log = new InMemoryConnectionLog(endpoint.ToString());
     HalibutLimits.ConnectionErrorRetryTimeout = TimeSpan.MaxValue;
 }
Exemple #10
0
        private string TestMethod(string payload)
        {
            var container = new ServiceContainer();
            var factory   = new DelegateServiceFactory(c => { return(new HappyPathService()); }, _ => { return; });

            container.AddEndpoint(new Endpoint("Happy", typeof(IHappyPath), factory));

            using (var host = new HttpListenerHost(string.Format(happyPathURI, port), container))
            {
                return(Execute(payload));
            }
        }
Exemple #11
0
        public TentacleForm()
        {
            InitializeComponent();

            log = new Logger(textBox1);

            var tentacleServices = new DelegateServiceFactory();

            tentacleServices.Register <IHealthCheckService>(() => new HealthCheck(log));

            tentacleHalibutRuntime = new HalibutRuntime(tentacleServices, new X509Certificate2("OctopusTentacle.pfx"));
        }
Exemple #12
0
        static int RunServer()
        {
            var services = new DelegateServiceFactory();

            services.Register <ICalculatorService>(() => new CalculatorService());

            var server = new HalibutRuntime(services, ServerCertificate);

            server.Trust("2074529C99D93D5955FEECA859AEAC6092741205");
            var port = server.Listen();

            return(port);
        }
        public SecureClientFixture()
        {
            var services = new DelegateServiceFactory();

            services.Register <IEchoService>(() => new EchoService());
            tentacle = new HalibutRuntime(services, Certificates.TentacleListening);
            var tentaclePort = tentacle.Listen();

            tentacle.Trust(Certificates.OctopusPublicThumbprint);
            endpoint = new ServiceEndPoint("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint);
            log      = new InMemoryConnectionLog(endpoint.ToString());
            HalibutLimits.ConnectionErrorRetryTimeout = TimeSpan.MaxValue;
        }
Exemple #14
0
        public void SetUp()
        {
            var services = new DelegateServiceFactory();

            services.Register <IEchoService>(() => new EchoService());
            tentacle = new HalibutRuntime(services, Certificates.TentacleListening);
            var tentaclePort = tentacle.Listen();

            tentacle.Trust(Certificates.OctopusPublicThumbprint);
            endpoint = new ServiceEndPoint("https://localhost:" + tentaclePort, Certificates.TentacleListeningPublicThumbprint)
            {
                ConnectionErrorRetryTimeout = TimeSpan.MaxValue
            };
        }
Exemple #15
0
        public void CanCallWithProxy()
        {
            var container = new ServiceContainer();
            var factory   = new DelegateServiceFactory(c => { return(new HappyPathService()); }, _ => { return; });

            container.AddEndpoint(new Endpoint("Happy", typeof(IHappyPath), factory));

            using (var host = new HttpListenerHost(string.Format(happyPathURI, port), container))
            {
                var client = new Client <IHappyPath>(string.Format(happyPathURI, port) + "Happy");
                var result = client.Proxy().Complex(new Complex {
                    Data = "hej", Value = 6004
                });
                result.Value.ShouldEqual(12008);
                result.Data.ShouldEqual("hej6004");
            }
        }
Exemple #16
0
        static HalibutRuntime RunServer(X509Certificate2 serverCertificate, out int port)
        {
            var services = new DelegateServiceFactory();

            services.Register <ICalculatorService>(() => new CalculatorService());

            var server = new HalibutRuntime(services, serverCertificate);

            //set up listening
            server.Trust(Certificates.TentacleListeningPublicThumbprint);
            port = server.Listen();

            //setup polling websocket
            AddSslCertToLocalStoreAndRegisterFor("0.0.0.0:8434");

            return(server);
        }
Exemple #17
0
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.ColoredConsole()
                         .CreateLogger();

            Console.Title = "Halibut Server";
            var certificate = new X509Certificate2("HalibutServer.pfx");

            var endPoint = new IPEndPoint(IPAddress.IPv6Any, 8433);

            var services = new DelegateServiceFactory();

            services.Register <ICalculatorService>(() => new CalculatorService());

            using (var server = new HalibutRuntime(services, certificate))
            {
                server.Listen(endPoint);
                server.Trust("2074529C99D93D5955FEECA859AEAC6092741205");

                Console.WriteLine("Server listening on port 8433. Type 'exit' to quit, or 'cls' to clear...");

                while (true)
                {
                    var line = Console.ReadLine();
                    if (string.Equals("cls", line, StringComparison.OrdinalIgnoreCase))
                    {
                        Console.Clear();
                        continue;
                    }

                    if (string.Equals("q", line, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    if (string.Equals("exit", line, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    Console.WriteLine("Unknown command. Enter 'q' to quit.");
                }
            }
        }
Exemple #18
0
        /// <summary>
        /// 获取委托服务
        /// </summary>
        /// <returns>委托服务类</returns>
        private DelegateServiceBase GetDelegateService()
        {
            //执行Action列表
            var delegateContext = new DelegateContext
            {
                AppInstanceID     = ActivityForwardContext.ProcessInstance.AppInstanceID,
                ProcessGUID       = ActivityForwardContext.ProcessInstance.ProcessGUID,
                ProcessInstanceID = ActivityForwardContext.ProcessInstance.ID,
                ActivityGUID      = ActivityForwardContext.FromActivityInstance.ActivityGUID,
                ActivityName      = ActivityForwardContext.FromActivityInstance.ActivityName
            };

            var delegateService = DelegateServiceFactory.CreateDelegateService(DelegateScopeTypeEnum.Activity,
                                                                               this.Session,
                                                                               delegateContext);

            return(delegateService);
        }
Exemple #19
0
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.ColoredConsole()
                         .MinimumLevel.Warning()
                         .CreateLogger();
            Console.Title = "Halibut Server";
            var certificate = new X509Certificate2("HalibutServer.pfx");

            var endPoint = new IPEndPoint(IPAddress.IPv6Any, 8433);

            var services = new DelegateServiceFactory();

            services.Register <IUserService>(() => new UserService());

            using (var server = new HalibutRuntime(services, certificate))
            {
                server.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("wss://localhost:8433/Halibut"), SslCertificateThumbprint));
                Console.WriteLine("Server listening on port 8433. Type 'exit' to quit, or 'cls' to clear...");
                while (true)
                {
                    var line = Console.ReadLine();
                    if (string.Equals("cls", line, StringComparison.OrdinalIgnoreCase))
                    {
                        Console.Clear();
                        continue;
                    }

                    if (string.Equals("q", line, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    if (string.Equals("exit", line, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    Console.WriteLine("Unknown command. Enter 'q' to quit.");
                }
            }
        }
Exemple #20
0
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .WriteTo.ColoredConsole()
                .CreateLogger();

            Console.Title = "Halibut Server";
            var certificate = new X509Certificate2("HalibutServer.pfx");

            var endPoint = new IPEndPoint(IPAddress.IPv6Any, 8433);

            var services = new DelegateServiceFactory();
            services.Register<ICalculatorService>(() => new CalculatorService());

            using (var server = new HalibutRuntime(services, certificate))
            {
                server.Listen(endPoint);
                server.Trust("2074529C99D93D5955FEECA859AEAC6092741205");

                Console.WriteLine("Server listening on port 8433. Type 'exit' to quit, or 'cls' to clear...");

                while (true)
                {
                    var line = Console.ReadLine();
                    if (string.Equals("cls", line, StringComparison.OrdinalIgnoreCase))
                    {
                        Console.Clear();
                        continue;
                    }

                    if (string.Equals("q", line, StringComparison.OrdinalIgnoreCase))
                        return;

                    if (string.Equals("exit", line, StringComparison.OrdinalIgnoreCase))
                        return;

                    Console.WriteLine("Unknown command. Enter 'q' to quit.");
                }
            }
        }
        /// <summary>
        /// 执行方法
        /// </summary>
        internal override void ExecuteWorkItem()
        {
            try
            {
                //执行Action列表
                var delegateContext = new DelegateContext
                {
                    AppInstanceID     = ActivityForwardContext.ProcessInstance.AppInstanceID,
                    ProcessGUID       = ActivityForwardContext.ProcessInstance.ProcessGUID,
                    ProcessInstanceID = ActivityForwardContext.ProcessInstance.ID,
                    ActivityGUID      = ActivityForwardContext.FromActivityInstance.ActivityGUID,
                    ActivityName      = ActivityForwardContext.FromActivityInstance.ActivityName
                };

                var delegateService = DelegateServiceFactory.CreateDelegateService(DelegateScopeTypeEnum.Activity,
                                                                                   this.Session,
                                                                                   delegateContext);
                ExecteActionList(base.EventActivity.ActionList, delegateService as IDelegateService);
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
Exemple #22
0
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.ColoredConsole()
                         .CreateLogger();

            var services = new DelegateServiceFactory();

            services.Register <ICalculatorService>(() => new CalculatorService());

            using (var client = new HalibutRuntime(services, ClientCertificate))
                using (var server = new HalibutRuntime(services, ServerCertificate))
                {
                    var octopusPort = client.Listen();
                    client.Trust(ServerCertificate.Thumbprint);

                    server.Poll(new Uri(PollUrl), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), ClientCertificate.Thumbprint));

                    var calculator = client.CreateClient <ICalculatorService>(PollUrl, ServerCertificate.Thumbprint);
                    var result     = calculator.Add(12, 18);
                    Debug.Assert(result == 30);
                }
            Console.ReadKey();
        }
 public void SetUp()
 {
     services = new DelegateServiceFactory();
     services.Register<IEchoService>(() => new EchoService());
 }
Exemple #24
0
        public void Start()
        {
            if (!Directory.Exists(SourcesPath))
            {
                Log.Fatal("{@SourcesPath} doesn't exist; service has nothing to do without sources", SourcesPath);
                Stop();
                return;
            }

            if (!Directory.Exists(SinksPath))
            {
                Log.Warning("{@SinksPath} doesn't exist; service has nothing to do without sinks", SinksPath);
            }

            _childDevices.CollectionChanged += (sender, args) =>
            {
                switch (args.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    foreach (IDualShockDevice item in args.NewItems)
                    {
                        Log.Information("Device {Device} got attached via {ConnectionType}", item,
                                        item.ConnectionType);
                        foreach (var plugin in SinkPlugins.Select(p => p.Value))
                        {
                            plugin.DeviceArrived(item);
                        }
                    }

                    break;

                case NotifyCollectionChangedAction.Remove:
                    foreach (IDualShockDevice item in args.OldItems)
                    {
                        Log.Information("Device {Device} got removed via {ConnectionType}", item,
                                        item.ConnectionType);
                        foreach (var plugin in SinkPlugins.Select(p => p.Value))
                        {
                            plugin.DeviceRemoved(item);
                        }
                    }

                    break;
                }
            };

            #region MEF

            //Creating an instance of aggregate catalog. It aggregates other catalogs
            var aggregateCatalog = new AggregateCatalog();

            //Load parts from the current assembly if available
            var asmCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            //Add to the aggregate catalog
            aggregateCatalog.Catalogs.Add(new DirectoryCatalog(SourcesPath, "*.dll"));
            aggregateCatalog.Catalogs.Add(new DirectoryCatalog(SinksPath, "*.dll"));
            aggregateCatalog.Catalogs.Add(asmCatalog);

            //Crete the composition container
            var container = new CompositionContainer(aggregateCatalog);

            // Composable parts are created here i.e.
            // the Import and Export components assembles here
            container.ComposeParts(this);

            #endregion

            // Log loaded sink plugins
            foreach (var plugin in SinkPlugins)
            {
                Log.Information("Loaded sink plugin {Plugin}", plugin.Metadata["Name"]);

                plugin.Value.RumbleRequestReceived += (sender, args) =>
                                                      _childDevices[(IDualShockDevice)sender].Rumble(args.LargeMotor, args.SmallMotor);
            }

            // Log and enable sources
            foreach (var emulator in BusEmulators)
            {
                Log.Information("Loaded bus emulator {Emulator}", emulator.Metadata["Name"]);

                emulator.Value.ChildDeviceAttached += (sender, args) => _childDevices.Add(args.Device);
                emulator.Value.ChildDeviceRemoved  += (sender, args) => _childDevices.Remove(args.Device);
                emulator.Value.InputReportReceived += EmulatorOnInputReportReceived;

                try
                {
                    Log.Information("Starting bus emulator {Emulator}", emulator.Metadata["Name"]);
                    emulator.Value.Start();
                    Log.Information("Bus emulator {Emulator} started successfully", emulator.Metadata["Name"]);
                }
                catch (Exception ex)
                {
                    Log.Error("Failed to start {@emulator}: {@ex}", emulator.Metadata["Name"], ex);
                }
            }

            #region IPC

            var services = new DelegateServiceFactory();
            services.Register <IPairingService>(() =>
            {
                var service = new PairingService();

                service.DeviceListRequested += (sender, args) => _childDevices
                                               .Where(d => d.ConnectionType.Equals(DualShockConnectionType.USB))
                                               .Select(d => new DualShockDeviceDescriptor
                {
                    ClientAddress  = new UniqueAddress(d.ClientAddress),
                    ConnectionType = d.ConnectionType,
                    DeviceType     = d.DeviceType,
                    HostAddress    = new UniqueAddress(d.HostAddress)
                }).ToList();

                service.DevicePairingRequested += (device, args) =>
                                                  _childDevices[device.ClientAddress].PairTo(new PhysicalAddress(args.HostAddress.AddressBytes));

                return(service);
            });

            _ipcServer = new HalibutRuntime(services, Configuration.ServerCertificate);
            _ipcServer.Listen(Configuration.ServerEndpoint);
            _ipcServer.Trust(Configuration.ClientCertificate.Thumbprint);

            #endregion
        }
Exemple #25
0
        public void Start()
        {
            if (!Directory.Exists(SourcesPath))
            {
                Log.Fatal("{@SourcesPath} doesn't exist; service has nothing to do without sources", SourcesPath);
                Stop();
                return;
            }

            if (!Directory.Exists(SinksPath))
            {
                Log.Warning("{@SinksPath} doesn't exist; service has nothing to do without sinks", SinksPath);
            }

            _childDevices.CollectionChanged += (sender, args) =>
            {
                switch (args.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    foreach (IDualShockDevice item in args.NewItems)
                    {
                        Log.Information("Device {Device} got attached via {ConnectionType}", item,
                                        item.ConnectionType);

                        // Crude auto-pairing mechanism in case BthPS3 is present
                        if (item.ConnectionType.Equals(DualShockConnectionType.USB) &&
                            BusEmulators.Select(be => be.Value).Any(b => b.Name == "BthPS3BusEmulator") &&
                            BluetoothAdapter.GetDefault() != null)
                        {
                            // Check if newly connected USB device is already connected via Bluetooth
                            if (item.ConnectionType.Equals(DualShockConnectionType.USB))
                            {
                                var emulator = BusEmulators.Select(be => be.Value).Where(b => b.Name == "BthPS3BusEmulator").First();

                                foreach (var otherItem in _childDevices)
                                {
                                    if (otherItem.ConnectionType.Equals(DualShockConnectionType.Bluetooth))
                                    {
                                        if (otherItem.ClientAddress.Equals(item.ClientAddress))     // If found remove bluetooth device
                                        {
                                            emulator.RemoveDevice(otherItem);
                                            break;
                                        }
                                    }
                                }
                            }

                            // Get address of detected primary radio
                            var hostAddress = new PhysicalAddress(BitConverter
                                                                  .GetBytes(BluetoothAdapter.GetDefault().BluetoothAddress).Take(6).Reverse()
                                                                  .ToArray());

                            if (!item.HostAddress.Equals(hostAddress))
                            {
                                Log.Information("Auto-pairing device {Device} to {HostAddress}",
                                                item, hostAddress.AsFriendlyName());

                                // Pair USB device
                                item.PairTo(hostAddress);
                            }
                            else
                            {
                                Log.Information("Device {Device} already paired to this radio {HostAddress}.", item, hostAddress.AsFriendlyName());
                            }
                        }
                        else
                        {
                            Log.Warning("Auto-pairing not supported as BthPS3 and/or Bluetooth Host Radio not found");
                        }

                        foreach (var plugin in SinkPlugins.Where(p => p.Value.IsEnabled).Select(p => p.Value))
                        {
                            plugin.DeviceArrived(item);
                        }
                    }

                    break;

                case NotifyCollectionChangedAction.Remove:
                    foreach (IDualShockDevice item in args.OldItems)
                    {
                        Log.Information("Device {Device} got removed via {ConnectionType}", item,
                                        item.ConnectionType);
                        foreach (var plugin in SinkPlugins.Where(p => p.Value.IsEnabled).Select(p => p.Value))
                        {
                            plugin.DeviceRemoved(item);
                        }
                    }

                    break;
                }

                UpdateLEDS();
            };

            #region MEF

            //Creating an instance of aggregate catalog. It aggregates other catalogs
            var aggregateCatalog = new AggregateCatalog();

            //Load parts from the current assembly if available
            var asmCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            //Add to the aggregate catalog
            aggregateCatalog.Catalogs.Add(new DirectoryCatalog(SourcesPath, "*.dll"));
            aggregateCatalog.Catalogs.Add(new DirectoryCatalog(SinksPath, "*.dll"));
            aggregateCatalog.Catalogs.Add(asmCatalog);

            //Crete the composition container
            var container = new CompositionContainer(aggregateCatalog);

            // Composable parts are created here i.e.
            // the Import and Export components assembles here
            container.ComposeParts(this);

            #endregion

            // Log loaded sink plugins
            foreach (var plugin in SinkPlugins.Where(p => p.Value.IsEnabled))
            {
                Log.Information("Loaded sink plugin {Plugin}", plugin.Metadata["Name"]);

                plugin.Value.RumbleRequestReceived += (sender, args) =>
                                                      _childDevices[(IDualShockDevice)sender].Rumble(args.LargeMotor, args.SmallMotor);
            }

            // Log and enable sources
            foreach (var emulator in BusEmulators.Where(p => p.Value.IsEnabled))
            {
                Log.Information("Loaded bus emulator {Emulator}", emulator.Metadata["Name"]);

                emulator.Value.ChildDeviceAttached += (sender, args) => _childDevices.Add(args.Device);
                emulator.Value.ChildDeviceRemoved  += (sender, args) => _childDevices.Remove(args.Device);
                emulator.Value.InputReportReceived += EmulatorOnInputReportReceived;

                try
                {
                    Log.Information("Starting bus emulator {Emulator}", emulator.Metadata["Name"]);
                    emulator.Value.Start();
                    Log.Information("Bus emulator {Emulator} started successfully", emulator.Metadata["Name"]);
                }
                catch (Exception ex)
                {
                    Log.Error("Failed to start {@emulator}: {@ex}", emulator.Metadata["Name"], ex);
                }
            }

            #region IPC

            if (Config.Global.Core.Halibut.IsEnabled)
            {
                var services = new DelegateServiceFactory();
                services.Register <IPairingService>(() =>
                {
                    var service = new PairingService();

                    service.DeviceListRequested += (sender, args) => _childDevices
                                                   .Where(d => d.ConnectionType.Equals(DualShockConnectionType.USB))
                                                   .Select(d => new DualShockDeviceDescriptor
                    {
                        ClientAddress  = new UniqueAddress(d.ClientAddress),
                        ConnectionType = d.ConnectionType,
                        DeviceType     = d.DeviceType,
                        HostAddress    = new UniqueAddress(d.HostAddress)
                    }).ToList();

                    service.DevicePairingRequested += (device, args) =>
                                                      _childDevices[device.ClientAddress].PairTo(new PhysicalAddress(args.HostAddress.AddressBytes));

                    return(service);
                });

                _ipcServer = new HalibutRuntime(services, Configuration.ServerCertificate);
                _ipcServer.Listen(Configuration.ServerEndpoint);
                _ipcServer.Trust(Configuration.ClientCertificate.Thumbprint);
            }

            #endregion

            Task.Factory.StartNew(PollBatteryLevel, _inputCancellationTokenSource.Token);
        }
Exemple #26
0
 public UsageFixture()
 {
     services = new DelegateServiceFactory();
     services.Register <IEchoService>(() => new EchoService());
 }
Exemple #27
0
 public void SetUp()
 {
     services = new DelegateServiceFactory();
     services.Register <IEchoService>(() => new EchoService());
 }
Exemple #28
0
 public FailureModesFixture()
 {
     services = new DelegateServiceFactory();
     services.Register <IEchoService>(() => new EchoService());
 }