コード例 #1
0
ファイル: CommandExecutor.cs プロジェクト: momothink/PLSoft
        private bool HasPermissionOnCmd(IApplicationCommand cmd)
        {
            var permissionValidator = new PermissionAttributeValidator(cmd);
            var hasPermission       = permissionValidator.HasPermissionOnInstance();

            return(hasPermission);
        }
コード例 #2
0
ファイル: CommandExecutor.cs プロジェクト: momothink/PLSoft
        private string GetModuleName(IApplicationCommand cmd)
        {
            string moduleName = string.Format("{0}|{1}|{2}|{3}", Application.ProductName, CmdType,
                                              cmd.GetType().Assembly.GetName().Name, cmd.GetType().Name);

            return(moduleName);
        }
コード例 #3
0
        private async Task PublishAsync(IApplicationCommand command, ApplicationCommandReplySchemes replyScheme, CancellationToken token = default)
        {
            command.ReplyScheme = replyScheme;
            command.Topic       = _options.Topic;

            await _messagePublisher.PublishAsync(command, token).ConfigureAwait(false);
        }
コード例 #4
0
        public static async Task DeleteGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, RequestOptions options = null)
        {
            Preconditions.NotNull(command, nameof(command));
            Preconditions.NotEqual(command.Id, 0, nameof(command.Id));

            await client.ApiClient.DeleteGlobalApplicationCommandAsync(command.Id, options).ConfigureAwait(false);
        }
コード例 #5
0
        public static IDomainCommand FillFrom(this IDomainCommand domainCommand, IApplicationCommand applicationCommand)
        {
            domainCommand.ApplicationCommandId          = applicationCommand.Id;
            domainCommand.ApplicationCommandType        = applicationCommand.GetType().FullName;
            domainCommand.ApplicationCommandReplyScheme = applicationCommand.ReplyScheme;

            return(domainCommand);
        }
コード例 #6
0
        protected async Task DisableCommandRunTaskAndEnableCommandAsync(IApplicationCommand command)
        {
            await DisableCommandAsync(command.GetType());

            await command.ExecuteAsync(this);

            await EnableCommandAsync(command.GetType());
        }
コード例 #7
0
 public ApplicationCommandResult <TPayload> ExecuteCommand <TPayload>(IApplicationCommand command,
                                                                      ApplicationCommandReplySchemes replyScheme = ApplicationCommandReplySchemes.OnDomainCommandHandled)
 {
     return(ExecuteCommandAsync <TPayload>(command, replyScheme)
            .ConfigureAwait(false)
            .GetAwaiter()
            .GetResult());
 }
コード例 #8
0
        public async Task PublishAsync(IApplicationCommand command, CancellationToken token = default)
        {
            PreConditions.NotNull(command, nameof(command));

            command.Topic       = _options.Topic;
            command.ReplyScheme = ApplicationCommandReplySchemes.None;

            await _messagePublisher.PublishAsync(command, token);
        }
コード例 #9
0
        public void Publish(IApplicationCommand command)
        {
            PreConditions.NotNull(command, nameof(command));

            command.Topic       = _options.Topic;
            command.ReplyScheme = ApplicationCommandReplySchemes.None;

            _messagePublisher.Publish(command);
        }
        public static Task DeleteAsync(this IApplicationCommand command,
                                       IRestRequestOptions options = null, CancellationToken cancellationToken = default)
        {
            var client = command.GetRestClient();

            return(command.GuildId != null
                ? client.DeleteGuildApplicationCommandAsync(command.ApplicationId, command.GuildId.Value, command.Id, options, cancellationToken)
                : client.DeleteGlobalApplicationCommandAsync(command.ApplicationId, command.Id, options, cancellationToken));
        }
        public static Task <IApplicationCommand> ModifyAsync(this IApplicationCommand command,
                                                             Action <ModifyApplicationCommandActionProperties> action,
                                                             IRestRequestOptions options = null, CancellationToken cancellationToken = default)
        {
            var client = command.GetRestClient();

            return(command.GuildId != null
                ? client.ModifyGuildApplicationCommandAsync(command.ApplicationId, command.GuildId.Value, command.Id, action, options, cancellationToken)
                : client.ModifyGlobalApplicationCommandAsync(command.ApplicationId, command.Id, action, options, cancellationToken));
        }
