private int?missionPreferenceToVehicleId(MissionPreference prefs, int userId) { if (prefs == null) { return(null); } if (EnableVehicleSynchronisation && prefs.User.Id == userId) { string selectionValue = prefs.Value; Regex r = new Regex(VEHICLE_PATTERN, RegexOptions.IgnoreCase); Match match = r.Match(selectionValue); if (match.Success) { if (!string.IsNullOrEmpty(match.Groups[1].Captures[0].Value)) { return(int.Parse(match.Groups[1].Captures[0].Value)); } else { return(null); } } } return(null); }
/// <summary> /// Gets selected vehicle. /// </summary> /// <returns>Return <see cref="null"/> if there are no info about selected vehicle, otherwise returns <see cref="ClientVehicleDto"/> object.</returns> public ClientVehicleDto GetSelectedVehicleId() { if (!_connectionService.IsConnected) { return(null); } var getMissionReq = new GetMissionPreferencesRequest() { User = _connectionService.GetUser(), ClientId = _connectionService.GetClientId(), Mission = null, }; var getMissionResp = _connectionService.Execute <GetMissionPreferencesResponse>(getMissionReq); MissionPreference pref = getMissionResp.Preferences.FirstOrDefault(p => p.Name == PREF_NAME); int?id = missionPreferenceToVehicleId(pref, getMissionReq.User.Id); if (id != null) { var v = getVehicleById(id.Value); if (v != null) { return(new ClientVehicleDto() { Name = v.Name, VehicleId = v.Id }); } } return(null); }
private int?getSelectedVehicleIdFromMissionPref(MissionPreference preference) { int?result = null; var r = new Regex(SELECTION_REGEX_PATTERN, RegexOptions.IgnoreCase); var selectionValue = preference?.Value; if (string.IsNullOrWhiteSpace(selectionValue)) { return(null); } var match = r.Match(selectionValue); if (!match.Success) { return(null); } var strId = match.Groups[1].Captures[0].Value; if (int.TryParse(strId, out var droneId)) { result = droneId; } return(result); }
/// <summary> /// Return <see cref="null"/> if there are no info about selected vehicle /// </summary> /// <returns></returns> public string GetSelectedVehicleTailNumber() { if (!_connectionService.IsConnected) { return(null); } var getMissionReq = new GetMissionPreferencesRequest() { User = _connectionService.User, ClientId = _connectionService.ClientId, Mission = null, }; var getMissionResp = _connectionService.Execute <GetMissionPreferencesResponse>(getMissionReq); MissionPreference pref = getMissionResp.Preferences.Where(p => p.Name == PREF_NAME).FirstOrDefault(); int?id = missionPreferenceToVehicleId(pref, getMissionReq.User.Id); if (id != null) { return(getVehicleTailNumberById(id.Value)); } return(null); }
private bool isUserMission(MissionPreference preference) { return(preference.Name.Equals("mission") && preference.User.Id == _connection.LastLoginResponse.User.Id); }