Esempio n. 1
0
        /// <summary>
        /// Gathers the response data from the V3 source for the context uri.
        /// </summary>
        public async Task Invoke(InterceptCallContext context)
        {
            try
            {
                if (_initialized != true)
                {
                    throw new InvalidOperationException("Requires Init");
                }

                string unescapedAbsolutePath = Uri.UnescapeDataString(context.RequestUri.AbsolutePath);

                string path = unescapedAbsolutePath;

                // v2 is still in the path for get-package
                if (unescapedAbsolutePath.IndexOf(ShimConstants.V2UrlPath) > -1)
                {
                    path = unescapedAbsolutePath.Remove(0, ShimConstants.V2UrlPath.Length);
                }
                else if (unescapedAbsolutePath.IndexOf(ShimConstants.V3UrlPath) > -1)
                {
                    path = unescapedAbsolutePath.Remove(0, ShimConstants.V3UrlPath.Length);
                }

                foreach (var func in _funcs)
                {
                    if (path == string.Empty)
                    {
                        await Root(context);

                        return;
                    }
                    else if (path.StartsWith(func.Item1))
                    {
                        await func.Item2(context);

                        return;
                    }
                }

                //  url was not recognized - perhaps this is a feed

                int index1 = path.IndexOf('/', 0) + 1;
                if (index1 < path.Length)
                {
                    int index2 = path.IndexOf('/', index1);
                    if (index2 < path.Length)
                    {
                        path = path.Remove(0, index2 + 1);
                    }
                }

                foreach (var func in _feedFuncs)
                {
                    if (path == string.Empty)
                    {
                        await _channel.Root(context);

                        //await Feed_Root(context);
                        return;
                    }
                    if (path.StartsWith(func.Item1))
                    {
                        await func.Item2(context);

                        return;
                    }
                }

                // unknown process
                throw new NotImplementedException();
            }
            catch (Exception ex)
            {
                context.Log(String.Format(CultureInfo.InvariantCulture, "[V3 ERR] (exception:{0}) {1}", ex.GetType().ToString(), context.RequestUri.AbsoluteUri), ConsoleColor.Red);
                throw;
            }
        }