Exemplo n.º 1
0
        private static int RunServiceHost()
        {
            Console.WriteLine(Environment.CommandLine);

            AppServiceOptions serviceOptions = null;

            var topshelfHost = HostFactory.New(config => { CreateHost(config, out serviceOptions); });

            // Инициализация окружения для приложения

            if (!string.IsNullOrWhiteSpace(serviceOptions.StartOptions) &&
                serviceOptions.StartOptions.IndexOf("init", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                var initAppServiceHost = new AppServiceHost();
                initAppServiceHost.Init(TimeSpan.FromSeconds(10));
            }

            // Запуск службы приложения

            if (string.IsNullOrWhiteSpace(serviceOptions.StartOptions) ||
                serviceOptions.StartOptions.IndexOf("start", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                var topshelfExitCode = topshelfHost.Run();
                return(topshelfExitCode == TopshelfExitCode.Ok
                           ? (int)TopshelfExitCode.Ok
                           : (int)topshelfExitCode);
            }

            return((int)TopshelfExitCode.Ok);
        }
Exemplo n.º 2
0
        private static int RunServiceHost()
        {
            Console.WriteLine(Environment.CommandLine);

            AppServiceOptions serviceOptions = null;

            var topshelfHost = HostFactory.New(config => { CreateHost(config, out serviceOptions); });
            
            // Инициализация окружения для приложения

            if (serviceOptions.StartOptions.IndexOf("init", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                var initAppServiceHost = new AppServiceHost();
                initAppServiceHost.Init(TimeSpan.FromSeconds(10));
            }

            // Запуск службы приложения

            if (string.IsNullOrWhiteSpace(serviceOptions.StartOptions) ||
                serviceOptions.StartOptions.IndexOf("start", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                var topshelfExitCode = topshelfHost.Run();
                return topshelfExitCode == TopshelfExitCode.Ok
                           ? (int)TopshelfExitCode.Ok
                           : (int)topshelfExitCode;
            }

            return (int)TopshelfExitCode.Ok;
        }
Exemplo n.º 3
0
        private void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            DeviceSettings settings = DeviceSettings.Instance;

            _host = new AppServiceHost(settings.ServerPrefix, settings.ServiceRootPath, settings.ServiceActionRootPath, settings.ServiceCredentials);
            DisplayIpAddress();
            _host.Init();
            _initialized = true;
        }
Exemplo n.º 4
0
        private bool Initialize()
        {
            if (!_initialized)
            {
                try
                {
                    // initialize PiCar
                    _piCar = PiCarClientFactory.CreatePiCar(_controlTopic.Server, _controlTopic.Credential);
                    if (_piCar != null)
                    {
                        _piCar.Initialize(_controlTopic.ServerAddress, _controlTopic.VideoPort);
                        _cameraHorizontalServo = new ServoStat {
                            Servo = _piCar.HeadHorizontalServo
                        };
                        _cameraVertialServo = new ServoStat {
                            Servo = _piCar.HeadVerticalServo
                        };
                        _rightLed = new LedState {
                            Led = _piCar.RightLed
                        };
                        _leftLed = new LedState {
                            Led = _piCar.LeftLed
                        };
                        // initialize AppServiceHost
                        DeviceSettings settings = DeviceSettings.Instance;
                        _host = new AppServiceHost(settings.ServerPrefix, settings.ServiceRootPath, settings.ServiceActionRootPath, settings.ServiceCredentials);
                        _host.Init();

                        _initialized = true;
                    }
                }
                catch (Exception err)
                {
                    responseLabel.Text = "Failed to initialize PiCar \n" + err.ToString();
                }
            }
            if (_initialized)
            {
                CommandButton.IsEnabled      = true;
                GpioButton.IsEnabled         = true;
                ServiceOnOffButton.IsEnabled = true;
            }
            else
            {
                CommandButton.IsEnabled      = false;
                GpioButton.IsEnabled         = false;
                ServiceOnOffButton.IsEnabled = false;
            }
            return(_initialized);
        }