Fix the LoadSessionFile method so that the BusyIndicator is displayed with the correct content.

This commit is contained in:
2025-02-18 19:09:20 -05:00
parent f0b765c5c8
commit 6fcb5f63ba
3 changed files with 149 additions and 93 deletions

View File

@@ -1236,42 +1236,63 @@ namespace TradeBlotter.ViewModels
return;
}
}
public bool LoadSessionFile()
{
if(!CMTSessionManager.IsValidSessionFile(pathFileName)) return false;
initialPath=Path.GetDirectoryName(pathFileName);
sessionParams=CMTSessionManager.RestoreSession(pathFileName);
if(null==sessionParams) { MessageBox.Show(String.Format("Unable to open {0}",pathFileName)); pathFileName=null; return false; }
modelStatistics=CMTTrendModel.GetModelStatistics(sessionParams);
configuration=sessionParams.CMTParams;
NVPCollection nvpCollection=sessionParams.CMTParams.ToNVPCollection();
nvpDictionary=nvpCollection.ToDictionary();
nvpDictionaryKeys=new ObservableCollection<String>(nvpDictionary.Keys);
selectedParameter=nvpDictionaryKeys[0];
positions=new CMTPositionModelCollection();
positions.Add(sessionParams.ActivePositions);
positions.Add(sessionParams.AllPositions);
trendCandidates=new ObservableCollection<CMTCandidate>();
foreach(CMTCandidate candidate in sessionParams.Candidates)trendCandidates.Add(candidate);
UpdatePositionPrices(true);
RunPerformance();
base.OnPropertyChanged("Parameters");
base.OnPropertyChanged("SelectedParameter");
base.OnPropertyChanged("ParameterValue");
base.OnPropertyChanged("Title");
base.OnPropertyChanged("DisplayName");
base.OnPropertyChanged("AllPositions");
base.OnPropertyChanged("CanMonitor");
base.OnPropertyChanged("AllItems");
base.OnPropertyChanged("CashBalance");
base.OnPropertyChanged("NonTradeableCash");
base.OnPropertyChanged("ModelExpectation");
base.OnPropertyChanged("ExpectationColor");
base.OnPropertyChanged("ExpectationDescription");
base.OnPropertyChanged("TradeableCashDescription");
base.OnPropertyChanged("NonTradeableCashDescription");
BusyIndicator = true;
BusyContent = $"Loading {Utility.GetFileNameNoExtension(pathFileName)}...";
Task workerTask = Task.Factory.StartNew( () =>
{
try
{
if(!CMTSessionManager.IsValidSessionFile(pathFileName)) return false;
initialPath=Path.GetDirectoryName(pathFileName);
sessionParams=CMTSessionManager.RestoreSession(pathFileName);
if(null==sessionParams) { MessageBox.Show(String.Format("Unable to open {0}",pathFileName)); pathFileName=null; return false; }
modelStatistics=CMTTrendModel.GetModelStatistics(sessionParams);
configuration=sessionParams.CMTParams;
NVPCollection nvpCollection=sessionParams.CMTParams.ToNVPCollection();
nvpDictionary=nvpCollection.ToDictionary();
nvpDictionaryKeys=new ObservableCollection<String>(nvpDictionary.Keys);
selectedParameter=nvpDictionaryKeys[0];
positions=new CMTPositionModelCollection();
positions.Add(sessionParams.ActivePositions);
positions.Add(sessionParams.AllPositions);
trendCandidates=new ObservableCollection<CMTCandidate>();
foreach(CMTCandidate candidate in sessionParams.Candidates)trendCandidates.Add(candidate);
UpdatePositionPrices(true);
RunPerformance();
return true;
}
catch(Exception exception)
{
System.Windows.MessageBox.Show(String.Format("Exception {0}",exception.ToString()),"Error",MessageBoxButton.OK,MessageBoxImage.Exclamation);
return false;
}
});
workerTask.ContinueWith(continuation =>
{
BusyIndicator = false;
base.OnPropertyChanged("Parameters");
base.OnPropertyChanged("SelectedParameter");
base.OnPropertyChanged("ParameterValue");
base.OnPropertyChanged("Title");
base.OnPropertyChanged("DisplayName");
base.OnPropertyChanged("AllPositions");
base.OnPropertyChanged("CanMonitor");
base.OnPropertyChanged("AllItems");
base.OnPropertyChanged("CashBalance");
base.OnPropertyChanged("NonTradeableCash");
base.OnPropertyChanged("ModelExpectation");
base.OnPropertyChanged("ExpectationColor");
base.OnPropertyChanged("ExpectationDescription");
base.OnPropertyChanged("TradeableCashDescription");
base.OnPropertyChanged("NonTradeableCashDescription");
});
return true;
}
private void RunPerformance()
{
if(null==sessionParams)return;