Esempio n. 1
0
        static void Register(PatternActionsRegistry <XmlMessage, XmlMessagePattern> registry)
        {
            registry.AddAction(
                new XmlMessagePattern(@"/ping"),
                (message, sender, self, resource, ms, logger) =>
            {
                // Pretend to use the lazy resource
                var res = resource.Value;
                logger.Info(@"Received {0}", message);
                dynamic xml = message.AsDynamic();
                if (xml.ping == "crash")
                {
                    throw new Exception("Crash requested");
                }
                sender.Tell(XmlMessage.FromString($@"
                        <pong>
                            <ping>{xml.ping}</ping>
                            <node>{self.Path}</node>
                        </pong>"), self);
            },
                "actor1");

            registry.SetProcessingUnitResourceFactory(
                "actor1",
                logger => new Lazy <IDisposable>(() => new FakeResource(logger))
                );
        }
Esempio n. 2
0
        public void ActorFromAssembly()
        {
            var registry = new PatternActionsRegistry <XmlMessage, XmlMessagePattern>();

            registry.AddFromAssembly(System.Reflection.Assembly.GetExecutingAssembly().GetName().FullName, null);
            var lookup = registry.LookupByProcessingUnit();

            lookup.Contains("actor").Should().BeTrue();
            lookup["actor"].Count().Should().Be(1);
            lookup["actor"].First().Pattern.Conjuncts[0].Should().Be("*");
        }
Esempio n. 3
0
 static void Register(PatternActionsRegistry <XmlMessage, XmlMessagePattern> registry)
 {
     registry.AddAction(
         new XmlMessagePattern(@"/plic"),
         (message, sender, self, resource, ms, logger) =>
     {
         logger.Info(@"Received {0}", message);
         var xml = message.AsDynamic();
         sender.Tell(XmlMessage.FromString($@"<ploc>{xml.plic}</ploc>"), self);
     },
         "actor2");
 }
 static void RegisterActions(PatternActionsRegistry <XmlMessage, XmlMessagePattern> registry)
 {
     registry.AddAction(
         new XmlMessagePattern(@"/question1"),
         (m, sender, self, resource, ms, logger) =>
     {
         sender.Tell(XmlMessage.FromString($@"<answer1>{self.Path}</answer1>"), self);
     },
         "routed");
     registry.AddPowershellScriptBody(
         new XmlMessagePattern(@"/question2"),
         @"'<answer2>{0}</answer2>' -f $self.Path",
         "routed");
     registry.AddPowershellScriptBody(
         new XmlMessagePattern(true, @"/question2"),
         @"$xml = [xml]$message; $xml.question2",
         "monitor");
 }
Esempio n. 5
0
 static void Register(PatternActionsRegistry <XmlMessage, XmlMessagePattern> registry)
 {
     registry.AddAction(new XmlMessagePattern("*"), (m, sender, self, resource, ms, logger) => { }, "actor");
 }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
 public XmlMessageSystemTests() : this(new XmlMessageSystemTestsConfig())
 {
     _registry = new PatternActionsRegistry <XmlMessage, XmlMessagePattern>();
 }