Skip to content

Commit

Permalink
bindablebase for vmDashboard and minor code style improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
drusteeby committed Jun 6, 2023
1 parent 75b1dbe commit d760af1
Showing 1 changed file with 64 additions and 91 deletions.
155 changes: 64 additions & 91 deletions ViewModel/vmDashboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,93 +3,76 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Prism.Mvvm;

namespace VisualHFT.ViewModel
{
public class vmDashboard : INotifyPropertyChanged
public class vmDashboard : BindableBase
{
System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
private Dictionary<string, Func<string, string, bool>> _dialogs;
private string _selectedSymbol;
private string _selectedLayer;
private string _selectedStrategy;

protected vmStrategyParameterFirmMM _vmStrategyParamsFirmMM;
protected vmPosition _vmPosition;
protected vmOrderBook _vmOrderBook;

public event PropertyChangedEventHandler PropertyChanged;

public vmDashboard(Dictionary<string, Func<string, string, bool>> dialogs)
{
this._dialogs = dialogs;
cmdAbort = new RelayCommand(DoAbort);
CmdAbort = new RelayCommand(DoAbort);

HelperCommon.ACTIVESTRATEGIES.CollectionChanged += ACTIVESTRATEGIES_CollectionChanged;
HelperCommon.ALLSYMBOLS.CollectionChanged += ALLSYMBOLS_CollectionChanged;
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1);
dispatcherTimer.Start();


this.StrategyParamsFirmMM = new vmStrategyParameterFirmMM(Helpers.HelperCommon.GLOBAL_DIALOGS);
this.Positions = new vmPosition(Helpers.HelperCommon.GLOBAL_DIALOGS);
this.OrderBook = new vmOrderBook(Helpers.HelperCommon.GLOBAL_DIALOGS);
}
public vmStrategyParameterFirmMM StrategyParamsFirmMM
{
get { return _vmStrategyParamsFirmMM; }
set { _vmStrategyParamsFirmMM = value; RaisePropertyChanged("StrategyParamsFirmMM"); }
get => _vmStrategyParamsFirmMM;
set => SetProperty(ref _vmStrategyParamsFirmMM, value);
}
public vmPosition Positions
{
get { return _vmPosition; }
set { _vmPosition = value; RaisePropertyChanged("Positions"); }
get => _vmPosition;
set => SetProperty(ref _vmPosition, value);
}
public vmOrderBook OrderBook
{
get { return _vmOrderBook; }
set { _vmOrderBook = value; RaisePropertyChanged("OrderBook"); }
}

public RelayCommand cmdAbort { get; set; }
protected void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
get => _vmOrderBook;
set => SetProperty(ref _vmOrderBook, value);
}

private void ALLSYMBOLS_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
RefreshSymbolList();
}
private void ACTIVESTRATEGIES_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
RaisePropertyChanged("StrategyList");
}
public RelayCommand CmdAbort { get; set; }


public ObservableCollection<string> StrategyList
private void ALLSYMBOLS_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
get { return HelperCommon.ACTIVESTRATEGIES; }
RefreshSymbolList();
}
private void ACTIVESTRATEGIES_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) => RaisePropertyChanged(nameof(StrategyList));

public ObservableCollection<string> StrategyList => HelperCommon.ACTIVESTRATEGIES;

private void dispatcherTimer_Tick(object sender, EventArgs e)
{
RefreshSymbolList();
}
private void dispatcherTimer_Tick(object sender, EventArgs e) => RefreshSymbolList();

private void RefreshSymbolList()
{
try
{
RaisePropertyChanged("SymbolList");
RaisePropertyChanged(nameof(SymbolList));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
catch (Exception ex) { Console.WriteLine(ex.Message); }
}

private void DoAbort(object item)
Expand All @@ -105,7 +88,7 @@ private void DoAbort(object item)
try
{
args.Result = RESTFulHelper.SetVariable<string>("ABORTSYSTEM");
}
}
catch { /*System.Threading.Thread.Sleep(5000);*/ }
};
bwDoAbort.RunWorkerCompleted += (ss, args) =>
Expand All @@ -123,78 +106,68 @@ private void DoAbort(object item)
}


public string SelectedStrategy
{
get
{
return _selectedStrategy;
}

set
{
if (string.IsNullOrEmpty(value))
value = "";
if (value.IndexOf(":") > -1)
{
_selectedStrategy = value.Split(':')[0].Trim();
_selectedLayer = value.Split(':')[1].Trim();
}
else
{
_selectedStrategy = value;
_selectedLayer = "";
}
if (value != "")
{
public string SelectedStrategy
{
get => _selectedStrategy;

set
{
if (string.IsNullOrEmpty(value))
value = "";
if (value.IndexOf(":") > -1)
{
_selectedStrategy = value.Split(':')[0].Trim();
_selectedLayer = value.Split(':')[1].Trim();
}
else
{
_selectedStrategy = value;
_selectedLayer = "";
}
if (value != "")
{
_selectedSymbol = "-- All symbols --";
_vmStrategyParamsFirmMM.SelectedStrategy = value;
_vmPosition.SelectedStrategy = value;

RaisePropertyChanged("SelectedStrategy");
RaisePropertyChanged("SelectedSymbol");
RaisePropertyChanged("SelectedLayer");
}
}
}
public string SelectedSymbol
RaisePropertyChanged(nameof(SelectedStrategy));
RaisePropertyChanged(nameof(SelectedSymbol));
RaisePropertyChanged(nameof(SelectedLayer));
};
}
}
public string SelectedSymbol
{
get { return _selectedSymbol; }
get => _selectedSymbol;
set
{
if (_selectedSymbol != value)
{
_selectedSymbol = value;
if (_selectedSymbol != value)
{
_selectedSymbol = value;
_vmStrategyParamsFirmMM.SelectedSymbol = value;
_vmPosition.SelectedSymbol = value;
_vmOrderBook.SelectedSymbol = value;

RaisePropertyChanged("SelectedSymbol");
}
RaisePropertyChanged(nameof(SelectedSymbol));
}
}
}
public string SelectedLayer
{
get { return _selectedLayer; }
get => _selectedLayer;
set
{
if (_selectedLayer != value)
{
_selectedLayer = value;
if (_selectedLayer != value)
{
_selectedLayer = value;
_vmOrderBook.SelectedLayer = value;

RaisePropertyChanged("SelectedLayer");
}
}
}

public ObservableCollection<string> SymbolList
{
get
{
return HelperCommon.ALLSYMBOLS;
RaisePropertyChanged(nameof(SelectedLayer));
}
}
}

public ObservableCollection<string> SymbolList => HelperCommon.ALLSYMBOLS;

}
}
}

0 comments on commit d760af1

Please sign in to comment.