Exemplo n.º 1
0
        /// <inheritdoc />
        /// <summary>
        /// Unlocks the device.
        /// </summary>
        /// <returns>The device.</returns>
        /// <param name="deviceId">Device identifier.</param>
        /// <param name="restClient">Rest client.</param>
        /// <param name="appiumService">Appium service.</param>
        public async Task <Device> UnlockDevice(string deviceId, IRestClient restClient,
                                                IAppiumService appiumService)
        {
            _logger.Debug($"{nameof(UnlockDevice)}: device id [{deviceId}].");

            var device = await restClient.GetDevice(deviceId);

            if (device == null)
            {
                throw new KeyNotFoundException("Failed to find device with id: " + deviceId);
            }

            _logger.Debug(
                $"{nameof(UnlockDevice)}: set device id [{deviceId}] available from [{device.Available}] to true.");
            device.Available = true;

            _logger.Debug($"{nameof(UnlockDevice)}: device id [{deviceId}] stop running Appium");
            if (!await appiumService.StopAppiumForDeviceIdAsync(deviceId))
            {
                return(device);
            }

            device.AppiumEndpoint = "";

            _logger.Debug(
                $"{nameof(UnlockDevice)}: device id [{deviceId}] set status from [{device.Status}] to OFFLINE");
            device.Status = DeviceStatus.Offline;

            var updatedDevice = await restClient.UpdateDevice(device);

            _logger.Debug($"{nameof(UnlockDevice)}: updated device [{JsonConvert.SerializeObject(updatedDevice)}]");
            return(updatedDevice);
        }
Exemplo n.º 2
0
 /// <inheritdoc />
 /// <summary>
 /// Initializes a new instance of the <see cref="T:MobileManager.Controllers.ReservationsAppliedController" /> class.
 /// </summary>
 /// <param name="reservationsAppliedRepository">Reservations applied repository.</param>
 /// <param name="restClient">Rest client.</param>
 /// <param name="appiumService">Appium service.</param>
 /// <param name="logger">Logger.</param>
 /// <param name="externalProcesses"></param>
 public ReservationsAppliedController(IRepository <ReservationApplied> reservationsAppliedRepository,
                                      IRestClient restClient, IAppiumService appiumService, IManagerLogger logger, IExternalProcesses externalProcesses) : base(logger)
 {
     _reservationsAppliedRepository = reservationsAppliedRepository;
     _restClient        = restClient;
     _appiumService     = appiumService;
     _logger            = logger;
     _externalProcesses = externalProcesses;
     _deviceUtils       = new DeviceUtils(_logger, _externalProcesses);
 }
Exemplo n.º 3
0
        /// <inheritdoc />
        /// <summary>
        /// Locks the device.
        /// </summary>
        /// <returns>The device.</returns>
        /// <param name="deviceId">Device identifier.</param>
        /// <param name="restClient">Rest client.</param>
        /// <param name="appiumService">Appium service.</param>
        public async Task <Device> LockDevice(string deviceId, IRestClient restClient,
                                              IAppiumService appiumService)
        {
            _logger.Debug($"{nameof(LockDevice)}: device id [{deviceId}].");

            var device = await restClient.GetDevice(deviceId);

            if (device == null)
            {
                throw new KeyNotFoundException("Failed to find device with id: " + deviceId);
            }

            _logger.Debug(
                $"{nameof(LockDevice)}: set device id [{deviceId}] available from [{device.Available}] to false.");
            device.Available = false;

            _logger.Debug($"{nameof(LockDevice)}: device id [{deviceId}] stop running Appium");
            try
            {
                device.AppiumEndpoint = Task.Run(() => appiumService.StartAppiumForDeviceId(deviceId)).Result;
            }
            catch (Exception e)
            {
                _logger.Error($"{nameof(LockDevice)} failed with exception.", e);
                await UnlockDevice(device.Id, restClient, appiumService);

                throw;
            }

            _logger.Debug($"{nameof(LockDevice)}: device id [{deviceId}] set status from [{device.Status}] to LOCKED");

            device.Status = DeviceStatus.Locked;

            var updatedDevice = await restClient.UpdateDevice(device);

            _logger.Debug($"{nameof(LockDevice)}: updated device [{JsonConvert.SerializeObject(updatedDevice)}]");

            return(updatedDevice);
        }