Exemplo n.º 1
0
 public void Post([FromBody] Alias alias)
 {
     if (ModelState.IsValid)
     {
         aliases.AddAlias(alias);
     }
 }
 public Alias Post([FromBody] Alias Alias)
 {
     if (ModelState.IsValid)
     {
         Alias = aliases.AddAlias(Alias);
     }
     return(Alias);
 }
Exemplo n.º 3
0
 public Alias Post([FromBody] Alias alias)
 {
     if (ModelState.IsValid)
     {
         alias = _aliases.AddAlias(alias);
         _logger.Log(LogLevel.Information, this, LogFunction.Create, "Alias Added {Alias}", alias);
     }
     return(alias);
 }
Exemplo n.º 4
0
 public Alias Post([FromBody] Alias alias)
 {
     if (ModelState.IsValid)
     {
         alias = _aliases.AddAlias(alias);
         _logger.Log(LogLevel.Information, this, LogFunction.Create, "Alias Added {Alias}", alias);
     }
     else
     {
         _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Alias Post Attempt {Alias}", alias);
         HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
         alias = null;
     }
     return(alias);
 }
Exemplo n.º 5
0
        public void Invoke(string[] args)
        {
            bool   showHelp    = false;
            string newAlias    = null;
            string deleteAlias = null;

            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => showHelp = x != null
                );
            options.Add(
                "n|new=",
                "Create a new {alias}.",
                x => newAlias = x
                );
            options.Add(
                "d|delete=",
                "Delete an existing {alias}.",
                x => deleteAlias = x
                );

            if (args == null)
            {
                this.CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
            }
            else
            {
                try
                {
                    var parsedArgs = options.Parse(args).ToArray();

                    if (parsedArgs.Length == args.Length)
                    {
                        this.CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
                    }
                    else
                    {
                        if (showHelp)
                        {
                            HelpUtility.WriteHelpInformation(
                                this.CommandResult,
                                this.Name,
                                this.Parameters,
                                this.Description,
                                options
                                );
                        }
                        else if (newAlias != null)
                        {
                            if (!newAlias.Is("HELP") && !this.AvailableCommands.Any(x => x.Name.Is(newAlias)))
                            {
                                var alias = _aliasRepository.GetAlias(this.CommandResult.CurrentUser.Username, newAlias);
                                if (alias == null)
                                {
                                    if (this.CommandResult.CommandContext.PromptData == null)
                                    {
                                        this.CommandResult.WriteLine("Type the value that should be sent to the terminal when you use your new alias.");
                                        this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} VALUE", newAlias.ToUpper()));
                                    }
                                    else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                                    {
                                        _aliasRepository.AddAlias(new Alias
                                        {
                                            Username = this.CommandResult.CurrentUser.Username,
                                            Shortcut = newAlias,
                                            Command  = this.CommandResult.CommandContext.PromptData[0]
                                        });
                                        this.CommandResult.WriteLine("Alias '{0}' was successfully defined.", newAlias.ToUpper());
                                        this.CommandResult.CommandContext.Restore();
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You have already defined an alias named '{0}'.", newAlias.ToUpper());
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("'{0}' is an existing command. You cannot create aliases with the same name as existing commands.", newAlias.ToUpper());
                            }
                        }
                        else if (deleteAlias != null)
                        {
                            var alias = _aliasRepository.GetAlias(this.CommandResult.CurrentUser.Username, deleteAlias);
                            if (alias != null)
                            {
                                _aliasRepository.DeleteAlias(alias);
                                this.CommandResult.WriteLine("Alias '{0}' was successfully deleted.", deleteAlias.ToUpper());
                            }
                            else
                            {
                                this.CommandResult.WriteLine("You have not defined an alias named '{0}'.", deleteAlias.ToUpper());
                            }
                        }
                    }
                }
                catch (OptionException ex)
                {
                    this.CommandResult.WriteLine(ex.Message);
                }
            }
        }