コード例 #1
0
        public void LoadSingleCbrRestaurantMenu()
        {
            #region Create message flow
            var terminator = MessageFlowBuilder.CreateTerminator("termination");
            var sendToA = MessageFlowBuilder.CreateSender("sendToA",
                inputMessage: "input", outputEndpoint: "OutA", nextNode: terminator);
            var cbr = MessageFlowBuilder.CreateCbr(name: "restaurant", testedMessage: "input",
                defaultTarget: terminator, cases: new[] {
                    new CbrCase("RestaurantMenu_schematron", sendToA),
                });
            var messageFlow = new MessageFlowConfiguration("sendToA", 1)
            {
                Nodes = { sendToA, terminator, cbr }
            };
            messageFlow.GetEntryNode().NextNode = sendToA;
            #endregion

            var xrm = configManager.LoadXrmItems(
                new[] { "RestaurantMenu_schematron" }, "Test1");

            var adapters = new AdapterConfiguration[] {
                new AdapterConfiguration("directoryAdapter", "gateway", "directoryAdapter",
                    XDocument.Parse(
            @"<objectConfig>
              <item name='checkingIntervalInSeconds'>0.1</item>
              <item name='inputEndpointToPathMap'>
            <pair>
              <key>In</key>
              <value>C:\XRouterTest\In</value>
            </pair>
              </item>
              <item name='outputEndpointToPathMap'>
            <pair>
              <key>OutB</key>
              <value>C:\XRouterTest\OutB</value>
            </pair>
            <pair>
              <key>OutA</key>
              <value>C:\XRouterTest\OutA</value>
            </pair>
            <pair>
              <key>OutC</key>
              <value>C:\XRouterTest\OutC</value>
            </pair>
              </item>
            </objectConfig>"))
            };

            configManager.ReplaceConfiguration(messageFlow, xrm, adapters);
        }
コード例 #2
0
ファイル: MessageFlow.cs プロジェクト: bzamecnik/XRouter
        public MessageFlow(MessageFlowConfiguration configuration, ProcessorService processor)
        {
            Configuration = configuration;
            Processor = processor;

            #region Create nodes
            nodesByName = new Dictionary<string, Node>();
            foreach (NodeConfiguration nodeCfg in configuration.Nodes)
            {
                Node node;
                if (nodeCfg is CbrNodeConfiguration)
                {
                    node = new CbrNode();
                }
                else if (nodeCfg is ActionNodeConfiguration)
                {
                    node = new ActionNode();
                }
                else if (nodeCfg is TerminatorNodeConfiguration)
                {
                    node = new TerminatorNode();
                }
                else if (nodeCfg is EntryNodeConfiguration)
                {
                    node = new EntryNode();
                }
                else
                {
                    throw new InvalidOperationException(string.Format(
                        "Cannot create a node named '{0}' of unknown node type.", nodeCfg.Name));
                }

                node.Initialize(nodeCfg, Processor);
                nodesByName.Add(node.Name, node);
            }
            #endregion

            entryNode = (EntryNode)nodesByName[configuration.GetEntryNode().Name];
        }
コード例 #3
0
ファイル: HandUtils.cs プロジェクト: bzamecnik/XRouter
        //[Fact]
        public void LoadSingleCbr()
        {
            #region Create message flow
            var terminator = MessageFlowBuilder.CreateTerminator("termination");
            var sendToA = MessageFlowBuilder.CreateSender("sendToA",
                inputMessage: "input", outputEndpoint: "OutA", nextNode: terminator);
            var cbr = MessageFlowBuilder.CreateCbr(name: "restaurant", testedMessage: "input",
                defaultTarget: terminator, cases: new[] {
                    new CbrCase("RestaurantMenu_schematron", sendToA),
                });
            var messageFlow = new MessageFlowConfiguration("sendToA", 1)
            {
                Nodes = { sendToA, terminator, cbr }
            };
            messageFlow.GetEntryNode().NextNode = sendToA;
            #endregion

            var xrm = configManager.LoadXrmItems(
                new[] { "RestaurantMenu_schematron" }, "Test1");

            configManager.ReplaceConfiguration(messageFlow, xrm);
        }
コード例 #4
0
        /// <summary>
        /// Gets a configuration of a message flow specified by its GUID.
        /// </summary>
        /// <param name="guid">GUID of the new message flow</param>
        /// <returns></returns>
        private MessageFlowConfiguration GetMessageFlow(Guid guid)
        {
            string xpath = string.Format("/configuration/messageflows/messageflow[@guid='{0}']", guid);
            XElement xMessageFlow = Content.XDocument.XPathSelectElement(xpath);

            // TODO: check for the solution of a situation when there is no
            // message flow at all

            //if (xMessageFlow == null)
            //{
            //    throw new ArgumentException(string.Format(
            //        "Cannot find message flow with GUID '{0}'.", guid), "guid");
            //}

            var result = XSerializer.Deserialize<MessageFlowConfiguration>(xMessageFlow);
            if (result == null)
            {
                // the message was empty
                System.Diagnostics.Debug.Assert(xMessageFlow.Attribute("name") != null);
                System.Diagnostics.Debug.Assert(xMessageFlow.Attribute("version") != null);

                string name = xMessageFlow.Attribute("name").Value;
                int version = 0;
                bool versionParsedOk = Int32.TryParse(xMessageFlow.Attribute("version").Value, out version);

                System.Diagnostics.Debug.Assert(versionParsedOk);

                result = new MessageFlowConfiguration(name, version);
            }
            return result;
        }
コード例 #5
0
        /// <summary>
        /// Adds a configuration of a new message flow.
        /// </summary>
        /// <param name="messageFlow">new message flow configuration</param>
        private void AddMessageFlow(MessageFlowConfiguration messageFlow)
        {
            XElement xMessageFlow = new XElement(XName.Get("messageflow"));
            XSerializer.Serializer(messageFlow, xMessageFlow);
            xMessageFlow.SetAttributeValue(XName.Get("guid"), messageFlow.Guid);

            // TODO: what about the situation when there already exists a
            // message flow with this GUID

            Content.XDocument.XPathSelectElement("/configuration/messageflows").Add(xMessageFlow);
        }
コード例 #6
0
        /// <summary>
        /// Updates the configuration of the current message flow.
        /// </summary>
        /// <remarks>
        /// It removes any other message flows.
        /// </remarks>
        /// <param name="messageFlow"></param>
        public void UpdateMessageFlow(MessageFlowConfiguration messageFlow)
        {
            // remove any previous message flow
            RemoveElements("/configuration/messageflows/messageflow");

            AddMessageFlow(messageFlow);
            SetCurrentMessageFlowGuid(messageFlow.Guid);
        }
コード例 #7
0
 public void ReplaceConfiguration(
     MessageFlowConfiguration messageFlow,
     XElement xrm,
     AdapterConfiguration[] adapters)
 {
     ReplaceConfiguration(consoleServer, messageFlow, xrm, adapters);
 }
コード例 #8
0
 /// <summary>
 /// Modifies the current XRouter configuration with a custom message
 /// flow and XML resource storage.
 /// </summary>
 public void ReplaceConfiguration(
     MessageFlowConfiguration messageFlow,
     XElement xrm)
 {
     ReplaceConfiguration(consoleServer, messageFlow, xrm, null);
 }
コード例 #9
0
        /// <summary>
        /// Modifies the current XRouter configuration with a custom message
        /// flow and XML resource storage.
        /// </summary>
        public void ReplaceConfiguration(
            IConsoleServer consoleServer,
            MessageFlowConfiguration messageFlow,
            XElement xrm,
            AdapterConfiguration[] adapters)
        {
            // load current configuration
            var configuration = consoleServer.GetConfiguration();
            var xConfig = configuration.Content.XDocument;

            if (adapters != null)
            {
                // remove all adapters
                xConfig.XPathSelectElement("/configuration/components/gateway/adapters").RemoveNodes();

                var gateway = xConfig.XPathSelectElements("/configuration/components/gateway").FirstOrDefault();
                if (gateway != null)
                {
                    string gatewayName = gateway.Attribute("name").Value;
                    foreach (var adapter in adapters)
                    {
                        configuration.SaveAdapterConfiguration(adapter);
                    }
                }
            }

            // remove all message flows
            xConfig.XPathSelectElement("/configuration/messageflows").RemoveNodes();

            // update current message flow
            configuration.UpdateMessageFlow(messageFlow);

            // remove all previous XRM items
            xConfig.XPathSelectElement("/configuration/xml-resource-storage").RemoveNodes();

            // add needed XRM items
            configuration.SaveXrmContent(xrm);

            // update the configuration
            consoleServer.ChangeConfiguration(configuration);
        }