Пример #1
0
        public static async Task EnableEmulationAsync(Action <Exception, string, int> operationCompleted = null)
        {
            try
            {
                TorizonRestAPI.Api.SetupApi api = new TorizonRestAPI.Api.SetupApi();
                ProgressApi progressApi         = new ProgressApi();
                Progress    progress            = progressApi.ProgressCreate();

                var task = api.SetupEnableemulationAsync(progress.Id);

                // check the status
                await Task.Run(() => {
                    while (progress.Pending)
                    {
                        progress = progressApi.ProgressStatus(progress.Id);

                        foreach (string msg in progress.Messages)
                        {
                            operationCompleted?.Invoke(null, msg, progress._Progress);
                        }
                    }

                    // send 100% for the current task
                    operationCompleted?.Invoke(null, "Done", 100);
                });

                await task;
            }
            catch (Exception e)
            {
                operationCompleted?.Invoke(e, null, 0);
            }
        }
Пример #2
0
        public static Action CreateProgressTask(ref Progress progressRef, Action <string, int> taskUpdateStatus)
        {
            ProgressApi progressApi = TorizonAPIManager.GetProgressApi();
            Progress    progress    = progressApi.ProgressCreate();

            progressRef = progress;

            return(() => {
                while (progress.Pending)
                {
                    progress = progressApi.ProgressStatus(progress.Id);

                    foreach (string msg in progress.Messages)
                    {
                        taskUpdateStatus?.Invoke(msg, progress._Progress);
                    }
                }

                // send 100% for the current task
                taskUpdateStatus?.Invoke("Done", -100);
            });
        }