Esempio n. 1
0
        public void EmptyAliasListJustPassesThroughStrings()
        {
            var subject = new AliasList();

            Assert.AreEqual("foo", subject.GetCanonicalNameFor("foo"));
            Assert.AreEqual("foo", subject.GetDisplayNameFor("foo"));
        }
Esempio n. 2
0
 public IAliasable AddAlias(IEnumerable <string> ieAliasable)
 {
     foreach (string s in ieAliasable)
     {
         AliasList.Add(s);
     }
     return(this);
 }
Esempio n. 3
0
        public void DoesntCrashOnDuplicates()
        {
            var subject = new AliasList();

            Assert.DoesNotThrow(() =>
            {
                subject.AddAlias("foo", "foo", new[] { "foo", "foo" });
                subject.AddAlias("foo", "foo", new[] { "foo", "foo" });
            });
        }
Esempio n. 4
0
        private GamesProcessor MakeGames()
        {
            var aliasList = new AliasList();

            aliasList.AddAlias("hiro.protagonist", "Hiro Protagonist", new[] { "GreatestSwordsman", "TheDeliverator" });
            aliasList.AddAlias("kourier.1992", "Yours Truly", new[] { "Y.T.", "YT" });
            aliasList.AddAlias("runner.2008", "Faith Connors", new[] { "Faith" });
            aliasList.AddAlias("robert.pope", "Robert Pope", new[] { "Pope" });
            return(new GamesProcessor(new InMemoryKeyValueStore(), aliasList));
        }
Esempio n. 5
0
        private static IAliasList GetAliasList(IEnumerable <SlackUser> users)
        {
            var aliasList = new AliasList();

            foreach (var user in users)
            {
                aliasList.AddAlias(user.SlackId, user.DisplayName, new[] {
                    user.UserName,
                    string.Format("<@{0}>", user.SlackId)
                });
            }
            return(aliasList);
        }
Esempio n. 6
0
        /// <summary>
        /// Adds an alias to this command.
        /// </summary>
        /// <param name="alias">Alias to add to the command.</param>
        /// <returns>This builder.</returns>
        public CommandBuilder WithAlias(string alias)
        {
            if (alias.ToCharArray().Any(xc => char.IsWhiteSpace(xc)))
            {
                throw new ArgumentException("Aliases cannot contain whitespace characters or null strings.", nameof(alias));
            }

            if (Name == alias || AliasList.Contains(alias))
            {
                throw new ArgumentException("Aliases cannot contain the command name, and cannot be duplicate.", nameof(alias));
            }

            AliasList.Add(alias);
            return(this);
        }
Esempio n. 7
0
        /// <summary>
        /// Opens a profile.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonOpenProfile_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                var dialog = new OpenFileDialog();
                dialog.InitialDirectory = App.Settings.AvalonSettings.SaveDirectory;
                dialog.Filter           = "JSON files (*.json)|*.json|Text Files (*.txt)|*.txt|All files (*.*)|*.*";

                if (dialog.ShowDialog() == true)
                {
                    // Load the settings for the file that was selected.
                    App.Settings.LoadSettings(dialog.FileName);

                    // Inject the Conveyor into the Triggers.
                    foreach (var trigger in App.Settings.ProfileSettings.TriggerList)
                    {
                        trigger.Conveyor = Conveyor;
                    }

                    // Important!  This is a new profile, we have to reload ALL of the DataList controls
                    // and reset their bindings.
                    AliasList.Reload();
                    DirectionList.Reload();
                    MacroList.Reload();
                    TriggersList.Reload();
                    VariableList.Reload();

                    // Show the user that the profile was successfully loaded.
                    Interp.EchoText("");
                    Interp.EchoText($"--> Loaded {dialog.FileName}.\r\n", AnsiColors.Cyan);

                    // Auto connect if it's setup to do so (this will disconnect from the previous server if it
                    // was connected.
                    if (App.Settings.ProfileSettings.AutoLogin)
                    {
                        Disconnect();
                        Connect();
                    }
                }
            }
            catch (Exception ex)
            {
                Interp.EchoText("");
                Interp.EchoText($"--> An error occured: {ex.Message}.\r\n", AnsiColors.Red);
            }
        }
Esempio n. 8
0
        private void MainWindow_Load(object sender, EventArgs e)
        {
            table.CellValueNeeded += new DataGridViewCellValueEventHandler(table_CellValueNeeded);
            table.CellValuePushed += new DataGridViewCellValueEventHandler(table_CellValuePushed);
            table.CellPainting    += new DataGridViewCellPaintingEventHandler(table_CellPainting);
            viewOffset             = 0;
            rowsToShow             = ((table.Height - table.ColumnHeadersHeight) / table.RowTemplate.Height);

            // https://stackoverflow.com/a/1506066
            typeof(DataGridView).InvokeMember(
                "DoubleBuffered",
                System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.SetProperty,
                null,
                table,
                new object[] { true });

            aliasList = new AliasList(this);
        }
