private PackageSource ResolvePackageSource(string nameOrLocation)
{
Debug(Resources.Messages.DebugInfoCallMethod3, "NuGetRequest", "ResolvePackageSource", nameOrLocation);
if (IsCanceled) {
return null;
}
var source = FindRegisteredSource(nameOrLocation);
if (source != null) {
Debug(Resources.Messages.FoundRegisteredSource, nameOrLocation, NuGetConstant.ProviderName);
return source;
}
Debug(Resources.Messages.NotFoundRegisteredSource, nameOrLocation, NuGetConstant.ProviderName);
try {
// is the given value a filename?
if (File.Exists(nameOrLocation)) {
Debug(Resources.Messages.SourceIsAFilePath, nameOrLocation);
return new PackageSource() {
Request = this,
IsRegistered = false,
IsValidated = true,
Location = nameOrLocation,
Name = nameOrLocation,
Trusted = true,
};
}
} catch {
}
try {
// is the given value a directory?
if (Directory.Exists(nameOrLocation)) {
Debug(Resources.Messages.SourceIsADirectory, nameOrLocation);
return new PackageSource() {
Request = this,
IsRegistered = false,
IsValidated = true,
Location = nameOrLocation,
Name = nameOrLocation,
Trusted = true,
};
}
} catch {
}
if (Uri.IsWellFormedUriString(nameOrLocation, UriKind.Absolute)) {
var uri = new Uri(nameOrLocation, UriKind.Absolute);
if (!SupportedSchemes.Contains(uri.Scheme.ToLowerInvariant())) {
WriteError(ErrorCategory.InvalidArgument, uri.ToString(), Constants.Messages.UriSchemeNotSupported, uri);
return null;
}
// this is an URI, and it looks like one type that we support
if (SkipValidate.Value || NuGetPathUtility.ValidateSourceUri(SupportedSchemes, uri, this)) {
var uriSource = new PackageSource {
Request = this,
IsRegistered = false,
IsValidated = !SkipValidate.Value,
Location = nameOrLocation,
Name = nameOrLocation,
Trusted = false,
};
return uriSource;
}
}
WriteError(ErrorCategory.InvalidArgument, nameOrLocation, Constants.Messages.UnableToResolveSource, nameOrLocation);
return null;
}