internal async Task Initiate() { // desubscribe from all day monitors and clear them up foreach (var monitor in m_dayMonitors) subscribeToThresholdMonitor(monitor.Value, false); m_dayMonitors.Clear(); subscribeToUserCache(false); var allSets = (ContractSet[])Enum.GetValues(typeof(ContractSet)); // desubscribe from update to userthresholds and clear them Array.ForEach(m_editLines.ToArray(), x => subscribeToEditLine(x, false)); m_editLines.Clear(); foreach (var set in allSets) { // set up the lines by which the user will edit the thresholds var userConfig = await UserThresholdCache.Intance().GetOrCreateSpreadVolumeMonitorForSet(set); var line = new ThresholdEditLine(set, userConfig.Threshold); subscribeToEditLine(line); m_editLines.Add(line); var ds = DaySet.Get(set); // if the contract set is live, then set up a monitor on that day, rebuild matching lines and subscribe to updates from it if (ds.Status.IsLive()) { var newMonitor = new ThresholdMonitor(ds.NextRollDay, userConfig); m_dayMonitors.Add(set, newMonitor); subscribeToThresholdMonitor(newMonitor); rebuildMatchingLines(newMonitor); } } // subscribe to update on the user's threshold items subscribeToUserCache(); HasBeenInitiated = true; }
private void subscribeToEditLine(ThresholdEditLine line_, bool do_=true) { if(line_==null)return; line_.PropertyChanged -= handleEditLineUpdated; if(!do_)return; line_.PropertyChanged += handleEditLineUpdated; }