public void Multiple() { var text = "circle(radius:5),text(hello,font:12px Helvetica,x:10,y:10)"; var reader = new ArgumentReader(text); Assert.True(reader.TryRead(out var circleArg)); Assert.Equal("circle(radius:5)", circleArg.Value); Assert.True(reader.TryRead(out var textArg)); Assert.Equal("text(hello,font:12px Helvetica,x:10,y:10)", textArg.Value); Assert.False(reader.TryRead(out var _)); /* * var circle = (Circle)circleCommand; * * Assert.Equal(5, circle.Radius); * * Assert.True(reader.TryRead(out var c)); * * var textShape = (Text)c; * * Assert.Equal("hello", textShape.Content); * Assert.Equal(10, textShape.Box.X); * Assert.Equal(10, textShape.Box.Y); */ }
static IEnumerable <TItem> ApplyToAll <TItem>(this IEnumerable <TItem> items, bool hasId, Func <Type, string, object?> getArguments) { if (hasId) { if (ArgumentReader.TryReadIds(getArguments, out var values)) { var predicate = ExpressionBuilder <TItem> .BuildPredicate("Id", Comparison.In, values); items = items.Where(predicate.Compile()); } } if (ArgumentReader.TryReadWhere(getArguments, out var wheres)) { var predicate = ExpressionBuilder <TItem> .BuildPredicate(wheres); items = items.Where(predicate.Compile()); } items = Order(items, getArguments); if (ArgumentReader.TryReadSkip(getArguments, out var skip)) { items = items.Skip(skip); } if (ArgumentReader.TryReadTake(getArguments, out var take)) { items = items.Take(take); } return(items); }
static IEnumerable <TItem> ApplyToAll <TItem>(this IEnumerable <TItem> items, Func <Type, string, object> getArguments) { if (ArgumentReader.TryReadId(getArguments, out var values)) { var predicate = FuncBuilder <TItem> .BuildPredicate("Id", Comparison.In, values); items = items.Where(predicate); } foreach (var where in ArgumentReader.ReadWhere(getArguments)) { var predicate = FuncBuilder <TItem> .BuildPredicate(where); items = items.Where(predicate); } items = Order(items, getArguments); if (ArgumentReader.TryReadSkip(getArguments, out var skip)) { items = items.Skip(skip); } if (ArgumentReader.TryReadTake(getArguments, out var take)) { items = items.Take(take); } return(items); }
public void Mixed2() { var text = "circle(radius:5), x: 100px, y: 50px, color: rgba(255, 255, 255, 10%)"; var reader = new ArgumentReader(text); Assert.True(reader.TryRead(out var command)); Assert.True(reader.TryRead(out var x)); Assert.True(reader.TryRead(out var y)); Assert.True(reader.TryRead(out var color)); Assert.False(reader.TryRead(out _)); Assert.Equal("x", x.Name); Assert.Equal("y", y.Name); Assert.Equal("color", color.Name); Assert.Equal("100px", x.Value); Assert.Equal("50px", y.Value); Assert.Equal("rgba(255, 255, 255, 10%)", color.Value); }
static IQueryable <TItem> ApplyToAll <TItem>(this IQueryable <TItem> queryable, Func <Type, string, object> getArguments) { if (ArgumentReader.TryReadId(getArguments, out var values)) { var predicate = ExpressionBuilder <TItem> .BuildPredicate("ID", Comparison.In, values); queryable = queryable.Where(predicate); } foreach (var where in ArgumentReader.ReadWhere(getArguments)) { var predicate = ExpressionBuilder <TItem> .BuildPredicate(where); queryable = queryable.Where(predicate); } queryable = Order(queryable, getArguments); if (ArgumentReader.TryReadSkip(getArguments, out var skip)) { queryable = queryable.Skip(skip); } if (ArgumentReader.TryReadTake(getArguments, out var take)) { queryable = queryable.Take(take); } return(queryable); }
public static void Init(TestContext testContext) { argReader = new ArgumentReader(false, SwitchArgument.CreateHelpArgument(SwitchCharacter.Slash), "My Error Text", "Using: program.exe <filename> [/D] [/F=3]", "Example", "BlaBla", new PureArgument <String>("MyPureArgument", false, false, "Filename", "Pure Argument: %message%"), new SwitchArgument(SwitchCharacter.Slash, "D", "Switch D", "Switch D: %message%"), new SwitchedContentArgument <Int32>("SwitchedArgument", SwitchCharacter.Slash, "F", SeparatorCharacter.Equal, true, true, "Switched Content F", "Switched Content F: %message%")); }
public void SpecifyingAnOverridingArgument_CorrectlyAddedToSettings(SettingsTester settingsTest) { var args = new List<string> { settingsTest.Argument }; var argumentSettings = new ArgumentReader(args, GetDefaultSettings()).ParseArguments(); Assert.AreEqual(settingsTest.ExpectedValue, settingsTest.RangeSelector(argumentSettings)); }
public void GetValue(string[] arguments, string key, string expected) { var reader = new ArgumentReader(arguments); string actual = reader.GetValue(key); Assert.AreEqual(expected, actual, $"GetValue(\"{key}\")"); }
//[HlePspNotImplemented] public void Kprintf(string Format, CpuThreadState CpuThreadState) { var Arguments = new ArgumentReader(CpuThreadState); Arguments.LoadInteger(); // Skips format ConsoleUtils.SaveRestoreConsoleColor(ConsoleColor.Blue, () => { Console.Error.Write("{0}", CStringFormater.Sprintf(Format, Arguments)); }); }
public void Kprintf(string Format, CpuThreadState CpuThreadState) { var Arguments = new ArgumentReader(CpuThreadState); Arguments.LoadInteger(); // Skips format ConsoleUtils.SaveRestoreConsoleColor(ConsoleColor.Blue, () => { Console.Error.Write("{0}", CStringFormater.Sprintf(Format, Arguments)); }); }
public static IQueryable <TItem> ApplyGraphQlArguments <TItem>( this IQueryable <TItem> queryable, IResolveFieldContext context, List <string>?keyNames, bool applyOrder) where TItem : class { Guard.AgainstNull(nameof(queryable), queryable); Guard.AgainstNull(nameof(context), context); object?GetArguments(Type type, string x) => context.GetArgument(type, x); if (keyNames != null) { if (ArgumentReader.TryReadIds(GetArguments, out var values)) { var keyName = GetKeyName(keyNames); var predicate = ExpressionBuilder <TItem> .BuildPredicate(keyName, Comparison.In, values); queryable = queryable.Where(predicate); } if (ArgumentReader.TryReadId(GetArguments, out var value)) { var keyName = GetKeyName(keyNames); var predicate = ExpressionBuilder <TItem> .BuildPredicate(keyName, Comparison.Equal, new[] { value }); queryable = queryable.Where(predicate); } } if (ArgumentReader.TryReadWhere(GetArguments, out var wheres)) { var predicate = ExpressionBuilder <TItem> .BuildPredicate(wheres); queryable = queryable.Where(predicate); } if (applyOrder) { queryable = Order(queryable, GetArguments); if (ArgumentReader.TryReadSkip(GetArguments, out var skip)) { queryable = queryable.Skip(skip); } if (ArgumentReader.TryReadTake(GetArguments, out var take)) { queryable = queryable.Take(take); } } return(queryable); }
public void TestRead() { var reader = new ArgumentReader(new TestObjects.FakeAttributeReader()); var rawCommands = new Dictionary <string, string>(); rawCommands["test1"] = "test1arg"; rawCommands["test2"] = "test2arg"; var actualResult = (TestObjects.FakeArguments)reader.Read <TestObjects.FakeArguments>(rawCommands); Assert.Equal("test1arg", actualResult.Test1); Assert.Equal("test2arg", actualResult.Test2); }
public void Mixed1() { var text = "stroke:red,fill:blue"; var reader = new ArgumentReader(text); Assert.True(reader.TryRead(out var stroke)); Assert.True(reader.TryRead(out var file)); Assert.False(reader.TryRead(out _)); Assert.Equal("red", stroke.Value); }
public static Argument[] Parse(ReadOnlySpan <char> text) { var reader = new ArgumentReader(text); var args = new List <Argument>(); while (reader.TryRead(out var arg)) { args.Add(arg); } return(args.ToArray()); }
public void Single() { var text = "circle(radius:5)"; var reader = new ArgumentReader(text); Assert.True(reader.TryRead(out var command)); // var circle = command as Circle; // Assert.Equal(5, circle.Radius); Assert.False(reader.TryRead(out _)); }
protected object[] ReadArguments(Buffer buffer) { if (argument_reader == null) { argument_reader = method.DeclaringType.CreateDynamicMethodDelegate <ArgumentReader>(delegate(ILValue il_buffer) { return(new ILReturn( new ILNewPopulatedArray( typeof(object), method.GetEffectiveParameterTypes().Convert(t => ILSerialize.GenerateObjectRead(t, il_buffer)) ) )); }); } return(argument_reader(buffer)); }
static int Main(string[] args) { var reader = new ArgumentReader(args); var name = reader.GetValue("name"); Console.WriteLine($"Hello {name ?? "World"}!"); var manager = new MenuManager(BuildMainMenu(), Console.WriteLine); while (Running) { manager.Show(); manager.Select(Console.ReadLine()); } return(0); }
static IQueryable <TItem> ApplyToAll <TItem>(this IQueryable <TItem> queryable, Func <Type, string, object?> getArguments, List <string>?keyNames) where TItem : class { if (keyNames != null) { if (ArgumentReader.TryReadIds(getArguments, out var values)) { var keyName = GetKeyName(keyNames); var predicate = ExpressionBuilder <TItem> .BuildPredicate(keyName, Comparison.In, values); queryable = queryable.Where(predicate); } if (ArgumentReader.TryReadId(getArguments, out var value)) { var keyName = GetKeyName(keyNames); var predicate = ExpressionBuilder <TItem> .BuildPredicate(keyName, Comparison.Equal, new[] { value }); queryable = queryable.Where(predicate); } } if (ArgumentReader.TryReadWhere(getArguments, out var wheres)) { var predicate = ExpressionBuilder <TItem> .BuildPredicate(wheres); queryable = queryable.Where(predicate); } queryable = Order(queryable, getArguments); if (ArgumentReader.TryReadSkip(getArguments, out var skip)) { queryable = queryable.Skip(skip); } if (ArgumentReader.TryReadTake(getArguments, out var take)) { queryable = queryable.Take(take); } return(queryable); }
public void NoGivenArguments_GivesDefaultSettings() { var reader = new ArgumentReader(new List<string>(), new Settings(new HostnameAccessor())); var argumentSettings = reader.ParseArguments(); var defaultSettings = GetDefaultSettings(); foreach (FieldInfo field in typeof(Settings).GetFields(BindingFlags.Public | BindingFlags.Instance)) { if (field.FieldType == typeof(HostnameAccessor)) { var defaultAccessor = (HostnameAccessor)field.GetValue(defaultSettings); var actualAccessor = (HostnameAccessor)field.GetValue(defaultSettings); Assert.AreEqual(defaultAccessor.GetAll().Single(), actualAccessor.GetAll().Single()); } else { Assert.AreEqual(field.GetValue(defaultSettings), field.GetValue(argumentSettings)); } } }
static IEnumerable <TItem> Order <TItem>(IEnumerable <TItem> queryable, Func <Type, string, object> getArguments) { var items = queryable.ToList(); var orderBys = ArgumentReader.ReadOrderBy(getArguments).ToList(); IOrderedEnumerable <TItem> ordered; if (orderBys.Count > 0) { var orderBy = orderBys.First(); var property = FuncBuilder <TItem> .BuildPropertyExpression(orderBy.Path); if (orderBy.Descending) { ordered = items.OrderByDescending(property); } else { ordered = items.OrderBy(property); } } else { return(items); } foreach (var orderBy in orderBys.Skip(1)) { var property = FuncBuilder <TItem> .BuildPropertyExpression(orderBy.Path); if (orderBy.Descending) { ordered = ordered.ThenByDescending(property); } else { ordered = ordered.ThenBy(property); } } return(ordered); }
static IQueryable <TItem> Order <TItem>(IQueryable <TItem> queryable, Func <Type, string, object> getArguments) { var orderBys = ArgumentReader.ReadOrderBy(getArguments).ToList(); IOrderedQueryable <TItem> ordered; if (orderBys.Count > 0) { var orderBy = orderBys.First(); var property = PropertyCache <TItem> .GetProperty(orderBy.Path).Lambda; if (orderBy.Descending) { ordered = queryable.OrderByDescending(property); } else { ordered = queryable.OrderBy(property); } } else { return(queryable); } foreach (var orderBy in orderBys.Skip(1)) { var property = PropertyCache <TItem> .GetProperty(orderBy.Path).Lambda; if (orderBy.Descending) { ordered = ordered.ThenByDescending(property); } else { ordered = ordered.ThenBy(property); } } return(ordered); }
private void Application_Startup(object sender, StartupEventArgs e) { Arguments = new ArgumentReader(false, SwitchArgument.CreateHelpArgument(SwitchCharacter.Slash), new PureArgument <String>("File Name", true, true, ""), new SwitchArgument(SwitchCharacter.Slash, "nosplash", "")); Arguments.AllowUnknownArgs = true; if (!Arguments.EvaluateArguments(false, e.Args)) { MessageDialogEx.ShowDialog("The arguments are invalid!", "Error", MessageButtons.OK, MessageIcons.Error); return; } if (Arguments.ArgumentList[NOSPLASHSWITCH].IsSet) { new MainWindow().Show(); } else { new Splash().Show(); } }
public void SetUp() { argumenReader = new ArgumentReader(false); }
public void SpecifyingACustomRange_WithInvalidData_ThrowsException(string xiRange) { var argument = new List<string> { xiRange }; var argumentReader = new ArgumentReader(argument, GetDefaultSettings()); Assert.Throws<UsageException>(() => argumentReader.ParseArguments()); }
public void UnexpectedArgument_ThrowsException() { var arguments = new List<string> { "TotallyNonExistantArgument:0,1" }; var argumentReader = new ArgumentReader(arguments, GetDefaultSettings()); Assert.Throws<UsageException>(() => argumentReader.ParseArguments()); }
/// <summary> /// 控制台模式的主要过程。 /// </summary> /// <param name="args">程序的启动参数。</param> private static void Run(string[] args) { if (ConsoleWindow.IsStarted) { return; } else { ConsoleWindow.IsStarted = true; } var param = new ArgumentReader(args, true, new[] { "-e", "-t", "-o" }, new[] { "-h" }); if (param.GetSwitch("-h")) { ConsoleWindow.ShowHelp(); } else { var pages = new List <YanderePage>(); for (int i = 0; i <= ushort.MaxValue; i++) { var pageLink = param.GetParameter(i); if (pageLink is null) { break; } pageLink = ConsoleWindow.FormatPageLink(pageLink); var page = new YanderePage(pageLink); if (!YanderePage.IsYanderePage(page)) { throw new ArgumentException(new ArgumentException().Message, "PageLink"); } pages.Add(page); } if (pages.Count == 0) { pages.Add(new YanderePage(YanderePage.IndexPageLink)); } int enumCount = int.Parse(param.GetParameter("-e") ?? 0.ToString()); if (!(param.GetParameter("-t") is null)) { int maxThreads = int.Parse(param.GetParameter("-t")); if (maxThreads < 1) { throw new ArgumentOutOfRangeException("-t MaxThreads"); } ThreadPool.SetMaxThreads(maxThreads, maxThreads); } if (!(param.GetParameter("-o") is null)) { ConsoleWindow.OutFile = Path.GetFullPath(param.GetParameter("-o")); if (!Directory.Exists(Path.GetDirectoryName(ConsoleWindow.OutFile))) { throw new DirectoryNotFoundException(); } } foreach (var page in pages) { if (enumCount == 0) { ConsoleWindow.ExtractImageLinksAsync(page); } else { ConsoleWindow.EnumeratePageExtractAsync(page, enumCount); } } while (ConsoleWindow.WorkingThreads != 0) { Thread.Sleep(10); } if (ConsoleWindow.ImageLinks.Count <= ushort.MaxValue) { Clipboard.SetText(string.Join(Environment.NewLine, ConsoleWindow.ImageLinks)); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine(Properties.StringResources.ConsoleWindow_Complete); Console.ReadKey(); } }
public FuckingReportStarter(ILogger logger, ArgumentReader argumentReader) { }
internal static ReadDelegate CreateArgumentGetter(System.Type type) { var reader = new ArgumentReader(type); return reader.Read; }
internal static ReadDelegate CreateArgumentGetter(System.Type type) { var reader = new ArgumentReader(type); return(reader.Read); }