public void Generate(IEnumerable <HelpCommand.Component> infos) { var catalog = ModuleCatalog.CreateInstance(_host); using (var sw = new StreamWriter(_csFilename)) { var writer = IndentingTextWriter.Wrap(sw, " "); // Generate header CSharpGeneratorUtils.GenerateHeader(writer); foreach (var entryPointInfo in catalog.AllEntryPoints().Where(x => !_excludedSet.Contains(x.Name)).OrderBy(x => x.Name)) { // Generate method CSharpGeneratorUtils.GenerateMethod(writer, entryPointInfo.Name, _defaultNamespace); } // Generate footer CSharpGeneratorUtils.GenerateFooter(writer); CSharpGeneratorUtils.GenerateFooter(writer); foreach (var entryPointInfo in catalog.AllEntryPoints().Where(x => !_excludedSet.Contains(x.Name)).OrderBy(x => x.Name)) { // Generate input and output classes GenerateInputOutput(writer, entryPointInfo, catalog); } writer.WriteLine("namespace Runtime"); writer.WriteLine("{"); writer.Indent(); foreach (var kind in catalog.GetAllComponentKinds()) { // Generate kind base class GenerateComponentKind(writer, kind); foreach (var component in catalog.GetAllComponents(kind)) { // Generate component GenerateComponent(writer, component, catalog); } } CSharpGeneratorUtils.GenerateFooter(writer); CSharpGeneratorUtils.GenerateFooter(writer); writer.WriteLine("#pragma warning restore"); } }
private void GenerateFile(ComponentCatalog.LoadableClassInfo info, string filename, Dictionary <Type, GeneratorBase> mapping, bool generateEnums) { using (var sw = new StreamWriter(filename)) { var writer = IndentingTextWriter.Wrap(sw, " "); foreach (var kvp in mapping) { if (info.IsOfType(kvp.Key)) { kvp.Value.Generate(writer, _modulePrefix, _regenerate, info, generateEnums, _moduleId ?? Guid.NewGuid().ToString(), _moduleName, _moduleOwner, _moduleVersion, _moduleState, _moduleType, _moduleDeterminism, _moduleCategory, _exclude, _namespaces); break; } } } }
public void Run(int?columns) { #pragma warning disable CS0618 // The help command should be entirely within the command line anyway. AssemblyLoadingUtils.LoadAndRegister(_env, _extraAssemblies); #pragma warning restore CCS0618 using (var ch = _env.Start("Help")) using (var sw = new StringWriter(CultureInfo.InvariantCulture)) using (var writer = IndentingTextWriter.Wrap(sw)) { if (_listKinds) { if (_component != null) { writer.WriteLine("Listing component kinds so ignoring specified component"); } else if (_kind != null) { writer.WriteLine("Listing component kinds so ignoring specified kind"); } ListKinds(writer); } else if (_component != null) { ShowHelp(writer, columns); } else if (_allComponents) { ShowAllHelp(writer, columns); } else { ShowComponents(writer); } ch.Info(sw.ToString()); } }
public void Run(int?columns) { ComponentCatalog.CacheClassesExtra(_extraAssemblies); using (var ch = _env.Start("Help")) using (var sw = new StringWriter(CultureInfo.InvariantCulture)) using (var writer = IndentingTextWriter.Wrap(sw)) { if (_listKinds) { if (_component != null) { writer.WriteLine("Listing component kinds so ignoring specified component"); } else if (_kind != null) { writer.WriteLine("Listing component kinds so ignoring specified kind"); } ListKinds(writer); } else if (_component != null) { ShowHelp(writer, columns); } else if (_allComponents) { ShowAllHelp(writer, columns); } else { ShowComponents(writer); } ch.Info(sw.ToString()); ch.Done(); } }
// Run the test. The init delegate is called once at the beginning of the test. // The action delegate is called on script in the input resource. private void Run(string dir, string name, Action <IndentingTextWriter> init, Action <IndentingTextWriter, string> action) { string text = GetResText(InResName(name)); string outName = OutFileName(name); string outPath = DeleteOutputPath(dir, outName); using (var writer = File.CreateText(outPath)) { var wrt = IndentingTextWriter.Wrap(writer); init(wrt); // Individual scripts are separated by $ int count = 0; int ichLim = 0; int lineLim = 1; while (ichLim < text.Length) { int ichMin = ichLim; int lineMin = lineLim; while (ichLim < text.Length && text[ichLim] != '$') { if (text[ichLim] == '\n') { lineLim++; } ichLim++; } while (ichMin < ichLim && char.IsWhiteSpace(text[ichMin])) { if (text[ichMin] == '\n') { lineMin++; } ichMin++; } if (ichMin < ichLim) { // Process the script. count++; string scriptName = string.Format("Script {0}, lines {1} to {2}", count, lineMin, lineLim); wrt.WriteLine("===== Start {0} =====", scriptName); string input = text.Substring(ichMin, ichLim - ichMin); try { action(wrt, input); } catch (Exception ex) { if (!ex.IsMarked()) { wrt.WriteLine("Unknown Exception!"); } wrt.WriteLine("Exception: {0}", ex.Message); } wrt.WriteLine("===== End {0} =====", scriptName); } // Skip the $ ichLim++; } } CheckEquality(dir, outName); Done(); }
private static void PrintSchema(TextWriter writer, Arguments args, ISchema schema, ITransposeSchema tschema) { Contracts.AssertValue(writer); Contracts.AssertValue(args); Contracts.AssertValue(schema); Contracts.AssertValueOrNull(tschema); #if !CORECLR if (args.ShowJson) { writer.WriteLine("Json Schema not supported."); return; } #endif int colLim = schema.ColumnCount; writer.WriteLine("{0} columns:", colLim); var itw = IndentingTextWriter.Wrap(writer); using (itw.Nest()) { var names = default(VBuffer <ReadOnlyMemory <char> >); for (int col = 0; col < colLim; col++) { var name = schema.GetColumnName(col); var type = schema.GetColumnType(col); var slotType = tschema == null ? null : tschema.GetSlotType(col); itw.WriteLine("{0}: {1}{2}", name, type, slotType == null ? "" : " (T)"); bool metaVals = args.ShowMetadataValues; if (metaVals || args.ShowMetadataTypes) { ShowMetadata(itw, schema, col, metaVals); continue; } if (!args.ShowSlots) { continue; } if (!type.IsKnownSizeVector) { continue; } ColumnType typeNames; if ((typeNames = schema.GetMetadataTypeOrNull(MetadataUtils.Kinds.SlotNames, col)) == null) { continue; } if (typeNames.VectorSize != type.VectorSize || !typeNames.ItemType.IsText) { Contracts.Assert(false, "Unexpected slot names type"); continue; } schema.GetMetadata(MetadataUtils.Kinds.SlotNames, col, ref names); if (names.Length != type.VectorSize) { Contracts.Assert(false, "Unexpected length of slot names vector"); continue; } using (itw.Nest()) { bool verbose = args.Verbose ?? false; foreach (var kvp in names.Items(all: verbose)) { if (verbose || !kvp.Value.IsEmpty) { itw.WriteLine("{0}:{1}", kvp.Key, kvp.Value); } } } } } }
internal void Run() { string text = GetResText("Microsoft.ML.Runtime.RunTests.CmdLine.IndenterTestInput.txt"); string outName = "CmdIndenterOutput.txt"; string outPath = DeleteOutputPath("CmdLine", outName); using (var writer = File.CreateText(outPath)) { var wrt = IndentingTextWriter.Wrap(writer); // Individual scripts are separated by $ int count = 0; int ichLim = 0; int lineLim = 1; while (ichLim < text.Length) { int ichMin = ichLim; int lineMin = lineLim; while (ichLim < text.Length && text[ichLim] != '$') { if (text[ichLim] == '\n') { lineLim++; } ichLim++; } while (ichMin < ichLim && char.IsWhiteSpace(text[ichMin])) { if (text[ichMin] == '\n') { lineMin++; } ichMin++; } if (ichMin < ichLim) { // Process the script. count++; string scriptName = string.Format("Script {0}, lines {1} to {2}", count, lineMin, lineLim); wrt.WriteLine("===== Start {0} =====", scriptName); string input = text.Substring(ichMin, ichLim - ichMin); try { wrt.WriteLine(CmdIndenter.GetIndentedCommandLine(input)); } catch (Exception ex) { if (!ex.IsMarked()) { wrt.WriteLine("Unknown Exception!"); } wrt.WriteLine("Exception: {0}", ex.Message); } wrt.WriteLine("===== End {0} =====", scriptName); } // Skip the $ ichLim++; } } CheckEquality("CmdLine", outName); Done(); }