示例#1
0
 /// <summary>
 /// Resolve the location of the indicated <see cref="SchemaRelease"/> (and
 /// any that it imports) to the schema set using default XML catalog to
 /// resolve the schema location.
 /// </summary>
 /// <param name="release">The <see cref="SchemaRelease"/> to be added.</param>
 public void Add(SchemaRelease release)
 {
     if (!schemas.Contains(release))
     {
         schemas.Add(release);
         schemaSet = null;
     }
 }
示例#2
0
        /// <summary>
        /// Creates a response message for a message that passed full validation.
        /// </summary>
        /// <param name="release">The FpML release to respond with.</param>
        /// <param name="context">Identifies the user.</param>
        /// <param name="document">The parsed form of the input messsage.</param>
        /// <returns></returns>
        private string CreateAcceptedMessage(SchemaRelease release, UserContext context, XmlDocument document)
        {
            Builder builder = CreateMessage(release, "serviceNotification", context, document);

            builder.AppendElementAndText("serviceName", "FpMLWebServices");
            builder.AppendElement("advisory");
            builder.AppendElementAndText("categpry", "Rules");
            builder.AppendElementAndText("description", "Message was accepted");
            builder.CloseElement();

            return(NestedWriter.ToString(builder.Document));
        }
示例#3
0
        /// <summary>
        /// Constructs an FpML message builds the message header, if possible
        /// copying data from the original input message.
        /// </summary>
        /// <param name="release">he FpML release to respond with.</param>
        /// <param name="rootElement">The name of the root element.</param>
        /// <param name="context">Identifies the user.</param>
        /// <param name="document">The parsed form of the input messsage or <b>null</b>.</param>
        /// <returns></returns>
        private Builder CreateMessage(SchemaRelease release, string rootElement,
                                      UserContext context, XmlDocument document)
        {
            Builder builder = new HandCoded.FpML.Xml.Builder(release.NewInstance(rootElement));

            builder.AppendElement("header");
            builder.AppendElement("messageId");
            builder.SetAttribute("messageIdScheme", "urn:handcoded:message-id");
            builder.AppendText(Guid.NewGuid().ToString());
            builder.CloseElement();

            if (document != null)
            {
                XmlElement messageId = (XmlElement)XPath.Path(document.DocumentElement, "header", "messageId");
                if (messageId != null)
                {
                    builder.AppendElement("inReplyTo");
                    builder.SetAttribute("messageIdScheme", messageId.GetAttribute("messageIdScheme"));
                    builder.AppendText(Types.ToString(messageId));
                    builder.CloseElement();
                }
            }

            builder.AppendElement("sentBy");
            builder.SetAttribute("messageAddressScheme", "urn:handcoded:message-address");
            builder.AppendText("FpMLWebServiceDemo");
            builder.CloseElement();

            builder.AppendElement("sendTo");
            builder.SetAttribute("messageAddressScheme", "urn:handcoded:message-address");
            builder.AppendText(context.Username);
            builder.CloseElement();

            builder.AppendElementAndText("creationTimestamp",
                                         HandCoded.Finance.DateTime.Now(true).ToString());

            builder.CloseElement();

            return(builder);
        }
示例#4
0
        /// <summary>
        /// Creates a response message for a message that failed XML or FpML
        /// validation.
        /// </summary>
        /// <param name="release">The FpML release to respond with.</param>
        /// <param name="context">Identifies the user.</param>
        /// <param name="document">The parsed form of the input messsage or <b>null</b>.</param>
        /// <param name="errorSet">The set of detected errors.</param>
        /// <returns></returns>
        private string CreateRejectedMessage(SchemaRelease release, UserContext context, XmlDocument document,
                                             ValidationErrorSet errorSet)
        {
            Builder builder = CreateMessage(release, "messageRejected", context, document);

            for (int index = 0; index < errorSet.Count; ++index)
            {
                ValidationError error = errorSet [index];

                builder.AppendElement("reason");

                builder.AppendElementAndText("reasonCode", error.Code);

                builder.AppendElement("location");
                builder.SetAttribute("locationType", error.IsLexical ? "lexical" : "xpath");
                builder.AppendText(error.Context);
                builder.CloseElement();

                if (error.Description != null)
                {
                    builder.AppendElementAndText("description", error.Description);
                }

                if (error.RuleName != null)
                {
                    builder.AppendElementAndText("validationRuleId", error.RuleName);
                }

                if (error.AdditionalData != null)
                {
                    builder.AppendElement("additionalData");
                    builder.AppendElementAndText("string", error.AdditionalData);
                    builder.CloseElement();
                }

                builder.CloseElement();
            }

            return(NestedWriter.ToString(builder.Document));
        }
        /// <summary>
        /// Resolve the location of the indicated <see cref="SchemaRelease"/> (and
        /// any that it imports) to the schema set using the given XML catalog to
        /// resolve the schema location.
        /// </summary>
        /// <param name="release">The <see cref="SchemaRelease"/> to be added.</param>
        /// <param name="catalog">The <see cref="Catalog"/> to resolve with.</param>
        public void Add(SchemaRelease release, Catalog catalog)
        {
            List <SchemaRelease> imports = release.ImportSet;

            foreach (SchemaRelease schema in imports)
            {
                if (!schemas.Contains(schema))
                {
                    Uri uri = catalog.ResolveUri(null, schema.NamespaceUri);

                    if (uri != null)
                    {
                        schemaSet.Add(schema.NamespaceUri, Unwrap(uri.LocalPath));
                        schemas.Add(schema);
                    }
                    else
                    {
                        log.Fatal("Failed to resolve schema for '" + schema.NamespaceUri + "'");
                    }
                }
            }
        }
示例#6
0
        /// <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)));
        }
示例#7
0
 /// <summary>
 /// Constructs a <b>Builder</b> instance attached the root element of
 /// a new FpML document of the given <see cref="SchemaRelease"/> and
 /// which has the indicated message type.
 /// </summary>
 /// <param name="release">The FpML <see cref="SchemaRelease"/> to construct.</param>
 /// <param name="type">The document or message type to construct.</param>
 public Builder(SchemaRelease release, string type)
     : this(release)
 {
     SetAttribute("xsi:type", type);
 }
示例#8
0
 /// <summary>
 /// Constructs a <b>Builder</b> instance attached the root element of
 /// a new FpML document of the given <see cref="SchemaRelease"/>.
 /// </summary>
 /// <param name="release">The FpML <see cref="SchemaRelease"/> to construct.</param>
 public Builder(SchemaRelease release)
     : base(release.NewInstance("FpML"))
 {
 }
示例#9
0
 /// <summary>
 /// Constructs a <b>NamespacePrecondition</b> instance for the
 /// specified <see cref="SchemaRelease"/> instance.
 /// </summary>
 /// <param name="release">The target <see cref="SchemaRelease"/>.</param>
 public NamespacePrecondition(SchemaRelease release)
     : this(release.NamespaceUri)
 {
 }
示例#10
0
 /// <summary>
 /// Resolve the location of the indicated <see cref="SchemaRelease"/> (and
 /// any that it imports) to the schema set using default XML catalog to
 /// resolve the schema location.
 /// </summary>
 /// <param name="release">The <see cref="SchemaRelease"/> to be added.</param>
 public void Add(SchemaRelease release)
 {
     Add(release, XmlUtility.DefaultCatalog);
 }