public async Task <VerificationProvider> UpdateVerificationProvider(VerificationProvider verificationProvider)
        {
            _context.Update(verificationProvider);
            await _context.SaveChangesAsync();

            return(verificationProvider);
        }
Пример #2
0
            /// <summary>
            /// Initializes a new instance of the <see cref="ObjectConverterRegistration"/> class.
            /// </summary>
            /// <param name="targetType">The type of conversion supported by the registered converter.</param>
            /// <param name="objectCreator">A function used to create an instance of the registered
            /// <see cref="IObjectConverter"/> implementation.</param>
            /// <exception cref="ArgumentNullException">Thrown when the given target type or object
            /// creation function is null.</exception>
            internal ObjectConverterRegistration(Type targetType, Func <IObjectConverter> objectCreator)
            {
                VerificationProvider.VerifyNotNull(objectCreator, "objectCreator");

                TargetType     = targetType;
                mObjectCreator = objectCreator;
            }
        private void HandleRegistration(string[] registrationParameters)
        {
            if (registrationParameters.Length != 2)
            {
                ConsoleHelper.WriteLine(ConsoleMessageType.Error,
                                        "Invalid number of values specified for command registration. Please specify the name and program path.");

                return;
            }

            // Extract the registration name and program path from the registration parameters
            string registrationName = registrationParameters[0];
            string programPath      = registrationParameters[1];

            VerificationProvider.VerifyValidString(registrationName, "registrationName");
            VerificationProvider.VerifyValidString(programPath, "programPath");

            // Check we haven't already made a registration with this name
            if (ApplicationContext.ProgramRegistrations.ContainsKey(registrationName))
            {
                ConsoleHelper.WriteLine(ConsoleMessageType.Warning,
                                        "A program has already been registered under the name '{0}' and will be overridden.",
                                        registrationName);
            }

            // Store the registration, overriding any existing registrations
            ApplicationContext.ProgramRegistrations[registrationName] = programPath;

            ConsoleHelper.WriteLine(ConsoleMessageType.Information,
                                    "A registration has been successfully made under '{0}' for the path '{1}'.",
                                    registrationName, programPath);
        }
        /// <summary>
        /// Registers the given information to make the command available for later execution.
        /// </summary>
        /// <typeparam name="TValue">The type of value expected to be handled by the execution action.</typeparam>
        /// <param name="name">The name of the command to be registered.</param>
        /// <param name="executionAction">The action to be executed when the command is triggered.</param>
        /// <exception cref="ArgumentException">Thrown when the given command name is not a valid string.</exception>
        /// <exception cref="ArgumentNullException">Thrown when the given execution action is null.</exception>
        /// <remarks>
        /// <para>
        /// If a command registration already exists under the given name, that registration will be overwritten
        /// by the given information.
        /// </para>
        /// </remarks>
        public void Register <TValue>(string name, Action <TValue> executionAction)
        {
            VerificationProvider.VerifyValidString(name, "name");
            VerificationProvider.VerifyNotNull(executionAction, "executionAction");

            mCommandRegistrations[name] = new ExecutableCommandRegistration <TValue>(name, executionAction, mObjectConverterFactory);
        }
Пример #5
0
 public TutorialServer(GlobalUserDataProvider gudp, VerificationProvider botVer, ProblemBoardService pbService, ProblemProvider problemProvider, ILocalization lang)
 {
     _gudp            = gudp;
     _botVer          = botVer;
     _pbService       = pbService;
     _problemProvider = problemProvider;
     _lang            = lang;
 }
        public async Task <VerificationProvider> AddVerificationProvider(VerificationProvider verificationProvider)
        {
            await _context.VerificationProvider.AddAsync(verificationProvider);

            await _context.SaveChangesAsync();

            return(verificationProvider);
        }
