private static object GetPropertyValue(IPropertyAnnotation annotation) { if (((string.Equals(annotation.XSDType, "date", StringComparison.OrdinalIgnoreCase) || string.Equals(annotation.XSDType, "time", StringComparison.OrdinalIgnoreCase)) || (string.Equals(annotation.XSDType, "dateTime", StringComparison.OrdinalIgnoreCase) || string.Equals(annotation.XSDType, "gMonthDay", StringComparison.OrdinalIgnoreCase))) || ((string.Equals(annotation.XSDType, "gDay", StringComparison.OrdinalIgnoreCase) || string.Equals(annotation.XSDType, "gYear", StringComparison.OrdinalIgnoreCase)) || (string.Equals(annotation.XSDType, "gYearMonth", StringComparison.OrdinalIgnoreCase) || string.Equals(annotation.XSDType, "gMonth", StringComparison.OrdinalIgnoreCase)))) { return(DateTime.Now); } if (((string.Equals(annotation.XSDType, "integer", StringComparison.OrdinalIgnoreCase) || string.Equals(annotation.XSDType, "byte", StringComparison.OrdinalIgnoreCase)) || (string.Equals(annotation.XSDType, "unsignedByte", StringComparison.OrdinalIgnoreCase) || string.Equals(annotation.XSDType, "positiveInteger", StringComparison.OrdinalIgnoreCase))) || (((string.Equals(annotation.XSDType, "nonNegativeInteger", StringComparison.OrdinalIgnoreCase) || string.Equals(annotation.XSDType, "int", StringComparison.OrdinalIgnoreCase)) || (string.Equals(annotation.XSDType, "unsignedInt", StringComparison.OrdinalIgnoreCase) || string.Equals(annotation.XSDType, "long", StringComparison.OrdinalIgnoreCase))) || ((string.Equals(annotation.XSDType, "unsignedLong", StringComparison.OrdinalIgnoreCase) || string.Equals(annotation.XSDType, "short", StringComparison.OrdinalIgnoreCase)) || string.Equals(annotation.XSDType, "unsignedShort", StringComparison.OrdinalIgnoreCase)))) { return(1); } if ((string.Equals(annotation.XSDType, "decimal", StringComparison.OrdinalIgnoreCase) || string.Equals(annotation.XSDType, "float", StringComparison.OrdinalIgnoreCase)) || string.Equals(annotation.XSDType, "double", StringComparison.OrdinalIgnoreCase)) { return(1.0); } if (string.Equals(annotation.XSDType, "boolean", StringComparison.OrdinalIgnoreCase)) { return(true); } if (string.Equals(annotation.XSDType, "base64Binary", StringComparison.OrdinalIgnoreCase)) { return("GpM7"); } if (string.Equals(annotation.XSDType, "negativeInteger", StringComparison.OrdinalIgnoreCase) || string.Equals(annotation.XSDType, "nonPositiveInteger", StringComparison.OrdinalIgnoreCase)) { return(-1); } if (string.Equals(annotation.XSDType, "hexBinary", StringComparison.OrdinalIgnoreCase)) { return("0FEE"); } if (string.Equals(annotation.XSDType, "duration", StringComparison.OrdinalIgnoreCase)) { return(TimeSpan.FromSeconds(1.0)); } if (string.Equals(annotation.XSDType, "language", StringComparison.OrdinalIgnoreCase)) { return("en-US"); } if (string.Equals(annotation.XSDType, "anyURI", StringComparison.OrdinalIgnoreCase)) { return("http://www.example.com"); } return(string.Format(CultureInfo.InvariantCulture, "{0}_{1}", new object[] { annotation.Name, annotation.XSDType })); }
/// <summary> /// Executes the logic for this component. /// </summary> /// <param name="pContext">Pipeline context</param> /// <param name="pInMsg">Input message</param> /// <returns>Outgoing message</returns> private IBaseMessage ExecuteInternal(IPipelineContext pContext, IBaseMessage pInMsg) { // Check arguments if (null == pContext) { throw new ArgumentNullException("pContext"); } if (null == pInMsg) { throw new ArgumentNullException("pInMsg"); } if (null == pInMsg.BodyPart) { throw new ArgumentNullException("pInMsg.BodyPart"); } if (null == pInMsg.BodyPart.GetOriginalDataStream()) { throw new ArgumentNullException("pInMsg.BodyPart.GetOriginalDataStream()"); } // // The logic behind this component is as follows: // 1. Create a seekable read-only stream over the input message body part stream // (because input message can be both large and stream can be non-seekable, // so it should have small memory footprint and change stream positions). // 2. Create a new outgoing message, new body part for it, assign seekable read-only stream // to the new body part, clone body part properties, clone message context. // 3. Get a schema for the input message or based on schemas specified during // design time. // 4. Load stream into XmlDocument. // 5. Walk through promoted properties and distinguished fields and promote/write // them to the message context of the outgoing message. // 6. Return outgoing message. // // // 1. Create a seekable read-only stream over the input message body part stream. // // Create a virtual stream, using GetOriginalDataStream() method on the IBaseMessagePart because // this call doesn't clone stream (instead of IBaseMessagePart.Data property). SeekableReadOnlyStream stream = new SeekableReadOnlyStream(pInMsg.BodyPart.GetOriginalDataStream()); // // 2. Create a new outgoing message, copy all required stuff. // // Create a new output message IBaseMessage outMessage = pContext.GetMessageFactory().CreateMessage(); // Copy message context by reference outMessage.Context = pInMsg.Context; // Create new message body part IBaseMessagePart newBodyPart = pContext.GetMessageFactory().CreateMessagePart(); // Copy body part properties by references. newBodyPart.PartProperties = pInMsg.BodyPart.PartProperties; // Set virtual stream as a data stream for the new message body part newBodyPart.Data = stream; // Copy message parts CopyMessageParts(pInMsg, outMessage, newBodyPart); // // 3. Get a schema for the message. // // Initialize schema map SchemaMap schemaMap = new SchemaMap(this.documentSchemaList); // Get message type from the message data stream string messageType = GetMessageType(stream); // Get a document spec from based on the message type IDocumentSpec documentSpec = schemaMap[messageType]; if (null == documentSpec) { documentSpec = pContext.GetDocumentSpecByType(messageType); } // Promote BTS.MessageType message context property to allow orchestration schedule instances be activated // on produced message. outMessage.Context.Promote(messageTypeWrapper.Name.Name, messageTypeWrapper.Name.Namespace, messageType); // // 4. Load document stream into XmlDocument. // // Save new message stream's current position long position = stream.Position; // Load document into XmlDocument XmlDocument document = new XmlDocument(); document.Load(stream); // Restore the 0 position for the virtual stream Debug.Assert(stream.CanSeek); // Restore new message stream's current position stream.Position = position; // // 5. Walk through promoted properties/distinguished fields and promote/write them. // // Walk through and promote properties IEnumerator annotations = documentSpec.GetPropertyAnnotationEnumerator(); while (annotations.MoveNext()) { IPropertyAnnotation annotation = (IPropertyAnnotation)annotations.Current; XmlNode propertyNode = document.SelectSingleNode(annotation.XPath); if (propertyNode != null) { // Promote context property to the message context as a typed value outMessage.Context.Promote(annotation.Name, annotation.Namespace, promotingMap.MapValue(propertyNode.InnerText, annotation.XSDType)); } } // Walk through and write distinguished fields IDictionaryEnumerator distFields = documentSpec.GetDistinguishedPropertyAnnotationEnumerator(); // IDocumentSpec.GetDistinguishedPropertyAnnotationEnumerator() can return null if (distFields != null) { while (distFields.MoveNext()) { DistinguishedFieldDefinition distField = (DistinguishedFieldDefinition)distFields.Value; XmlNode distFieldNode = document.SelectSingleNode(distField.XPath); if (distFieldNode != null) { // Write distinguished field to the message context as a string value outMessage.Context.Write(distField.XPath, Globals.DistinguishedFieldsNamespace, distFieldNode.InnerText); } } } // // 6. Return outgoing message. // return(outMessage); }
public void AddAnnotation(IPropertyAnnotation annotation) { this.annotationList.Add(annotation); }