Beispiel #1
0
        public static ControllerConfig ReadConfig(string path)
        {
            FileInfo file = new FileInfo(path);

            XmlSerializer    xml = new XmlSerializer(typeof(ControllerConfig));
            ControllerConfig cfg = new ControllerConfig();

            if (!file.Exists)
            {
                cfg.ListenPrefixes.Add("http://localhost:80");
                HostConnection c = new HostConnection();
                c.Name        = "A host";
                c.CryptoCache = new RijndaelManaged();
                c.CryptoKey   = EncodingTools.Encryption.GetTokenSalt(c.CryptoCache);

                cfg.Hosts.Add(c);

                cfg.RootTempFolder = Path.GetTempPath();

                var fs = file.OpenWrite();
                xml.Serialize(fs, cfg);
                fs.Close();
            }
            else
            {
                var fs = file.OpenText();
                cfg = xml.Deserialize(fs) as ControllerConfig;
                fs.Close();
            }

            return(cfg);
        }
Beispiel #2
0
 static ControllerConfig GetConfig()
 {
     if (ConfigCache == null)
     {
         ConfigCache = ControllerConfig.ReadConfig(ConfigPath);
     }
     return(ConfigCache);
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                ConfigPath = args[0];
            }
            else
            {
                ConfigPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "NodeController.cfg.xml");
            }

            // load config

            var cfg = ControllerConfig.ReadConfig(ConfigPath);

            // setup control listener
            InboundControlListener = new JsonMessageHost();
            InboundControlListener.MessageProcessor = HandleControllMessage;
            InboundControlListener.Prefixes.AddRange(cfg.ListenPrefixes.ToArray());

            InboundControlListener.Startup();

            while (!Done())
            {
                lock (Nodes)
                {
                    foreach (var node in Nodes)
                    {
                        if (node.Alive)
                        {
                        }
                        else
                        {
                            // notify them that the node died
                        }
                    }
                }
                Thread.Sleep(100);
            }

            InboundControlListener.Shutdown();
        }