Beispiel #1
0
        static void Main(string[] args)
        {
            Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            comms = new HostCommunication(Console.In, Console.Out);

            //basic REPL loop logic on main thread
            while (true)
            {
                HostMessage message = comms.Receive();
                if (message.Command == HostCommand.HeartBeat)
                {
                    message.Message = HostingManager.Instance.RealtimeState().ToString();
                    comms.Send(message); //just an echo back
                }
                else if (message.Command == HostCommand.Pause)
                {
                    Pause();
                }
                else if (message.Command == HostCommand.Resume)
                {
                    Resume();
                }
                else if (message.Command == HostCommand.Stop)
                {
                    Stop();
                }
                else if (message.Command == HostCommand.Start)
                {
                    Start();
                }
                else if (message.Command == HostCommand.Init)
                {
                    Init();
                }
                else if (message.Command == HostCommand.Shutdown)
                {
                    Shutdown();
                    Environment.Exit(0); //exits the app
                }
            }
        }
Beispiel #2
0
        static void Init()
        {
            lock (syncRoot)
            {
                HostMessage m = new HostMessage();
                m.Command = HostCommand.Init;

                if (state == RunState.Created)
                {
                    IEnumerable <TypeNameReference> names = null;
                    m.Message = "";

                    LogProviderBase log = null;
                    try
                    {
                        ConfigurationManager.Instance.Bootstrap();
                        ConfigurationManager.Instance.Initialize();
                        ConfigurationManager.Instance.Start();
                        if (ConfigurationManager.Instance.State == RunState.Running)
                        {
                            LogManager.Instance.Bootstrap();
                            LogManager.Instance.Initialize();
                            LogManager.Instance.Start();
                            if (LogManager.Instance.State == RunState.Running)
                            {
                                log = LogManager.Instance.GetProvider(typeof(Program));
                            }
                            if (log == null)
                            {
                                log = new NullLogger(typeof(Program));
                            }

                            ConfigurationProviderBase prov = ConfigurationManager.Instance.GetProvider();
                            if (prov != null)
                            {
                                ConfigurationParameter param = prov.Get(typeof(Program), "hostList");
                                if (param != null)
                                {
                                    string[] values = param.Value as string[];
                                    if (values != null && values.Length > 0)
                                    {
                                        HashSet <TypeNameReference> tps = new HashSet <TypeNameReference>();
                                        foreach (string s in values)
                                        {
                                            TypeNameReference cur = TypeNameReference.Parse(s);
                                            if (cur != null)
                                            {
                                                tps.Add(cur);
                                            }
                                            else
                                            {
                                                log.Log(5, "Failed to parse TypeName for: " + s);
                                            }
                                        }
                                        if (tps.Count > 0)
                                        {
                                            names = tps;
                                        }
                                    }
                                    else
                                    {
                                        m.Message = "Failed to get configuration value";
                                        log.Log(1000, m.Message);
                                    }
                                }
                                else
                                {
                                    m.Message = "Failed to get configuration parameter: hostList";
                                    log.Log(1000, m.Message);
                                }
                            }
                            else
                            {
                                m.Message = "Failed to get configuration provider";
                                log.Log(1000, m.Message);
                            }
                        }
                        else
                        {
                            m.Message = "Failed to initialize using local file, quitting (" + AppContext.BaseDirectory + ")";
                            if (log != null)
                            {
                                log.Log(1000, m.Message);
                            }
                        }
                    }
                    catch
                    {
                        m.Message = "Failed to initialize using config, falling back to local file";
                        if (log != null)
                        {
                            log.Log(1000, m.Message);
                        }
                    }

                    if (names != null)
                    {
                        HostingManager.Instance.Initialize(names);
                        state = HostingManager.Instance.State;
                        if (state == RunState.Initialized)
                        {
                            m.Message = "success " + m.Message;
                            if (log != null)
                            {
                                log.Log(0, m.Message);
                            }
                        }
                        else
                        {
                            m.Message = "failed " + m.Message;
                            if (log != null)
                            {
                                log.Log(1000, m.Message);
                            }
                        }
                    }
                    else
                    {
                        state     = HostingManager.Instance.State;
                        m.Message = "failed " + m.Message;
                        if (log != null)
                        {
                            log.Log(1000, m.Message);
                        }
                    }
                }
                else
                {
                    state     = HostingManager.Instance.State;
                    m.Message = "ignored";
                }

                comms.Send(m);
            }
        }