/// <summary>Initializes a command service.</summary>
        /// <param name="client">WOLF client. Required.</param>
        /// <param name="options">Commands options that will be used as default when running a command. Required.</param>
        /// <param name="services">Services provider that will be used by all commands. Null will cause a backup provider to be used.</param>
        /// <param name="log">Logger to log messages and errors to. If null, all logging will be disabled.</param>
        /// <param name="cancellationToken">Cancellation token that can be used for cancelling all tasks.</param>
        public CommandsService(IWolfClient client, CommandsOptions options, ILogger log, IServiceProvider services = null, CancellationToken cancellationToken = default)
        {
            // init private
            this._commands           = new Dictionary <ICommandInstanceDescriptor, ICommandInstance>();
            this._lock               = new SemaphoreSlim(1, 1);
            this._cts                = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
            this._disposableServices = new List <IDisposable>(2);
            this._started            = false;

            // init required
            this._client  = client ?? services?.GetService <IWolfClient>() ?? throw new ArgumentNullException(nameof(client));
            this._options = options ?? services?.GetService <CommandsOptions>() ?? throw new ArgumentNullException(nameof(options));

            // init optionals
            this._log = log ?? services?.GetService <ILogger <CommandsService> >() ?? services?.GetService <ILogger <ICommandsService> >() ?? services.GetService <ILogger>();
            this._argumentConverterProvider = services?.GetService <IArgumentConverterProvider>() ?? CreateAsDisposable <ArgumentConverterProvider>();
            this._handlerProvider           = services?.GetService <ICommandsHandlerProvider>() ?? CreateAsDisposable <CommandsHandlerProvider>();
            this._argumentsParser           = services?.GetService <IArgumentsParser>() ?? new ArgumentsParser();
            this._parameterBuilder          = services?.GetService <IParameterBuilder>() ?? new ParameterBuilder();
            this._initializers   = services?.GetService <ICommandInitializerProvider>() ?? new CommandInitializerProvider();
            this._commandsLoader = services?.GetService <ICommandsLoader>() ?? new CommandsLoader(this._initializers, this._log);

            // init service provider - use combine, to use fallback one as well
            this._fallbackServices = this.CreateFallbackServiceProvider();
            this._services         = CombinedServiceProvider.Combine(services, this._fallbackServices);

            // register event handlers
            this._client.AddMessageListener <ChatMessage>(OnMessageReceived);
        }
 public Application(IConsoleWrapper consoleWrapper, IArgumentsParser argumentsParser,
                    IFileDetailsWrapper fileDetailsWrapper)
 {
     _consoleWrapper     = consoleWrapper;
     _argumentsParser    = argumentsParser;
     _fileDetailsWrapper = fileDetailsWrapper;
 }
Beispiel #3
0
 public ApplicationForm(IArgumentsParser <UserInterfaceArguments> argumentsParser)
 {
     this.argumentsParser = argumentsParser;
     Size       = new Size(800, 600);
     Text       = @"TagsCloudContainer";
     ShadowType = MetroFormShadowType.None;
     Controls.Add(InitTable());
 }
 internal ApplicationContext(Action <ApplicationConfiguration> application)
 {
     this._configuration = new ApplicationConfiguration();
     application?.Invoke(this._configuration);
     this._configuration.RegisterDependency((IApplicationContext)this);
     this._container = CastleWindsor.Initialize(this._configuration);
     this._parser    = this.Resolve <IArgumentsParser>();
     this._hosts     = this.Resolve <IHostFactory>().GetAll();
 }
 public CommandsApplication(
     IServiceProvider services, ICommandResolver commandResolver,
     IArgumentsParser argumentsParser, ICommandExecutor commandExecutor,
     ApplicationModel appModel)
 {
     _services        = services ?? throw new ArgumentNullException(nameof(services));
     _commandResolver = commandResolver ?? throw new ArgumentNullException(nameof(commandResolver));
     _argumentsParser = argumentsParser ?? throw new ArgumentNullException(nameof(argumentsParser));
     _commandExecutor = commandExecutor ?? throw new ArgumentNullException(nameof(commandExecutor));
     _appModel        = appModel ?? throw new ArgumentNullException(nameof(appModel));
 }
