public static bool TryCreate(string source, IShimCache cache, out InterceptChannel channel) { // create the interceptor from the intercept.json file. exper string interceptUrl = String.Format(CultureInfo.InvariantCulture, "{0}/intercept.json", source); using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient()) { var reqTask = client.GetAsync(interceptUrl); reqTask.Wait(); HttpResponseMessage response = reqTask.Result; if (response.StatusCode == System.Net.HttpStatusCode.OK) { var resTask = response.Content.ReadAsStringAsync(); resTask.Wait(); JObject obj = JObject.Parse(resTask.Result); channel = new InterceptChannel(source, obj, cache); return true; } channel = null; return false; } }
/// <summary> /// Creates an uninitialized InterceptDispatcher. /// </summary> /// <param name="source">Source url from VS package sources.</param> /// <param name="cache">Cache for storing json blobs.</param> public InterceptDispatcher(string source, IShimCache cache) { _funcs = new Tuple<string, Func<InterceptCallContext, Task>>[] { new Tuple<string, Func<InterceptCallContext, Task>>("Search()/$count", Count), new Tuple<string, Func<InterceptCallContext, Task>>("Search", Search), new Tuple<string, Func<InterceptCallContext, Task>>("FindPackagesById", FindPackagesById), new Tuple<string, Func<InterceptCallContext, Task>>("GetUpdates", GetUpdates), new Tuple<string, Func<InterceptCallContext, Task>>("Packages", Packages), new Tuple<string, Func<InterceptCallContext, Task>>("package-ids", PackageIds), new Tuple<string, Func<InterceptCallContext, Task>>("package-versions", PackageVersions), new Tuple<string, Func<InterceptCallContext, Task>>("api/v2/package-ids", PackageIds), new Tuple<string, Func<InterceptCallContext, Task>>("api/v2/package-versions", PackageVersions), new Tuple<string, Func<InterceptCallContext, Task>>("$metadata", Metadata), new Tuple<string, Func<InterceptCallContext, Task>>("package", DownloadPackage), }; _feedFuncs = new Tuple<string, Func<InterceptCallContext, Task>>[] { new Tuple<string, Func<InterceptCallContext, Task>>("Search()/$count", Feed_Count), new Tuple<string, Func<InterceptCallContext, Task>>("Search", Feed_Search), new Tuple<string, Func<InterceptCallContext, Task>>("FindPackagesById", Feed_FindPackagesById), new Tuple<string, Func<InterceptCallContext, Task>>("Packages", Feed_Packages), new Tuple<string, Func<InterceptCallContext, Task>>("$metadata", Feed_Metadata) }; _source = source.Trim('/'); _initialized = null; _cache = cache; }
/// <summary> /// Creates an uninitialized InterceptDispatcher. /// </summary> /// <param name="source">Source url from VS package sources.</param> /// <param name="cache">Cache for storing json blobs.</param> public InterceptDispatcher(string source, IShimCache cache) { _funcs = new Tuple <string, Func <InterceptCallContext, Task> >[] { new Tuple <string, Func <InterceptCallContext, Task> >("Search()/$count", Count), new Tuple <string, Func <InterceptCallContext, Task> >("Search", Search), new Tuple <string, Func <InterceptCallContext, Task> >("FindPackagesById", FindPackagesById), new Tuple <string, Func <InterceptCallContext, Task> >("GetUpdates", GetUpdates), new Tuple <string, Func <InterceptCallContext, Task> >("Packages", Packages), new Tuple <string, Func <InterceptCallContext, Task> >("package-ids", PackageIds), new Tuple <string, Func <InterceptCallContext, Task> >("package-versions", PackageVersions), new Tuple <string, Func <InterceptCallContext, Task> >("$metadata", Metadata), new Tuple <string, Func <InterceptCallContext, Task> >("package", DownloadPackage) }; _feedFuncs = new Tuple <string, Func <InterceptCallContext, Task> >[] { new Tuple <string, Func <InterceptCallContext, Task> >("Search()/$count", Feed_Count), new Tuple <string, Func <InterceptCallContext, Task> >("Search", Feed_Search), new Tuple <string, Func <InterceptCallContext, Task> >("FindPackagesById", Feed_FindPackagesById), new Tuple <string, Func <InterceptCallContext, Task> >("Packages", Feed_Packages), new Tuple <string, Func <InterceptCallContext, Task> >("$metadata", Feed_Metadata) }; _source = source.Trim('/'); _initialized = null; _cache = cache; }
public static bool TryCreate(string source, IShimCache cache, out InterceptChannel channel) { // create the interceptor from the intercept.json file. exper string interceptUrl = String.Format(CultureInfo.InvariantCulture, "{0}/intercept.json", source); using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient()) { var reqTask = client.GetAsync(interceptUrl); reqTask.Wait(); HttpResponseMessage response = reqTask.Result; if (response.StatusCode == System.Net.HttpStatusCode.OK) { var resTask = response.Content.ReadAsStringAsync(); resTask.Wait(); JObject obj = JObject.Parse(resTask.Result); channel = new InterceptChannel(source, obj, cache); return(true); } channel = null; return(false); } }
public void Dispose() { if (_cache != null) { _cache.Dispose(); _cache = null; } }
internal InterceptChannel(string source, JObject interceptBlob, IShimCache cache) { _resolverBaseAddress = interceptBlob["resolverBaseAddress"].ToString().TrimEnd('/'); _searchAddress = interceptBlob["searchAddress"].ToString().TrimEnd('/'); _passThroughAddress = interceptBlob["passThroughAddress"].ToString().TrimEnd('/'); _listAvailableLatestStableIndex = interceptBlob["isLatestStable"].ToString(); _listAvailableAllIndex = interceptBlob["allVersions"].ToString(); _listAvailableLatestPrereleaseIndex = interceptBlob["isLatest"].ToString(); _source = source.TrimEnd('/'); _cache = cache; }
public void Disable() { _sourceProvider = null; _dispatchers.Clear(); // remove all handlers HttpShim.Instance.ClearHandlers(); if (_cache != null) { _cache.Dispose(); _cache = null; } }
internal InterceptChannel(string source, JObject interceptBlob, IShimCache cache) { _resolverBaseAddress = interceptBlob["resolverBaseAddress"].ToString().TrimEnd('/'); _searchAddress = interceptBlob["searchAddress"].ToString().TrimEnd('/'); _passThroughAddress = interceptBlob["passThroughAddress"].ToString().TrimEnd('/'); _listAvailableLatestStableIndex = interceptBlob["isLatestStable"].ToString(); _listAvailableAllIndex = interceptBlob["allVersions"].ToString(); _listAvailableLatestPrereleaseIndex = interceptBlob["isLatest"].ToString(); if (interceptBlob["metricAddress"] != null) { _metricService = new MetricService(new Uri(interceptBlob["metricAddress"].ToString())); } else { // TODO: Remove this once it has been added to intercept.json _metricService = new MetricService(new Uri("http://api-metrics.nuget.org")); } _source = source.TrimEnd('/'); _cache = cache; }