コード例 #12
0
        public void AddCommand(IApplicationCommand command, bool defaultEnabled)
        {
            Commands.Add(command);
            var commandType = command.GetType();

            lock (EnableRequests) {
                EnableRequests[commandType] = 0;
            }
            lock (DisableRequests) {
                DisableRequests[commandType] = 0;
            }
            DefaultEnabled[commandType] = defaultEnabled;
        }
コード例 #13
0
        internal void Construct(IApplicationCommand command, ApplicationCommandArguments arguments, Func <Task <bool> > preCondition)
        {
            _command      = command;
            _preCondition = preCondition;
            _arguments    = arguments;

            title.Text    = command.Title;
            subtitle.Text = command.Subtitle;
            button.SetTitle(command.Label, UIControlState.Normal);

            subtitle.SizeToFit();
            button.SetBackgroundImage(Theme.CommandButton, UIControlState.Normal);
        }
コード例 #14
0
        public MainWindowViewModel(IRegionManager regionManager, IApplicationCommand applicationCommand,
                                   TmsClient nepse, IDialogService dialog, MeroshareClient meroshareClient, IConfiguration config)
        {
            _regionManager     = regionManager;
            _client            = nepse;
            _dialog            = dialog;
            _meroshareClient   = meroshareClient;
            _config            = config;
            ApplicationCommand = applicationCommand;

            applicationCommand.ShowMessage    = ShowMessage;
            _client.PromptCredentials         = GetTmsCredentials;
            _meroshareClient.PromptCredential = GetMeroShareCredentials;
        }
コード例 #15
0
        public async Task <ApplicationCommandResult> ExecuteCommandAsync(
            IApplicationCommand command,
            ApplicationCommandReplySchemes replyScheme = ApplicationCommandReplySchemes.OnDomainCommandHandled,
            CancellationToken token = default)
        {
            PreConditions.NotNull(command, nameof(command));

            await PublishAsync(command, replyScheme, token);

            var promise = new ApplicationCommandExecutionPromise(command);

            _commandResultListener.AddExecutingPromise(promise);

            return(await promise.Future.ConfigureAwait(false));
        }
コード例 #16
0
ファイル: CommandExecutor.cs プロジェクト: momothink/PLSoft
        private void Execute(IApplicationCommand cmd, bool log, bool audit)
        {
            if (audit && cmd.Audit)
            {
                AuditCommand(cmd);
            }

            if (HasPermissionOnCmd(cmd))
            {
                cmd.Execute();
            }
            else
            {
                ShowNoPermissionMessage();
            }
        }
コード例 #17
0
        private static TArg GetApplicationCommandProperties<TArg>(IApplicationCommand command)
            where TArg : ApplicationCommandProperties
        {
            bool isBaseClass = typeof(TArg) == typeof(ApplicationCommandProperties);

            switch (true)
            {
                case true when (typeof(TArg) == typeof(SlashCommandProperties) || isBaseClass) && command.Type == ApplicationCommandType.Slash:
                    return new SlashCommandProperties() as TArg;
                case true when (typeof(TArg) == typeof(MessageCommandProperties) || isBaseClass) && command.Type == ApplicationCommandType.Message:
                    return new MessageCommandProperties() as TArg;
                case true when (typeof(TArg) == typeof(UserCommandProperties) || isBaseClass) && command.Type == ApplicationCommandType.User:
                    return new UserCommandProperties() as TArg;
                default:
                    throw new InvalidOperationException($"Cannot modify application command of type {command.Type} with the parameter type {typeof(TArg).FullName}");
            }
        }
コード例 #18
0
 public static Task DeleteUnknownApplicationCommandAsync(BaseDiscordClient client, ulong?guildId, IApplicationCommand command, RequestOptions options = null)
 {
     return(guildId.HasValue
         ? DeleteGuildCommandAsync(client, guildId.Value, command, options)
         : DeleteGlobalCommandAsync(client, command, options));
 }
コード例 #19
0
        public static async Task <ApplicationCommand> ModifyGuildCommandAsync(BaseDiscordClient client, IApplicationCommand command, ulong guildId,
                                                                              ApplicationCommandProperties arg, RequestOptions options = null)
        {
            var model = new ModifyApplicationCommandParams
            {
                Name = arg.Name,
                DefaultPermission = arg.IsDefaultPermission.IsSpecified
                        ? arg.IsDefaultPermission.Value
                        : Optional <bool> .Unspecified
            };

            if (arg is SlashCommandProperties slashProps)
            {
                Preconditions.NotNullOrEmpty(slashProps.Description, nameof(slashProps.Description));

                model.Description = slashProps.Description.Value;

                model.Options = slashProps.Options.IsSpecified
                    ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray()
                    : Optional <ApplicationCommandOption[]> .Unspecified;
            }

            return(await client.ApiClient.ModifyGuildApplicationCommandAsync(model, guildId, command.Id, options).ConfigureAwait(false));
        }
