Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/28/12 17:22:34 (13 years ago)
Author:
spimming
Message:

#1680: Show progress view while restoring Azure Subscriptions

Location:
branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/CloudManagerClient.cs

    r7668 r7670  
    227227    }
    228228
    229     public void RestoreSubscriptionsFromUserConfig() {
     229    public List<Subscription> RestoreSubscriptionsFromUserConfig() {
     230      List<Subscription> result = new List<Subscription>();
    230231      StringCollection strCol = Settings.Default.AzureSubscriptions;
    231232      foreach (string azureSub in strCol) {
    232233        string setting = CryptoService.ToInsecureString(CryptoService.DecryptString(azureSub));
    233         Subscription s = Subscription.ParseSettingString(setting);
     234        Subscription tmp = Subscription.ParseSettingString(setting);
     235        Subscription s = CloudManagerClient.Instance.AzureProvider.GetSubscriptionInfo(tmp.SubscriptionID, tmp.CertificateThumbprint);
    234236        s.SaveToConfig = true;
    235237        s.DiscoverServices = true;
    236         Add(s);
    237       }
     238        result.Add(s);
     239      }
     240      return result;
    238241    }
    239242  }
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/CloudResourcesView.cs

    r7668 r7670  
    11using System;
     2using System.Collections.Generic;
    23using System.Diagnostics;
     4using System.Threading.Tasks;
    35using System.Timers;
    46using System.Windows.Forms;
     
    810using HeuristicLab.Core.Views;
    911using HeuristicLab.MainForm;
     12using HeuristicLab.MainForm.WindowsForms;
     13using HeuristicLab.PluginInfrastructure;
    1014
    1115namespace HeuristicLab.Clients.Hive.CloudManager.Views {
     
    1317  [Content(typeof(IItemList<Subscription>), IsDefaultView = true)]
    1418  public partial class CloudResourcesView : ItemView, IDisposable {
     19    ProgressView progressView;
    1520    private System.Timers.Timer timer = new System.Timers.Timer();
    1621    private int updateInterval = 15000;
     
    5257      dueTime = DateTime.Now.AddMilliseconds(updateInterval);
    5358
    54       CloudManagerClient.Instance.RestoreSubscriptionsFromUserConfig();
     59      //IProgress progress = new Progress();
     60      //progress.Status = "Restore Subscriptions";
     61      //progressView = new ProgressView(this, progress);
     62      //CloudManagerClient.Instance.RestoreSubscriptionsFromUserConfig();
     63      //progressView.Finish();
    5564    }
    5665
     
    8594    }
    8695
     96    private void SetProgressView(IProgress progress) {
     97      if (InvokeRequired) {
     98        Invoke(new Action<IProgress>(SetProgressView), progress);
     99      } else {
     100        if (progressView == null) {
     101          progressView = new ProgressView(this, progress);
     102        } else {
     103          progressView.Progress = progress;
     104        }
     105      }
     106    }
     107
     108    private void FinishProgressView() {
     109      if (InvokeRequired) {
     110        Invoke(new Action(FinishProgressView));
     111      } else {
     112        if (progressView != null) {
     113          progressView.Finish();
     114          progressView = null;
     115          SetEnabledStateOfControls();
     116        }
     117      }
     118    }
     119
     120    public void Restore() {
     121      var task = System.Threading.Tasks.Task.Factory.StartNew(RestoreAsync);
     122      task.ContinueWith((t) => {
     123        FinishProgressView();
     124        ErrorHandling.ShowErrorDialog(this, "An error occured while restoring Azure Subscriptions.", t.Exception);
     125      }, TaskContinuationOptions.OnlyOnFaulted);
     126      FinishProgressView();
     127    }
     128
     129    private void RestoreAsync() {
     130      IProgress progress = new Progress();
     131      progress.Status = "Restoring Azure Subscriptions";
     132      SetProgressView(progress);
     133      List<Subscription> result = CloudManagerClient.Instance.RestoreSubscriptionsFromUserConfig();
     134      FinishProgressView();
     135      foreach (Subscription s in result) this.BeginInvoke((MethodInvoker)delegate() { CloudManagerClient.Instance.Add(s); });
     136    }
     137
    87138    protected override void SetEnabledStateOfControls() {
    88139      base.SetEnabledStateOfControls();
    89140      if (Content == null || Content.Count == 0) {
    90         btnAddSlaveService.Enabled = false;
    91         btnDelete.Enabled = false;
    92         btnSave.Enabled = false;
    93       } else {
    94         btnAddSlaveService.Enabled = true;
    95         btnDelete.Enabled = true;
    96         btnSave.Enabled = true;
    97       }
     141        if (this.InvokeRequired) {
     142          this.BeginInvoke((MethodInvoker)delegate() { SetBtnControlsEnabled(false); });
     143        } else {
     144          SetBtnControlsEnabled(false);
     145        }
     146      } else {
     147        if (this.InvokeRequired) {
     148          this.BeginInvoke((MethodInvoker)delegate() { SetBtnControlsEnabled(true); });
     149        } else {
     150          SetBtnControlsEnabled(true);
     151        }
     152      }
     153    }
     154
     155    private void SetBtnControlsEnabled(bool enabled) {
     156      btnAddSlaveService.Enabled = enabled;
     157      btnDelete.Enabled = enabled;
     158      btnSave.Enabled = enabled;
    98159    }
    99160
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/HiveCloudManagerView.cs

    r7387 r7670  
    4040      cloudResourcesView.Content = CloudManagerClient.Instance.Subscriptions;
    4141      cloudResourcesView.HostedServices = CloudManagerClient.Instance.HostedServices;
     42
     43      cloudResourcesView.Restore();
    4244    }
    4345
Note: See TracChangeset for help on using the changeset viewer.