Beispiel #1
0
        public void AddPackage(IPackage package, bool isAbsoluteLatestVersion, bool isLatestVersion)
        {
            IInternalPackage localPackage;

            using (var transaction = _store.BeginTransaction())
            {
                localPackage = InternalPackage.Create(_feedId, package, isAbsoluteLatestVersion, isLatestVersion);
                transaction.Insert(localPackage);
                transaction.Commit();
            }

            _factory.AddFrameworkNames(localPackage.SupportedFrameworks);
        }
            public static IInternalPackage GetTestPackage(string id, string version)
            {
                var p = new InternalPackage
                {
                    Id                   = 1,
                    PackageId            = id,
                    DownloadCount        = -1,
                    VersionDownloadCount = -1
                };

                p.Version = version;

                return(p);
            }
        public Package Parse(StreamReader scriptsFileStream)
        {
            if (scriptsFileStream == null)
            {
                throw new ArgumentNullException(nameof(scriptsFileStream));
            }

            var content = scriptsFileStream.ReadToEnd();

            InternalPackage pkgInstance = null;

            try
            {
                pkgInstance =
                    JsonConvert.DeserializeObject <InternalPackage>(content);
            }
            catch (Exception ex)
            {
                throw new InvalidDataException("Unable to parse the scripts file!", ex);
            }

            if (pkgInstance == null)
            {
                throw new InvalidDataException("Unable to parse the scripts file!");
            }
            if (String.IsNullOrWhiteSpace(pkgInstance.Name))
            {
                throw new InvalidDataException("The 'name' property is required!");
            }


            if (pkgInstance.Env.Any(s => string.IsNullOrWhiteSpace(s.Key)))
            {
                throw new InvalidDataException("The Variable `name` is required!");
            }
            if (pkgInstance.Commands.Any(s => string.IsNullOrWhiteSpace(s.Key)))
            {
                throw new InvalidDataException("The Command `name` is required!");
            }

            var entryPoint = pkgInstance.EntrypointObject ?? this.defaultEntrypointDetector.GetDefaultEntrypoint();
            var pkg        = new Package(
                pkgInstance.Name,
                pkgInstance.EntrypointObject ?? this.defaultEntrypointDetector.GetDefaultEntrypoint(),
                pkgInstance.Env.Select(s => new EnvVariable(s.Key, s.Value)).ToArray(),
                pkgInstance.Commands.Select(s => new Command(s.Key, s.Value)).ToArray());

            return(pkg);
        }
Beispiel #4
0
 public Factorial()
 {
     PackageToSend = new InternalPackage();
 }
        public override async Task <FileSystemInfo> DownloadAsync(DirectoryInfo folder = null)
        {
            FileInfo downloadFile = (FileInfo)DownloadItem;

            if (IsWinGet)
            {
                // Find the package URI
                await PopulatePackageUri();

                if (Status.IsLessThan(PackageStatus.DownloadReady))
                {
                    return(null);
                }

                // Download package
                downloadFile = (FileInfo)await InternalPackage.DownloadAsync(folder);

                Status = InternalPackage.Status;

                // Set the proper file type and extension
                string filename = Path.GetFileName(PackageUri.ToString());
                downloadFile.MoveRename(filename);
            }
            else
            {
                try
                {
                    // Get system and package info
                    string[] categoryIds = new[] { Model.Skus[0].FulfillmentData.WuCategoryId };
                    var      sysInfo     = Handlers.MicrosoftStore.Win32Helper.GetSystemInfo();
                    folder ??= StorageHelper.GetTempDirectory();

                    // Get update data
                    WeakReferenceMessenger.Default.Send(new PackageFetchStartedMessage(this));
                    var updates = await WindowsUpdateLib.FE3Handler.GetUpdates(categoryIds, sysInfo, "", WindowsUpdateLib.FileExchangeV3UpdateFilter.Application);

                    if (updates == null || !updates.Any())
                    {
                        WeakReferenceMessenger.Default.Send(new ErrorMessage(
                                                                WebException.Create(404, "No packages are available for " + ShortTitle), this, ErrorType.PackageFetchFailed));
                        return(null);
                    }
                    WeakReferenceMessenger.Default.Send(new SuccessMessage(null, this, SuccessType.PackageFetchCompleted));

                    // Set up progress handler
                    void DownloadProgress(DownloadLib.GeneralDownloadProgress progress)
                    {
                        var status = progress.DownloadedStatus[0];

                        WeakReferenceMessenger.Default.Send(
                            new PackageDownloadProgressMessage(this, status.DownloadedBytes, status.File.FileSize));
                    }

                    // Start download
                    WeakReferenceMessenger.Default.Send(new PackageDownloadStartedMessage(this));
                    string[] files = await MSStoreDownloader.DownloadPackageAsync(updates, folder, new DownloadProgress(DownloadProgress));

                    if (files == null || files.Length == 0)
                    {
                        throw new Exception("Failed to download pacakges using WindowsUpdateLib");
                    }
                    Status = InternalPackage.Status = PackageStatus.Downloaded;

                    InternalPackage.DownloadItem = downloadFile = new(Path.Combine(folder.FullName, files[0]));
                    await((ModernPackage <ProductDetails>)InternalPackage).GetInstallerType();
                    Type = InternalPackage.Type;
                }
                catch (Exception ex)
                {
                    WeakReferenceMessenger.Default.Send(new ErrorMessage(ex, this, ErrorType.PackageDownloadFailed));
                    return(null);
                }
            }

            if (Status.IsLessThan(PackageStatus.Downloaded))
            {
                return(null);
            }

            DownloadItem = downloadFile;
            WeakReferenceMessenger.Default.Send(SuccessMessage.CreateForPackageDownloadCompleted(this));
            return(DownloadItem);
        }