Esempio n. 1
0
        private async Task DownloadPackage(ILocalBaseFolder localBaseFolder,
                                           string sourceName,
                                           CancellationToken cancelationToken, InternalPackageInformation info)
        {
            var descriptionPath = $@"{info.Package.OutputFolder}\vendor.dependency.description.json";
            VendorDependencyDescription description;

            if (!_forceRefresh && localBaseFolder.ContainsFolder(info.Package.OutputFolder))
            {
                var content = await localBaseFolder.FileContentOrEmptyAsync(
                    descriptionPath,
                    cancelationToken);

                if (!string.IsNullOrWhiteSpace(content))
                {
                    try
                    {
                        description = JsonConvert.DeserializeObject <VendorDependencyDescription>(content);
                    }
                    catch (Exception)
                    {
                        // TODO : log this error
                        description = new VendorDependencyDescription {
                            Version = ""
                        };
                    }

                    if (info.Identity.Version.ToFullString() == description.Version)
                    {
                        listeners(new AlreadyUpToDate(info.Package));
                        return;
                    }
                }
            }

            await Download(sourceName, info, localBaseFolder, cancelationToken);

            using (var descriptionStream = localBaseFolder.OpenStreamForWriting(descriptionPath))
            {
                description = new VendorDependencyDescription
                {
                    Version = info.Identity.Version.ToFullString()
                };
                var serialized = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(description, Formatting.Indented));

                await descriptionStream.WriteAsync(serialized, 0, serialized.Length, cancelationToken);
            }
        }