コード例 #1
0
        public void XmlMustNotMatch()
        {
            var message  = Hexagon.XmlMessage.FromString(xml);
            var patterns = new XmlMessagePattern(new string[] {
                "//Client[@id='4' and Status != 'Deleted']"
            });

            Assert.IsFalse(patterns.Match(message));
        }
コード例 #2
0
        public void XmlMustMatch()
        {
            var message  = Hexagon.XmlMessage.FromString(xml);
            var patterns = new XmlMessagePattern(new string[] {
                "//Client[@id='1' and Nom = 'Laroche']",
                "//Client[@id='4' and Status = 'Deleted']",
            });

            Assert.IsTrue(patterns.Match(message));
        }
コード例 #3
0
        protected override void EndProcessing()
        {
            PatternActionsRegistry <XmlMessage, XmlMessagePattern> registry = new PatternActionsRegistry <XmlMessage, XmlMessagePattern>();

            if (MessagePatterns != null && MessagePatterns.Any())
            {
                foreach (var messagePattern in MessagePatterns)
                {
                    string processingUnitId = (string)messagePattern.Properties["Id"].Value;
                    var    pattern          = ((object[])messagePattern.Properties["Pattern"].Value).Select(o => (string)o).ToArray();
                    var    script           = (ScriptBlock)messagePattern.Properties["Script"].Value;
                    var    sec               = messagePattern.Properties["Secondary"];
                    bool   secondary         = sec != null ? (bool)sec.Value : false;
                    var    xmlMessagePattern = new XmlMessagePattern(secondary, pattern);
                    registry.AddPowershellScript(xmlMessagePattern, script, processingUnitId);
                }
            }
            if (Resources != null && Resources.Any())
            {
                foreach (var resource in Resources)
                {
                    string      processingUnitId    = (string)resource.Properties["Id"].Value;
                    ScriptBlock resourceConstructor = (ScriptBlock)resource.Properties["Constructor"].Value;
                    ScriptBlock resourceDestructor  = (ScriptBlock)resource.Properties["Destructor"]?.Value;
                    registry.SetProcessingUnitResourceFactory(
                        processingUnitId,
                        logger => new Lazy <IDisposable>(() =>
                    {
                        var outputs = new PowershellScriptExecutor(logger).Execute(resourceConstructor.ToString());
                        if (outputs == null || !outputs.Any())
                        {
                            return(null);
                        }
                        System.Collections.Hashtable resources = outputs.First() as System.Collections.Hashtable;
                        if (resources == null)
                        {
                            return(null);
                        }
                        return(new PSResources(resources, logger, resourceDestructor));
                    })
                        );
                }
            }
            var config = Hexagon.NodeConfig.FromFile <AkkaNodeConfig>(NodeConfig);

            using (MessageSystem <XmlMessage, XmlMessagePattern> xmlMessageSystem = CreateSystem(config))
            {
                xmlMessageSystem.Start(config, registry);
                Console.WriteLine("Press Control-C to exit, Enter to clear screen.");
                Console.CancelKeyPress += (sender, e) =>
                {
                    _quitEvent.Set();
                    e.Cancel = true;
                };
                bool exit = false;
                do
                {
                    if (Console.KeyAvailable)
                    {
                        var key = Console.ReadKey(true);
                        if (key.Key == ConsoleKey.Enter)
                        {
                            Console.Clear();
                        }
                    }
                    exit = _quitEvent.WaitOne(100);
                } while (!exit);
            }
        }