예제 #1
0
파일: InitCommand.cs 프로젝트: alexi-t/spm
        protected async override Task RunCommandAsync()
        {
            bool   explicitInclude = HasModifier(explicitIncludeModifier);
            string ignoreSetup     = GetArgumentValue(ignoreList);

            List <string> packageFiles = fileService.GetWorkingDirectoryFiles(ignoreSetup.Split(','));

            FolderVersionEntry version = await versioningService.CreateInitialVersion(packageFiles.ToArray <string>());

            string packageName = uiService.RequestValue($"Enter package name: ");
            string packageHash = hashService.ComputeFilesHash(packageFiles);

            configService.CreateConfig(packageName, packageHash);

            await onlineStoreService.PushPackageAsync($"{packageName}@initial", version);
        }
예제 #2
0
        protected async override Task RunCommandAsync()
        {
            string packageNameAndTag = GetCommandInputValue(packageNameInput);

            string packageName    = packageNameAndTag.Split('@').FirstOrDefault();
            string packageTagName = packageNameAndTag.Contains("@") ? packageNameAndTag.Split('@').LastOrDefault() : string.Empty;

            string[] packageTagHistory = null;

            bool createConfig = false;

            if (configService.TryGetConfig(out Config.PackageConfiguration config))
            {
                if (packageName != config.Name)
                {
                    throw new InvalidOperationException($"Folder binded to another package {config.Name}");
                }

                string currentPackageName = $"{config.Name}@{config.Tag}";
                packageTagHistory = await onlineStoreService.GetPackageTagsAsync(packageNameAndTag, currentPackageName);
            }
            else
            {
                createConfig      = true;
                packageTagHistory = await onlineStoreService.GetAllPackageTagsAsync(packageName);

                if (!string.IsNullOrEmpty(packageTagName))
                {
                    packageTagHistory = packageTagHistory.SkipWhile(t => t != packageTagName).ToArray();
                }
                else
                {
                    uiService.AddMessage($"Pulling {packageName}@{packageTagHistory.FirstOrDefault()}");
                }
            }

            foreach (string packageTag in packageTagHistory.Reverse())
            {
                PackageInfo packageInfo = await onlineStoreService.GetPackageVersionAsync($"{packageName}@{packageTag}");

                FolderVersionEntry folderVersion = JsonConvert.DeserializeObject <FolderVersionEntry>(packageInfo.VersionInfo);

                if (!localStoreService.PackageExist(packageInfo))
                {
                    HttpOperationWithProgress downloadOperation = onlineStoreService.DownloadPackage(packageName, packageTag);

                    downloadOperation.OnProgress += (processedCount, totalCount) =>
                    {
                        uiService.DisplayProgress((float)processedCount * 100 / totalCount);
                    };

                    HttpResponseMessage response = await downloadOperation.GetOperationResultAsync();

                    localStoreService.SavePackage(packageInfo, await response.Content.ReadAsByteArrayAsync());
                }

                localStoreService.RestorePackage(packageName, packageTag);

                if (createConfig)
                {
                    configService.CreateConfig(packageNameAndTag, packageInfo.Hash);
                    createConfig = false;
                }
                else
                {
                    configService.SetTag(packageTag);
                }
            }
        }