//not overriding BeginProcessing so resource context validation will happen here public override void ExecuteCmdlet() { try { List <IscsiConnection> iscsiConnections = null; var currentResourceName = StorSimpleClient.GetResourceContext().ResourceName; string deviceIdFinal = null; if (ParameterSetName == StorSimpleCmdletParameterSet.IdentifyByName) { var deviceToUse = StorSimpleClient.GetAllDevices().Where(x => x.FriendlyName.Equals(DeviceName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (deviceToUse == null) { throw new ArgumentException(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage, currentResourceName, DeviceName)); } deviceIdFinal = deviceToUse.DeviceId; } else { deviceIdFinal = DeviceId; } //verify that this device is configured this.VerifyDeviceConfigurationCompleteForDevice(deviceIdFinal); iscsiConnections = StorSimpleClient.GetAllIscsiConnections(deviceIdFinal); WriteObject(iscsiConnections); WriteVerbose(string.Format(Resources.IscsiConnectionGet_StatusMessage, iscsiConnections.Count, (iscsiConnections.Count > 1?"s":string.Empty))); } catch (Exception exception) { this.HandleException(exception); } }
public override void ExecuteCmdlet() { try { var deviceInfos = StorSimpleClient.GetAllDevices(); switch (ParameterSetName) { case StorSimpleCmdletParameterSet.IdentifyByName: deviceInfos = deviceInfos.Where(x => x.FriendlyName.Equals(DeviceName, System.StringComparison.InvariantCultureIgnoreCase)); break; case StorSimpleCmdletParameterSet.IdentifyById: deviceInfos = deviceInfos.Where(x => x.DeviceId.Equals(DeviceId, System.StringComparison.InvariantCultureIgnoreCase)); break; default: break; } if (Type != null) { DeviceType deviceType; bool parseSuccess = Enum.TryParse(Type, true, out deviceType); if (parseSuccess) { deviceInfos = deviceInfos.Where(x => x.Type.Equals(deviceType)); } } if (ModelID != null) { deviceInfos = deviceInfos.Where(x => x.ModelDescription.Equals(ModelID, System.StringComparison.InvariantCultureIgnoreCase)); } if (Detailed.IsPresent) { List <DeviceDetails> deviceDetailsList = new List <DeviceDetails>(); foreach (var deviceInfo in deviceInfos) { deviceDetailsList.Add(StorSimpleClient.GetDeviceDetails(deviceInfo.DeviceId)); } WriteObject(deviceDetailsList, true); } else { WriteObject(deviceInfos, true); } WriteVerbose(string.Format(Resources.DeviceGet_StatusMessage, deviceInfos.Count(), deviceInfos.Count() > 1 ? "s" : string.Empty)); } catch (Exception exception) { this.HandleException(exception); } }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { try { this.WriteVerbose(Resources.ResourceContextInitializeMessage); var resCred = StorSimpleClient.GetResourceDetails(ResourceName); if (resCred == null) { this.WriteVerbose(Resources.NotFoundMessageResource); throw GetGenericException(Resources.NotFoundMessageResource, null); } StorSimpleClient.SetResourceContext(resCred); var deviceInfos = StorSimpleClient.GetAllDevices(); if (!deviceInfos.Any()) { StorSimpleClient.ResetResourceContext(); throw base.GetGenericException(Resources.DeviceNotRegisteredMessage, null); } //now check for the key if (string.IsNullOrEmpty(RegistrationKey)) { this.WriteVerbose(Resources.RegistrationKeyNotPassedMessage); } else { this.WriteVerbose(Resources.RegistrationKeyPassedMessage); EncryptionCmdLetHelper.PersistCIK(this, resCred.ResourceId, StorSimpleClient.ParseCIKFromRegistrationKey(RegistrationKey)); } EncryptionCmdLetHelper.ValidatePersistedCIK(this, resCred.ResourceId); this.WriteVerbose(Resources.SecretsValidationCompleteMessage); this.WriteVerbose(Resources.SuccessMessageSetResourceContext); var currentContext = StorSimpleClient.GetResourceContext(); this.WriteObject(currentContext); } catch (Exception exception) { this.HandleException(exception); } }