Example #1
0
        public DownloadStashViewModel(IDialogCoordinator dialogCoordinator, IPersistentData persistentData, StashViewModel stash)
        {
            _stash             = stash;
            _persistenData     = persistentData;
            _dialogCoordinator = dialogCoordinator;
            DisplayName        = L10n.Message("Download & Import Stash");
            Build = persistentData.CurrentBuild;

            if (Build.League != null && _persistenData.LeagueStashes.ContainsKey(Build.League))
            {
                _tabs = new List <StashBookmark>(_persistenData.LeagueStashes[Build.League]);
            }
            TabsView = new ListCollectionView(_tabs);
            TabsView.CurrentChanged += (sender, args) => UpdateTabLink();

            Build.PropertyChanged += BuildOnPropertyChanged;
            BuildOnPropertyChanged(this, null);

            _viewLoadedCompletionSource = new TaskCompletionSource <object>();
            if (CurrentLeagues == null)
            {
                CurrentLeagues = new NotifyingTask <IReadOnlyList <string> >(LoadCurrentLeaguesAsync(),
                                                                             async e =>
                {
                    await _viewLoadedCompletionSource.Task;
                    await _dialogCoordinator.ShowWarningAsync(this,
                                                              L10n.Message("Could not load the currently running leagues."), e.Message);
                });
            }
        }
Example #2
0
        private async Task LoadTabContents()
        {
            var      tabContents    = Clipboard.GetText();
            IntRange highlightrange = null;

            try
            {
                var json  = JObject.Parse(tabContents);
                var items = json["items"].Select(i => new Item(_persistenData, (JObject)i)).ToArray();

                var yStart = _stash.LastOccupiedLine + 3;

                var selectedBookmark = TabsView.CurrentItem as StashBookmark;
                var sb = selectedBookmark != null
                    ? new StashBookmark(selectedBookmark.Name, yStart, selectedBookmark.Color)
                    : new StashBookmark("imported", yStart);

                _stash.BeginUpdate();
                _stash.AddBookmark(sb);

                var yOffsetInImported = items.Min(i => i.Y);
                var yEnd = yStart;
                foreach (var item in items)
                {
                    item.Y += yStart - yOffsetInImported;
                    yEnd    = Math.Max(yEnd, item.Y + item.Height);
                    if (item.X + item.Width > 12)
                    {
                        await _dialogCoordinator.ShowWarningAsync(this, "Skipping item because it is too wide.");

                        continue;
                    }
                    _stash.Items.Add(item);
                }

                await _dialogCoordinator.ShowInfoAsync(this, L10n.Message("New tab added"),
                                                       string.Format(L10n.Message("New tab with {0} items was added to stash."), items.Length));

                highlightrange = new IntRange {
                    From = yStart, Range = yEnd - yStart
                };
            }
            catch (Exception e)
            {
                _dialogCoordinator.ShowErrorAsync(this,
                                                  L10n.Message("An error occurred while attempting to load stash data."), e.Message);
            }
            finally
            {
                _stash.EndUpdate();
            }

            if (highlightrange != null)
            {
                _stash.AddHighlightRange(highlightrange);
            }
        }
Example #3
0
        /// <summary>
        /// Initializes the solver asynchronously.
        /// </summary>
        /// <returns>Whether the initialization was successful.</returns>
        private async Task <bool> InitializeAsync()
        {
            var success = true;

            try
            {
                await Task.Run(() =>
                {
#if DEBUG
                    var stopwatch = new Stopwatch();
                    stopwatch.Start();
#endif
                    _solver.Initialize();
#if DEBUG
                    stopwatch.Stop();
                    Debug.WriteLine("Initialization took " + stopwatch.ElapsedMilliseconds + " ms\n-----------------");
#endif
                });
            }
            catch (GraphNotConnectedException)
            {
                // No await in catch
                success = false;
            }
            if (!success)
            {
                // Show a dialog and close this if the omitted nodes disconnect the tree.
                await _dialogCoordinator.ShowWarningAsync(this,
                                                          L10n.Message("The optimizer was unable to find a conforming tree.\nPlease change skill node tagging and try again.\n\n" +
                                                                       "Note: When using the Advanced generator, you need to check-tag all keystones you want."));

                Close();
                return(false);
            }

            ProgressbarMax  = _solver.Steps * _solver.Iterations;
            ProgressbarText = "1/" + ProgressbarMax;

            CancelCloseEnabled = true;
            PauseResumeEnabled = true;

            return(true);
        }
        public DownloadStashViewModel(IDialogCoordinator dialogCoordinator, IPersistentData persistentData, Stash stash)
        {
            _stash = stash;
            _persistenData = persistentData;
            _dialogCoordinator = dialogCoordinator;
            DisplayName = L10n.Message("Download & Import Stash");
            Build = persistentData.CurrentBuild;

            if (Build.League != null && _persistenData.LeagueStashes.ContainsKey(Build.League))
                _tabs = new List<StashBookmark>(_persistenData.LeagueStashes[Build.League]);
            TabsView = new ListCollectionView(_tabs);
            TabsView.CurrentChanged += (sender, args) => UpdateTabLink();

            Build.PropertyChanged += BuildOnPropertyChanged;
            BuildOnPropertyChanged(this, null);
            RequestsClose += _ => Build.PropertyChanged -= BuildOnPropertyChanged;

            _viewLoadedCompletionSource = new TaskCompletionSource<object>();
            if (CurrentLeagues == null)
            {
                CurrentLeagues = new NotifyingTask<IReadOnlyList<string>>(LoadCurrentLeaguesAsync(),
                    async e =>
                    {
                        await _viewLoadedCompletionSource.Task;
                        await _dialogCoordinator.ShowWarningAsync(this,
                            L10n.Message("Could not load the currently running leagues."), e.Message);
                    });
            }
        }