public void SetActiveAlias(ulong userId, string aliasName, Action <IAliasConfiguration> configurationOptions) { var config = new AliasConfiguration(); configurationOptions(config); var currentActive = GetActiveAliases(userId).ToList(); if (currentActive.Any(a => a.Name.Equals(aliasName) && config.IsMultiBoxAlias)) { return; } if (!config.IsMultiBoxAlias) { foreach (var alias in currentActive) { alias.IsActive = false; } } var aliases = GetAliases(userId); if (!aliases.Any(a => a.Name.Equals(aliasName))) { throw new ArgumentException($"No alias named {aliasName} could be found for the specified user."); } var newActive = aliases.First(a => a.Name.Equals(aliasName)); newActive.IsActive = true; _dbContext.SaveChanges(); _eventAlerter.RaiseActiveAliasChanged(new AliasChangeEventArgs(userId, currentActive, aliases.Where(a => a.IsActive).ToList())); }
/// <summary> Loads, displays, saves and returns an alias configuration. </summary> /// <remarks> Any changes to the alias list are saved even if the form is cancelled. </remarks> public static AliasConfiguration Execute() { AliasConfiguration configuration = AliasManager.LoadConfiguration(); Execute(configuration); return(configuration); }
private void SetConfiguration(AliasConfiguration configuration) { _configuration = configuration; _serverList.Items.Clear(); foreach (ServerAlias alias in configuration.Aliases.Values) { AddItem(alias); } SelectAlias(configuration.DefaultAliasName); }
public static void Execute(AliasConfiguration configuration) { using (ServerConnectForm form = new ServerConnectForm()) { form.SetConfiguration(configuration); form.EnsureServerSelected(); DialogResult result = form.ShowDialog(); ServerAlias selected = form.SelectedAlias; if (selected != null) { selected.SessionInfo.UserID = form.UserIDTextBox.Text; } if (selected != null) { form.Configuration.DefaultAliasName = selected.Name; } else { form.Configuration.DefaultAliasName = String.Empty; } AliasManager.SaveConfiguration(form.Configuration); if (result != DialogResult.OK) { throw new AbortException(); } if (selected != null) { selected.SessionInfo.Password = form.PasswordTextBox.Text; } } }
private void Page_Load(object sender, System.EventArgs e) { _configuration = (AliasConfiguration)Session["AliasConfiguration"]; if (_configuration == null) { _configuration = AliasConfiguration.Load(AliasConfigurationFileName); Session["AliasConfiguration"] = _configuration; } // End any previous session Web.Session session = (Web.Session)Session["WebSession"]; if (session != null) { try { session.Dispose(); } finally { Session["WebSession"] = null; } } string aliasName = Request.QueryString["Alias"]; if (aliasName == null) { aliasName = String.Empty; } if (IsPostBack) { if (aliasName != String.Empty) { UserIDTextBox.Text = _configuration.Aliases[aliasName].SessionInfo.UserID; _configuration.DefaultAliasName = aliasName; } string deleteAlias = Request.QueryString["Delete"]; if ((deleteAlias != null) && (deleteAlias != String.Empty)) { _configuration.Aliases.Remove(deleteAlias); if (String.Compare(deleteAlias, _configuration.DefaultAliasName, true) == 0) { _configuration.DefaultAliasName = String.Empty; } _configuration.Save(AliasConfigurationFileName); } } else { if (_configuration.DefaultAliasName != String.Empty) { ServerAlias connection = _configuration.Aliases[_configuration.DefaultAliasName]; if (connection != null) { UserIDTextBox.Text = connection.SessionInfo.UserID; } } string applicationID = Request.QueryString["ApplicationID"]; if ((applicationID != null) && (applicationID != String.Empty)) { Session["ApplicationID"] = applicationID; } if (aliasName != String.Empty) { _configuration.DefaultAliasName = aliasName; AdvanceToApplication(); } } _editButton.Enabled = _configuration.Aliases.Count > 0; _deleteButton.Enabled = _editButton.Enabled; _deleteButton.Attributes.Add ( "onclick", HttpUtility.HtmlAttributeEncode ( String.Format ( @"if (confirm('{0}')) Submit('Connect.aspx?Delete={1}',event)", Strings.Get("ConfirmAliasDeleteMessage"), HttpUtility.UrlEncode(Configuration.DefaultAliasName).Replace("'", "\\'") ) ) ); UserIDTextBox.Attributes.Add("onkeydown", "TrapKeyDown(FLogin, event)"); PasswordTextBox.Attributes.Add("onkeydown", "TrapKeyDown(FLogin, event)"); }