예제 #1
0
        private List <FeedConfiguration> GetSource(params string[] names)
        {
            var sources = new List <FeedConfiguration>();
            var all     = new List <FeedConfiguration>();

            PackageManager.FeedConfigurationAvailable += (sender, args) =>
            {
                all.Add(args.FeedConfiguration);
            };

            ClientLibraryRequest clientLibraryRequest = PackageManager.GetFeedConfigurations();

            clientLibraryRequest.WaitUntilRequestCompletes();

            if (names.Any())
            {
                // the system is requesting sources that match the values passed.
                // if the value passed can be a legitimate source, but is not registered, return a package source marked unregistered.
                foreach (var source in all)
                {
                    if (names.Any(name => name.ToLower() == source.Name.ToLower() || name.ToLower() == source.Uri.ToLower()))
                    {
                        sources.Add(source);
                    }
                }
            }
            else
            {
                sources = all;
            }
            return(sources);
        }
예제 #2
0
        /// <summary>
        /// Searches package sources given name and version information
        ///
        /// Package information must be returned using <c>request.YieldPackage(...)</c> function.
        /// </summary>
        /// <param name="name">a name or partial name of the package(s) requested</param>
        /// <param name="requiredVersion">A specific version of the package. Null or empty if the user did not specify</param>
        /// <param name="minimumVersion">A minimum version of the package. Null or empty if the user did not specify</param>
        /// <param name="maximumVersion">A maximum version of the package. Null or empty if the user did not specify</param>
        /// <param name="id">if this is greater than zero (and the number should have been generated using <c>StartFind(...)</c>, the core is calling this multiple times to do a batch search request. The operation can be delayed until <c>CompleteFind(...)</c> is called</param>
        /// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
        public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, Request request)
        {
            request.Debug("Calling '{0}::FindPackage' '{1}','{2}','{3}','{4}'", PackageProviderName, requiredVersion, minimumVersion, maximumVersion, id);

            var availablePackages = new List <PackageMetadata>();

            PackageManager.PackageMetadataAvailable += (sender, args) =>
            {
                availablePackages.Add(args.PackageMetadata);
            };
            try
            {
                var sources = GetSource(request.Sources.ToArray()).Select(source => source.Name);
                ClientLibraryRequest clientLibraryRequest = PackageManager.GetAvailablePackages(sources);
                clientLibraryRequest.WaitUntilRequestCompletes();
            }
            catch (NIPkgException e)
            {
                request.Debug(e.Message);
            }
            foreach (var package in availablePackages.Where(package => package.GetDisplayName(CultureInfo.CurrentCulture).ToLower() == name.ToLower() || package.PackageName.ToLower() == name.ToLower() || name.Equals(string.Empty)))
            {
                request.YieldSoftwareIdentity(package);
            }
        }
예제 #3
0
        /// <summary>
        /// Returns the packages that are installed
        /// </summary>
        /// <param name="name">the package name to match. Empty or null means match everything</param>
        /// <param name="requiredVersion">the specific version asked for. If this parameter is specified (ie, not null or empty string) then the minimum and maximum values are ignored</param>
        /// <param name="minimumVersion">the minimum version of packages to return . If the <code>requiredVersion</code> parameter is specified (ie, not null or empty string) this should be ignored</param>
        /// <param name="maximumVersion">the maximum version of packages to return . If the <code>requiredVersion</code> parameter is specified (ie, not null or empty string) this should be ignored</param>
        /// <param name="request">
        ///     An object passed in from the CORE that contains functions that can be used to interact with
        ///     the CORE and HOST
        /// </param>
        public void GetInstalledPackages(string name, string requiredVersion, string minimumVersion, string maximumVersion, Request request)
        {
            // Nice-to-have put a debug message in that tells what's going on.
            request.Debug("Calling '{0}::GetInstalledPackages' '{1}','{2}','{3}','{4}'", PackageProviderName, name, requiredVersion, minimumVersion, maximumVersion);

            var installedPackages = new List <PackageMetadata>();

            PackageManager.InstalledPackageMetadataAvailable += (sender, args) =>
            {
                if (name == string.Empty || name == args.PackageMetadata.PackageName || name == args.PackageMetadata.GetDisplayName(CultureInfo.CurrentCulture))
                {
                    installedPackages.Add(args.PackageMetadata);
                }
            };
            try
            {
                ClientLibraryRequest clientLibraryRequest = PackageManager.GetInstalledPackages();
                clientLibraryRequest.WaitUntilRequestCompletes();
            }
            catch (NIPkgException e)
            {
                request.Debug(e.Message);
            }
            foreach (var package in installedPackages)
            {
                request.YieldSoftwareIdentity(package);
            }
        }
