示例#1
0
        public void Delete(int id)
        {
            var alias = _aliases.GetAlias(id);

            if (alias != null)
            {
                _aliases.DeleteAlias(id);
                _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Alias Deleted {AliasId}", id);
            }
            else
            {
                _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Alias Delete Attempt {AliasId}", id);
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
            }
        }
 public void Delete(int id)
 {
     _aliases.DeleteAlias(id);
     _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Alias Deleted {AliasId}", id);
 }
 public void Delete(int id)
 {
     aliases.DeleteAlias(id);
 }
示例#4
0
文件: ALIAS.cs 项目: mBr001/u413-C-
        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);
                }
            }
        }