Пример #7
0
        /// <summary>
        /// Allows the application to be configured by derived classes.
        /// </summary>
        /// <param name="configuration">An action used to configure the rule set being used by the application for
        /// defining the context parameters for the command-line argument parsing operation.</param>
        /// <exception cref="ArgumentNullException">Thrown when the given configuration action is null.</exception>
        protected ConsoleApplication <TContext> Configure(Action <CommandLineRuleSet> configuration)
        {
            VerificationProvider.VerifyNotNull(configuration, "configuration");

            configuration.Invoke(mParser.RuleSet);

            return(this);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RunCommandApplicationContext"/> class.
        /// </summary>
        /// <param name="filePath">The path to which the context information should be written to and read from.</param>
        /// <exception cref="ArgumentException">Thrown when the given file path is not a valid string.</exception>
        public RunCommandApplicationContext(string filePath)
        {
            VerificationProvider.VerifyValidString(filePath, "filePath");

            mFilePath = filePath;

            // Make sure the directory exists
            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
        }
Пример #9
0
        /// <summary>
        /// Mimics the <see cref="Console.WriteLine(string, object[])"/> method while changing the color of the output message
        /// based on the specified message type.
        /// </summary>
        /// <param name="messageType">The type of message that is being displayed, which dictates the color of the output message.</param>
        /// <param name="format">The message to be displayed that may optionally contain markers for string formatting.</param>
        /// <param name="parameters">An optional collection of parameters to be formatted into the given message format.</param>
        /// <exception cref="ArgumentNullException">Thrown when the given message format is a null reference.</exception>
        public static void WriteLine(ConsoleMessageType messageType, string format, params object[] parameters)
        {
            VerificationProvider.VerifyNotNull(format, "format");

            ChangeConsoleColor(messageType);

            Console.WriteLine(format, parameters);
            Console.ResetColor();
        }
Пример #10
0
        /// <summary>
        /// Copies all configuration details from the given rule set into the current rule set.
        /// </summary>
        /// <param name="ruleSet">The rule set to copy the configuration details from.</param>
        /// <exception cref="ArgumentNullException">Thrown when the given rule set is null.</exception>
        public void Copy(CommandLineRuleSet ruleSet)
        {
            VerificationProvider.VerifyNotNull(ruleSet, "ruleSet");

            // Copy the configuration details
            Prefixes            = ruleSet.Prefixes;
            Separators          = ruleSet.Separators;
            AllowMultipleValues = ruleSet.AllowMultipleValues;
            AllowSwitches       = ruleSet.AllowSwitches;
        }
Пример #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExecutableCommandRegistration{TValue}"/> class.
        /// </summary>
        /// <typeparam name="TValue">The type of value expected to be handled by the execution action.</typeparam>
        /// <param name="name">The name of the command to be registered.</param>
        /// <param name="executionAction">The action to be invoked when the command is triggered.</param>
        /// <param name="objectConverterFactory">A factory used to create requested object converters.</param>
        /// <exception cref="ArgumentException">Thrown when the given name is an invalid string.</exception>
        /// <exception cref="ArgumentNullException">Thrown when the given or execution action object converter factory is null.</exception>
        internal ExecutableCommandRegistration(string name, Action <TValue> executionAction, ObjectConverterFactory objectConverterFactory)
        {
            VerificationProvider.VerifyValidString(name, "name");
            VerificationProvider.VerifyNotNull(executionAction, "executionAction");
            VerificationProvider.VerifyNotNull(objectConverterFactory, "objectConverterFactory");

            mName                   = name;
            mExecutionAction        = executionAction;
            mObjectConverterFactory = objectConverterFactory;
        }
Пример #12
0
        public WaitingRoomService(DiscordSocketClient client, ILocalization lang, VerificationProvider botVer)
        {
            _client = client;

            _lang = lang;

            _botVer = botVer;

            AlertedUserIds = new List <ulong>();
        }
Пример #13
0
        public async Task <IActionResult> PostPayment([FromBody] VerificationProvider provider)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _verificationProviderRepository.AddVerificationProvider(provider);

            return(CreatedAtAction("GetPayment", new { id = provider.VerificationProviderId }, provider));
        }
