public void OnGet() { var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies(); foreach (Assembly assembly in assemblies) { ProcessHostResources(assembly); ProcessModuleControls(assembly); ProcessThemeControls(assembly); } // if culture not specified and framework is installed if (HttpContext.Request.Cookies[CookieRequestCultureProvider.DefaultCookieName] == null && !string.IsNullOrEmpty(_configuration.GetConnectionString("DefaultConnection"))) { var uri = new Uri(Request.GetDisplayUrl()); var alias = _aliases.GetAlias(uri.Authority + "/" + uri.LocalPath.Substring(1)); _state.Alias = alias; // set default language for site if the culture is not supported var languages = _languages.GetLanguages(alias.SiteId); if (languages.Any() && languages.All(l => l.Code != CultureInfo.CurrentUICulture.Name)) { var defaultLanguage = languages.Where(l => l.IsDefault).SingleOrDefault() ?? languages.First(); SetLocalizationCookie(defaultLanguage.Code); } else { SetLocalizationCookie(_localizationManager.GetDefaultCulture()); } } }
/// <summary> /// Get User by Id /// </summary> /// <param name="userId"></param> /// <returns></returns> //public User GetUser(string userId) //{ // _logger.LogInformation($"BEGIN GetUser"); // try // { // var user = _userRepository.GetUser(userId); // if (user == null) return null; // var result = new User // { // AppId = user.AppId, // Email = user.Email, // FacebookInfo = user.FacebookInfo, // GoogleInfo = user.GoogleInfo, // Id = user.Id, // Name = user.Name, // TwitterInfo = user.TwitterInfo // }; // return result; // } // catch (Exception ex) // { // _logger.LogError($"Exception on GetUser with message: {ex.Message}"); // return null; // } //} /// <summary> /// Get Alias information by id (including associated Product) /// </summary> /// <param name="aliasId"></param> /// <returns></returns> public Alias GetAlias(int aliasId) { _logger.LogInformation($"BEGIN GetAlias"); try { var alias = _aliasRepository.GetAlias(aliasId); if (alias == null) { return(null); } var result = new Alias { Id = alias.AliasId, Modified = alias.Alias.Modified, Name = alias.Name, VirtualName = alias.Name.RemoveDiacritics(), }; return(result); } catch (Exception ex) { _logger.LogError($"Exception on GetAlias with message: {ex.Message}"); return(null); } }
public Installation IsInstalled(string path) { var installation = _databaseManager.IsInstalled(); if (installation.Success) { path = _accessor.HttpContext.Request.Host.Value + "/" + WebUtility.UrlDecode(path); installation.Alias = _aliases.GetAlias(path); } return(installation); }
public Alias GetAlias() { Alias alias = null; if (_siteState != null && _siteState.Alias != null) { alias = _siteState.Alias; } else { // if there is http context if (_httpContextAccessor.HttpContext != null) { // legacy support for client api requests which would include the alias as a path prefix ( ie. {alias}/api/[controller] ) int aliasId; string[] segments = _httpContextAccessor.HttpContext.Request.Path.Value.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (segments.Length > 1 && (segments[1] == "api" || segments[1] == "pages") && int.TryParse(segments[0], out aliasId)) { alias = _aliasRepository.GetAliases().ToList().FirstOrDefault(item => item.AliasId == aliasId); } // resolve alias based on host name and path if (alias == null) { string name = _httpContextAccessor.HttpContext.Request.Host.Value + _httpContextAccessor.HttpContext.Request.Path; alias = _aliasRepository.GetAlias(name); } // if there is a match save it if (alias != null) { _siteState.Alias = alias; } } } return(alias); }
public Alias Get(int id) { return(_aliases.GetAlias(id)); }
/// <summary> /// Accepts a command string and handles the parsing and execution of the command and the included arguments. /// </summary> /// <param name="commandString">The command string. Usually a string passed in from a command line interface by the user.</param> /// <returns>A CommandResult option containing properties relevant to how data should be processed by the UI.</returns> public CommandResult ExecuteCommand(string commandString) { if (commandString == null) { commandString = string.Empty; } var hasSpace = commandString.Contains(' '); var spaceIndex = 0; if (hasSpace) { spaceIndex = commandString.IndexOf(' '); } // Parse command string to find the command name. string commandName = hasSpace ? commandString.Remove(spaceIndex) : commandString; if (_currentUser != null) { _currentUser.LastLogin = DateTime.UtcNow; _userRepository.UpdateUser(_currentUser); // Check for alias. Replace command name with alias. if ((_commandContext.Status & ContextStatus.Forced) == 0) { var alias = _aliasRepository.GetAlias(_currentUser.Username, commandName); if (alias != null) { commandString = hasSpace ? alias.Command + commandString.Remove(0, spaceIndex) : alias.Command; hasSpace = commandString.Contains(' '); spaceIndex = 0; if (hasSpace) { spaceIndex = commandString.IndexOf(' '); } commandName = hasSpace ? commandString.Remove(spaceIndex) : commandString; } } } // Parse command string and divide up arguments into a string array. var args = hasSpace ? commandString.Remove(0, spaceIndex) .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) : null; // Obtain all roles the current user is a part of. var availableRoles = _currentUser != null?_currentUser.Roles.Select(x => x.Name).ToArray() : new string[] { "Visitor" }; // Create command result. var commandResult = new CommandResult { Command = commandName.ToUpper(), CurrentUser = _currentUser, CommandContext = this._commandContext }; // Obtain all commands for the roles the user is a part of. var commands = _commands .Where(x => x.Roles.Any(y => availableRoles.Any(z => z.Is(y)))) .ToList(); foreach (var cmd in commands) { cmd.CommandResult = commandResult; cmd.AvailableCommands = commands; } if (_currentUser != null && _currentUser.BanInfo != null) { if (DateTime.UtcNow < _currentUser.BanInfo.EndDate) { return(BanMessage(commandResult)); } else { _userRepository.UnbanUser(_currentUser.Username); _userRepository.UpdateUser(_currentUser); } } // Obtain the command the user intends to execute from the list of available commands. var command = commands.SingleOrDefault(x => x.Name.Is(commandName)); if (commandName.Is("INITIALIZE")) { this._commandContext.Deactivate(); } // Perform different behaviors based on the current command context. switch (this._commandContext.Status) { // Perform normal command execution. case ContextStatus.Disabled: if (command != null) { command.CommandResult.Command = command.Name; command.Invoke(args); } break; // Perform normal command execution. // If command does not exist, attempt to use command context instead. case ContextStatus.Passive: if (command != null) { command.CommandResult.Command = command.Name; command.Invoke(args); } else if (!commandName.Is("HELP")) { command = commands.SingleOrDefault(x => x.Name.Is(this._commandContext.Command)); if (command != null) { args = commandString.Contains(' ') ? commandString.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries) : new string[] { commandString }; var newArgs = new List <string>(); if (this._commandContext.Args != null) { newArgs.AddRange(this._commandContext.Args); } newArgs.AddRange(args); command.CommandResult.Command = command.Name; command.Invoke(newArgs.ToArray()); } } break; // Perform command execution using command context. // Reset command context if "CANCEL" is supplied. case ContextStatus.Forced: if (!commandName.Is("CANCEL")) { command = commands.SingleOrDefault(x => x.Name.Is(this._commandContext.Command)); if (command != null) { command.CommandResult.Command = command.Name; if (this._commandContext.Prompt) { var newStrings = new List <string>(); if (this._commandContext.PromptData != null) { newStrings.AddRange(this._commandContext.PromptData); } newStrings.Add(commandString); this._commandContext.PromptData = newStrings.ToArray(); command.Invoke(this._commandContext.Args); } else { args = commandString.Contains(' ') ? commandString.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries) : new string[] { commandString }; var newArgs = new List <string>(); if (this._commandContext.Args != null) { newArgs.AddRange(this._commandContext.Args); } newArgs.AddRange(args); args = newArgs.ToArray(); command.Invoke(args); } } } else { commandResult.CommandContext.Restore(); commandResult.WriteLine("Action canceled."); } break; } // If command does not exist, check if the command was "HELP". // If so, call the ShowHelp method to show help information for all available commands. if (command == null) { if (commandName.Is("HELP")) { commandResult = DisplayHelp(commands, args, commandResult); } else if (!commandName.Is("CANCEL")) { if (commandName.IsNullOrWhiteSpace()) { commandResult.WriteLine("You must supply a command."); } else { commandResult.WriteLine("'{0}' is not a recognized command or is not available in the current context.", commandName); } } } _currentUser = commandResult.CurrentUser; if (_currentUser != null && _currentUser.BanInfo != null) { if (DateTime.UtcNow < _currentUser.BanInfo.EndDate) { return(BanMessage(commandResult)); } else { _userRepository.UnbanUser(_currentUser.Username); _userRepository.UpdateUser(_currentUser); } } // Temporarily notify of messages on each command execution. if (_currentUser != null) { var unreadMessageCount = _messageRepository.UnreadMessages(_currentUser.Username); if (unreadMessageCount > 0) { commandResult.WriteLine(); commandResult.WriteLine("You have {0} unread message(s).", unreadMessageCount); } } commandResult.TerminalTitle = string.Format("Terminal - {0}", _currentUser != null ? _currentUser.Username : "******"); FinalParsing(commandResult); return(commandResult); }
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); } } }