public AssetRobotValueDto ToDto() { return(new AssetRobotValueDto { RobotId = RobotId, StringValue = TextValue, IntValue = IntValue, BoolValue = BoolValue, ValueType = ValueType, CredentialUsername = Credential?.UserName, CredentialPassword = Credential?.ExtractPassword() }); }
public AssetRobotValueDto ToDto() { return(new AssetRobotValueDto { RobotId = RobotId, RobotName = "Ignore robot name require dby 19.10 bug", StringValue = TextValue, IntValue = IntValue, BoolValue = BoolValue, ValueType = ValueType, CredentialUsername = Credential?.UserName, CredentialPassword = Credential?.ExtractPassword() }); }
protected override void ProcessRecord() { var asset = new AssetDto { Name = Name, ValueScope = AssetDtoValueScope.Global }; switch (ParameterSetName) { case NewAssetRobotValue.TextValueSet: asset.ValueType = AssetDtoValueType.Text; asset.StringValue = TextValue; break; case NewAssetRobotValue.IntValueSet: asset.ValueType = AssetDtoValueType.Integer; asset.IntValue = IntValue; break; case NewAssetRobotValue.BoolValueSet: asset.ValueType = AssetDtoValueType.Bool; asset.BoolValue = BoolValue; break; case NewAssetRobotValue.DBConnectionStringSet: asset.ValueType = AssetDtoValueType.DBConnectionString; asset.StringValue = DBConnectionString; break; case NewAssetRobotValue.HttpConnectionStringSet: asset.ValueType = AssetDtoValueType.HttpConnectionString; asset.StringValue = HttpConnectionString; break; case NewAssetRobotValue.KeyValueListSet: asset.ValueType = AssetDtoValueType.KeyValueList; asset.KeyValueList = KeyValueList.ToKeyList(); break; case NewAssetRobotValue.WindowsCredentialSet: asset.ValueType = AssetDtoValueType.WindowsCredential; asset.CredentialUsername = WindowsCredential.UserName; asset.CredentialPassword = WindowsCredential.ExtractPassword(); break; case NewAssetRobotValue.CredentialSet: asset.ValueType = AssetDtoValueType.Credential; asset.CredentialUsername = Credential.UserName; asset.CredentialPassword = Credential.ExtractPassword(); break; case RobotValuesSet: asset.ValueScope = AssetDtoValueScope.PerRobot; if (RobotValues.Any()) { asset.ValueType = (AssetDtoValueType)Enum.Parse(typeof(AssetDtoValueType), RobotValues.First().ValueType.ToString()); asset.RobotValues = RobotValues.Select(rv => rv.ToDto()).ToList(); } break; } var dto = HandleHttpOperationException(() => Api.Assets.Post(asset)); WriteObject(Asset.FromDto(dto)); }
private void ProcessDto(AssetDto dto) { if (dto.ValueScope == AssetDtoValueScope.Global && ParameterSetName != AddAsset.RobotValuesSet) { switch (ParameterSetName) { case NewAssetRobotValue.TextValueSet: dto.ValueType = AssetDtoValueType.Text; dto.StringValue = TextValue; break; case NewAssetRobotValue.IntValueSet: dto.ValueType = AssetDtoValueType.Integer; dto.IntValue = IntValue; break; case NewAssetRobotValue.BoolValueSet: dto.ValueType = AssetDtoValueType.Bool; dto.BoolValue = BoolValue; break; case NewAssetRobotValue.DBConnectionStringSet: dto.ValueType = AssetDtoValueType.DBConnectionString; dto.StringValue = DBConnectionString; break; case NewAssetRobotValue.HttpConnectionStringSet: dto.ValueType = AssetDtoValueType.HttpConnectionString; dto.StringValue = HttpConnectionString; break; case NewAssetRobotValue.KeyValueListSet: dto.ValueType = AssetDtoValueType.KeyValueList; dto.KeyValueList = KeyValueList.ToKeyList(); break; case NewAssetRobotValue.WindowsCredentialSet: dto.ValueType = AssetDtoValueType.WindowsCredential; dto.CredentialUsername = WindowsCredential.UserName; dto.CredentialPassword = WindowsCredential.ExtractPassword(); break; case NewAssetRobotValue.CredentialSet: dto.ValueType = AssetDtoValueType.Credential; dto.CredentialUsername = Credential.UserName; dto.CredentialPassword = Credential.ExtractPassword(); break; } } else if (dto.ValueScope == AssetDtoValueScope.PerRobot && ParameterSetName == AddAsset.RobotValuesSet) { dto.RobotValues = dto.RobotValues.MergeAddRemove( AddRobotValues?.Select(rv => rv.ToDto()), // Robot values to add to the list RemoveRobotIdValues?.Select(rid => new AssetRobotValueDto { RobotId = rid }), // Robot IDs to remove, expressed as AssetRobotValue for sake of MergeAddRemove.. IEnumerable<T> ... rv => rv.RobotId) // T->K Key selector expression .ToList(); } else { throw new RuntimeException("Mismatched parameters and asset scope"); } HandleHttpOperationException(() => Api.Assets.PutById(dto.Id.Value, dto)); }