Пример #14
0
        /// <summary>
        /// Converts the given object value to an instance of the supported type.
        /// </summary>
        /// <param name="value">The object value to be converted.</param>
        /// <returns>A strongly-typed representation of the given value converted to the supported type.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the given value is null.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the given value cannot be converted to the target type.</exception>
        public TTarget Convert(object value)
        {
            VerificationProvider.VerifyNotNull(value, "value");

            // Attempt a direct cast to the target type
            if (value is TTarget)
            {
                return((TTarget)value);
            }

            return(ConvertCore(value));
        }
        /// <summary>
        /// Attempts to retrieve an executable command registered under the given name.
        /// </summary>
        /// <param name="name">The name of the command registration to find.</param>
        /// <returns>The executable command registered under the given name if it exists; otherwise null.</returns>
        /// <exception cref="ArgumentException">Thrown when the given command name is not a valid string.</exception>
        public IExecutableCommandRegistration GetCommandRegistration(string name)
        {
            VerificationProvider.VerifyValidString(name, "name");

            IExecutableCommandRegistration registration;

            if (!mCommandRegistrations.TryGetValue(name, out registration))
            {
                return(null);
            }

            return(registration);
        }
Пример #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConsoleApplication" /> class.
        /// </summary>
        /// <param name="applicationContext">An instance of the strongly-typed application context.</param>
        /// <param name="arguments">A collection of all arguments passed through to the application
        /// from the command line.</param>
        /// <exception cref="ArgumentNullException">Thrown when the given application context or collection of arguments is null.</exception>
        protected ConsoleApplication(TContext applicationContext, string[] arguments)
        {
            VerificationProvider.VerifyNotNull(applicationContext, "applicationContext");
            VerificationProvider.VerifyNotNull(arguments, "arguments");

            mRegistrar = new ExecutableCommandRegistrar(mObjectConverterFactory);

            mArguments = arguments;

            // Initialize and load the application context
            mApplicationContext = applicationContext;
            mApplicationContext.Load();
        }
Пример #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandResultSet"/> class.
        /// </summary>
        /// <param name="objectConverterFactory">A factory used to create requested object converters.</param>
        /// <param name="commands">A collection of commands to add to the set.</param>
        /// <exception cref="ArgumentNullException">Thrown when the given object converter factory or collection of commands is null.</exception>
        internal CommandResultSet(ObjectConverterFactory objectConverterFactory, IEnumerable <CommandResult> commands)
        {
            VerificationProvider.VerifyNotNull(objectConverterFactory, "objectConverterFactory");
            VerificationProvider.VerifyNotNull(commands, "commands");

            mObjectConverterFactory = objectConverterFactory;
            mCommands = commands;

            // Extract all commands that have a key value
            foreach (var command in commands)
            {
                mKeyedCommands[command.Key] = command;
            }
        }
Пример #18
0
        /// <summary>
        /// Parses the given collection of arguments based on the current parser rule set.
        /// </summary>
        /// <param name="arguments">A collection of all arguments passed through to the application
        /// from the command line.</param>
        /// <returns>A collection of commands resulting from the parse operation.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the given collection of arguments is null.</exception>
        public IEnumerable <CommandResult> Parse(string[] arguments)
        {
            VerificationProvider.VerifyNotNull(arguments, "arguments");

            var context = new CommandParsingContext(RuleSet);

            foreach (string argument in arguments)
            {
                var command = Parse(context, argument);
                if (command != null)
                {
                    yield return(command);
                }
            }
        }
Пример #19
0
        /// <summary>
        /// Executes the registered command by invoking the contained action.
        /// </summary>
        /// <param name="result">The result of the command parsing process pertinent to the registered command.</param>
        /// <exception cref="ArgumentNullException">Thrown when the given command result is null.</exception>
        /// <exception cref="InvalidOperationException">Thrown when invocation of the contained action fails.</exception>
        public void Execute(CommandResult result)
        {
            VerificationProvider.VerifyNotNull(result, "result");

            // Get hold of the relevant converter for the command value type
            var    converter = mObjectConverterFactory.Create <TValue>();
            TValue value     = converter.Convert(result.Value);

            try
            {
                mExecutionAction.Invoke(value);
            }
            catch (Exception ex)
            {
                // Wrap the exception within an InvalidOperationException and re-throw
                throw new InvalidOperationException(
                          "An error occurred while executing the command. See inner exception for details.", ex);
            }
        }
