Exemplo n.º 1
0
        /// <summary>
        /// Adds a command to the collection.
        /// </summary>
        public void AddCommand(PluginCommand pluginCommand)
        {
            lock (_lock)
            {
                // First check for duplicate command names.
                foreach (var command in Commands)
                {
                    string duplicateCommandName = null;
                    foreach (var commandName1 in pluginCommand.CommandNames)
                    {
                        foreach (var commandName2 in command.CommandNames)
                        {
                            if (string.Equals(commandName1, commandName2, StringComparison.CurrentCultureIgnoreCase))
                            {
                                VChatPlugin.LogError($"Command with the name \"{Prefix}{duplicateCommandName}\" already exists, types {command.Type} and {pluginCommand.Type}.");
                                duplicateCommandName = commandName1;
                                break;
                            }
                        }
                    }
                }

                // Add the command, we currently don't care if a duplicate command name is found.
                _commands.Add(pluginCommand);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Registers a <see cref="Kamilla.Network.Viewing.Plugins.PluginCommand"/>.
        /// </summary>
        /// <param name="command">
        /// The <see cref="Kamilla.Network.Viewing.Plugins.PluginCommand"/> that should be registered.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// <c>command</c> is null.
        /// </exception>
        public override void RegisterPluginCommand(PluginCommand command)
        {
            if (m_pluginCommands.Contains(command))
            {
                throw new ArgumentException("Such command is already registered.", "command");
            }

            m_pluginCommands.Add(command);

            m_window.ThreadSafeBegin(_ =>
            {
                var item = new MenuItem();

                item.Header           = command.Title;
                item.InputGestureText = command.Gesture.GetDisplayString();
                item.Tag    = command;
                item.Click += (o, e) =>
                {
                    e.Handled = true;
                    command.Callback();
                };

                _.ui_miPlugins.Items.Add(item);
                _.ui_miPlugins.IsEnabled = true;
            });
        }
Exemplo n.º 3
0
 private void ProcessPluginRequest(PluginCommand cmd)
 {
     if (cmd.Name == "cliententerview" && cmd.Data == "version")
     {
         SendPluginCommand("cliententerview", "TAB", PluginTargetMode.Client);
     }
 }
Exemplo n.º 4
0
 async partial void ProcessEachPluginCommand(PluginCommand cmd)
 {
     if (cmd.Name == "cliententerview" && cmd.Data == "version")
     {
         await SendPluginCommand("cliententerview", "TAB", PluginTargetMode.Server);
     }
 }
Exemplo n.º 5
0
        public PlugIn()
        {
            // Defines the Command list, which will contain user commands, which a user can select
            // via the PlugIn Menu.
            Commands = new List <PluginCommand>();

            DataContext = this;

            // Every PlugIn needs at least an Activation command, which will be called by a user to activate the PlugIn.
            ActivatePlugin = new PluginCommand()
            {
                Command = new RelayCommand <object>(this.StartCommandExecute,
                                                    this.StartCommandCanExecute),
                CommandName    = "Start",
                CommandToolTip = "Start the PlugIn"
            };

            // Every PlugIn should provide a Termination command, which will be called when the PlugIn window is closed by the user. This can only
            // occur, if the PlugIn view is embedded in a docking window by the Editor.
            TerminatePlugin = new PluginCommand()
            {
                Command        = new RelayCommand <object>(this.StopCommandExecute, this.StopCommandCanExecute),
                CommandName    = "Stop",
                CommandToolTip = "Stop the PlugIn"
            };

            InitializeComponent();


            // Add the StartCommand (should exist in any PlugIn)
            Commands.Add(ActivatePlugin);

            // Add the Stop Command (should exist in any PlugIn)
            Commands.Add(TerminatePlugin);
        }
Exemplo n.º 6
0
 private void OnPluginCommand(UInt64 serverConnectionHandlerID, string pluginCommand)
 {
     if (PluginCommand != null)
     {
         var args = new PluginCommandEventArgs(new ServerConnectionHandler(serverConnectionHandlerID), pluginCommand);
         PluginCommand.Invoke(args);
     }
 }
Exemplo n.º 7
0
        private void UpdatePluginMenu()
        {
            int index = toolsToolStripMenuItem.DropDownItems.IndexOf(pluginToolsSeparatorItem) + 1;

            while (true)
            {
                if (index >= toolsToolStripMenuItem.DropDownItems.Count)
                {
                    break;
                }

                if (toolsToolStripMenuItem.DropDownItems[index] is ToolStripSeparator)
                {
                    break;
                }

                toolsToolStripMenuItem.DropDownItems.RemoveAt(index);
            }

            PluginCommand[] commands = PluginCommandRegistry.Commands;

            if (commands.Length == 0)
            {
                ToolStripItem item = new ToolStripMenuItem("No Plugin Commands");
                item.Enabled = false;

                toolsToolStripMenuItem.DropDownItems.Insert(index, item);
            }
            else
            {
                for (int i = 0; i < commands.Length; i++)
                {
                    PluginCommand command = commands[i];

                    ToolStripItem item = new ToolStripMenuItem(command.Text);
                    if (CurrentArchive == null)
                    {
                        item.Enabled = false;
                    }
                    else if (command.CheckConditions == null)
                    {
                        item.Enabled = true;
                    }
                    else
                    {
                        item.Enabled = command.CheckConditions(CurrentArchive);
                    }

                    item.Click += (sender, args) => command.Use(this, CurrentArchive);

                    toolsToolStripMenuItem.DropDownItems.Insert(index + i, item);
                }
            }
        }
Exemplo n.º 8
0
        public void Initialize(NetworkLogViewerBase viewer)
        {
            m_viewer  = viewer;
            m_command = new PluginCommand(this, Strings.Gossip_OpenParser,
                                          new KeyGesture(Key.G, ModifierKeys.Control | ModifierKeys.Alt), Clicked);

            viewer.ProtocolChanged   += new EventHandler(viewer_ProtocolChanged);
            viewer.NetworkLogChanged += new EventHandler(viewer_NetworkLogChanged);

            this.UpdateCommand();
            Console.WriteLine("Debug: Gossip Parser initialized.");
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HelloAml"/> class.
        /// </summary>
        public HelloAml()
        {
            // Defines the Command list, which will contain user commands, which a user can select
            // via the PlugIn Menu.
            Commands = new List <PluginCommand>();


            // Every PlugIn needs at least an Activation command, which will be called by a user to activate the PlugIn.
            ActivatePlugin = new PluginCommand()
            {
                Command = new RelayCommand <object>(this.StartCommandExecute,
                                                    this.StartCommandCanExecute),
                CommandName    = "Start",
                CommandToolTip = "Start the PlugIn"
            };

            // Every PlugIn should provide a Termination command, which will be called when the PlugIn window is closed by the user. This can only
            // occur, if the PlugIn view is embedded in a docking window by the Editor.
            TerminatePlugin = new PluginCommand()
            {
                Command        = new RelayCommand <object>(this.StopCommandExecute, this.StopCommandCanExecute),
                CommandName    = "Stop",
                CommandToolTip = "Stop the PlugIn"
            };

            InitializeComponent();


            // Add the StartCommand (should exist in any PlugIn)
            Commands.Add(ActivatePlugin);

            // Add the Stop Command (should exist in any PlugIn)
            Commands.Add(TerminatePlugin);

            // Add the change spelling command (an additional command, only for this special PlugIn)
            Commands.Add(new PluginCommand()
            {
                CommandName    = "Change Spelling",
                Command        = InvertCase,
                CommandToolTip = "Change from Uppercase to Lowercase and vice versa"
            });

            // Add the About Command (recommended to exist in any PlugIn)
            Commands.Add(new PluginCommand()
            {
                CommandName    = "About",
                Command        = AboutCommand,
                CommandToolTip = "Information about this PlugIn"
            });

            this.IsActive = false;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Attempts to find the command and executes it if found. see <see cref="TryFindCommand(string, out PluginCommand, out string)"/>.
        /// </summary>
        /// <param name="executedCommand">The executed command, if any.</param>
        /// <returns>True if successful</returns>
        public bool TryFindAndExecuteCommand(string input, Chat chat, out PluginCommand executedCommand)
        {
            if (TryFindCommand(input, out PluginCommand command, out string remainder))
            {
                if (command.Method != null)
                {
                    command.Method.Invoke(remainder, chat);
                    executedCommand = command;
                    return(true);
                }
            }

            executedCommand = null;
            return(false);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Compares the input string with the accepted command names for the provided command.
        /// Case insensitive check.
        /// </summary>
        /// <param name="input">The complete string that includes the prefix for the command and any optional arguments</param>
        /// <param name="command">The command that we're comparing for</param>
        /// <param name="remainder">The remainder message of the input</param>
        /// <returns>True if successful</returns>
        public bool IsValidCommandString(string input, PluginCommand command, out string remainder)
        {
            foreach (var commandName in command.CommandNames)
            {
                if (!string.IsNullOrEmpty(commandName) &&
                    (input.TrimEnd().Equals($"{Prefix}{commandName}", StringComparison.CurrentCultureIgnoreCase) ||
                     input.TrimEnd().StartsWith($"{Prefix}{commandName} ", StringComparison.CurrentCultureIgnoreCase)))
                {
                    remainder = input.Remove(0, Prefix.Length + commandName.Length).TrimStart();
                    return(true);
                }
            }

            remainder = input;
            return(false);
        }
Exemplo n.º 12
0
        private void RunCommand(PluginCommand command, object param = null)
        {
            Seri.SetModule(command.Name);
            Seri.Log.Here().Debug($"Run command {command.Name}");

            try
            {
                command.Execute(param);
            }
            catch (Exception ex)
            {
                Seri.LogException(ex);
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            Seri.Log.Here().Debug($"End command {command.Name}");
            Seri.SetModule(string.Empty);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Attempt to find the command based on the input, this is case insensitive.
        /// </summary>
        /// <param name="input">The string that comtains the prefix, command name and any arguments that are required</param>
        /// <param name="pluginCommand">The found command, if any.</param>
        /// <param name="remainder">The remainder message of the input, these are the arguments that can be used when executing the action of the command.</param>
        /// <returns>True if successful.</returns>
        public bool TryFindCommand(string input, out PluginCommand pluginCommand, out string remainder)
        {
            lock (_lock)
            {
                foreach (var command in Commands)
                {
                    if (IsValidCommandString(input, command, out remainder))
                    {
                        pluginCommand = command;
                        return(true);
                    }
                }
            }

            pluginCommand = null;
            remainder     = input;
            return(false);
        }
Exemplo n.º 14
0
        public PluginCommand GetCommand(string name)
        {
            string        alias   = name.ToLower();
            PluginCommand command = server.GetPluginCommand(alias);

            if ((command != null) && (command.GetPlugin() != this))
            {
                command = server.GetPluginCommand(description.Name.ToLower() + ":" + alias);
            }

            if ((command != null) && (command.GetPlugin() == this))
            {
                return(command);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Unregisters a <see cref="Kamilla.Network.Viewing.Plugins.PluginCommand"/>.
        /// </summary>
        /// <param name="command">
        /// The <see cref="Kamilla.Network.Viewing.Plugins.PluginCommand"/> that should be unregistered.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// <c>command</c> is null.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// The provided <see cref="Kamilla.Network.Viewing.Plugins.PluginCommand"/> is not
        /// registered with the current <see cref="Kamilla.Network.Viewing.NetworkLogViewerBase"/>.
        /// </exception>
        public override void UnregisterPluginCommand(PluginCommand command)
        {
            if (!m_pluginCommands.Contains(command))
            {
                throw new ArgumentException("Such command is not registered.", "command");
            }

            m_pluginCommands.Remove(command);

            m_window.ThreadSafeBegin(_ =>
            {
                _.ui_miPlugins.Items.Remove(
                    _.ui_miPlugins.Items
                    .Cast <MenuItem>()
                    .Single(item => (PluginCommand)((MenuItem)item).Tag == command)
                    );

                if (!_.ui_miPlugins.HasItems)
                {
                    _.ui_miPlugins.IsEnabled = false;
                }
            });
        }
Exemplo n.º 16
0
 public PluginCommandEventArgs(WillowTreeMain willowTreeMain, PluginCommand command)
 {
     _Command = command;
     _WTM     = willowTreeMain;
 }
Exemplo n.º 17
0
        public static void Seed(this ModelBuilder modelBuilder)
        {
            var dotnetBuildPlugin = new BuildPlugin()
            {
                Id                 = 1,
                Command            = "dotnet",
                PluginName         = ".NET Core",
                DockerImageName    = "mcr.microsoft.com/dotnet/core/sdk",
                DockerRegistryName = "microsoft%2Fdotnet"
            };
            var nodeBuildPlugin = new BuildPlugin()
            {
                Id                 = 2,
                Command            = "npm",
                PluginName         = "Node.js",
                DockerImageName    = "node",
                DockerRegistryName = "node"
            };

            var dotnetBuildCommand = new PluginCommand()
            {
                Id       = 1,
                Name     = "build",
                PluginId = dotnetBuildPlugin.Id
            };

            var dotnetRestoreCommand = new PluginCommand()
            {
                Id       = 2,
                Name     = "restore",
                PluginId = dotnetBuildPlugin.Id
            };

            var npmInstallCommand = new PluginCommand()
            {
                Id       = 3,
                Name     = "install",
                PluginId = nodeBuildPlugin.Id
            };

            //var buildPlugins = GenerateRandomBuildPlugins();
            //var groups = GenerateRandomGroups();
            //var pluginCommands = GenerateRandomPluginCommands(buildPlugins);
            //var users = GenerateRandomUsers();
            //var userSocialNetworks = GenerateRandomUserSocialNetworks(users, socialNetworks);
            //var projects = GenerateRandomProjects(users);
            //var buildHistories = GenerateRandomBuildHistories(users, projects);
            //var buildSteps = GenerateRandomBuildSteps(buildPlugins, projects);
            //var buildPluginParameters = GenerateRandomBuildPluginParameters(buildSteps);
            //var projectGroups = GenerateRandomProjectGroups(projects, groups);
            //var projectTriggers = GenerateRandomProjectTriggers(projects);
            //var teamMembers = GenerateRandomTeamMembers(groups, users);
            //var notifications = GenerateRandomNotifications();

            modelBuilder.Entity <BuildPlugin>().HasData(dotnetBuildPlugin, nodeBuildPlugin);
            //modelBuilder.Entity<Group>().HasData(groups);
            modelBuilder.Entity <PluginCommand>().HasData(dotnetRestoreCommand, dotnetBuildCommand, npmInstallCommand);
            //modelBuilder.Entity<User>().HasData(users);
            //modelBuilder.Entity<UserSocialNetwork>().HasData(userSocialNetworks);
            //modelBuilder.Entity<Project>().HasData(projects);
            //modelBuilder.Entity<BuildHistory>().HasData(buildHistories);
            //modelBuilder.Entity<BuildStep>().HasData(buildSteps);
            //modelBuilder.Entity<BuildPluginParameter>().HasData(buildPluginParameters);
            //modelBuilder.Entity<ProjectGroup>().HasData(projectGroups);
            //modelBuilder.Entity<ProjectTrigger>().HasData(projectTriggers);
            //modelBuilder.Entity<TeamMember>().HasData(teamMembers);
            //modelBuilder.Entity<Notification>().HasData(notifications);
        }
Exemplo n.º 18
0
        public PluginCommandMethodReturnValue ParsePluginCommand(string command)
        {
            var pluginCommand = PluginCommand.CreateWithParse(command);

            return(ShellPluginCommand(pluginCommand.PluginName, pluginCommand.PluginCommandContent));
        }
Exemplo n.º 19
0
 public bool IsValidCommandString(string input, PluginCommand command)
 => IsValidCommandString(input, command, out string _);
Exemplo n.º 20
0
 public void AddExportedCommand(PluginCommand cmd)
 {
     exported.Add(cmd.ExportedCommand, cmd);
 }
Exemplo n.º 21
0
 partial void ProcessEachPluginCommand(PluginCommand notifies);
Exemplo n.º 22
0
 /// <summary>
 /// Unregisters a <see cref="Kamilla.Network.Viewing.Plugins.PluginCommand"/>.
 /// </summary>
 /// <param name="command">
 /// The <see cref="Kamilla.Network.Viewing.Plugins.PluginCommand"/> that should be unregistered.
 /// </param>
 /// <exception cref="System.ArgumentNullException">
 /// <c>command</c> is null.
 /// </exception>
 /// <exception cref="System.ArgumentException">
 /// The provided <see cref="Kamilla.Network.Viewing.Plugins.PluginCommand"/> is not
 /// registered with the current <see cref="Kamilla.Network.Viewing.NetworkLogViewerBase"/>.
 /// </exception>
 public abstract void UnregisterPluginCommand(PluginCommand command);
Exemplo n.º 23
0
        public CDLSQIamltransformer()
        {
            cDLSQIcontroller = new CDLSQIcontroller(this);


            // Defines the Command list, which will contain user commands, which a user can select
            // via the PlugIn Menu.
            Commands = new List <PluginCommand>();

            // Every PlugIn needs at least an Activation command, which will be called by a user to activate the PlugIn.
            ActivatePlugin = new PluginCommand()
            {
                Command = new RelayCommand <object>(this.StartCommandExecute,
                                                    this.StartCommandCanExecute),
                CommandName    = "Start",
                CommandToolTip = "Start the PlugIn"
            };

            // Every PlugIn should provide a Termination command, which will be called when the PlugIn window is closed by the user. This can only
            // occur, if the PlugIn view is embedded in a docking window by the Editor.
            TerminatePlugin = new PluginCommand()
            {
                Command        = new RelayCommand <object>(this.StopCommandExecute, this.StopCommandCanExecute),
                CommandName    = "Stop",
                CommandToolTip = "Stop the PlugIn"
            };

            ReloadObjects = new PluginCommand()
            {
                Command        = new RelayCommand <object>(this.ReloadObjectsExecute, this.StopCommandCanExecute),
                CommandName    = "Reload Objects",
                CommandToolTip = "Reload all .amlx in the plugin folder"
            };

            InitializeComponent();

            // Add the StartCommand (should exist in any PlugIn)
            Commands.Add(ActivatePlugin);

            // Add the Stop Command (should exist in any PlugIn)
            Commands.Add(TerminatePlugin);

            Commands.Add(ReloadObjects);

            //// Add the change spelling command (an additional command, only for this special PlugIn)
            //Commands.Add(new PluginCommand()
            //{
            //    CommandName = "Load File",
            //    Command = InvertCase,
            //    CommandToolTip = "Load a new test file"
            //});

            // Add the About Command (recommended to exist in any PlugIn)
            Commands.Add(new PluginCommand()
            {
                CommandName    = "About",
                Command        = AboutCommand,
                CommandToolTip = "Information about this PlugIn"
            });

            this.IsActive = false;
        }
Exemplo n.º 24
0
 public CommandHandler(LoadedPlugin plugin, PluginCommand _command)
 {
     Parent  = plugin;
     Command = _command;
     ID      = string.Format("{0}->[{1}]", plugin.PluginID, _command.Name);
 }
Exemplo n.º 25
0
        public PlugIn()
        {
            // Defines the Command list, which will contain user commands, which a user can select
            // via the PlugIn Menu.
            Commands = new List <PluginCommand>();

            DataContext = this;

            // Every PlugIn needs at least an Activation command, which will be called by a user to activate the PlugIn.
            ActivatePlugin = new PluginCommand()
            {
                Command = new RelayCommand <object>(this.StartCommandExecute,
                                                    this.StartCommandCanExecute),
                CommandName    = "Start",
                CommandToolTip = "Start the PlugIn"
            };

            // Every PlugIn should provide a Termination command, which will be called when the PlugIn window is closed by the user. This can only
            // occur, if the PlugIn view is embedded in a docking window by the Editor.
            TerminatePlugin = new PluginCommand()
            {
                Command        = new RelayCommand <object>(this.StopCommandExecute, this.StopCommandCanExecute),
                CommandName    = "Stop",
                CommandToolTip = "Stop the PlugIn"
            };

            InitializeComponent();


            Counter.Text = "0";

            // Add the StartCommand (should exist in any PlugIn)
            Commands.Add(ActivatePlugin);

            // Add the Stop Command (should exist in any PlugIn)
            Commands.Add(TerminatePlugin);

            // ToolBar Integration
            ToolBarCommands = new List <PluginCommand>();

            CountAddCommand = new PluginCommand
            {
                Command        = new RelayCommand <object>(this.CountAddExecute, this.CountExecuteCanExecute),
                CommandName    = "Add",
                IsCheckable    = false,
                IsChecked      = false,
                CommandIcon    = new BitmapImage(new Uri("pack://application:,,,/PluginWithToolBar;component/Resource/appbar.add.png")),
                CommandToolTip = "Add 1"
            };

            CountSubCommand = new PluginCommand
            {
                Command        = new RelayCommand <object>(this.CountSubExecute, this.CountExecuteCanExecute),
                CommandName    = "Sub",
                IsCheckable    = false,
                IsChecked      = false,
                CommandIcon    = new BitmapImage(new Uri("pack://application:,,,/PluginWithToolBar;component/Resource/appbar.minus.png")),
                CommandToolTip = "Sub 1"
            };

            ToolBarCommands.Add(CountAddCommand);
            ToolBarCommands.Add(CountSubCommand);
        }