Пример #1
0
        public bool Execute(XLANGMessage msg, out string nextId)
        {
            nextId = null;
            Hashtable resolverResults = new Hashtable();
            string    key             = this.step.ResolverCollection[Convert.ToInt32(this.parameterCollection["resolverPosition"])];
            Dictionary <string, string> dictionary;

            if (!resolverResults.ContainsKey(key))
            {
                ResolverInfo resolverInfo = ResolverMgr.GetResolverInfo(ResolutionType.Endpoint, this.step.ResolverCollection[0]);
                if (!resolverInfo.Success)
                {
                    throw new ApplicationException("Could not locate resolver");
                }
                dictionary = ResolverMgr.Resolve(resolverInfo, msg);

                resolverResults.Add(key, dictionary);
            }
            else
            {
                dictionary = (resolverResults[key] as Dictionary <string, string>);
            }
            string filterMoniker    = string.Empty;
            string filterExpression = string.Empty;

            this.ParseFilterSettings(this.filterConfig, out filterMoniker, out filterExpression);
            IFilter filter = FilterFactory.Create(filterMoniker);

            if (filter.Execute(filterExpression, dictionary))
            {
                nextId = this.parameterCollection["id"];
                return(true);
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="resolverInfo"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public Dictionary <string, string> Resolve(ResolverInfo resolverInfo, XLANGMessage message)
        {
            #region Argument Check
            if (null == message)
            {
                throw new ArgumentNullException("message");
            }
            #endregion Argument Check

            // Resolve the params from arguments by creating
            // class from schema, and storing the results
            Resolution resolution = new Resolution();
            try
            {
                // Populate context
                ResolverMgr.SetContext(resolution, message);

                // resolve with rules and return dictionary
                return(ResolveStatic(resolverInfo.Config, resolverInfo.Resolver, resolution));
            }
            catch (System.Exception ex)
            {
                Exception exception = new Exception("Error performing SelectItinerary resolution in orchestration context.", ex);
                Logger.WriteTrace(string.Format("Error occured in {0} \r\n Details: {1}", this.GetType().Name, exception.ToString()));
                throw exception;
            }
            finally
            {
                if (null != resolution)
                {
                    resolution = null;
                }
            }
        }
Пример #3
0
        public string GetColor(ResolverInfo info)
        {
            var test   = info.GetParent <Test>();
            var source = info.GetSource <Lego>();

            return(test != null ? $"TestId:{test.Id}, color:{source.Color}" : source.Color);
        }
        // <summary>
        // This is the main interface that is called from the ResolverMgr class.
        // This interface supports being called from an orchestration.
        // </summary>
        // <param name="resolverInfo">Configuration string containing configuration and resolver</param>.
        // <param name="message">XLANGMessage passed from orchestration</param>.
        // <returns>Dictionary object fully populated</returns>.
        public Dictionary <string, string> Resolve(ResolverInfo resolverInfo, XLANGMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            Dictionary <string, string> resolverDictionary = null;

            try
            {
                Resolution resolution = new Resolution();

                ResolverMgr.SetContext(resolution, message);

                resolverDictionary = ResolveHelper(resolverInfo.Config, resolverInfo.Resolver, resolution);
            }
            catch (Exception exception)
            {
                EventLog.WriteEntry("BizTalk Server", exception.ToString(), EventLogEntryType.Error);
                throw;
            }

            return(resolverDictionary);
        }
        public IResolverInfo <TException, TError> Register <TException, TError>(int errorCode) where TException : Exception where TError : AppError, new()
        {
            var resolverInfo = new ResolverInfo <TException, TError>(errorCode);

            _lookUp.Add(typeof(TException).GetHashCode(), resolverInfo);
            return(resolverInfo);
        }
Пример #6
0
        public IBaseMessage Execute(IPipelineContext context, IBaseMessage msg, string resolverString, IItineraryStep step)
        {
            Logger.WriteTrace(string.Format("******{0} Started******", this.GetType().Name));
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (msg == null)
            {
                throw new ArgumentNullException("msg");
            }
            if (string.IsNullOrEmpty(resolverString))
            {
                throw new Exception("Resolver string is required.");
            }
            IBaseMessage result = msg;
            List <ManipulatorDescription> manipulatorList = new List <ManipulatorDescription>();

            try
            {
                foreach (string resolver in step.ResolverCollection)
                {
                    Logger.WriteTrace("        Resolver: " + resolver);
                    ResolverInfo resolverInfo = ResolverMgr.GetResolverInfo(ResolutionType.Transform, resolver);
                    Dictionary <string, string> dictionary = ResolverMgr.Resolve(resolverInfo, msg, context);

                    ManipulatorDescription description = new ManipulatorDescription();
                    description.ReadFrom  = dictionary["Resolver.ReadFrom"];
                    description.ReadItem  = dictionary["Resolver.ReadItem"];
                    description.WriteTo   = dictionary["Resolver.WriteTo"];
                    description.WriteItem = dictionary["Resolver.WriteItem"];
                    manipulatorList.Add(description);

                    dictionary.Remove("Resolver.ReadFrom");
                    dictionary.Remove("Resolver.ReadItem");
                    dictionary.Remove("Resolver.WriteTo");
                    dictionary.Remove("Resolver.WriteItem");
                }
                if (manipulatorList.Count > 0)
                {
                    Manipulator manipulator = new Manipulator();
                    manipulatorList = manipulator.GetManipulationData(manipulatorList, msg, context);
                    result          = manipulator.WriteManipulationData(manipulatorList, msg, context);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteTrace(string.Format("Error occured in {0} \r\n Details: {1}", this.GetType().Name, ex.ToString()));
                throw ex;
            }
            Logger.WriteTrace(string.Format("******{0} Completed******", this.GetType().Name));
            return(result);
        }
Пример #7
0
        public IBaseMessage Execute(IPipelineContext pipelineContext, IBaseMessage message, string resolverString, IItineraryStep step)
        {
            Logger.WriteTrace(string.Format("******{0} Started******", this.GetType().Name));
            Logger.WriteTrace("Resolver String: " + resolverString);

            if (string.IsNullOrEmpty(resolverString))
            {
                throw new ArgumentException("ResolverString is required.", "resolverString");
            }
            try
            {
                ResolverInfo info = ResolverMgr.GetResolverInfo(ResolutionType.Transform, resolverString);
                if (info.Success)
                {
                    Dictionary <string, string> dictionary = ResolverMgr.Resolve(info, message, pipelineContext);

                    // Archive the message.
                    ArchiveManager archiveManager = new ArchiveManager();

                    int    expiryMinutes     = Convert.ToInt32(dictionary["Archive.ExpiryMinutes"]);
                    bool   includeProperties = Convert.ToBoolean(dictionary["Archive.IncludeProperties"]);
                    string failureEventId    = dictionary["Archive.FailureEventId"];
                    string tag           = dictionary["Archive.Tag"];
                    string failureAction = dictionary["Archive.FailureAction"];

                    string messageId = archiveManager.ArchiveMessage(pipelineContext, message, expiryMinutes, includeProperties, tag);
                    Logger.WriteTrace("Message Id: '" + messageId + "' has been archived.");

                    SetMetadata(message, tag, messageId);
                }
                else
                {
                    throw new Exception("Unable to get archive resolver information from the resolver string: " + resolverString);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteTrace(string.Format("Error occured in {0} \r\n Details: {1}", this.GetType().Name, ex.ToString()));
                throw ex;
            }
            Logger.WriteTrace(string.Format("******{0} Completed******", this.GetType().Name));
            return(message);
        }
        /// <summary>
        /// Resolve implementation for use within an Orchestration. This method is typically used by creating an instance of the BRE Resolver Provider class inside an orchestration expression to resolve entities, such as itinerary, maps and endpoint addresses. This method invokes the BRE Policies that were configured through the Config and Resolver connection string values.
        /// </summary>
        /// <param name="resolverInfo">Resolver collection of entries</param>
        /// <param name="message">BizTalk XLangMessage class which is used to pass to the BRE policies if configured properly</param>
        /// <returns>Resolver Dictionary Collection containing resolved entries, such as itinerary name, map name, and endpoint address resolution values</returns>
        public Dictionary <string, string> Resolve(ResolverInfo resolverInfo, XLANGMessage message)
        {
            Dictionary <string, string> dictionary;

            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            Resolution resolution = new Resolution();

            try
            {
                BRE bre = this.CreateResolverDescriptor(resolverInfo.Config, resolverInfo.Resolver);
                if (bre.recognizeMessageFormat || bre.useMsgCtxt)
                {
                    throw new ResolveException("The attributes  recognizeMessageFormat and useMsgCtxt are not supported from orchestrations.");
                }
                ResolverMgr.SetContext(resolution, message);
                XmlDocument document = null;
                if (bre.useMsg)
                {
                    document = (XmlDocument)message[0].RetrieveAs(typeof(XmlDocument));
                }


                IBaseMessage msg = null;
                dictionary = ResolveRules(resolverInfo.Config, resolverInfo.Resolver, document, resolution, bre, null, null, ref msg);
            }
            catch (Exception exception)
            {
                EventLogger.Write(MethodBase.GetCurrentMethod(), exception);
                throw;
            }
            finally
            {
                if (resolution != null)
                {
                    resolution = null;
                }
            }
            return(dictionary);
        }
Пример #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="resolverInfo"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public Dictionary <string, string> Resolve(ResolverInfo resolverInfo, XLANGMessage message)
        {
            #region Argument Check
            if (null == message)
            {
                throw new ArgumentNullException("message");
            }
            #endregion Argument Check

            // Resolve the params from arguments by creating
            // class from schema, and storing the results
            Resolution resolution = new Resolution();
            try
            {
                // Populate context
                ResolverMgr.SetContext(resolution, message);

                Dictionary <string, string> resolverDictionary = new Dictionary <string, string>();

                XmlDocument xmlMessage = (XmlDocument)message[0].RetrieveAs(typeof(XmlDocument));

                resolverDictionary.Add("MessageContent", xmlMessage.OuterXml);

                return(resolverDictionary);
            }
            catch (System.Exception ex)
            {
                Exception exception = new Exception("Error performing Content resolution in orchestration context.", ex);
                Logger.WriteTrace(string.Format("Error occured in {0} \r\n Details: {1}", this.GetType().Name, exception.ToString()));
                throw exception;
            }
            finally
            {
                if (null != resolution)
                {
                    resolution = null;
                }
            }
        }
Пример #10
0
        public IBaseMessage ExecuteTransform(IPipelineContext context, IBaseMessage msg, string resolverString, IItineraryStep step, bool validateSource, bool promoteDocSpecName = true)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (msg == null)
            {
                throw new ArgumentNullException("msg");
            }
            if (string.IsNullOrEmpty(resolverString))
            {
                throw new Exception("Resolver string is required to determine map name.");
            }

            IBaseMessage result;
            ArrayList    mapList = new ArrayList();
            string       mapName = string.Empty;

            try
            {
                foreach (string resolver in step.ResolverCollection)
                {
                    ResolverInfo resolverInfo = ResolverMgr.GetResolverInfo(ResolutionType.Transform, resolver);

                    Dictionary <string, string> dictionary = ResolverMgr.Resolve(resolverInfo, msg, context);
                    if (dictionary.ContainsKey("TransformType") && !string.IsNullOrEmpty(dictionary["TransformType"]))
                    {
                        mapList.Add(dictionary["TransformType"]);
                        dictionary.Remove("TransformType");
                    }
                    else
                    {
                        mapList.Add(dictionary["Resolver.TransformType"]);
                        dictionary.Remove("Resolver.TransformType");
                    }
                }

                Stream stream = msg.BodyPart.GetOriginalDataStream();
                if (!stream.CanSeek)
                {
                    stream = new ReadOnlySeekableStream(stream)
                    {
                        Position = 0L
                    };
                }
                else
                {
                    stream.Position = 0L;
                }

                string btsMsgType = msg.Context.Read(BtsProperties.MessageType.Name, BtsProperties.MessageType.Namespace) as string;

                string obj = null;
                if (string.IsNullOrEmpty(btsMsgType))
                {
                    btsMsgType = Microsoft.Practices.ESB.Utilities.MessageHelper.GetMessageType(msg, context);
                }

                mapName = GetSourceMessageMatchingMapName(mapList, btsMsgType, context);

                IBaseMessage baseMessage = Microsoft.Practices.ESB.Utilities.MessageHelper.CreateNewMessage(context, msg, TransformStream(stream, mapName, validateSource, ref btsMsgType, ref obj));
                baseMessage.Context.Write(BtsProperties.SchemaStrongName.Name, BtsProperties.SchemaStrongName.Namespace, null);
                baseMessage.Context.Promote(BtsProperties.MessageType.Name, BtsProperties.MessageType.Namespace, btsMsgType);
                if (promoteDocSpecName)
                {
                    baseMessage.Context.Write(DasmProperties.DocumentSpecName.Name, DasmProperties.DocumentSpecName.Namespace, obj);
                }
                Microsoft.Practices.ESB.Utilities.MessageHelper.SetDocProperties(context, baseMessage);
                result = baseMessage;
            }
            catch (Exception)
            {
                throw;
            }
            return(result);
        }
Пример #11
0
        public IBaseMessage Execute(IPipelineContext pipelineContext, IBaseMessage message, string resolverString, IItineraryStep step)
        {
            Logger.WriteTrace(string.Format("******{0} Started******", this.GetType().Name));
            Logger.WriteTrace("Resolver String: " + resolverString);

            Stream inStream = null;
            string content  = string.Empty;

            if (string.IsNullOrEmpty(resolverString))
            {
                throw new ArgumentException("ResolverString is required.", "resolverString");
            }
            try
            {
                ResolverInfo info = ResolverMgr.GetResolverInfo(ResolutionType.Transform, resolverString);
                if (info.Success)
                {
                    Dictionary <string, string> dictionary = ResolverMgr.Resolve(info, message, pipelineContext);

                    string action       = dictionary["Cache.Action"];
                    string cacheMsgName = dictionary["Cache.CacheMessageName"];
                    int.TryParse(dictionary["Cache.CacheTimeOut"].ToString(), out defaultCacheTimeout);

                    string key = (string)message.Context.Read(BtsProperties.InterchangeID.Name, BtsProperties.InterchangeID.Namespace) + cacheMsgName;

                    if (action == "Get")
                    {
                        content = (string)this.Cache.Get(key);
                    }
                    else //Default action is Add
                    {
                        inStream = message.BodyPart.Data;

                        using (StreamReader reader = new StreamReader(inStream))
                        {
                            content = reader.ReadToEnd();
                        }

                        try
                        {
                            this.Cache.Add(key, content, DateTime.Now.AddMinutes(defaultCacheTimeout));
                        }
                        catch (ArgumentException ex)
                        {
                            throw new Exception("CacheService : '" + key + "' - DUPLICATE!! ERROR TYPE: " + ex.GetType().Name + "  Message: " + ex.Message);
                        }
                    }
                    inStream = new MemoryStream();
                    StreamWriter writer = new StreamWriter(inStream);
                    writer.Write(content);
                    writer.Flush();
                    inStream.Position = 0L;

                    message = Microsoft.Practices.ESB.Utilities.MessageHelper.CreateNewMessage(pipelineContext, message, inStream);
                }
                else
                {
                    throw new Exception("Unable to get cache resolver information from the resolver string: " + resolverString);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteTrace(string.Format("Error occured in {0} \r\n Details: {1}", this.GetType().Name, ex.ToString()));
                throw ex;
            }

            Logger.WriteTrace(string.Format("******{0} Completed******", this.GetType().Name));

            return(message);
        }