コード例 #1
0
        /// <summary>
        /// ParseConfiguration is parsing elements of config file.
        /// </summary>
        /// <param name="NodeFile"></param>
        /// <returns>Config</returns>
        public static NetworkNodeConfiguration ParseConfiguration(string NodeFile)
        {
            var LoadedFile   = File.ReadAllLines(NodeFile).ToList();
            var ConfigWorker = new NetworkNodeConfiguration();

            ConfigWorker.NodeName          = GetFromFile(LoadedFile, "NODENAME");
            ConfigWorker.CloudPort         = int.Parse(GetFromFile(LoadedFile, "CLOUDPORT"));
            ConfigWorker.CloudAddress      = IPAddress.Parse(GetFromFile(LoadedFile, "CLOUDADDRESS"));
            ConfigWorker.ManagementPort    = int.Parse(GetFromFile(LoadedFile, "MANAGEMENTPORT"));
            ConfigWorker.ManagementAddress = IPAddress.Parse(GetFromFile(LoadedFile, "MANAGEMENTADDRESS"));

            string[] ports_string = GetFromFile(LoadedFile, "PORTS").Split(", ");
            foreach (string el in ports_string)
            {
                port_map link = new port_map();
                link.Config(el);
                ConfigWorker.port_maps.Add(link);
            }

            return(ConfigWorker);
        }
コード例 #2
0
        /// <summary>
        /// Start function creating new NetworkNode object and then return it to Main.
        /// </summary>
        /// <param name="FilePath"></param>
        /// <returns>NetworkNode</returns>
        public NetworkNode Start(string FilePath)
        {
            NetworkNode nn = new NetworkNode();

            ViewOnScreen("Node is running!");
            try
            {
                config        = NetworkNodeConfiguration.ParseConfiguration(FilePath);
                Console.Title = config.NodeName;

                nn.node_name       = config.NodeName;
                nn.management_port = config.ManagementPort;
                nn.management_addr = config.ManagementAddress;
                nn.cloud_addr      = config.CloudAddress;
                nn.cloud_port      = config.CloudPort;
                nn.port_maps       = config.port_maps;
            }
            catch (FileNotFoundException e)
            {
                ViewOnScreen(e.Message);
            }
            return(nn);
        }