Exemple #1
0
        private static KeyValuePair <string, IServiceTopology> ParseServiceNameAndTopology(string line)
        {
            var match = ServiceTopologyRegex.Match(line.Trim());

            if (!match.Success)
            {
                throw new InvalidDataException(string.Format("'{0}' is not a valid service topology description", line));
            }
            var serviceName         = match.Groups[1].Value;
            var serviceTopologyType = match.Groups[2].Value;
            var endPointsText       = match.Groups[4].Value;

            IServiceTopology serviceTopology;

            switch (serviceTopologyType)
            {
            case "single": serviceTopology = ParseSingleServiceTopology(endPointsText); break;

            case "even": serviceTopology = ParseEvenlyDistibutedServiceTopology(endPointsText); break;

            case "random": serviceTopology = ParseRandomServiceTopology(endPointsText); break;

            case "map": serviceTopology = ParseMapServiceTopology(endPointsText); break;

            case "endpoint": serviceTopology = new EndPointServiceTopology(); break;

            default: throw new InvalidDataException(string.Format("Unknown service topology type '{0}'", serviceTopologyType));
            }

            return(new KeyValuePair <string, IServiceTopology>(serviceName, serviceTopology));
        }
        private static KeyValuePair<string, IServiceTopology> ParseServiceNameAndTopology(string line)
        {
            var match = ServiceTopologyRegex.Match(line.Trim());
            if (!match.Success)
                throw new InvalidDataException(string.Format("'{0}' is not a valid service topology description", line));
            var serviceName = match.Groups[1].Value;
            var serviceTopologyType = match.Groups[2].Value;
            var endPointsText = match.Groups[4].Value;

            IServiceTopology serviceTopology;
            switch (serviceTopologyType)
            {
                case "single": serviceTopology = ParseSingleServiceTopology(endPointsText); break;
                case "even": serviceTopology = ParseEvenlyDistibutedServiceTopology(endPointsText); break;
                case "random": serviceTopology = ParseRandomServiceTopology(endPointsText); break;
                case "map": serviceTopology = ParseMapServiceTopology(endPointsText); break;
                case "endpoint": serviceTopology = new EndPointServiceTopology(); break;
                default: throw new InvalidDataException(string.Format("Unknown service topology type '{0}'", serviceTopologyType));
            }

            return new KeyValuePair<string, IServiceTopology>(serviceName, serviceTopology);
        }