예제 #4
0
        /// <summary>
        /// Removes/Unregisters a package source
        /// </summary>
        /// <param name="name">The name or location of a package source to remove.</param>
        /// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
        public void RemovePackageSource(string name, Request request)
        {
            request.Debug("Entering {0} source remove -n={1})", PackageProviderName, name);

            try
            {
                ClientLibraryRequest clientLibraryRequest = PackageManager.RemoveFeedConfiguration(name.ToLower());
                clientLibraryRequest.WaitUntilRequestCompletes();
            }
            catch (NIPkgException e)
            {
                request.Debug(e.Message);
            }
        }
예제 #5
0
        /// <summary>
        /// This is called when the user is adding (or updating) a package source
        ///
        /// If this PROVIDER doesn't support user-defined package sources, remove this method.
        /// </summary>
        /// <param name="name">The name of the package source. If this parameter is null or empty the PROVIDER should use the location as the name (if the PROVIDER actually stores names of package sources)</param>
        /// <param name="location">The location (ie, directory, URL, etc) of the package source. If this is null or empty, the PROVIDER should use the name as the location (if valid)</param>
        /// <param name="trusted">A boolean indicating that the user trusts this package source. Packages returned from this source should be marked as 'trusted'</param>
        /// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
        public void AddPackageSource(string name, string location, bool trusted, Request request)
        {
            request.Debug("Entering {0} source add -n={1} -s'{2}' (we don't support trusted = '{3}')", PackageProviderName, name, location, trusted);

            try
            {
                ClientLibraryRequest addFeedRequest = PackageManager.AddFeedConfiguration(location, name.ToLower());
                addFeedRequest.WaitUntilRequestCompletes();
                ClientLibraryRequest updateFeedRequest = PackageManager.UpdateFeed(name.ToLower());
                updateFeedRequest.WaitUntilRequestCompletes();
            }
            catch (NIPkgException e)
            {
                request.Debug(e.Message);
            }
        }
예제 #6
0
        /// <summary>
        /// Uninstalls a package
        /// </summary>
        /// <param name="fastPackageReference"></param>
        /// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
        public void UninstallPackage(string fastPackageReference, Request request)
        {
            request.Debug("Calling '{0}::UninstallPackage' '{1}'", PackageProviderName, fastPackageReference);

            var    packageName   = GetPackageNameFromFastPackageReference(fastPackageReference);
            string oldAction     = string.Empty;
            string currentAction = string.Empty;
            int    activityID    = 0;

            PackageManager.RequestMadeProgress += (sender, args) =>
            {
                currentAction = args.Progress.ActionCode.ToString();
                if (currentAction != oldAction)
                {
                    if (activityID != 0)
                    {
                        request.CompleteProgress(activityID, true);
                    }
                    activityID = request.StartProgress(NipkgConstants.ParentActivityID, NipkgConstants.UninstallText + packageName);
                    oldAction  = currentAction;
                }
                request.Progress(activityID, (int)args.Progress.PercentageCompleted, currentAction + " " + args.Progress.Arg1);
                request.Debug(args.Progress.PercentageCompleted + string.Empty);
            };
            try
            {
                ClientLibraryRequest clientLibraryRequest = PackageManager.RemovePackages(new List <string>()
                {
                    packageName
                }, NIPkgTransactionFlag.AcceptLicenses);
                clientLibraryRequest.WaitUntilRequestCompletes();
            }
            catch (NIPkgException e)
            {
                request.Debug(e.Message);
            }
            request.YieldSoftwareIdentity(
                fastPackageReference,
                packageName,
                GetPackageVersionFromFastPackageReference(fastPackageReference),
                NipkgConstants.VersionScheme,
                GetPackageSummaryFromFastPackageReference(fastPackageReference),
                NipkgConstants.PackageSource,
                packageName /* useless */,
                string.Empty /* useless */,
                packageName + NipkgConstants.NipkgFileExtension /* useless */);
        }
