コード例 #1
0
        public CableCloudConfigDto ReadFromFile()
        {
            var config          = new CableCloudConfigDto();
            var forwardingTable = new List <ForwardingInfoDto>();

            var lines = File.ReadAllLines(_filePath);

            foreach (var line in lines)
            {
                var parts = line.Split(' ');

                if (line.StartsWith("IPADDRESS"))
                {
                    config.Ip = IPAddress.Parse(parts[1]);
                }
                else if (line.StartsWith("PORT"))
                {
                    config.Port = int.Parse(parts[1]);
                }
                else if (line.StartsWith("CABLE"))
                {
                    forwardingTable.Add(new ForwardingInfoDto(forwardingTable.Count, parts[1], int.Parse(parts[2]), parts[3], int.Parse(parts[4]), parts[5].Equals("1")));
                }
            }

            config.ForwardingTable = forwardingTable;

            return(config);
        }
コード例 #2
0
        public CableCloudService(IConfigReaderService configReaderService, ILogService logService, IObjectSerializerService objectSerializerService)
        {
            _logService = logService;
            _objectSerializerService = objectSerializerService;

            try
            {
                CableCloudConfig = configReaderService.ReadFromFile();
            }
            catch (Exception e)
            {
                _logService.LogError("WRONG CONFIG: " + e.Message);
            }
        }