Beispiel #6
0
        public void Run(IArgumentsParser parser, params string[] args)
        {
            parser = parser ?? Parser.Unix;

            if (!TryDelegate(args))
            {
                parser.ParseArgs(args, Arguments);
                Validate();
                Execute();
            }
        }
Beispiel #7
0
        public async Task RunAsync(IArgumentsParser parser, params string[] args)
        {
            parser = parser ?? Parser.Unix;

            if (!TryDelegate(args))
            {
                parser.ParseArgs(args, Arguments);
                Validate();
                await ExecuteAsync();
            }
        }
        public void Setup()
        {
            _mockArgumentsParser    = MockRepository.GenerateMock <IArgumentsParser>();
            _mockFileDetailsWrapper = MockRepository.GenerateMock <IFileDetailsWrapper>();
            _stubConsoleWrapper     = MockRepository.GenerateStub <IConsoleWrapper>();

            _dummyParsedArguments = new Arguments(OperationType.GetSize, DUMMY_FILE_PATH);
            _dummyArgs            = new[] { string.Empty };

            _sut = new Application(_stubConsoleWrapper, _mockArgumentsParser, _mockFileDetailsWrapper);
        }
Beispiel #9
0
 public ApplicationFlow(ILogger <ApplicationFlow> logger,
                        IJobBatchOrchestrator jobBatchOrchestrator,
                        ICommandLineValidator commandLineValidator,
                        IArgumentsParser argumentsParser,
                        IJobContext jobContext)
 {
     this.commandLineValidator = commandLineValidator;
     this.argumentsParser      = argumentsParser;
     this.jobContext           = jobContext;
     this.logger = logger;
     this.jobBatchOrchestrator = jobBatchOrchestrator;
 }
        public Application(ILogManager logManager, IArgumentsParser argumentsParser, IWordsLoader wordsLoader,
                           IAdjacentWordsAppender adjacentWordsAppender, IBreadthFirstSearch breadthFirstSearch)
        {
            if (_logger == null)
            {
                _logger = logManager.GetLogger("Application");
            }

            _argumentsParser       = argumentsParser;
            _wordsLoader           = wordsLoader;
            _adjacentWordsAppender = adjacentWordsAppender;
            _breadthFirstSearch    = breadthFirstSearch;
        }
Beispiel #11
0
        /// <inheritdoc/>
        public Task <ICommandResult> CheckMatchAsync(ICommandContext context, IServiceProvider services, CancellationToken cancellationToken = default)
        {
            // ignore non-text messages
            if (!(context.Message is ChatMessage message))
            {
                return(FailureResult());
            }
            if (!message.IsText)
            {
                return(FailureResult());
            }
            // ignore deleted messages (should never be the case, but let's make sure of it)
            if (message.IsDeleted)
            {
                return(FailureResult());
            }
            // ignore own messages
            if (message.SenderID == context.Client.CurrentUserID)
            {
                return(FailureResult());
            }

            // check prefix
            bool caseSensitive = this.CaseSensitivityOverride ?? context.Options.CaseSensitivity;

            if (!message.MatchesPrefixRequirement(
                    this.PrefixOverride ?? context.Options.Prefix,
                    this.PrefixRequirementOverride ?? context.Options.RequirePrefix,
                    caseSensitive, out int startIndex))
            {
                return(FailureResult());
            }

            // check command text - ironically, I'll use regex here cause it makes things much simpler
            Regex regex = caseSensitive ? _caseSensitiveRegex.Value : _caseInsensitiveRegex.Value;
            Match match = regex.Match(message.Text, startIndex);

            if (match?.Success != true)
            {
                return(FailureResult());
            }

            // parse arguments
            IArgumentsParser parser = services.GetRequiredService <IArgumentsParser>();

            string[] args = match.Groups.Count > 1 ? parser.ParseArguments(match.Groups[1].Value, 0).ToArray() : Array.Empty <string>();
            return(Task.FromResult <ICommandResult>(StandardCommandMatchResult.Success(args)));

            Task <ICommandResult> FailureResult() => Task.FromResult <ICommandResult>(StandardCommandMatchResult.Failure);
        }
