private void AutoDispatchIfRequired(Action action) { if (AutomaticallyDispatchEvents) { DispatcherService.BeginInvokeIfRequired(action); } else { action(); } }
private Task AutoDispatchIfRequiredAsync(Func <Task> action) { if (AutomaticallyDispatchEvents) { DispatcherService.BeginInvokeIfRequired(async() => await action()); } else { return(action()); } return(TaskHelper.Completed); }
private async void DownloadUpdateTC() { if (String.IsNullOrEmpty(Settings.Default.TrunkLocation)) { if (_messageService.Show("You must first set your trunk location! Want to do this right now?", "Trunk location not set!", MessageButton.YesNo, MessageImage.Question) == MessageResult.Yes) { SetTrunkLocation(); } return; } if (_isCloning) { _messageService.ShowError("Cloning is already in progress!"); return; } if (_isCompiling) { _messageService.ShowError("Currently compiling TrinityCore! Please wait until this has finished."); return; } Busy = true; BusyIndeterminate = true; _isCloning = true; if (new DirectoryInfo(Settings.Default.TrunkLocation).GetFiles().Length == 0) { var progress = new Progress <double>(prog => _dispatcherService.BeginInvoke(() => { if (BusyIndeterminate) { BusyIndeterminate = false; } if (prog - BusyProgress > 1 || prog >= 99) { BusyProgress = prog; } })); bool cloneSuccess = await TrinityCoreRepository.Clone(Settings.Default.TrunkLocation, progress); _dispatcherService.Invoke(() => { if (cloneSuccess) { _messageService.Show("Cloning has been completed!", "Success", MessageButton.OK, MessageImage.Information); } else { _messageService.Show("Cloning could not be completed!", "Something went wrong", MessageButton.OK, MessageImage.Error); } }); _isCloning = false; } else { BusyIndeterminate = true; OutputText = String.Empty; var progress = new Progress <string>(prog => _dispatcherService.BeginInvokeIfRequired(delegate { OutputText += prog + Environment.NewLine; })); bool pullSuccess = await TrinityCoreRepository.Pull(Settings.Default.TrunkLocation, progress); _dispatcherService.Invoke(() => { if (pullSuccess) { _messageService.Show("The TrinityCore repository has been updated to the latest version.", "Success", MessageButton.OK, MessageImage.Information); } else { _messageService.Show("Pulling could not be completed!", "Something went wrong", MessageButton.OK, MessageImage.Error); } }); _isCloning = false; } BusyIndeterminate = false; BusyProgress = 0; Busy = false; }