Пример #1
0
        /// <inheritdoc />
        public IUriComponents GetUriComponents(string uriString, RESTableContext context)
        {
            var uri   = new DefaultProtocolUriComponents(this);
            var match = Regex.Match(uriString, RegEx.RESTableRequestUri);

            if (!match.Success)
            {
                throw new InvalidSyntax(ErrorCodes.InvalidUriSyntax, "Check URI syntax");
            }
            var resourceOrMacro = match.Groups["res"].Value.TrimStart('/');
            var view            = match.Groups["view"].Value.TrimStart('-');
            var conditions      = match.Groups["cond"].Value.TrimStart('/');
            var metaConditions  = match.Groups["meta"].Value.TrimStart('/');

            switch (conditions)
            {
            case string { Length: 0 } :

            case "_": break;

            default:
            {
                foreach (var uriCondition in ParseUriConditions(conditions, true))
                {
                    uri.Conditions.Add(uriCondition);
                }
                break;
            }
            }

            switch (metaConditions)
            {
            case string { Length: 0 } :

            case "_": break;

            default:
            {
                foreach (var uriCondition in ParseUriConditions(metaConditions, true))
                {
                    uri.MetaConditions.Add(uriCondition);
                }
                break;
            }
            }

            if (view.Length != 0)
            {
                uri.ViewName = view;
            }

            switch (resourceOrMacro)
            {
            case "":
            case "_":
                uri.ResourceSpecifier = context.WebSocket?.Status == WebSocketStatus.Waiting
                        ? ResourceCollection.GetResourceSpecifier <Shell>()
                        : ResourceCollection.GetResourceSpecifier <AvailableResource>();
                break;

            case var resource when resourceOrMacro[0] != '$':
                uri.ResourceSpecifier = resource;
                break;

            case var _macro when _macro.Substring(1) is string _: throw new MacrosNotSupported();
            }

            return(uri);
        }