Esempio n. 1
0
        public async Task ScheduleAsync(BackgroundTask task)
        {
            EventLog.LogEvent("scheduleTask", "{type}", task.TypeName);

            task.Status = BackgroundTaskStatus.Scheduled;

            // send message with MVVM messenger
            Messenger.Default.Send(new BackgroundTaskMessage(task));

            Tasks.Insert(0, task);
            OnNewTask?.Invoke(task);
            //ExecuteWithTracking(task).Forget();
            await Task.Factory.StartNew(() => ExecuteWithTracking(task), TaskCreationOptions.LongRunning);
        }
Esempio n. 2
0
        public async Task DownloadLatestVersion()
        {
            try
            {
                OnStart?.Invoke(this, EventArgs.Empty);

                _webClient = new WebClient();

                _webClient.DownloadProgressChanged += (sender, e) => OnProgress?.Invoke(this, e);

                var release = await LatestVersion();

                var userprofile  = UserProfile.Get();
                var downloadPath = Path.Combine(Path.Combine(SaveFolderPath, "EliteVA"), release.TagName);

                Directory.CreateDirectory(downloadPath);
                Directory.CreateDirectory(userprofile.EliteVA.InstallationDirectory);

                userprofile.EliteVA.IsInstalled      = true;
                userprofile.EliteVA.InstalledVersion = release.TagName;
                userprofile.Save();

                foreach (var releaseAsset in release.Assets)
                {
                    var path = Path.Combine(downloadPath, releaseAsset.Name);
                    OnNewTask?.Invoke(this, "Downloading files");
                    await _webClient.DownloadFileTaskAsync(releaseAsset.BrowserDownloadUrl, path);

                    OnNewTask?.Invoke(this, "Extracting files");
                    ZipFile.ExtractToDirectory(path, userprofile.EliteVA.InstallationDirectory, true);
                }

                OnFinished?.Invoke(this, EventArgs.Empty);
                _webClient.Dispose();
            }
            catch (Exception ex)
            {
                OnError?.Invoke(this, ex.Message);
            }
        }