예제 #7
0
        /// <summary>
        /// Performs one-time initialization of the $provider.
        /// </summary>
        /// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
        public void InitializeProvider(Request request)
        {
            request.Debug("Calling '{0}::InitializeProvider'", PackageProviderName);

            try
            {
                PackageManager = new PackageManager();
                PackageManager.InitializeSession(GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version.ToString());
                SetConfiguration("nipkg.disablefileagent", "false");
                foreach (var feed in GetSource(request.Sources.ToArray()))
                {
                    ClientLibraryRequest clientLibraryRequest = PackageManager.UpdateFeed(feed);
                    clientLibraryRequest.WaitUntilRequestCompletes();
                }
            }
            catch (NIPkgException e)
            {
                request.Debug(e.Message);
            }
        }
예제 #8
0
        /*
         * /// <summary>
         * /// Finds packages given a locally-accessible filename
         * ///
         * /// Package information must be returned using <c>request.YieldPackage(...)</c> function.
         * /// </summary>
         * /// <param name="file">the full path to the file to determine if it is a package</param>
         * /// <param name="id">if this is greater than zero (and the number should have been generated using <c>StartFind(...)</c>, the core is calling this multiple times to do a batch search request. The operation can be delayed until <c>CompleteFind(...)</c> is called</param>
         * /// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
         * public void FindPackageByFile(string file, int id, Request request)
         * {
         *  // Nice-to-have put a debug message in that tells what's going on.
         *  request.Debug("Calling '{0}::FindPackageByFile' '{1}','{2}'", PackageProviderName, file, id);
         *
         *  // todo: find a package by file
         * }
         *
         * /// <summary>
         * /// Finds packages given a URI.
         * ///
         * /// The function is responsible for downloading any content required to make this work
         * ///
         * /// Package information must be returned using <c>request.YieldPackage(...)</c> function.
         * /// </summary>
         * /// <param name="uri">the URI the client requesting a package for.</param>
         * /// <param name="id">if this is greater than zero (and the number should have been generated using <c>StartFind(...)</c>, the core is calling this multiple times to do a batch search request. The operation can be delayed until <c>CompleteFind(...)</c> is called</param>
         * /// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
         * public void FindPackageByUri(Uri uri, int id, Request request)
         * {
         *  // Nice-to-have put a debug message in that tells what's going on.
         *  request.Debug("Calling '{0}::FindPackageByUri' '{1}','{2}'", PackageProviderName, uri, id);
         *
         *  // todo: find a package by uri
         * }
         */

        /// <summary>
        /// Downloads a remote package file to a local location.
        /// </summary>
        /// <param name="fastPackageReference"></param>
        /// <param name="location"></param>
        /// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
        public void DownloadPackage(string fastPackageReference, string location, Request request)
        {
            request.Debug("Calling '{0}::DownloadPackage' '{1}','{2}'", PackageProviderName, fastPackageReference, location);

            var packageName     = GetPackageNameFromFastPackageReference(fastPackageReference);
            var childActivityID = request.StartProgress(NipkgConstants.ParentActivityID, packageName);

            PackageManager.RequestMadeProgress += (sender, args) =>
            {
                request.Progress(childActivityID, (int)args.Progress.PercentageCompleted, NipkgConstants.DownloadText + packageName);
                request.Debug(args.Progress.PercentageCompleted + string.Empty);
            };
            try
            {
                ClientLibraryRequest clientLibraryRequest = PackageManager.DownloadPackage(new List <string>()
                {
                    packageName
                }, location);
                clientLibraryRequest.WaitUntilRequestCompletes();
            }
            catch (NIPkgException e)
            {
                request.CompleteProgress(childActivityID, false);
                request.Debug(e.Message);
            }
            request.CompleteProgress(childActivityID, true);
            request.YieldSoftwareIdentity(
                fastPackageReference,
                packageName,
                GetPackageVersionFromFastPackageReference(fastPackageReference),
                NipkgConstants.VersionScheme,
                GetPackageSummaryFromFastPackageReference(fastPackageReference),
                NipkgConstants.PackageSource,
                packageName /* useless */,
                location,
                packageName + NipkgConstants.NipkgFileExtension /* useless */);
        }
예제 #9
0
        /// <summary>
        /// Sets a Package Manager configuration attribute value.
        /// </summary>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <param name="attributeValue">The attribute value.</param>
        public void SetConfiguration(string attributeName, string attributeValue)
        {
            ClientLibraryRequest clientLibraryRequest = PackageManager.SetConfiguration(attributeName, attributeValue);

            clientLibraryRequest.WaitUntilRequestCompletes();
        }