internal static Uri GetUpstreamUrl()

in src/Microsoft.Azure.SignalR.Emulator/Common/Utils.cs [33:76]


        internal static Uri GetUpstreamUrl(string template, string hub, string category, string @event)
        {
            if (string.IsNullOrEmpty(template))
            {
                throw new ArgumentNullException(nameof(template));
            }

            if (string.IsNullOrEmpty(hub))
            {
                throw new ArgumentNullException(nameof(hub));
            }

            if (string.IsNullOrEmpty(category))
            {
                throw new ArgumentNullException(nameof(category));
            }

            if (string.IsNullOrEmpty(@event))
            {
                throw new ArgumentNullException(nameof(@event));
            }

            var replaced = UpstreamReplaceRegex.Replace(template, m =>
            {
                switch (m.Value)
                {
                    case "{hub}":
                        return Uri.EscapeDataString(hub);
                    case "{category}":
                        return Uri.EscapeDataString(category);
                    case "{event}":
                        return Uri.EscapeDataString(@event);
                    default:
                        throw new InvalidOperationException($"Invalid template {m.Value}");
                }
            });

            if (!Uri.TryCreate(replaced, UriKind.Absolute, out var result))
            {
                throw new ArgumentException($"The Upstream url {replaced} is not in a validate absolute URI format.");
            }

            return result;
        }