Beispiel #12
0
        private static void ProcessGraph(IArgumentsParser parser, TextWriter writer)
        {
            IGraphLoader loader = ServiceLocator.Current.GetInstance <IGraphLoader>();
            IList <Node> graph  = loader.LoadGraph(parser.Path, writer);

            IGraphStorageService storage = ServiceLocator.Current.GetInstance <IGraphStorageService>();

            if (parser.UseRecreationMode)
            {
                storage.DeleteGraph();
                writer.WriteLine("Old graph has been deleted.");
            }

            storage.SaveGraph(graph);
            writer.WriteLine("Graph data has been saved.");
            writer.Flush();
        }
 internal ApplicationContext(Action <ApplicationConfiguration> application)
 {
     this._configuration = new ApplicationConfiguration();
     if (application != null)
     {
         application(this._configuration);
     }
     this._configuration.RegisterDependency <IApplicationContext>(this);
     if (this._configuration.IgnoreSslErrors)
     {
         ServicePointManager.ServerCertificateValidationCallback = (RemoteCertificateValidationCallback)Delegate.Combine(ServicePointManager.ServerCertificateValidationCallback, new RemoteCertificateValidationCallback((object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true));
     }
     this._container = CastleWindsor.Initialize(this._configuration);
     this._parser    = this.Resolve <IArgumentsParser>();
     this._hosts     = this.Resolve <IHostFactory>().GetAll();
     AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(this.LogException);
 }
Beispiel #14
0
        public static void Main(string[] args)
        {
            Activator.Initialise();

            IArgumentsParser parser = ServiceLocator.Current.GetInstance <IArgumentsParser>();

            parser.Parse(args);

            using (TextWriter writer = new StreamWriter(Console.OpenStandardOutput()))
            {
                if (!parser.AreValid || parser.IsHelpPageRequested)
                {
                    ShowHelp(writer);
                    Console.ReadLine();
                    return;
                }

                ProcessGraph(parser, writer);
            }

            Console.ReadLine();
        }
Beispiel #15
0
 public Launcher(IArgumentsParser argumentsParser, IURLGenerator URLGenerator, ICsvHandler csvHandler)
 {
     _argumentsParser = argumentsParser;
     _URLGenerator    = URLGenerator;
     _csvHandler      = csvHandler;
 }
Beispiel #16
0
 public void SetUp()
 {
     _argumentsParser = A.Fake <IArgumentsParser>();
     _calculator      = A.Fake <ICalculator>();
     _sut             = new Application(_argumentsParser, _calculator);
 }
Beispiel #17
0
 public Application(IArgumentsParser argumentsParser, ICalculator calculator)
 {
     _argumentsParser = argumentsParser;
     _calculator      = calculator;
 }
Beispiel #18
0
 public ConsoleUserInterface(IArgumentsParser <UserInterfaceArguments> argumentsParser)
 {
     this.argumentsParser = argumentsParser;
 }
Beispiel #19
0
 public void SetUp()
 {
     _sut = new ArgumentsParser();
 }
 public URLGenerator(IArgumentsParser argumentsParser)
 {
     _argumentsParser = argumentsParser;
 }
Beispiel #21
0
 public Application(IArgumentsParser argumentsParser, ICalculator calculator)
 {
     _argumentsParser = argumentsParser;
     _calculator = calculator;
 }