Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix bugs & issues.
  • Loading branch information
jianyunt committed Jun 21, 2016
1 parent 1a704b7 commit c466661
Show file tree
Hide file tree
Showing 50 changed files with 2,815 additions and 861 deletions.
24 changes: 24 additions & 0 deletions PackageManagement/Api/IHostAPI.cs
Expand Up @@ -15,6 +15,7 @@
namespace Microsoft.PackageManagement.Internal.Api {
using System.Collections.Generic;
using System.Security;
using System.Net;

/// <summary>
/// Functions implemented by the HOST to provide contexual information and control to for the current request.
Expand Down Expand Up @@ -110,6 +111,24 @@ public interface IHostApi {
/// </returns>
int StartProgress(int parentActivityId, string messageText);

/// <summary>
/// Write progress using powershell write progress directly
/// </summary>
/// <param name="activity">Specifies the first line of text in the heading above the status bar.</param>
/// <param name="messageText">Corresponds to status on write-progress. Specifies the second line of text in the heading above the status bar. This text describes current state of the activity.</param>
/// <param name="activityId">
/// Corresponds to id on write-progress. Specifies an ID that distinguishes each progress bar from the others.
/// Use this parameter when you are creating more than one progress bar in a single command.
/// If the progress bars do not have different IDs, they are superimposed instead of being displayed in a series.
/// </param>
/// <param name="progressPercentage">Specifies the percentage of the activity that is completed. Use the value -1 if the percentage complete is unknown or not applicable.</param>
/// <param name="secondsRemaining">Specifies the projected number of seconds remaining until the activity is completed. Use the value -1 if the number of seconds remaining is unknown or not applicable.</param>
/// <param name="currentOperation">Specifies the line of text below the progress bar. This text describes the operation that is currently taking place.</param>
/// <param name="parentActivityId">Identifies the parent activity of the current activity. Use the value -1 if the current activity has no parent activity.</param>
/// <param name="completed">Indicates whether the progress bar is visible</param>
/// <returns></returns>
bool Progress(string activity, string messageText, int activityId, int progressPercentage, int secondsRemaining, string currentOperation, int parentActivityId, bool completed);

/// <summary>
/// Sends a progress update
/// </summary>
Expand Down Expand Up @@ -154,6 +173,11 @@ public interface IHostApi {
/// <returns>an collection of the value for the specified dynamic option</returns>
IEnumerable<string> GetOptionValues(string key);

/// <summary>
/// Proxy used by provider
/// </summary>
IWebProxy WebProxy { get; }

/// <summary>
/// A collection of sources specified by the user. If this is null or empty, the provider should assume 'all the registered sources'
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions PackageManagement/Constants.cs
Expand Up @@ -32,6 +32,7 @@ internal static class Constants {
internal static TimeSpan DefaultResponsiveness = TimeSpan.FromSeconds(15 * 60);

internal static TimeSpan Zero = new TimeSpan(0);
internal static string BootstrapNuGet = "BootstrapNuGet";

#region declare common-constants-implementation

Expand Down Expand Up @@ -72,6 +73,7 @@ internal static class Messages {
internal const string MissingRequiredParameter = "MSG:MissingRequiredParameter";
internal const string NetworkNotAvailable = "MSG:NetworkNotAvailable";
internal const string PackageFailedInstall = "MSG:UnableToInstallPackage_package_reason";
internal const string PackageFailedInstallErrorLog = "MSG:PackageFailedInstallErrorLog";
internal const string PackageSourceExists = "MSG:PackageSourceExists";
internal const string ProtocolNotSupported = "MSG:ProtocolNotSupported";
internal const string ProviderPluginLoadFailure = "MSG:ProviderPluginLoadFailure";
Expand Down
37 changes: 30 additions & 7 deletions PackageManagement/Implementation/PackageManagementService.cs
Expand Up @@ -68,6 +68,7 @@ internal class PackageManagementService : IPackageManagementService {
private readonly Dictionary<string, byte[]> _providerFiles = new Dictionary<string, byte[]>(StringComparer.OrdinalIgnoreCase);
private string _baseDir;
internal bool InternalPackageManagementInstallOnly = false;
private readonly string _nuget ="NuGet";

internal enum ProviderOption
{
Expand Down Expand Up @@ -261,14 +262,35 @@ internal static string CurrentAssemblyLocation
return _packageProviders[providerName].SingleItemAsEnumerable();
}
}

// SelectProviders() is iterating through the loaded provider list. As we still need to go through the
// unloaded provider list, we should not warn users yet at this point of time.
// If the provider is not found, eventually we will error out in SelectProviders()/cmdletbase.cs().

//hostApi.Warn(hostApi.FormatMessageString(Constants.Messages.UnknownProvider, providerName));
}
return Enumerable.Empty<PackageProvider>();
} else {
// If a user does not specify -provider or -provider name, we will bootstrap the nuget provider if it does not exist.
//Only find, install, uninstall, and save cmdlets requires the bootstrap.
var bootstrapNuGet = hostApi.GetOptionValues(Constants.BootstrapNuGet).FirstOrDefault();

if ((bootstrapNuGet != null) && bootstrapNuGet.EqualsIgnoreCase("true")) {
//check if the NuGet provider is already loaded
if (!_packageProviders.Keys.Any(each => each.EqualsIgnoreCase(_nuget))) {
//we'll bootstrap NuGet provider under the following cases:
//case 1: on a clean VM, type install-package foobar
//case 2: on a existing VM, if the nuget provider does not exist and type install-package foobar
//case 3: An existing VM has a old version of the NuGet installed, no bootstrap will occur. This means there is no changes
// to the user, unless he does 'install-packageprovider -name nuget -force'.
if (RequirePackageProvider(null, _nuget, Constants.MinVersion, hostApi)) {
// seems to think we found it.
if (_packageProviders.ContainsKey(_nuget)) {
return PackageProviders.Concat(_packageProviders[_nuget].SingleItemAsEnumerable());
}
}
}
}
}

return PackageProviders;
Expand Down Expand Up @@ -443,7 +465,8 @@ private IEnumerable<PackageProvider> GetPackageProviderFromCacheTable(string pro
Version requiredVersion,
Version minimumVersion,
Version maximumVersion,
bool shouldRefreshCache = false) {
bool shouldRefreshCache = false,
bool logWarning = true) {

ResetProviderCachetable();

Expand Down Expand Up @@ -473,7 +496,7 @@ private IEnumerable<PackageProvider> GetPackageProviderFromCacheTable(string pro
}

//Get available powershell providers
powerShellMetaProvider.RefreshProviders(request.As<IRequest>(), providerName, requiredVersion, minimumVersion, maximumVersion);
powerShellMetaProvider.RefreshProviders(request.As<IRequest>(), providerName, requiredVersion, minimumVersion, maximumVersion, logWarning);
}

/// <summary>
Expand Down Expand Up @@ -548,7 +571,7 @@ private IEnumerable<PackageProvider> GetPackageProviderFromCacheTable(string pro

var providers = isPathRooted ? ImportPackageProviderViaPath(request, providerName, requiredVersion, minimumVersion, maximumVersion, force)
: ImportPackageProviderViaName(request, providerName, requiredVersion, minimumVersion, maximumVersion, force, throwErrorWhenImportWithName);

return providers;
}

Expand Down Expand Up @@ -638,7 +661,7 @@ private IEnumerable<PackageProvider> GetPackageProviderFromCacheTable(string pro
}

//If the provider is not in the cache list, rescan for providers
ScanForAvailableProviders(request, providerName, requiredVersion, minimumVersion, maximumVersion, true);
ScanForAvailableProviders(request, providerName, requiredVersion, minimumVersion, maximumVersion, true, false);
results = FindMatchedProvidersFromInternalCacheTable(request, providerName, requiredVersion, minimumVersion, maximumVersion, force).ToArray();
if (!results.Any()) {
if (throwErrorWhenImportWithName)
Expand Down Expand Up @@ -1113,7 +1136,7 @@ private IMetaProvider GetMetaProviderObject(IHostApi request)
return _packageProviders.Values.SelectMany(each => each.ResolvePackageSources(request));
}
/// <summary>
/// Searches for the assembly, interrogates it for it's providers and then proceeds to load
/// </summary>
Expand Down
12 changes: 11 additions & 1 deletion PackageManagement/Implementation/Request.cs
Expand Up @@ -14,6 +14,7 @@

namespace Microsoft.PackageManagement.Internal.Implementation {
using System;
using System.Net;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand Down Expand Up @@ -50,6 +51,8 @@ public abstract class Request : IRequest {

public abstract bool Progress(int activityId, int progressPercentage, string messageText);

public abstract bool Progress(string activity, string messageText, int activityId, int progressPercentage, int secondsRemaining, string currentOperation, int parentActivityId, bool completed);

public abstract bool CompleteProgress(int activityId, bool isSuccessful);

/// <summary>
Expand All @@ -66,6 +69,8 @@ public abstract class Request : IRequest {

public abstract IEnumerable<string> Sources {get;}

public abstract IWebProxy WebProxy { get; }

public abstract string CredentialUsername { get; }

public abstract SecureString CredentialPassword { get; }
Expand Down Expand Up @@ -215,6 +220,11 @@ public abstract class Request : IRequest {
return StartProgress(parentActivityId, FormatMessageString(messageText, args));
}

public bool Progress(string activity, string messageText, int activityId, int progressPercentage, int secondsRemaining, string currentOperation, int parentActivityId, bool completed, params object[] args)
{
return Progress(activity, FormatMessageString(messageText, args), activityId, progressPercentage, secondsRemaining, currentOperation, parentActivityId, completed);
}

public bool Progress(int activityId, int progressPercentage, string messageText, params object[] args) {
return Progress(activityId, progressPercentage, FormatMessageString(messageText, args));
}
Expand All @@ -234,7 +244,7 @@ public abstract class Request : IRequest {

#endregion

private string FormatMessageString(string messageText, params object[] args) {
protected string FormatMessageString(string messageText, params object[] args) {
if (string.IsNullOrWhiteSpace(messageText)) {
return string.Empty;
}
Expand Down
19 changes: 19 additions & 0 deletions PackageManagement/Implementation/RequestObject.cs
Expand Up @@ -23,6 +23,7 @@ namespace Microsoft.PackageManagement.Internal.Implementation {
using Utility.Async;
using Utility.Extensions;
using Microsoft.PackageManagement.Internal.Packaging;
using System.Net;

public abstract class RequestObject : AsyncAction, IRequest, IHostApi {
private static int _c;
Expand Down Expand Up @@ -171,6 +172,16 @@ public abstract class RequestObject : AsyncAction, IRequest, IHostApi {
return true;
}

public bool Progress(string activity, string status, int id, int percentcomplete, int secondsremaining, string currentoperation, int parentid, bool completed)
{
if (CanCallHost)
{
return _hostApi.Progress(activity, status, id, percentcomplete, secondsremaining, currentoperation, parentid, completed);
}

return true;
}

public bool CompleteProgress(int activityId, bool isSuccessful) {
if (CanCallHost) {
return _hostApi.CompleteProgress(activityId, isSuccessful);
Expand Down Expand Up @@ -203,6 +214,14 @@ public abstract class RequestObject : AsyncAction, IRequest, IHostApi {
}
}

public IWebProxy WebProxy
{
get
{
return CanCallHost ? _hostApi.WebProxy : null;
}
}

public string CredentialUsername {
get {
return CanCallHost ? _hostApi.CredentialUsername : null;
Expand Down
35 changes: 27 additions & 8 deletions PackageManagement/Packaging/SoftwareIdentity.cs
Expand Up @@ -36,7 +36,7 @@ public SoftwareIdentity(XDocument document)
public SoftwareIdentity() {
}

internal string FastPackageReference {get; set;}
public string FastPackageReference {get; set;}
internal PackageProvider Provider {get; set;}

public string ProviderName {
Expand All @@ -45,18 +45,12 @@ public SoftwareIdentity(XDocument document)
}
}

public IEnumerable<string> Dependencies {
get {
return Links.Where(each => Iso19770_2.Relationship.Requires == each.Relationship).Select(each => each.HRef).WhereNotNull().Select(each => Uri.UnescapeDataString(each.ToString())).ReEnumerable();
}
}

public string Source {get; internal set;}
public string Status {get; internal set;}
public string SearchKey {get; internal set;}
public string FullPath {get; internal set;}
public string PackageFilename {get; internal set;}
public bool FromTrustedSource {get; internal set;}
public bool FromTrustedSource {get; set;}

public string Summary {
get {
Expand Down Expand Up @@ -94,6 +88,31 @@ public SoftwareIdentity(XDocument document)
}
}

internal string InstallationPath
{
get
{
// no payload or directories, just returns empty string
if (Payload == null || Payload.Directories == null)
{
return string.Empty;
}

// find the installation directories based on the payload.
var installationDirectories = Payload.Directories
// Use the directory if it is key, if its location is not null or white space and its name is not null or whitespace
.Where(directory => directory.IsKey.HasValue
&& (bool)directory.IsKey
&& !string.IsNullOrWhiteSpace(directory.Location)
&& !string.IsNullOrWhiteSpace(directory.Name))
// combine location and name to get the directory
.Select(directory => System.IO.Path.Combine(directory.Location, directory.Name));

// if there is installation directories, concat them with comma
return installationDirectories.JoinWithComma();
}
}

internal static string CreateCanonicalId(string provider, string name, string version, string source) {
if (provider == null || name == null) {
return null;
Expand Down
8 changes: 8 additions & 0 deletions PackageManagement/Packaging/Swidtag.cs
Expand Up @@ -105,6 +105,14 @@ private void ChangeCurrentNameSpace()
return MediaQuery.IsApplicable(AppliesToMedia, environment);
}

public IEnumerable<string> Dependencies
{
get
{
return Links.Where(each => Iso19770_2.Relationship.Requires == each.Relationship).Select(each => each.HRef).WhereNotNull().Select(each => Uri.UnescapeDataString(each.ToString())).ReEnumerable();
}
}

#region Attributes

public bool? IsCorpus {
Expand Down
3 changes: 2 additions & 1 deletion PackageManagement/Providers/IMetaProvider.cs
Expand Up @@ -62,9 +62,10 @@ public interface IMetaProvider : IProvider {
/// <param name="requiredVersion">Retrieves only the specified version of the provider</param>
/// <param name="minimumVersion">Retrieves only a version of the provider that is greater than or equal to the specified value</param>
/// <param name="maximumVersion">Retrieves only a version of the provider that is less than the specified value</param>
/// <param name="logWarning"></param>
/// <returns></returns>
[Required]
void RefreshProviders(IRequest request, string providerName, Version requiredVersion, Version minimumVersion, Version maximumVersion);
void RefreshProviders(IRequest request, string providerName, Version requiredVersion, Version minimumVersion, Version maximumVersion, bool logWarning);

/// <summary>
/// Load a particular provider written in powershell module.
Expand Down
4 changes: 4 additions & 0 deletions PackageManagement/Resources/Messages.resx
Expand Up @@ -189,6 +189,10 @@
<value>Unable to download from URI '{0}' to '{1}'.</value>
<comment>0 source uri, 1 destination file name</comment>
</data>
<data name="PackageFailedInstallErrorLog" xml:space="preserve">
<value>The package '{0}' failed to install. Please look at '{1}' file for details.</value>
<comment>0 package id, 1 path to error log file</comment>
</data>
<data name="UnableToInstallPackage_package_reason" xml:space="preserve">
<value>The package '{0}' failed to install.</value>
<comment>0 package id</comment>
Expand Down

0 comments on commit c466661

Please sign in to comment.