/// <summary>
        /// Writes to the context of the message
        /// </summary>
        /// <typeparam name="TContextProperty">Type of the target property</typeparam>
        /// <param name="message">BizTalk pipeline message</param>
        /// <param name="value">Requested value of the property</param>
        public static void WriteContextProperty <TContextProperty>(this XLANGMessage message, object value) where TContextProperty : MessageContextPropertyBase, new()
        {
            Guard.NotNull(message, "message");

            object actualValue = ContextPropertySerializer.SerializeToContextPropertyValue <TContextProperty>(value);

            message.SetPropertyValue(typeof(TContextProperty), actualValue);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Save component properties to a property bag.
        /// </summary>
        /// <param name="propertyBag">Property bag</param>
        /// <param name="clearDirty">Clear dirty flag</param>
        /// <param name="saveAllProperties">Save all properties flag</param>
        protected override void SaveProperties(IPropertyBag propertyBag, bool clearDirty, bool saveAllProperties)
        {
            string xml = null;

            if (this.ContextProperties != null)
            {
                ContextPropertySerializer serializer = new ContextPropertySerializer(this.ContextProperties);
                xml = serializer.Serialize();
            }
            this.WritePropertyValue(propertyBag, PROPERTIES_PROP_NAME, xml);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load component properties from a property bag.
        /// </summary>
        /// <param name="propertyBag">Property bag</param>
        /// <param name="errorLog">Error log level</param>
        protected override void LoadProperties(IPropertyBag propertyBag, int errorLog)
        {
            string xml = this.ReadPropertyValue <string>(propertyBag, PROPERTIES_PROP_NAME, null);

            if (string.IsNullOrEmpty(xml) == false)
            {
                ContextPropertySerializer serializer = new ContextPropertySerializer();
                serializer.Deserialize(xml);
                this.ContextProperties = serializer.Properties;
            }
        }
Exemplo n.º 4
0
        public IBaseMessage Execute(IPipelineContext pipelineContext, IBaseMessage inputMessage, string objectArguement)
        {
            var callToken = TraceProvider.Logger.TraceIn(this.Name);

            try
            {
                Guard.ArgumentNotNull(objectArguement, "objectArguement");

                // set the dynamic expression context required for ContextProperty properties of type "Expression"
                ExpressionData expressionData = new ExpressionData(inputMessage);
                this.ExpressionContext = new Expressions.ExpressionContext(ExpressionImports, expressionData);
                ContextPropertySerializer ser = new ContextPropertySerializer();
                ser.Deserialize(objectArguement);

                // iterate through all context properties promoting or writing
                foreach (ContextProperty contextProperty in ser.Properties)
                {
                    object value = this.GetPropertyValue(pipelineContext, inputMessage, contextProperty);
                    if (contextProperty.IgnoreNullOrEmptyValue == false || this.IsNullOrEmptyValue(value) == false)
                    {
                        if (contextProperty.Promote == true)
                        {
                            TraceProvider.Logger.TraceInfo("Promoting property into context: {0} = {1}; Namespace = {2}, Source = {3}", contextProperty.Name, value, contextProperty.Namespace, contextProperty.Source.ToString());
                            inputMessage.Context.Promote(contextProperty.Name, contextProperty.Namespace, value);
                        }
                        else
                        {
                            TraceProvider.Logger.TraceInfo("Writing property into context: {0} = {1}; Namespace = {2}, Source = {3}", contextProperty.Name, value, contextProperty.Namespace, contextProperty.Source.ToString());
                            inputMessage.Context.Write(contextProperty.Name, contextProperty.Namespace, value);
                        }
                    }
                    else
                    {
                        TraceProvider.Logger.TraceInfo("Ignoring null or empty value: {0} = {1}; Namespace = {2}, Source = {3}", contextProperty.Name, value, contextProperty.Namespace, contextProperty.Source.ToString());
                    }
                }

                return(inputMessage);
            }
            catch (Exception ex)
            {
                // put component name as a source information in this exception,
                // so the event log in message could reflect this
                ex.Source = this.Name;
                TraceProvider.Logger.TraceError(ex);
                throw ex;
            }
            finally
            {
                TraceProvider.Logger.TraceOut(callToken, this.Name);
            }
        }
        /// <summary>
        /// Reads a property in the context of the message
        /// </summary>
        /// <typeparam name="TContextProperty">Type of the target property</typeparam>
        /// <typeparam name="TExpected">Expected type of the value</typeparam>
        /// <param name="message">BizTalk pipeline message</param>
        /// <param name="isMandatory">Indication if it is mandatory for the property to be present</param>
        /// <returns>Value from the property, if present</returns>
        /// <exception cref="BizTalk.Extended.Core.Exceptions.ContextPropertyNotFoundException">Thrown when a mandatory property is not present</exception>
        public static TExpected ReadContextProperty <TContextProperty, TExpected>(this XLANGMessage message, bool isMandatory) where TContextProperty : MessageContextPropertyBase, new()
        {
            Guard.NotNull(message, "message");

            object value = message.GetPropertyValue(typeof(TContextProperty));

            if (value == null && isMandatory)
            {
                var propertyInstance = new TContextProperty();
                throw new ContextPropertyNotFoundException(propertyInstance.Name.Name, propertyInstance.Name.Namespace);
            }

            return(ContextPropertySerializer.DeserializeFromContextPropertyValue <TExpected>(value));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Writes to the context of the message
        /// </summary>
        /// <typeparam name="TContextProperty">Type of the target property</typeparam>
        /// <param name="message">BizTalk pipeline message</param>
        /// <param name="value">Requested value of the property</param>
        public static void WriteContextProperty <TContextProperty>(this IBaseMessage message, object value) where TContextProperty : MessageContextPropertyBase, new()
        {
            Guard.NotNull(message, "message");
            Guard.Against(message.Context == null, "message");

            var    contextProperty = new TContextProperty();
            object actualValue     = value;

            if (typeof(TContextProperty).IsEnum || value is Enum)
            {
                actualValue = ContextPropertySerializer.SerializeToContextPropertyValue <TContextProperty>(value);
            }

            WriteContextProperty(message, contextProperty.Name.Name, contextProperty.Name.Namespace, actualValue);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Reads a property in the context of the message
        /// </summary>
        /// <typeparam name="TExpected">Expected type of the value</typeparam>
        /// <param name="message">BizTalk pipeline message</param>
        /// <param name="name">Name of the property</param>
        /// <param name="ns">Namespace of the property</param>
        /// <param name="isMandatory">Indication if it is mandatory for the property to be present</param>
        /// <returns>Value from the property, if present</returns>
        /// <exception cref="BizTalk.Extended.Core.Exceptions.ContextPropertyNotFoundException">Thrown when a mandatory property is not present</exception>
        public static TExpected ReadContextProperty <TExpected>(this IBaseMessage message, string name, string ns, bool isMandatory)
        {
            Guard.NotNull(message, "msg");
            Guard.Against(message.Context == null, "msg");
            Guard.NotNullOrEmpty(name, "name");
            Guard.NotNullOrEmpty(ns, "ns");

            object value = message.Context.Read(name, ns);

            if (value == null && isMandatory)
            {
                throw new ContextPropertyNotFoundException(name, ns);
            }

            return(ContextPropertySerializer.DeserializeFromContextPropertyValue <TExpected>(value));
        }