Esempio n. 1
0
        public async Task IndexPackage(UserInfo userInfo, IStorageFeed feed, PackageName packageName, IPackageStorageItem packageItem, ZipPackage package)
        {
            var statusPackageBuilder = CreatePackage(packageName, package);
            var statusPackageState   = PackageState.Partial;

            try
            {
                var statusFiles = await ProcessThrottled(
                    2, addInfoBuilder.Build(new NugetPackage(package)),
                    async i => await IndexImage(feed, packageName, i));

                foreach (var statusFile in statusFiles)
                {
                    statusPackageBuilder.Files.Add(CreateFile(statusFile.FilePath, statusFile.ImageStatus));
                }

                if (statusFiles.All(s => s.ImageStatus.Check(true)))
                {
                    statusPackageState = PackageState.Succeded;
                }

                Trace.TraceInformation("Marking package {0} as {1}", packageName, statusPackageState);
            }
            catch (Exception e)
            {
                support.TrackException(e, new { packageName });
                Trace.TraceError("Error while indexing package {0}:\n{1}", packageName, e);
                statusPackageBuilder.Files.Add(CreateFile("error.txt", e.ToString()));
            }

            if (statusPackageBuilder.Files.Count == 0)
            {
                statusPackageBuilder.Files.Add(CreateFile("empty.txt", string.Empty));
            }

            Debug.WriteLine("Saving package processing status {0}", packageName);
            var statusPackageItem = feed.GetPackage(await packageItem.GetUserName(), statusPackageState, packageName);

            using (var statusStream = await statusPackageItem.Put())
                statusPackageBuilder.SaveBuffered(statusStream);

            switch (statusPackageState)
            {
            case PackageState.Partial:
                await notifier.PartiallyIndexed(userInfo, packageName);

                break;

            case PackageState.Succeded:
                await notifier.Indexed(userInfo, packageName);

                break;

            default:
                // ReSharper disable once NotResolvedInText
                throw new ArgumentOutOfRangeException("statusPackageState", statusPackageState, null);
            }
        }