public ITargetDevice CreateDevice(string InRef, string InParam) { LuminDeviceData DeviceData = null; if (!String.IsNullOrEmpty(InParam)) { DeviceData = fastJSON.JSON.Instance.ToObject<LuminDeviceData>(InParam); } return new TargetDeviceLumin(InRef, DeviceData); }
/// <summary> /// Constructor /// </summary> /// <param name="InReferenceName"></param> /// <param name="InRemoveOnDestruction"></param> public TargetDeviceLumin(string InDeviceName = "", LuminDeviceData DeviceData = null) { DeviceName = InDeviceName; // If no device name or its 'default' then use the first default device if (string.IsNullOrEmpty(DeviceName) || DeviceName.Equals("default", StringComparison.OrdinalIgnoreCase)) { var DefaultDevices = GetAllAvailableDevices(); if (DefaultDevices.Count() == 0) { if (GetAllConnectedDevices().Count > 0) { throw new AutomationException("No default device available. One or more devices are connected but unauthorized. See 'mldb devices'"); } else { throw new AutomationException("No default device available. See 'mldb devices'"); } } DeviceName = DefaultDevices.First(); } if (Log.IsVerbose) { RunOptions = CommandUtils.ERunOptions.NoWaitForExit; } else { RunOptions = CommandUtils.ERunOptions.NoWaitForExit | CommandUtils.ERunOptions.NoLoggingOfRunCommand; } // if this is not a connected device then remove when done var ConnectedDevices = GetAllConnectedDevices(); IsExistingDevice = ConnectedDevices.Keys.Contains(DeviceName); if (!IsExistingDevice) { // TODO: adb uses 5555 by default, not sure about mldb? if (DeviceName.Contains(":") == false) { DeviceName = DeviceName + ":5555"; } lock (Globals.MainLock) { using (var PauseEC = new ScopedSuspendECErrorParsing()) { IProcessResult MldbResult = RunMldbGlobalCommand(string.Format("connect {0}", DeviceName)); if (MldbResult.ExitCode != 0) { throw new AutomationException("mldb failed to connect to {0}. {1}", DeviceName, MldbResult.Output); } } Log.Info("Connected to {0}", DeviceName); // Need to sleep for mldb service process to register, otherwise get an unauthorized (especially on parallel device use) Thread.Sleep(5000); } } LocalDirectoryMappings = new Dictionary<EIntendedBaseCopyDirectory, string>(); // for IP devices need to sanitize this Name = DeviceName.Replace(":", "_"); // Path we use for artifacts, we'll create it later when we need it LocalCachePath = Path.Combine(Globals.TempDir, "LuminDevice_" + Name); ConnectedDevices = GetAllConnectedDevices(); SetUpDirectoryMappings(); // sanity check that it was now dound if (ConnectedDevices.Keys.Contains(DeviceName) == false) { throw new AutomationException("Failed to find new device {0} in connection list", DeviceName); } if (ConnectedDevices[DeviceName] == false) { Dispose(); throw new AutomationException("Device {0} is connected but this PC is not authorized.", DeviceName); } }