public static NuGetModel GetModel(INuGetGalleryDescriptor descriptor, IWebMatrixHost webMatrixHost, FeedSource remoteSource, string destination, Func <Uri, string, INuGetPackageManager> packageManagerCreator, TaskScheduler scheduler, bool includePrerelease = false) { if (destination == null) { var siteRoot = webMatrixHost.WebSite == null ? null : webMatrixHost.WebSite.Path; if (String.IsNullOrWhiteSpace(siteRoot)) { Debug.Fail("The NuGetModel needs a site with a physical path"); return(null); } destination = siteRoot; } NuGetModel model; lock (_cache) { var key = new Tuple <string, FeedSource, bool>(destination, remoteSource, includePrerelease); if (_cache.TryGetValue(key, out model)) { model.FromCache = true; } else { INuGetPackageManager packageManager; if (packageManagerCreator == null) { packageManager = new NuGetPackageManager(remoteSource.SourceUrl, destination, webMatrixHost); } else { packageManager = packageManagerCreator(remoteSource.SourceUrl, destination); } model = new NuGetModel(descriptor, webMatrixHost, remoteSource, destination, packageManager, scheduler); packageManager.IncludePrerelease = includePrerelease; _cache[key] = model; } } Debug.Assert(model != null, "model should be created"); return(model); }
public static NuGetModel GetModel(INuGetGalleryDescriptor descriptor, IWebMatrixHost webMatrixHost, FeedSource remoteSource, string destination, Func<Uri, string, INuGetPackageManager> packageManagerCreator, TaskScheduler scheduler, bool includePrerelease = false) { if (destination == null) { var siteRoot = webMatrixHost.WebSite == null ? null : webMatrixHost.WebSite.Path; if (String.IsNullOrWhiteSpace(siteRoot)) { Debug.Fail("The NuGetModel needs a site with a physical path"); return null; } destination = siteRoot; } NuGetModel model; lock (_cache) { var key = new Tuple<string, FeedSource, bool>(destination, remoteSource, includePrerelease); if (_cache.TryGetValue(key, out model)) { model.FromCache = true; } else { INuGetPackageManager packageManager; if (packageManagerCreator == null) { packageManager = new NuGetPackageManager(remoteSource.SourceUrl, destination, webMatrixHost); } else { packageManager = packageManagerCreator(remoteSource.SourceUrl, destination); } model = new NuGetModel(descriptor, webMatrixHost, remoteSource, destination, packageManager, scheduler); packageManager.IncludePrerelease = includePrerelease; _cache[key] = model; } } Debug.Assert(model != null, "model should be created"); return model; }