Ejemplo n.º 1
0
 public CommandDispatchContext(CommandDescriptor command, ParsedCommandLine parsedCommandLine, object commandTarget, CancellationToken cancellationToken)
 {
     Command           = command;
     ParsedCommandLine = parsedCommandLine;
     CommandTarget     = commandTarget;
     CancellationToken = cancellationToken;
 }
Ejemplo n.º 2
0
        public void ResolveOverload_No_Overloads()
        {
            var matcher           = new CoconaCommandMatcher();
            var command           = CreateCommand("A", Array.Empty <ICommandParameterDescriptor>());
            var parsedCommandLine = new ParsedCommandLine(new CommandOption[] { }, new CommandArgument[] { }, new string[] { });
            var resolved          = matcher.ResolveOverload(command, parsedCommandLine);

            resolved.Should().NotBeNull();
        }
Ejemplo n.º 3
0
        public void ResolveOverload_Ambiguous()
        {
            var matcher        = new CoconaCommandMatcher();
            var commandOption0 = new CommandOptionDescriptor(typeof(bool), "foo", new[] { 'm' }, string.Empty, CoconaDefaultValue.None, null, CommandOptionFlags.None, Array.Empty <Attribute>());
            var commandOption1 = new CommandOptionDescriptor(typeof(bool), "bar", new[] { 'm' }, string.Empty, CoconaDefaultValue.None, null, CommandOptionFlags.None, Array.Empty <Attribute>());
            var command        = CreateCommand(
                "A",
                new ICommandParameterDescriptor[]
            {
                commandOption0, commandOption1
            },
                new CommandOverloadDescriptor[]
            {
                new CommandOverloadDescriptor(commandOption0, null, CreateCommand("A2", Array.Empty <ICommandParameterDescriptor>()), StringComparer.OrdinalIgnoreCase),
                new CommandOverloadDescriptor(commandOption0, null, CreateCommand("A3", Array.Empty <ICommandParameterDescriptor>()), StringComparer.OrdinalIgnoreCase),
            });
            var parsedCommandLine = new ParsedCommandLine(new CommandOption[] { new CommandOption(commandOption0, "true") }, new CommandArgument[] { }, new string[] { });

            Assert.Throws <CoconaException>(() => matcher.ResolveOverload(command, parsedCommandLine));
        }
Ejemplo n.º 4
0
        public void ResolveOverload_Overload_1()
        {
            var matcher       = new CoconaCommandMatcher();
            var commandOption = new CommandOptionDescriptor(typeof(string), "mode", new[] { 'm' }, string.Empty, CoconaDefaultValue.None, null, CommandOptionFlags.None, Array.Empty <Attribute>());
            var command       = CreateCommand(
                "A",
                new ICommandParameterDescriptor[]
            {
                commandOption
            },
                new CommandOverloadDescriptor[]
            {
                new CommandOverloadDescriptor(commandOption, "foo", CreateCommand("A2", Array.Empty <ICommandParameterDescriptor>()), StringComparer.OrdinalIgnoreCase),
                new CommandOverloadDescriptor(commandOption, "bar", CreateCommand("A3", Array.Empty <ICommandParameterDescriptor>()), StringComparer.OrdinalIgnoreCase),
            });
            var parsedCommandLine = new ParsedCommandLine(new CommandOption[] { }, new CommandArgument[] { }, new string[] { });
            var resolved          = matcher.ResolveOverload(command, parsedCommandLine);

            resolved.Should().NotBeNull();
            resolved.Name.Should().Be("A");
        }
Ejemplo n.º 5
0
        public CommandDescriptor ResolveOverload(CommandDescriptor command, ParsedCommandLine parsedCommandLine)
        {
            var valueByOption = parsedCommandLine.Options.ToDictionary(k => k.Option, v => v);

            var resolvedCommand = default(CommandDescriptor);

            foreach (var overloadCommand in command.Overloads)
            {
                if (valueByOption.TryGetValue(overloadCommand.Option, out var value))
                {
                    if ((overloadCommand.Value == null) || (value.Value != null && overloadCommand.Comparer.Equals(value.Value, overloadCommand.Value)))
                    {
                        if (resolvedCommand != null)
                        {
                            throw new CoconaException($"Command '{command.Name}' and option '{overloadCommand.Option}' has option overloads more than one.");
                        }
                        resolvedCommand = overloadCommand.Command;
                        continue;
                    }
                }
            }

            return(resolvedCommand ?? command);
        }
