protected override void EndProcessing()
        {
            var config = Hexagon.NodeConfig.FromFile <AkkaNodeConfig>(NodeConfig);
            MessageSystem <XmlMessage, XmlMessagePattern> xmlMessageSystem = null;

            switch (ImplType)
            {
            case EImplType.Akka:
                xmlMessageSystem = AkkaXmlMessageSystem.Create(config);
                break;

            default:
                throw new ArgumentException("only Akka implementation type is handled");
            }
            xmlMessageSystem.Start(config);
            WriteObject(xmlMessageSystem);
        }
Esempio n. 2
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);
            }
        }