protected bool ValidateNoImageInOtherType(out VirtualMachineImageType otherType)
        {
            var allTypes = new VirtualMachineImageHelper(this.ComputeClient).GetImageType(this.ImageName);

            otherType = string.IsNullOrEmpty(this.OSState) ? VirtualMachineImageType.VMImage
                                                           : VirtualMachineImageType.OSImage;

            return(allTypes == VirtualMachineImageType.None || !allTypes.HasFlag(otherType));
        }
        protected override void ExecuteCommand()
        {
            ServiceManagementProfile.Initialize();

            base.ExecuteCommand();

            if (CurrentDeploymentNewSM == null)
            {
                WriteWarning(string.Format(Resources.NoDeploymentFoundByServiceAndVMName, this.ServiceName, this.Name));
                return;
            }

            VirtualMachineImageType otherImagetype = VirtualMachineImageType.None;

            if (!ValidateNoImageInOtherType(out otherImagetype))
            {
                // If there is another type of image with the same name,
                // WAPS will stop here to avoid duplicates and potential conflicts
                WriteErrorWithTimestamp(
                    string.Format(
                        Resources.ErrorAnotherImageTypeFoundWithTheSameName,
                        otherImagetype,
                        this.ImageName));

                return;
            }

            Func <OperationStatusResponse> action = null;

            if (string.IsNullOrEmpty(this.OSState))
            {
                action = () => this.ComputeClient.VirtualMachines.CaptureOSImage(
                    this.ServiceName,
                    CurrentDeploymentNewSM.Name,
                    this.Name,
                    new VirtualMachineCaptureOSImageParameters
                {
                    PostCaptureAction = PostCaptureAction.Delete,
                    TargetImageLabel  = string.IsNullOrEmpty(this.ImageLabel) ? this.ImageName : this.ImageLabel,
                    TargetImageName   = this.ImageName
                });
            }
            else
            {
                if (string.Equals(GetRoleInstanceStatus(), RoleInstanceStatus.ReadyRole))
                {
                    WriteWarning(Resources.CaptureVMImageOperationWhileVMIsStillRunning);
                }

                action = () => this.ComputeClient.VirtualMachines.CaptureVMImage(
                    this.ServiceName,
                    CurrentDeploymentNewSM.Name,
                    this.Name, new VirtualMachineCaptureVMImageParameters
                {
                    VMImageName  = this.ImageName,
                    VMImageLabel = string.IsNullOrEmpty(this.ImageLabel) ? this.ImageName : this.ImageLabel,
                    OSState      = this.OSState
                });
            }

            if (action != null)
            {
                ExecuteClientActionNewSM(null, CommandRuntime.ToString(), action);
            }
        }
        protected bool ValidateNoImageInOtherType(out VirtualMachineImageType otherType)
        {
            var allTypes = new VirtualMachineImageHelper(this.ComputeClient).GetImageType(this.ImageName);

            otherType = string.IsNullOrEmpty(this.OSState) ? VirtualMachineImageType.VMImage
                                                           : VirtualMachineImageType.OSImage;

            return allTypes == VirtualMachineImageType.None || !allTypes.HasFlag(otherType);
        }