Exemple #1
0
 public static IForm <AllVirtualMachinesFormState> BuildAllVirtualMachinesForm()
 {
     return(EntityForms.CreateCustomForm <AllVirtualMachinesFormState>()
            .Field(nameof(AllVirtualMachinesFormState.Operation), (state) => false)
            .Field(nameof(AllVirtualMachinesFormState.VirtualMachines), (state) => false)
            .Confirm("You are trying to {Operation} the following virtual machines: {VirtualMachines} Are you sure?", (state) => (Operations)Enum.Parse(typeof(Operations), state.Operation, true) == Operations.Start, null)
            .Confirm("You are trying to {Operation} the following virtual machines: {VirtualMachines} Are you sure? Please note that your VMs will still incur compute charges.", (state) => (Operations)Enum.Parse(typeof(Operations), state.Operation, true) == Operations.Shutdown, null)
            .Confirm("You are trying to {Operation} the following virtual machines: {VirtualMachines} Are you sure? Your VMs won't incur charges and all IP addresses will be released.", (state) => (Operations)Enum.Parse(typeof(Operations), state.Operation, true) == Operations.Stop, null)
            .Build());
 }
Exemple #2
0
        public static IForm <RunbookFormState> BuildRunbookForm()
        {
            return(EntityForms.CreateCustomForm <RunbookFormState>()
                   .Field(new FieldReflector <RunbookFormState>(nameof(RunbookFormState.AutomationAccountName))
                          .SetType(null)
                          .SetPrompt(EntityForms.PerLinePromptAttribute("Please select the automation account you want to use: {||}"))
                          .SetDefine((state, field) =>
            {
                foreach (var account in state.AvailableAutomationAccounts)
                {
                    field
                    .AddDescription(account.AutomationAccountName, account.AutomationAccountName)
                    .AddTerms(account.AutomationAccountName, account.AutomationAccountName);
                }

                return Task.FromResult(true);
            }))
                   .Field(new FieldReflector <RunbookFormState>(nameof(RunbookFormState.RunbookName))
                          .SetType(null)
                          .SetPrompt(EntityForms.PerLinePromptAttribute("Please select the runbook you want to run: {||}"))
                          .SetActive(state => !string.IsNullOrWhiteSpace(state.AutomationAccountName))
                          .SetDefine((state, field) =>
            {
                if (string.IsNullOrWhiteSpace(state.AutomationAccountName))
                {
                    return Task.FromResult(false);
                }

                foreach (var runbook in state.AvailableAutomationAccounts.Single(
                             a => a.AutomationAccountName == state.AutomationAccountName).Runbooks.Where(x => x.RunbookState.Equals("Published", StringComparison.InvariantCultureIgnoreCase)))
                {
                    field
                    .AddDescription(runbook.RunbookName, runbook.RunbookName)
                    .AddTerms(runbook.RunbookName, runbook.RunbookName);
                }

                return Task.FromResult(true);
            }))
                   .Confirm("Would you like to run runbook '{RunbookName}' of automation acccount '{AutomationAccountName}'?")
                   .Build());
        }
Exemple #3
0
        public static IForm <VirtualMachineFormState> BuildVirtualMachinesForm()
        {
            return(EntityForms.CreateCustomForm <VirtualMachineFormState>()
                   .Field(nameof(VirtualMachineFormState.Operation), (state) => false)
                   .Field(new FieldReflector <VirtualMachineFormState>(nameof(VirtualMachineFormState.VirtualMachine))
                          .SetType(null)
                          .SetPrompt(EntityForms.PerLinePromptAttribute("Please select the virtual machine you want to {Operation}: {||}"))
                          .SetDefine((state, field) =>
            {
                foreach (var vm in state.AvailableVMs)
                {
                    field
                    .AddDescription(vm.Name, vm.ToString())
                    .AddTerms(vm.Name, vm.Name);
                }

                return Task.FromResult(true);
            }))
                   .Confirm("Would you like to {Operation} virtual machine '{VirtualMachine}'?", (state) => (Operations)Enum.Parse(typeof(Operations), state.Operation, true) == Operations.Start, null)
                   .Confirm("Would you like to {Operation} virtual machine '{VirtualMachine}'? Please note that your VM will still incur compute charges.", (state) => (Operations)Enum.Parse(typeof(Operations), state.Operation, true) == Operations.Shutdown, null)
                   .Confirm("Would you like to {Operation} virtual machine '{VirtualMachine}'? Your VM won't incur charges and all IP addresses will be released.", (state) => (Operations)Enum.Parse(typeof(Operations), state.Operation, true) == Operations.Stop, null)
                   .Build());
        }
Exemple #4
0
        public static IForm <RunbookParameterFormState> BuildRunbookParametersForm()
        {
            return(EntityForms.CreateCustomForm <RunbookParameterFormState>()
                   .Field(nameof(RunbookParameterFormState.ParameterName), (state) => false)
                   .Field(new FieldReflector <RunbookParameterFormState>(nameof(RunbookParameterFormState.ParameterValue))
                          .SetDefine((state, field) =>
            {
                var firstParamMessage = state.IsFirstParameter ? $"\n\r If you're unsure what to input, type **quit** followed by **show runbook {state.RunbookName} description** to get more details." : string.Empty;

                if (!state.IsMandatory)
                {
                    field.SetOptional(true);

                    field.SetPrompt(new PromptAttribute($"Please enter the value for optional parameter {state.ParameterName} or type *none* to skip it: {firstParamMessage}"));
                }
                else
                {
                    field.SetPrompt(new PromptAttribute($"Please enter the value for mandatory parameter {state.ParameterName}: {firstParamMessage}"));
                }

                return Task.FromResult(true);
            }))
                   .Build());
        }