public static string ParseWsPath(string template, string serviceName)
        {
            var wsPath = string.Empty;

            template = TrimPrefix(template);
            var segementLines = template.Split(separator);

            foreach (var segementLine in segementLines)
            {
                var segmentType = TemplateSegmentHelper.GetSegmentType(segementLine, serviceName);
                switch (segmentType)
                {
                case SegmentType.Literal:
                    wsPath += "/" + segementLine;
                    break;

                case SegmentType.AppService:
                {
                    var appServiceName = ParseAppServiceName(TemplateSegmentHelper.GetSegmentVal(segementLine),
                                                             serviceName);
                    wsPath += "/" + appServiceName;
                    break;
                }

                default:
                    throw new LmsException("解析websocketPath失败");
                }
            }

            return(wsPath.TrimEnd('/'));
        }
Beispiel #2
0
        private void ParseRouteTemplate(string template, string serviceName, MethodInfo methodInfo)
        {
            template = TrimPrefix(template);
            var segementLines = template.Split(separator);

            foreach (var segementLine in segementLines)
            {
                var segmentType = TemplateSegmentHelper.GetSegmentType(segementLine, serviceName);
                switch (segmentType)
                {
                case SegmentType.Literal:
                    RouteTemplate.Segments.Add(new TemplateSegment(SegmentType.Literal, segementLine));
                    break;

                case SegmentType.AppService:
                {
                    var appServiceName = ParseAppServiceName(TemplateSegmentHelper.GetSegmentVal(segementLine),
                                                             serviceName);
                    RouteTemplate.Segments.Add(new TemplateSegment(SegmentType.AppService, appServiceName));
                    break;
                }

                case SegmentType.Path:
                {
                    var pathParameterSegment =
                        ParsePathParameterSegment(TemplateSegmentHelper.GetSegmentVal(segementLine), methodInfo);
                    RouteTemplate.Segments.Add(pathParameterSegment.Item1);
                    RouteTemplate.Parameters.Add(pathParameterSegment.Item2);
                    break;
                }
                }
            }

            var appServiceSegmentCount = RouteTemplate.Segments?.Count(p => p.SegmentType == SegmentType.AppService);

            if (appServiceSegmentCount != 1)
            {
                throw new LmsException("路由模板未指定服务应用", StatusCode.RouteParseError);
            }
        }
        public static string GetWsPath([NotNull] this IRouteTemplateProvider routeTemplateProvider, string serviceName)
        {
            Check.NotNull(routeTemplateProvider, nameof(routeTemplateProvider));
            var template      = TrimPrefix(routeTemplateProvider.Template);
            var segementLines = template.Split(separator);
            var wsPath        = "/";

            foreach (var segementLine in segementLines)
            {
                var segmentType = TemplateSegmentHelper.GetSegmentType(segementLine, serviceName);
                if (segmentType == SegmentType.AppService)
                {
                    var appServiceName = ParseAppServiceName(TemplateSegmentHelper.GetSegmentVal(segementLine),
                                                             serviceName);
                    wsPath += appServiceName;
                }
                else
                {
                    wsPath += TemplateSegmentHelper.GetSegmentVal(segementLine);
                }
            }

            return(wsPath);
        }