private void btnExecute_Click(object sender, System.EventArgs e) { OutputFormatting format = (OutputFormatting)cbOutput.SelectedItem; Validator val = new Validator(format); val.AddSchema(new StringReader(txtSchemaXml.Text)); //val.ReturnType = NavigableType.XmlDocument; if (txtPhase.Text.Length != 0) { val.Phase = txtPhase.Text; } try { // Validate using document literal in textbox. IXPathNavigable doc = val.Validate(new StringReader(txtDocumentXml.Text)); // Continue processing valid document. txtMsg.Text = "Valid file!"; } catch (ValidationException ex) { txtMsg.Text = ex.Message; } tabControl1.SelectedTab = tabPage1; }
//outputs users total scouts public List <string> OutputTotalScouts() { List <string> output = new List <string>(); OutputFormatting f = new OutputFormatting("User", 15, "Scouts", 7); for (int i = 0; i < users.Count; ++i) { if (f.output.Length >= 1900) { f.insertEnd(); output.Add(f.output); f = new OutputFormatting("Name", 16, "Status", 10); } f.addLine(users[i].Username, users[i].NumberOfScouts.ToString()); if (i + 1 == users.Count) { f.insertEnd(); output.Add(f.output); } } return(output); }
/// <summary> /// Initializes the validator with the options received from the constructor overloads. /// </summary> /// <param name="format">Output format of error messages.</param> /// <param name="type">The <see cref="IXPathNavigable"/> type to use for validation and return type.</param> private void InitValidator(OutputFormatting format, NavigableType type) { if (!Enum.IsDefined(typeof(OutputFormatting), format)) { throw new ArgumentException("Invalid type.", "type"); } switch (format) { case OutputFormatting.Boolean: _evaluationctx.Formatter = new BooleanFormatter(); break; case OutputFormatting.Log: case OutputFormatting.Default: _evaluationctx.Formatter = new LogFormatter(); break; case OutputFormatting.Simple: _evaluationctx.Formatter = new SimpleFormatter(); break; case OutputFormatting.XML: _evaluationctx.Formatter = new XmlFormatter(); break; } if (!Enum.IsDefined(typeof(NavigableType), type)) { throw new ArgumentException("Invalid type.", "type"); } // If type is Default, set it to XPathDocument. _navtype = (type != NavigableType.Default) ? type : NavigableType.XPathDocument; }
public string Print() { OutputFormatting f = new OutputFormatting("Username", 15, "Times seen", 10); for (int i = 0; i < users.Count; ++i) { f.addLine(users[i].Username, users[i].TimesSeen.ToString()); } f.insertEnd(); return(f.output); }
public string PrintPromotions() { OutputFormatting f = new OutputFormatting("Promotions", 15, "", 0); for (int i = 0; i < users.Count; ++i) { if (users[i].TimesSeen >= Config.FC_PROMOTION_LIMIT) { f.addLine(users[i].Username, ""); } } f.insertEnd(); return(f.output); }
/// <summary> /// Format the Enigma's output according to a formatting scheme. /// The historical german formatting was 5 letters block for the army and air force, and 4 /// letters block for the Navy. /// </summary> /// <param name="input">The string to format</param> /// <param name="formatting">The formatting scheme</param> /// <returns>The formatted string</returns> private static string FormatOutput(string input, OutputFormatting formatting) { int blockLength; switch (formatting) { case OutputFormatting.Original: blockLength = -1; break; case OutputFormatting.FiveLettersBlock: blockLength = 6; break; case OutputFormatting.FourLettersBlock: blockLength = 5; break; default: blockLength = -1; break; } if (blockLength > 0) { for (int i = 0; i < input.Length; i += blockLength) { input = input.Insert(i, " "); } } return input; }
/// <summary> /// Submits a text to the Enigma and get the encrypted result. /// </summary> /// <param name="input">The desired text.</param> /// <returns>The encrypted result</returns> public string SubmitString(string input, OutputFormatting formatting = OutputFormatting.Original) { if (input == null) { throw new ArgumentNullException("The input string cannot be null."); } if (input.Equals(string.Empty)) { return string.Empty; } // Historical enigma only wrote upper case text. input = input.ToUpperInvariant(); // And did not accept anything else than the 26 upper case letters of the roman alphabet. input = input.Replace(" ", ""); StringBuilder sb = new StringBuilder(); for (int i = 0; i < input.Length; i++) { sb.Append(PressKey(input[i])); } string result = sb.ToString(); // The cryptographers also formatted the output in 4 or 5 letters blocks. result = FormatOutput(result, formatting); return result; }
/// <summary> /// Initializes the attribute for a certain schema. /// </summary> /// <param name="schemas">The set of schemas to validate the webmethod with.</param> /// <param name="formatting">The formatting to use for the validation output.</param> public ValidationAttribute(string[] schemas, OutputFormatting formatting) { this.schemas = schemas; this.formatting = formatting; }
/// <summary> /// Initializes the attribute for a certain schema. /// </summary> /// <param name="schema">The schema to validate the webmethod with.</param> /// <param name="formatting">The formatting to use for the validation output.</param> public ValidationAttribute(string schema, OutputFormatting formatting) : this(new string[] { schema }, formatting) { }
/// <summary> /// Initializes a new instance of the class, using the specified options. /// </summary> /// <param name="format">Output format of error messages.</param> /// <param name="type">The <see cref="IXPathNavigable"/> type to use for validation and return type.</param> public Validator(OutputFormatting format, NavigableType type) : this() { InitValidator(format, type); }
/// <summary> /// Initializes a new instance of the class, using the specified output format for error messages. /// </summary> /// <param name="format">Output format of error messages.</param> public Validator(OutputFormatting format) : this() { InitValidator(format, NavigableType.Default); }