private bool TryGetCredentials(Uri uri, out NetworkCredential configurationCredentials)
{
var source = _packageSourceProvider.LoadPackageSources().FirstOrDefault(p =>
{
Uri sourceUri;
return !String.IsNullOrEmpty(p.UserName)
&& !String.IsNullOrEmpty(p.Password)
&& Uri.TryCreate(p.Source, UriKind.Absolute, out sourceUri)
&& UriUtility.UriEquals(sourceUri, uri);
});
if (source == null)
{
// The source is not in the config file
configurationCredentials = null;
return false;
}
configurationCredentials = new NetworkCredential(source.UserName, source.Password);
return true;
}
}