Пример #1
0
 private static async Task <List <Recipe> > GetRecipes(
     CraftingQuery craftingQuery,
     ProgressTask progress
     )
 {
     progress.StartTask();
     try
     {
         return(await craftingQuery
                .GetRecipes(
                    progress : new Progress <ICollectionContext>(ctx => UpdateProgress(ctx, progress))
                    )
                .OrderByDescending(recipe => recipe.Id)
                .ToListAsync());
     }
     finally
     {
         progress.StopTask();
     }
 }
Пример #2
0
    private static async Task <List <Item> > GetItems(
        IReadOnlyCollection <int> itemIds,
        ItemsQuery itemsQuery,
        ProgressTask progress
        )
    {
        var items = new List <Item>(itemIds.Count);

        progress.StartTask();
        await foreach (var item in itemsQuery.GetItemsByIds(
                           itemIds,
                           progress: new Progress <ICollectionContext>(ctx => UpdateProgress(ctx, progress))
                           ))
        {
            items.Add(item);
        }

        progress.StopTask();

        return(items);
    }
 public void StopTask()
 {
     _task.Value = _task.MaxValue;
     _task.StopTask();
 }
Пример #4
0
        public override int Execute([NotNull] CommandContext context, [NotNull] SdkDownloadCommandSettings settings)
        {
            if (string.IsNullOrEmpty(settings?.Home))
            {
                throw new ArgumentException(nameof(settings.Home));
            }

            try
            {
                var dir = new DirectoryInfo(settings.Home);

                if (settings.Force)
                {
                    if (dir.Exists)
                    {
                        dir.Delete(true);
                    }
                }

                if (dir.Exists && ((dir.GetDirectories()?.Any() ?? false) || (dir.GetFiles()?.Any() ?? false)))
                {
                    throw new InvalidOperationException("Directory already exists and is not empty!");
                }

                if (!dir.Exists)
                {
                    dir.Create();
                }

                var m = new SdkManager(dir);

                m.FindToolPath(new DirectoryInfo(settings.Home));

                var tcsResult = new TaskCompletionSource <int>();

                var          px     = AnsiConsole.Progress();
                ProgressTask dlTask = null;

                var progress = 0;

                m.DownloadSdk(dir, progressHandler: (p) =>
                {
                    progress = p;
                }).ContinueWith(t =>
                {
                    dlTask?.StopTask();
                    tcsResult.TrySetResult(0);
                });

                AnsiConsole.Progress()
                .Start(ctx =>
                {
                    // Define tasks
                    dlTask = ctx.AddTask("Downloading Android SDK...");

                    while (!ctx.IsFinished)
                    {
                        dlTask.Value = progress;
                    }
                });

                return(tcsResult.Task.Result);
            }
            catch (SdkToolFailedExitException sdkEx)
            {
                Program.WriteException(sdkEx);
                return(1);
            }
        }