Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/11/16 15:29:05 (8 years ago)
Author:
abeham
Message:

#2588: Adapted OKBProblemView to include download/upload of solutions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBProblemView.cs

    r13684 r13691  
    7373      uploadCharacteristicsButton.Text = string.Empty;
    7474      uploadCharacteristicsButton.Image = VSImageLibrary.PublishToWeb;
     75      refreshSolutionsButton.Text = string.Empty;
     76      refreshSolutionsButton.Image = VSImageLibrary.Refresh;
     77      uploadSolutionsButton.Text = string.Empty;
     78      uploadSolutionsButton.Image = VSImageLibrary.PublishToWeb;
    7579    }
    7680
     
    9397      base.RegisterContentEvents();
    9498      Content.ProblemChanged += new EventHandler(Content_ProblemChanged);
     99      Content.Solutions.ItemsAdded += SolutionsOnChanged;
     100      Content.Solutions.ItemsReplaced += SolutionsOnChanged;
     101      Content.Solutions.ItemsRemoved += SolutionsOnChanged;
     102      Content.Solutions.CollectionReset += SolutionsOnChanged;
     103    }
     104
     105    private void SolutionsOnChanged(object sender, EventArgs e) {
     106      SetEnabledStateOfControls();
    95107    }
    96108
     
    100112        problemComboBox.SelectedIndex = -1;
    101113        parameterCollectionView.Content = null;
     114        solutionsViewHost.Content = null;
    102115      } else {
    103116        problemComboBox.SelectedItem = RunCreationClient.Instance.Problems.FirstOrDefault(x => x.Id == Content.ProblemId);
    104117        parameterCollectionView.Content = Content.Parameters;
     118        solutionsViewHost.Content = Content.Solutions;
    105119      }
    106120      UpdateCharacteristicCalculators();
     
    118132        && characteristicsMatrixView.Content != null && characteristicsMatrixView.Content.Rows > 0;
    119133      calculateButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked && !ReadOnly && calculatorList.CheckedItems.Any();
     134      refreshSolutionsButton.Enabled = Content != null && !ReadOnly && !Locked && Content.ProblemId != -1;
     135      uploadSolutionsButton.Enabled = Content != null && !ReadOnly && !Locked && Content.ProblemId != -1 && Content.Solutions.Any(x => x.SolutionId == -1);
    120136    }
    121137
     
    217233      }
    218234      var matrix = (characteristicsMatrixView.Content as StringMatrix) ?? (new StringMatrix(results.Count, 3));
    219       for (var i = 0; i < matrix.Rows; i++) {
    220         Value r;
    221         if (results.TryGetValue(matrix[i, 0], out r)) {
    222           matrix[i, 1] = r.GetValue();
    223           matrix[i, 2] = r.GetType().Name;
    224           results.Remove(matrix[i, 0]);
     235      try {
     236        for (var i = 0; i < matrix.Rows; i++) {
     237          Value r;
     238          if (results.TryGetValue(matrix[i, 0], out r)) {
     239            matrix[i, 1] = r.GetValue();
     240            matrix[i, 2] = r.GetType().Name;
     241            results.Remove(matrix[i, 0]);
     242          }
    225243        }
    226       }
    227       if (results.Count == 0) return;
    228       var resultsList = results.ToList();
    229       var counter = resultsList.Count - 1;
    230       for (var i = 0; i < matrix.Rows; i++) {
    231         if (string.IsNullOrEmpty(matrix[i, 0])) {
    232           matrix[i, 0] = resultsList[counter].Key;
    233           matrix[i, 1] = resultsList[counter].Value.GetValue();
    234           matrix[i, 2] = resultsList[counter].Value.GetType().Name;
    235           resultsList.RemoveAt(counter);
    236           counter--;
    237           if (counter < 0) return;
     244        if (results.Count == 0) return;
     245        var resultsList = results.ToList();
     246        var counter = resultsList.Count - 1;
     247        for (var i = 0; i < matrix.Rows; i++) {
     248          if (string.IsNullOrEmpty(matrix[i, 0])) {
     249            matrix[i, 0] = resultsList[counter].Key;
     250            matrix[i, 1] = resultsList[counter].Value.GetValue();
     251            matrix[i, 2] = resultsList[counter].Value.GetType().Name;
     252            resultsList.RemoveAt(counter);
     253            counter--;
     254            if (counter < 0) return;
     255          }
    238256        }
    239       }
    240       if (counter >= 0) {
    241         ((IStringConvertibleMatrix)matrix).Rows += counter + 1;
    242         for (var i = matrix.Rows - 1; counter >= 0; i--) {
    243           matrix[i, 0] = resultsList[0].Key;
    244           matrix[i, 1] = resultsList[0].Value.GetValue();
    245           matrix[i, 2] = resultsList[0].Value.GetType().Name;
    246           resultsList.RemoveAt(0);
    247           counter--;
     257        if (counter >= 0) {
     258          ((IStringConvertibleMatrix)matrix).Rows += counter + 1;
     259          for (var i = matrix.Rows - 1; counter >= 0; i--) {
     260            matrix[i, 0] = resultsList[0].Key;
     261            matrix[i, 1] = resultsList[0].Value.GetValue();
     262            matrix[i, 2] = resultsList[0].Value.GetType().Name;
     263            resultsList.RemoveAt(0);
     264            counter--;
     265          }
    248266        }
    249       }
    250       characteristicsMatrixView.Content = matrix;
    251       SetEnabledStateOfControls();
     267      } finally {
     268        characteristicsMatrixView.Content = matrix;
     269        SetEnabledStateOfControls();
     270      }
    252271    }
    253272    #endregion
     
    261280    #endregion
    262281
     282    private void refreshSolutionsButton_Click(object sender, EventArgs e) {
     283      Content.RefreshSolutions();
     284    }
     285
     286    private void uploadSolutionsButton_Click(object sender, EventArgs e) {
     287      foreach (var solution in Content.Solutions.Where(x => x.SolutionId == -1))
     288        solution.Upload();
     289    }
     290
    263291  }
    264292}
Note: See TracChangeset for help on using the changeset viewer.