Пример #20
0
        public async Task InitializeAsync(DiscordSocketClient client)
        {
            _client         = client;
            Global.Client   = client;
            _commandService = new CommandService();

            _lang = Unity.Resolve <ILocalization>();

            _botVer = Unity.Resolve <VerificationProvider>();

            _waitingRoomService = Unity.Resolve <WaitingRoomService>();

            _problemBoardService = Unity.Resolve <ProblemBoardService>();

            _services = new ServiceCollection()
                        .AddSingleton(_client)
                        .AddSingleton(_commandService)
                        .AddSingleton(_lang)
                        .AddSingleton(Unity.Resolve <IDataStorage>())
                        .AddSingleton(Unity.Resolve <GlobalUserDataProvider>())
                        .AddSingleton(Unity.Resolve <AppConfig>())
                        .AddSingleton(Unity.Resolve <RpgRepository>())
                        .AddSingleton(Unity.Resolve <DiggingJobProvider>())
                        .AddSingleton(_waitingRoomService)
                        .AddSingleton(_problemBoardService)
                        .AddSingleton(Unity.Resolve <ProblemProvider>())
                        .AddSingleton(_botVer)
                        .BuildServiceProvider();

            await _commandService.AddModulesAsync(Assembly.GetEntryAssembly());

            _client.MessageReceived += HandleCommandAsync;
            _client.MessageReceived += _waitingRoomService.MessageReceived;
            _client.UserJoined      += _waitingRoomService.UserJoined;
            _client.UserLeft        += _waitingRoomService.UserLeft;

            _client.MessageReceived += _problemBoardService.MessageReceived;

            _client.ReactionAdded += DmDeletions.CheckDeletionRequest;
        }
Пример #21
0
        /// <summary>
        /// Attempts to retrieve a value from the set of commands that is stored under the given key.
        /// </summary>
        /// <typeparam name="TValue">The type of the value to be retrieved.</typeparam>
        /// <param name="key">The key of the command to retrieve.</param>
        /// <param name="value">An output parameter that will be populated with the requested value.</param>
        /// <returns>True if the given key matches a stored command; false otherwise.</returns>
        /// <exception cref="ArgumentException">Thrown when the given key value is not a valid string.</exception>
        public bool TryGetValue <TValue>(string key, out TValue value)
        {
            VerificationProvider.VerifyValidString(key, "key");

            // Initialize the output parameter with a default value
            value = default(TValue);

            CommandResult command;

            if (!mKeyedCommands.TryGetValue(key, out command))
            {
                // The command does not exist under the given key
                return(false);
            }

            // We have the command, so get hold of the relevant converter for its type
            var converter = mObjectConverterFactory.Create <TValue>();

            value = converter.Convert(command.Value);

            return(true);
        }
Пример #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandParsingContext"/> class.
        /// </summary>
        /// <param name="ruleSet">The rule set in use by the command parsing operations.</param>
        /// <exception cref="ArgumentNullException">Thrown when the given rule set is null.</exception>
        internal CommandParsingContext(CommandLineRuleSet ruleSet)
        {
            VerificationProvider.VerifyNotNull(ruleSet, "ruleSet");

            mRuleSet = ruleSet;
        }
Пример #23
0
 public Debug(GlobalUserDataProvider gudp, VerificationProvider botVer, DiscordSocketClient client)
 {
     _gudp   = gudp;
     _botVer = botVer;
     _client = client;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ExecutableCommandRegistrar"/> class.
        /// </summary>
        /// <param name="objectConverterFactory">A factory used to create requested object converters.</param>
        /// <exception cref="ArgumentNullException">Thrown when the given object converter factory is null.</exception>
        internal ExecutableCommandRegistrar(ObjectConverterFactory objectConverterFactory)
        {
            VerificationProvider.VerifyNotNull(objectConverterFactory, "objectConverterFactory");

            mObjectConverterFactory = objectConverterFactory;
        }