/// <summary> /// Initializes a new instance of the <see cref="T:Sharpdown.MarkdownElement.InlineElement.Image"/> class. /// </summary> /// <param name="text">The description.</param> /// <param name="src">The source of this image.</param> /// <param name="title">The title of this image.</param> /// <param name="config">Configuration of the parser.</param> public Image(InlineElement[] text, string src, string title, ParserConfig config) : base(config) { Alt = TextFromInlines(text); Children = text; Source = src; Title = title; }
public Link(InlineElement[] linkText, string destination, string title, ParserConfig config) : base(config) { Children = linkText; Destination = InlineElementUtils.UrlEncode(InlineText.HandleEscapeAndHtmlEntity(RemoveAngleBrackets(destination))); Title = title == null ? null : InlineText.HandleEscapeAndHtmlEntity(RemoveQuotes(title)); }
public void ReadParserConfig(byte chr, byte left, sbyte right, byte name, sbyte strand, sbyte summit, byte value, bool dropPeakIfInvalidValue, double defaultValue, PValueFormats pValueFormat) { // Arrange ParserConfig cols = new ParserConfig() { Chr = chr, Left = left, Right = right, Name = name, Strand = strand, Summit = summit, Value = value, DefaultValue = defaultValue, PValueFormat = pValueFormat, DropPeakIfInvalidValue = dropPeakIfInvalidValue, }; var path = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "MSPCTests_" + new Random().NextDouble().ToString(); using (StreamWriter w = new StreamWriter(path)) w.WriteLine(JsonConvert.SerializeObject(cols)); // Act ParserConfig parsedCols = ParserConfig.LoadFromJSON(path); File.Delete(path); // Assert Assert.True(parsedCols.Equals(cols)); }
public void DoesNotEqualToANullObject() { // Arrange var config = new ParserConfig(); // Act & Assert Assert.True(!config.Equals(null)); }
public ParserConfigProvider(ParserConfig config) { if (config == null) { throw new ArgumentNullException(); } this.config = config; }
private void bCsvConfig_Click( object sender, EventArgs e ) { var newConfig = Jas.Utils.CSVTools.Forms.SettingsForm.GetConfig( parserConfig ); if ( newConfig != null ) { parserConfig = newConfig; } }
public void TwoEqualConfigs() { // Arrange var c1 = new ParserConfig(); var c2 = new ParserConfig(); // Act & Assert Assert.Equal(c1, c2); }
/// <summary> /// Registers the template of the help option. /// </summary> /// <param name="template">Template that identifies invocation of the help option.</param> /// <param name="helpWriter">Help writer instance to use. If not specified, the default console /// writer is used.</param> /// <returns>Configuration.</returns> public ApplicationConfiguration <TOptions> HelpOption(string template, IHelpWriter?helpWriter = null) { HelpTemplate = Template.Parse(template); _helpWriter = helpWriter; ParserConfig.AddTemplate(HelpTemplate); ParserConfig.AddParser(new HelpOptionParser <TOptions>(HelpTemplate)); return(this); }
/// <summary> /// Initializes a new instance of <see cref="LinkReferenceDefinition"/> /// with link label ,destination, title. /// </summary> /// <param name="label"></param> /// <param name="destination"></param> /// <param name="title"></param> /// <param name="elem"></param> /// <param name="config">Configuration of the parser.</param> internal LinkReferenceDefinition(string label, string destination, string title, UnknownElement elem, ParserConfig config) : base(config) { Label = GetSimpleName(label?.Trim(whiteSpaceChars) ?? throw new ArgumentNullException(nameof(title))); Destination = InlineElementUtils.UrlEncode(InlineText.HandleEscapeAndHtmlEntity( destination ?? throw new ArgumentNullException(nameof(destination)))); Title = title == null ? null : InlineText.HandleEscapeAndHtmlEntity(title); warnings.AddRange(elem?.Warnings ?? new List <string>()); }
/// <summary> /// Adds a position argument to the configuration. /// </summary> /// <param name="configureAction">Configuration action.</param> /// <typeparam name="TValue">Value type.</typeparam> /// <returns>Configuration.</returns> public CommandConfiguration <TOptions> PositionArgument <TValue>( Action <MultiValueArgumentConfiguration <TOptions, TValue> > configureAction) { var index = ParserConfig.GetNextArgumentIdentity(); return(ConfigureArgument <TValue>(Common.FormatArgumentContext(index), builder => MultiValueArgumentConfiguration <TOptions, TValue> .Configure(builder, configureAction) .PositionArgument(index))); }
public DefaultRdpUrlParser(ParserConfig config, IDictionary <Token, string> dictionary = null, List <string> defs = null) : this(config) { if (dictionary != null) { Dictionary = dictionary; } if (defs != null) { _msArgList = defs; } }
/// <summary> /// Initializes a new instance of <see cref="SetextHeading"/> /// with header level. /// </summary> /// <param name="elem"> /// The <see cref="UnknownElement"/> object to create this object from. /// </param> /// <param name="level">The header level.</param> /// <param name="config">Configuration of the parser.</param> internal SetextHeading(UnknownElement elem, int level, ParserConfig config) : base(config) { if (level != 1 && level != 2) { throw new ArgumentException("level must be 1 or 2.", nameof(level)); } HeaderLevel = level; content = string.Join("\r\n", elem.content).TrimEnd(new[] { ' ', '\n', '\r', '\t' }); warnings.AddRange(elem.Warnings); }
public static string CreateCopy(ParserConfig dataConfig, string[] headerArrayQuery, int startIndex, int numTableColumns) { string insertInto = "COPY " + headerArrayQuery[startIndex] + @"(sensorid, time,"; for (int i = startIndex; i < startIndex + numTableColumns - 1; i++) { insertInto += headerArrayQuery[i] + ", "; } insertInto += headerArrayQuery[startIndex + numTableColumns - 1] + ") FROM STDIN"; return(insertInto); }
public void AssertUsingParserConfig() { // Arrange var rep1Path = Path.GetTempPath() + Guid.NewGuid().ToString() + ".bed"; var rep2Path = Path.GetTempPath() + Guid.NewGuid().ToString() + ".bed"; using (var writter = new StreamWriter(rep1Path)) { writter.WriteLine("10\t20\tchr1"); writter.WriteLine("50\t60\tchr1"); } using (var writter = new StreamWriter(rep2Path)) { writter.WriteLine("15\t25\tchr1"); writter.WriteLine("55\t65\tchr1"); } ParserConfig cols = new ParserConfig() { Chr = 2, Left = 0, Right = 1, DefaultValue = 1E-8, DropPeakIfInvalidValue = false }; var parserConfigFile = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "MSPCTests_" + new Random().NextDouble().ToString(); using (StreamWriter w = new StreamWriter(parserConfigFile)) w.WriteLine(JsonConvert.SerializeObject(cols)); // Act string consoleOutput = ""; using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); Program.Main(string.Format("-i {0} -i {1} -r bio -w 1E-4 -s 1E-6 -p {2}", rep1Path, rep2Path, parserConfigFile).Split(' ')); consoleOutput = sw.ToString(); } // Assert Assert.True(Regex.Matches(consoleOutput, "Read peaks#: 2").Count == 2); // Clean up File.Delete(rep1Path); File.Delete(rep2Path); File.Delete(parserConfigFile); foreach (var path in Directory.GetDirectories(Environment.CurrentDirectory, "session_*")) { Directory.Delete(path, true); } }
public void TwoNotEqualConfigs() { // Arrange var c1 = new ParserConfig() { Chr = 1 }; var c2 = new ParserConfig() { Chr = 2 }; // Act & Assert Assert.NotEqual(c1, c2); }
public static void PrepareQueryAndWrite(List <String> record, ParserConfig dataConfig, string[] headerArrayQuery) { headerArrayQuery = cleanString(headerArrayQuery); int [] id = dataConfig.sensorIDs; for (int i = 0; i < id.Length; i++) { int numColumns = dataConfig.sensors[i + 1] - dataConfig.sensors[i]; string createTable = CreateTable(dataConfig, headerArrayQuery, dataConfig.sensors[i], numColumns, id[i], record); // create a sql string for doing bulk insert string copyInto = CreateCopy(dataConfig, headerArrayQuery, dataConfig.sensors[i], numColumns); WriteToDB.WriteData(createTable, copyInto, dataConfig.sensors[i], numColumns, record, headerArrayQuery[dataConfig.sensors[i]], headerArrayQuery, id[i]); } }
public void ReadDataAccordingToParserConfig() { // Arrange ParserConfig cols = new ParserConfig() { Chr = 0, Left = 3, Right = 4, Name = 1, Strand = 2, Summit = 6, Value = 5, DefaultValue = 1.23E-45, PValueFormat = PValueFormats.minus1_Log10_pValue, DropPeakIfInvalidValue = false, }; var path = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "MSPCTests_" + new Random().NextDouble().ToString(); using (StreamWriter w = new StreamWriter(path)) w.WriteLine(JsonConvert.SerializeObject(cols)); string rep1Path = Path.GetTempPath() + Guid.NewGuid().ToString() + ".bed"; string rep2Path = Path.GetTempPath() + Guid.NewGuid().ToString() + ".bed"; FileStream stream = File.Create(rep1Path); using (StreamWriter writter = new StreamWriter(stream)) writter.WriteLine("chr1\tMSPC_PEAK\t.\t10\t20\t16\t15"); stream = File.Create(rep2Path); using (StreamWriter writter = new StreamWriter(stream)) writter.WriteLine("chr1\tMSPC_PEAK\t.\t15\t25\tEEE\t20"); // Act string msg; using (var tmpMspc = new TmpMspc()) msg = tmpMspc.Run(createSample: false, template: string.Format("-i {0} -i {1} -p {2} -r bio -w 1e-2 -s 1e-4", rep1Path, rep2Path, path)); // Assert Assert.Contains("1.000E-016", msg); Assert.Contains("1.230E-045", msg); }
public void ReadMalformedJSON() { // Arrange var expected = new ParserConfig() { Chr = 123 }; var path = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "MSPCTests_" + new Random().NextDouble().ToString(); using (StreamWriter w = new StreamWriter(path)) w.WriteLine("{\"m\":7,\"l\":789,\"u\":-1,\"Chr\":123,\"L\":9,\"R\":2,\"d\":-1}"); // Act var parsedCols = ParserConfig.LoadFromJSON(path); File.Delete(path); // Assert Assert.True(parsedCols.Equals(expected)); }
/// <summary> /// Registers a command as an application sub-program. /// </summary> /// <param name="template">Template that identifies the command.</param> /// <param name="configureAction">Configuration action.</param> /// <typeparam name="TCommandOptions">Command options.</typeparam> /// <returns>Configuration.</returns> /// <exception cref="Exception">Invalid configuration.</exception> public ApplicationConfiguration <TOptions> Command <TCommandOptions>(string template, Action <CommandConfiguration <TCommandOptions> > configureAction) where TCommandOptions : class, TOptions { Check.NotNull(configureAction, nameof(configureAction)); try { var commandTemplate = Template.ForCommand(template); var configuration = new CommandConfiguration <TCommandOptions>(commandTemplate); configureAction(configuration); _subConfigurations.Add(configuration); ParserConfig.AddTemplate(commandTemplate); return(this); } catch (Exception ex) { throw ConfigurationExceptions.InvalidCommandConfiguration(template, ex); } }
public static string CreateTable(ParserConfig dataConfig, string[] headerArrayQuery, int startIndex, int numTableColumns, int sensorID, List <String> record) { string createTable = @"CREATE TABLE IF NOT EXISTS " + headerArrayQuery[startIndex] + @" ("; createTable += "sensorid INTEGER NOT NULL,"; createTable += "time TIMESTAMPTZ NOT NULL,"; for (int i = startIndex; i < startIndex + numTableColumns; i++) { if (Decimal.TryParse(record[i], NumberStyles.Any, CultureInfo.InvariantCulture, out decimal f)) { createTable += headerArrayQuery[i] + " NUMERIC NULL,"; } else { createTable += headerArrayQuery[i] + " TEXT NULL,"; } } createTable += " PRIMARY KEY (sensorid, time));"; return(createTable); }
//This class parses a standard URL into components: public UrlParser(ParserConfig config) : base(config) { FileExtension = "url"; }
// Invokes configuration for an argument. private CommandConfiguration <TOptions> ConfigureArgument <TValue>(object context, Func <ParserBuilder <TOptions, TValue>, IArgumentParser <TOptions> > configuration) { ParserConfig.ConfigureParser(context, configuration); return(this); }
public DefaultRdpUrlParser(ParserConfig config) : base(config) { FileExtension = ".rdp"; }
public DefaultSshUrlParser(ParserConfig config, IDictionary <Token, string> dictionary) : this(config) { if (dictionary != null) { Dictionary = dictionary; } }
//This class parses a string in the format: // - <protocol>://<user>@<host>[:<port>] // where: // protocol: ssh // user : Username - this can contain a Safeguard auth string //If this doesnt match, it defaults to parsing the string as a standard URL. public DefaultSshUrlParser(ParserConfig config) : base(config) { FileExtension = ".ssh"; }
public void CorrectAndSuccessfulAnalysis() { /// TODO: This is a big test as it does an end-to-end assertion /// of many aspects. However, using some mock types this test /// implementation can be significantly simplified. /// // Arrange string outputPath = "session_" + DateTime.Now.ToString("yyyyMMdd_HHmmssfff_", CultureInfo.InvariantCulture) + new Random().Next(100000, 999999).ToString(); WriteSampleFiles(out string rep1Filename, out string rep2Filename, out string culture); ParserConfig cols = new ParserConfig() { Culture = culture }; var configFilename = Path.GetTempPath() + Guid.NewGuid().ToString() + ".json"; using (StreamWriter w = new StreamWriter(configFilename)) w.WriteLine(JsonConvert.SerializeObject(cols)); string args = $"-i {rep1Filename} -i {rep2Filename} -r bio -w 1e-2 -s 1e-4 -p {configFilename} -o {outputPath}"; // Act string output; using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); Program.Main(args.Split(' ')); output = sw.ToString(); } var standardOutput = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true }; Console.SetOut(standardOutput); // Assert Assert.Contains("All processes successfully finished", output); using (var reader = new StreamReader(Directory.GetFiles(outputPath, "*ConsensusPeaks.bed")[0])) { Assert.Equal("chr\tstart\tstop\tname\t-1xlog10(p-value)", reader.ReadLine()); Assert.Equal("chr1\t4\t20\tMSPC_Peak_2\t25.219", reader.ReadLine()); Assert.Equal("chr1\t25\t45\tMSPC_Peak_1\t12.97", reader.ReadLine()); Assert.Null(reader.ReadLine()); } var dirs = Directory.GetDirectories(outputPath); Assert.True(dirs.Length == 2); Assert.True(Directory.GetFiles(dirs[0]).Length == 14); string line; using (var reader = new StreamReader(Directory.GetFiles(dirs[0], "*TruePositive.bed")[0])) { Assert.Equal("chr\tstart\tstop\tname\t-1xlog10(p-value)", reader.ReadLine()); line = reader.ReadLine(); Assert.True("chr1\t10\t20\tmspc_peak_1\t7.12" == line || "chr1\t4\t12\tmspc_peak_3\t19.9" == line); line = reader.ReadLine(); Assert.True("chr1\t25\t35\tmspc_peak_2\t5.507" == line || "chr1\t30\t45\tmspc_peak_4\t9" == line); Assert.Null(reader.ReadLine()); } Assert.True(Environment.ExitCode == 0); Assert.True(Directory.GetFiles(dirs[1]).Length == 14); using (var reader = new StreamReader(Directory.GetFiles(dirs[1], "*TruePositive.bed")[0])) { Assert.Equal("chr\tstart\tstop\tname\t-1xlog10(p-value)", reader.ReadLine()); line = reader.ReadLine(); Assert.True("chr1\t10\t20\tmspc_peak_1\t7.12" == line || "chr1\t4\t12\tmspc_peak_3\t19.9" == line); line = reader.ReadLine(); Assert.True("chr1\t25\t35\tmspc_peak_2\t5.507" == line || "chr1\t30\t45\tmspc_peak_4\t9" == line); Assert.Null(reader.ReadLine()); } // Clean up Directory.Delete(outputPath, true); File.Delete(rep1Filename); File.Delete(rep2Filename); }
public ParserWorker(ParserProcess parserProcess, IOptions <ParserConfig> config) { this.parserProcess = parserProcess; this.config = config.Value; }
public DefaultSshUrlParser(ParserConfig config) : base(config) { }
public ArgumentEnumerator(CommandLineApplication command, ParserConfig config, IReadOnlyList <string> rawArguments) { _config = config; CurrentCommand = command; _rawArgEnumerator = rawArguments.GetEnumerator(); }
/// <summary> /// Initializes a new instance of <see cref="BlockElement"/>. /// </summary> /// <param name="config">Configuration of parser.</param> protected BlockElement(ParserConfig config) { warnings = new List <string>(); parserConfig = config; }
public RdpFileUrlParser(ParserConfig config) : base(config) { }