Esempio n. 9
0
        public void CanAddAndFetchCanonicalName()
        {
            var subject = new AliasList();

            subject.AddAlias("hiro.protagonist", "Hiro Protagonist", new[] { "The Deliverator", "GreatestSwordsman" });

            Assert.AreEqual("hiro.protagonist", subject.GetCanonicalNameFor("Hiro Protagonist"),
                            "should convert display name to canonical name");
            Assert.AreEqual("hiro.protagonist", subject.GetCanonicalNameFor("hiro.protagonist"),
                            "should pass through canonical name");
            Assert.AreEqual("hiro.protagonist", subject.GetCanonicalNameFor("The Deliverator"),
                            "other aliases should also work");
            Assert.AreEqual("hiro.protagonist", subject.GetCanonicalNameFor("GreatestSwordsman"),
                            "more than one other aliases should also work");
            Assert.AreEqual("hiro.protagonist", subject.GetCanonicalNameFor("HIRO.PROTAGONIST"),
                            "should canonicalize canonical name by case");
            Assert.AreEqual("hiro.protagonist", subject.GetCanonicalNameFor("HIRO PROTAGONIST"),
                            "should not be case-sensitive");
        }
Esempio n. 10
0
        /// <summary>
        /// Sets the name for this command.
        /// </summary>
        /// <param name="name">Name for this command.</param>
        /// <returns>This builder.</returns>
        public CommandBuilder WithName(string name)
        {
            if (name == null || name.ToCharArray().Any(xc => char.IsWhiteSpace(xc)))
            {
                throw new ArgumentException("Command name cannot be null or contain any whitespace characters.", nameof(name));
            }

            if (Name != null)
            {
                throw new InvalidOperationException("This command already has a name.");
            }

            if (AliasList.Contains(name))
            {
                throw new ArgumentException("Command name cannot be one of its aliases.", nameof(name));
            }

            Name = name;
            return(this);
        }
Esempio n. 11
0
 public IAliasable ClearAliasList()
 {
     AliasList.Clear(); return(this);
 }
Esempio n. 12
0
 public IAliasable AddAlias(string sAliasable)
 {
     AliasList.Add(sAliasable); return(this);
 }
Esempio n. 13
0
        /// <summary>
        /// Button event to create a package.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ButtonCreate_Click(object sender, RoutedEventArgs e)
        {
            int count = AliasList.SelectedCount() + TriggerList.SelectedCount() + DirectionList.SelectedCount();

            if (count == 0)
            {
                var msgbox = new MessageBoxDialog()
                {
                    Title   = "Info",
                    Content = "No items were selected to create a package from.",
                };

                await msgbox.ShowAsync();

                return;
            }

            var package = new Package
            {
                GameAddress = App.Settings.ProfileSettings.IpAddress
            };

            foreach (object obj in AliasList.DataList.SelectedItems)
            {
                // Make sure the item is an Alias.  The last item in the list which is a new record is sometimes
                // an different object type.
                if (obj is Alias item)
                {
                    var alias = (Alias)item.Clone();
                    alias.Count     = 0;
                    alias.Character = "";
                    package.AliasList.Add(alias);
                }
            }

            foreach (object obj in TriggerList.DataList.SelectedItems)
            {
                // Make sure the item is an Alias.  The last item in the list which is a new record is sometimes
                // an different object type.
                if (obj is Common.Triggers.Trigger item)
                {
                    var trigger = (Common.Triggers.Trigger)item.Clone();
                    trigger.Character   = "";
                    trigger.LastMatched = DateTime.MinValue;
                    trigger.Count       = 0;
                    package.TriggerList.Add(trigger);
                }
            }

            foreach (object obj in DirectionList.DataList.SelectedItems)
            {
                // Make sure the item is an Alias.  The last item in the list which is a new record is sometimes
                // an different object type.
                if (obj is Direction item)
                {
                    var direction = (Direction)item.Clone();
                    package.DirectionList.Add(direction);
                }
            }

            var dialog = new SaveFileDialog
            {
                InitialDirectory = App.Settings.AvalonSettings.SaveDirectory,
                Filter           = "JSON files (*.json)|*.json",
                Title            = "Save Package"
            };

            try
            {
                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    File.WriteAllText(dialog.FileName, Newtonsoft.Json.JsonConvert.SerializeObject(package, Newtonsoft.Json.Formatting.Indented));
                }
            }
            catch (Exception ex)
            {
                var msgbox = new MessageBoxDialog()
                {
                    Title   = "Error",
                    Content = ex.Message,
                };

                return;
            }

            this.Close();
        }
Esempio n. 14
0
 private void ShowCommentList()
 {
     AliasList.Show();
 }