public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Acquirable ac = value as Acquirable;

            if (ac != null)
            {
                return(string.Format("{0:0.00} {1}", ac.Cost, ac.Currency));
            }
            else
            {
                return(string.Empty);
            }
        }
 public static async Task RunAsync(Acquirable acquirable, ITextWriter writer, ToolArguments args)
 {
     try
     {
         var sdkAcquirer = new SdkAcquirer(new HttpClient(), writer, new InstallerLauncher(writer, args), new PlatformIdentifier(), new DotnetInfo());
         await sdkAcquirer.Acquire(acquirable);
     }
     catch (FileNotFoundException e)
     {
         writer.WriteLine(e.Message);
     }
     catch (TaskCanceledException e)
     {
         if (!e.CancellationToken.IsCancellationRequested)
         {
             writer.WriteLine("Connection to acquire .NET SDK timed out, please try again");
         }
     }
 }
示例#3
0
 /**
  * If an item isn't currently readied, then the next item of the
  * acquired-item type is readied.
  */
 private void OnAcquisitionOf(Acquirable acquirable)
 {
     // The item isn't readied directly using ReadyItem() because we want it to
     // be pulled from inventory.
     if (!readiedItem)
         ReadyNext(acquirable.type);
 }
示例#4
0
    /**
     * Removes the acquirable from the current temptations.
     */
    public void Forget(Acquirable acquirable)
    {
        temptations.Remove(acquirable.id);

        if (fixation != null && fixation.id == acquirable.id)
            fixation = null;
    }
示例#5
0
 /**
  * Disables items upon acquisition.
  */
 private void OnAcquisitionOf(Acquirable acquirable)
 {
     acquirable.inventoryObject.SetActiveRecursively(false);
 }
示例#6
0
    /**
     * Calculate the current fixation by calling the fixator delegate.
     */
    private void CalculateFixation()
    {
        fixation = fixate(temptations);

        if (oldFixation != fixation)
            UpdateFixations();
    }
示例#7
0
    /**
     * Tempts the acquirer with the given acquirable and returns whether the
     * acquirer is tempted.
     */
    public bool TemptWith(Acquirable acquirable)
    {
        if (acquires.Contains(acquirable.type)) {
            if (!temptations.ContainsKey(acquirable.id)) {
                temptations.Add(acquirable.id, acquirable);
            }

            return true;
        }

        return false;
    }
        public async Task Acquire(Acquirable acquirable)
        {
            var result = await acquirable.Fetch(_httpClient);

            if (!result.IsSuccess)
            {
                return;
            }

            if (await CheckSdkExists(result.Version))
            {
                _textWriter.WriteLine($"SDK version {result.Version} is already installed.");
                return;
            }

            using var channelResponse = await JsonDocument.ParseAsync(await _httpClient.GetStreamAsync(result.ChannelJson));

            var file = channelResponse
                       .RootElement.GetProperty("releases").EnumerateArray()
                       .SelectMany(x =>
            {
                IEnumerable <JsonElement> GetSdks()
                {
                    yield return(x.GetProperty("sdk"));

                    if (x.TryGetProperty("sdks", out var sdks))
                    {
                        foreach (var y in sdks.EnumerateArray())
                        {
                            yield return(y);
                        }
                    }
                }

                return(GetSdks());
            })
                       .First(x => x.GetProperty("version").GetString() == result.Version)
                       .GetProperty("files")
                       .EnumerateArray()
                       .First(FileFilter);

            var name         = file.GetProperty("name").GetString();
            var installerUrl = file.GetProperty("url").GetString();
            var fileHash     = file.GetProperty("hash").GetString();

            var filePath = Path.Combine(Path.GetTempPath(), name);

            _textWriter.WriteLine($"Starting download of .NET Core SDK Version {result.Version}");
            using (var installerStream = await _httpClient.GetStreamAsync(installerUrl))
            {
                using var fileStream = new FileStream(filePath, FileMode.Create);
                var progress = new Progress <long>();

                var lastReportedBytesMbs = 0;
                progress.ProgressChanged += (sender, totalBytes) =>
                {
                    var currentBytesMbs = (int)Math.Floor(totalBytes / Math.Pow(2, 20));
                    if (currentBytesMbs <= lastReportedBytesMbs)
                    {
                        return;
                    }
                    lastReportedBytesMbs = currentBytesMbs;
                    _textWriter.SetCursorPosition(0, Console.CursorTop);
                    _textWriter.Write($"Downloading: {currentBytesMbs}MB");
                };

                await CopyToWithProgress(installerStream, fileStream, progress);
            }

            CheckHash(filePath, fileHash);
            _installerLauncher.Launch(filePath);
        }