Ejemplo n.º 6
0
        static int Main(string[] arguments)
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                string connectionString = CM.AppSettings["connectionString"];

                if (string.IsNullOrEmpty(connectionString))
                {
                    Console.WriteLine("Connection string not specified");
                    return(1);
                }

                CommandLineParser parser = new CommandLineParser();
                ParsedCommandLine parsed = parser.Parse(arguments);
                if (parsed.PositionalArguments.Count != 0)
                {
                    connectionString = parsed.PositionalArguments[0];
                }

                using (IrbisConnection connection = new IrbisConnection(connectionString))
                {
                    int maxMfn = connection.GetMaxMfn();

                    string expression = RequestPrefixes.Unfulfilled /* I=0 */
                                        + " + "
                                        + RequestPrefixes.Reserved; /* I=2 */

                    if (parsed.HaveSwitch("expression"))
                    {
                        expression = parsed.GetSwitch("expression")
                                     .ThrowIfNull()
                                     .Value;
                    }

                    expression = expression.ThrowIfNull("expression");

                    Console.Write("Reading good records ");

                    MarcRecord[] goodRecords = BatchRecordReader.Search
                                               (
                        connection,
                        connection.Database,
                        expression,
                        1000,
                        batch => Console.Write(".")
                                               )
                                               .ToArray();

                    Console.WriteLine();
                    Console.WriteLine
                    (
                        "Good records loaded: {0}",
                        goodRecords.Length
                    );

                    if (goodRecords.Length == maxMfn)
                    {
                        Console.WriteLine("No truncation needed, exiting");
                        return(0);
                    }

                    connection.TruncateDatabase(connection.Database);

                    Console.WriteLine("Database truncated");

                    using (BatchRecordWriter writer = new BatchRecordWriter
                                                      (
                               connection,
                               connection.Database,
                               500
                                                      ))
                    {
                        foreach (MarcRecord record in goodRecords)
                        {
                            record.Version = 0;
                            record.Mfn     = 0;
                            writer.Append(record);
                        }
                    }

                    Console.WriteLine("Good records restored");

                    stopwatch.Stop();
                    Console.WriteLine
                    (
                        "Elapsed: {0}",
                        stopwatch.Elapsed.ToAutoString()
                    );
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                return(1);
            }

            return(0);
        }
Ejemplo n.º 7
0
        static int Main(string[] arguments)
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                string connectionString = ConfigurationManager.AppSettings["connectionString"];

                if (string.IsNullOrEmpty(connectionString))
                {
                    Console.WriteLine("Connection string not specified");
                    return(1);
                }

                CommandLineParser parser = new CommandLineParser();
                ParsedCommandLine parsed = parser.Parse(arguments);
                if (parsed.PositionalArguments.Count != 0)
                {
                    connectionString = parsed.PositionalArguments[0];
                }

                string searchExpression = "V=01  + V=02";
                string filterExpression = null;

                if (parsed.HaveSwitch("search"))
                {
                    searchExpression = parsed.GetSwitch("search")
                                       .ThrowIfNull().Value;
                }

                searchExpression = searchExpression.ThrowIfNull();

                if (parsed.HaveSwitch("filter"))
                {
                    filterExpression = parsed.GetSwitch("filter")
                                       .ThrowIfNull().Value;
                }

                using (IrbisConnection connection
                           = new IrbisConnection(connectionString))
                {
                    IEnumerable <MarcRecord> allRecords = BatchRecordReader.Search
                                                          (
                        connection,
                        connection.Database,
                        searchExpression,
                        500,
                        batch => Console.Write(".")
                                                          );
                }

                stopwatch.Stop();
                Console.WriteLine
                (
                    "Elapsed: {0}",
                    stopwatch.Elapsed.ToAutoString()
                );
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                return(1);
            }

            return(0);
        }
 public CoconaCommandExecutingContext(CommandDescriptor command, ParsedCommandLine parsedCommandLine, object commandTarget)
 {
     Command           = command ?? throw new ArgumentNullException(nameof(command));
     ParsedCommandLine = parsedCommandLine ?? throw new ArgumentNullException(nameof(parsedCommandLine));
     CommandTarget     = commandTarget ?? throw new ArgumentNullException(nameof(commandTarget));
 }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            try
            {
                CommandLineParser parser      = new CommandLineParser();
                ParsedCommandLine commandLine = parser.Parse(args);

                CommandLineSwitch flag = commandLine.GetSwitch("V");
                if (!ReferenceEquals(flag, null))
                {
                    Console.WriteLine("mx64 version {0}", MxExecutive.Version);
                    return;
                }

                string fileToExecute    = commandLine.GetArgument(0, null);
                string commandToExecute = null;

                flag = commandLine.GetSwitch("c");
                if (!ReferenceEquals(flag, null))
                {
                    commandToExecute = flag.Value;
                }

                using (executive = new MxExecutive())
                {
                    flag = commandLine.GetSwitch("q");
                    if (!ReferenceEquals(flag, null))
                    {
                        executive.VerbosityLevel = 0;
                    }

                    if (!executive.ExecuteInitScript())
                    {
                        return;
                    }

                    if (!ReferenceEquals(commandToExecute, null))
                    {
                        executive.ExecuteLine(commandToExecute);
                    }
                    else if (ReferenceEquals(fileToExecute, null))
                    {
                        if (executive.VerbosityLevel >= 3)
                        {
                            executive.Banner();
                        }

                        executive.Repl();
                        executive.GetCommand <DisconnectCommand>()
                        .Execute(executive, MxArgument.EmptyArray);
                    }
                    else
                    {
                        executive.ExecuteFile(fileToExecute);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Ejemplo n.º 10
0
 public IReadOnlyList <CompletionCandidateValue> GetCandidates(CoconaCompletionCandidatesMetadata metadata, ParsedCommandLine parsedCommandLine)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
 public IReadOnlyList <CompletionCandidateValue> GetCandidates(CoconaCompletionCandidatesMetadata metadata, ParsedCommandLine parsedCommandLine)
 => parsedCommandLine.Options.Any(x => x.Option.Name == "group" && string.Equals(x.Value, "trysail", StringComparison.OrdinalIgnoreCase))
         ? _resultsTrySail
         : _resultsSphere;