/// <summary> /// Initiates the processing for a message and returns a resulting /// message or <b>null</b> if none. /// </summary> /// <param name="context">Identifies the user.</param> /// <param name="message">The message to be processed.</param> /// <returns>The resulting message or <b>null</b>.</returns> public override Message Process(UserContext context, Message message) { ValidationErrorSet errorSet = new ValidationErrorSet(); ValidationErrorSetAdapter adapter = new ValidationErrorSetAdapter(errorSet); SchemaRelease release = Releases.R5_9_CONFIRMATION; XmlDocument document = FpMLUtility.Parse(message.Payload, adapter.SyntaxError); if (errorSet.Count == 0) { release = (SchemaRelease)Releases.FPML.GetReleaseForDocument(document); if (release == null) { release = Releases.R5_9_CONFIRMATION; } if (FpMLUtility.Validate(document, adapter.SemanticError)) { return(message.Reply(CreateAcceptedMessage(release, context, document))); } } return(message.Reply(CreateRejectedMessage(release, context, document, errorSet))); }
/// <summary> /// Perform the file processing while timing the operation. /// </summary> protected override void Execute() { DirectoryInfo directory = new DirectoryInfo(Environment.CurrentDirectory); ArrayList files = new ArrayList(); try { for (int index = 0; index < Arguments.Length; ++index) { String location = directory.ToString(); string target = Arguments [index]; while (target.StartsWith(@"..\")) { location = location.Substring(0, location.LastIndexOf(Path.DirectorySeparatorChar)); target = target.Substring(3); } FindFiles(files, Path.Combine(location, target)); } } catch (Exception) { log.Fatal("Invalid command line argument"); Finished = true; return; } RuleSet rules = strictOption.Present ? FpMLRules.Rules : AllRules.Rules; Random rng = new Random(); DateTime start = DateTime.Now; int count = 0; try { while (repeat-- > 0) { for (int index = 0; index < files.Count; ++index) { int which = random ? rng.Next(files.Count) : index; if (reportOption.Present) { writer.WriteLine("\t<file name=\"" + (files [which] as FileInfo).Name + "\">"); } else { writer.WriteLine(">> " + (files [which] as FileInfo).Name); } FileStream stream = File.OpenRead((files [which] as FileInfo).FullName); FpMLUtility.ParseAndValidate(schemaOnly, stream, rules, new ValidationEventHandler(SyntaxError), new ValidationErrorHandler(SemanticError)); stream.Close(); if (reportOption.Present) { writer.WriteLine("\t</file>"); } ++count; } } DateTime end = DateTime.Now; TimeSpan span = end.Subtract(start); if (reportOption.Present) { writer.WriteLine("\t<statistics count=\"" + count + "\" time=\"" + span.TotalMilliseconds + "\" rate=\"" + ((1000.0 * count) / span.TotalMilliseconds) + "\" rules=\"" + rules.Size + "\"/>"); } else { writer.WriteLine("== Processed " + count + " files in " + span.TotalMilliseconds + " milliseconds"); writer.WriteLine("== " + ((1000.0 * count) / span.TotalMilliseconds) + " files/sec checking " + rules.Size + " rules"); } } catch (Exception error) { log.Fatal("Unexpected exception during processing", error); } Finished = true; }