コード例 #20
0
        public static Task <ApplicationCommand> ModifyGuildCommandAsync <TArg>(BaseDiscordClient client, IApplicationCommand command, ulong guildId,
                                                                               Action <TArg> func, RequestOptions options = null) where TArg : ApplicationCommandProperties
        {
            var arg = GetApplicationCommandProperties <TArg>(command);

            func(arg);
            return(ModifyGuildCommandAsync(client, command, guildId, arg, options));
        }
コード例 #21
0
        public static async Task <ApplicationCommand> ModifyGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command,
                                                                               ApplicationCommandProperties args, RequestOptions options = null)
        {
            if (args.Name.IsSpecified)
            {
                Preconditions.AtMost(args.Name.Value.Length, 32, nameof(args.Name));
                Preconditions.AtLeast(args.Name.Value.Length, 1, nameof(args.Name));
            }

            var model = new ModifyApplicationCommandParams
            {
                Name = args.Name,
                DefaultPermission = args.IsDefaultPermission.IsSpecified
                        ? args.IsDefaultPermission.Value
                        : Optional <bool> .Unspecified
            };

            if (args is SlashCommandProperties slashProps)
            {
                if (slashProps.Description.IsSpecified)
                {
                    Preconditions.AtMost(slashProps.Description.Value.Length, 100, nameof(slashProps.Description));
                    Preconditions.AtLeast(slashProps.Description.Value.Length, 1, nameof(slashProps.Description));
                }

                if (slashProps.Options.IsSpecified)
                {
                    if (slashProps.Options.Value.Count > 10)
                    {
                        throw new ArgumentException("Option count must be 10 or less");
                    }
                }

                model.Description = slashProps.Description;

                model.Options = slashProps.Options.IsSpecified
                    ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray()
                    : Optional <ApplicationCommandOption[]> .Unspecified;
            }

            return(await client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options).ConfigureAwait(false));
        }
コード例 #22
0
 public void SetApplicationCommand(IApplicationCommand command)
 {
     _applicationCommand = command;
 }
コード例 #23
0
 public ApplicationCommandExecutionPromise(IApplicationCommand command)
 {
     ApplicationCommand = command;
     _completionSource  = new TaskCompletionSource <ApplicationCommandResult>();
 }
コード例 #24
0
 public TmsLiveMarketPageViewModel(IApplicationCommand appCommand, TmsClient client)
     : base(appCommand)
 {
     _client = client;
 }
コード例 #25
0
 public ActiveAwareBindableBase(IApplicationCommand appCommand)
 {
     AppCommand = appCommand;
     AppCommand.RefreshCommand.RegisterCommand(RefreshCommand);
 }
コード例 #26
0
 public ApplicationCommandResult <TResult> ExecuteCommand <TResult>(
     IApplicationCommand command,
     ApplicationCommandReplySchemes replyScheme = ApplicationCommandReplySchemes.OnDomainCommandHandled)
 => _executor.ExecuteCommand <TResult>(command, replyScheme);
コード例 #27
0
 public async Task <ApplicationCommandResult <TPayload> > ExecuteCommandAsync <TPayload>(IApplicationCommand command, CancellationToken token = default)
 {
     return(await ExecuteCommandAsync <TPayload>(command, ApplicationCommandReplySchemes.OnDomainCommandHandled, token)
            .ConfigureAwait(false));
 }
コード例 #28
0
ファイル: CommandBinding.cs プロジェクト: lhrolim/softwrench
 public CommandBinding(IApplicationCommand command)
 {
     _command = command;
 }
 public MeroShareAsbaApplicationReportPageViewModel(IApplicationCommand appCommand,
                                                    MeroshareClient client, IDialogService dialog) : base(appCommand)
 {
     _client = client;
     _dialog = dialog;
 }
コード例 #30
0
 public async Task <ApplicationCommandResult <TResult> > ExecuteCommandAsync <TResult>(
     IApplicationCommand command,
     ApplicationCommandReplySchemes replyScheme = ApplicationCommandReplySchemes.OnDomainCommandHandled,
     CancellationToken token = default)
 => await _executor.ExecuteCommandAsync <TResult>(command, replyScheme, token);