Пример #1
0
        /// <summary>Handle trades added or removed from the Trades collection</summary>
        private void HandleTradesListChanging(object sender, ListChgEventArgs <Trade> e)
        {
            switch (e.ChangeType)
            {
            case ListChg.Reset:
            {
                // Watch for order changed
                foreach (var trade in Trades)
                {
                    trade.Changed -= SignalChanged;
                    trade.Changed += SignalChanged;
                }
                SignalChanged();
                break;
            }

            case ListChg.ItemAdded:
            {
                e.Item.Changed += SignalChanged;
                SignalChanged();
                break;
            }

            case ListChg.ItemRemoved:
            {
                e.Item.Changed -= SignalChanged;
                e.Item.Dispose();
                SignalChanged();
                break;
            }
            }
        }
Пример #2
0
        /// <summary>Handle orders being associated with this trade</summary>
        private void HandleOrderListChanging(object sender, ListChgEventArgs <Order> e)
        {
            switch (e.ChangeType)
            {
            case ListChg.Reset:
            {
                foreach (var order in Orders)
                {
                    order.Changed -= SignalChanged;
                    order.Changed += SignalChanged;
                }
                break;
            }

            case ListChg.ItemAdded:
            {
                e.Item.Changed += SignalChanged;
                break;
            }

            case ListChg.ItemRemoved:
            {
                e.Item.Changed -= SignalChanged;
                break;
            }
            }

            // Invalidate cached values based on Orders
            if (e.IsPostEvent)
            {
                Invalidate();
            }
        }
Пример #3
0
        /// <summary>Handle SnR levels added/removed</summary>
        private void HandleSnRLevelsChanging(object sender, ListChgEventArgs <SnRLevel> e)
        {
            switch (e.ChangeType)
            {
            case ListChg.ItemAdded:
            {
                // Watch for changes to the SnRLevel so we can update the DB
                e.Item.PropertyChanged += HandleSnRLevelChanged;
                HandleSnRLevelChanged(e.Item);
                break;
            }

            case ListChg.ItemRemoved:
            {
                // Stop watching for changes
                e.Item.PropertyChanged -= HandleSnRLevelChanged;

                // Remove this level from the db.
                // Note: this isn't called during shutdown because this event handler
                // is removed from the binding source before it is disposed.
                m_db.Execute(SqlExpr.RemoveSnRLevel(), 1, SqlExpr.RemoveSnRLevelParams(e.Item));

                break;
            }
            }
        }
Пример #4
0
 private void HandleCollectionChanged <T>(object sender, ListChgEventArgs <T> e)
 {
     if (e.ChangeType == ListChg.ItemAdded || e.ChangeType == ListChg.ItemRemoved)
     {
         OnChanged();
     }
 }
Пример #5
0
            protected override void OnListChanging(ListChgEventArgs <Element> args)
            {
                // Handle elements added/removed from the selection list
                var elem = args.Item;

                if (elem != null && (elem.Chart != null && elem.Chart != m_chart))
                {
                    throw new ArgumentException("element belongs to another chart");
                }

                switch (args.ChangeType)
                {
                case ListChg.Reset:
                {
                    // Clear the selected state from all elements
                    foreach (var e in m_chart.Elements)
                    {
                        e.SetSelectedInternal(false, false);
                    }

                    // Set the selected state on all selected elements
                    foreach (var e in this)
                    {
                        e.SetSelectedInternal(true, false);
                    }

                    Debug.Assert(m_chart.CheckConsistency());
                    break;
                }

                case ListChg.ItemAdded:
                {
                    // Set the selected state on the added element
                    if (elem == null)
                    {
                        throw new Exception("ItemAdded should provide the added element");
                    }
                    elem.SetSelectedInternal(true, false);

                    Debug.Assert(m_chart.CheckConsistency());
                    break;
                }

                case ListChg.ItemRemoved:
                {
                    // Clear the selected state from the removed element
                    if (elem == null)
                    {
                        throw new Exception("ItemRemoved should provide the removed element");
                    }
                    elem.SetSelectedInternal(false, false);

                    Debug.Assert(m_chart.CheckConsistency());
                    break;
                }
                }

                base.OnListChanging(args);
            }
Пример #6
0
 /// <summary>Handle a pair being added/removed to/from an exchange</summary>
 private void HandlePairsChanging(object sender, ListChgEventArgs <TradePair> e)
 {
     if (e.Before)
     {
         return;
     }
     SignalLoopSearch();
 }
Пример #7
0
 /// <summary>Handle the list of favourite instruments changing</summary>
 private void HandleFavouritesListChanging(object sender, ListChgEventArgs <Instrument> e)
 {
     switch (e.ChangeType)
     {
     case ListChg.ItemAdded:
     case ListChg.ItemRemoved:
         Settings.General.FavouriteInstruments = Favourites.Select(x => x.SymbolCode).ToArray();
         break;
     }
 }
Пример #8
0
 /// <summary>Optimise the event history as it changes</summary>
 private void HandleEventHistoryListChanging(object sender, ListChgEventArgs <TradeEvent> e)
 {
     switch (e.ChangeType)
     {
     case ListChg.ItemAdded:
     {
         break;
     }
     }
 }
Пример #9
0
        /// <summary>Handle orders being added/removed from the collection</summary>
        private void HandleOrdersListChanging(object sender, ListChgEventArgs <Order> e)
        {
            // Every Order should belong to a Trade, create trades if necessary
            switch (e.ChangeType)
            {
            case ListChg.Reset:
            {
                // Refresh the order lookup map
                OrderLookup.Clear();
                foreach (var order in Orders)
                {
                    OrderLookup.Add(order.Id, order);
                }

                // Watch for order changed
                foreach (var order in Orders)
                {
                    order.Changed -= SignalChanged;
                    order.Changed += SignalChanged;
                }

                InvalidateTrades();
                SignalChanged();
                break;
            }

            case ListChg.ItemAdded:
            {
                OrderLookup[e.Item.Id] = e.Item;
                e.Item.Changed        += SignalChanged;

                InvalidateTrades();
                SignalChanged();
                break;
            }

            case ListChg.ItemRemoved:
            {
                OrderLookup.Remove(e.Item.Id);
                e.Item.Changed -= SignalChanged;

                InvalidateTrades();
                SignalChanged();
                break;
            }
            }
        }
Пример #10
0
        /// <summary>Handle changes to the list of transmitters</summary>
        private void HandleTransmitterListChanging(object sender, ListChgEventArgs <Transmitter> e)
        {
            switch (e.ChangeType)
            {
            case ListChg.ItemRemoved:
            {
                // Remove the settings for this transmitter
                var list = Settings.Transmitters.ToList();
                list.Remove(e.Item.Settings);
                Settings.Transmitters = list.ToArray();

                // Dispose the transmitter
                e.Item.Dispose();
                break;
            }
            }
        }
Пример #11
0
        /// <summary>Handle changes to the instruments collection</summary>
        private void HandleInstrumentListChanging(object sender, ListChgEventArgs <Instrument> e)
        {
            var instrument = e.Item;

            switch (e.ChangeType)
            {
            case ListChg.ItemAdded:
                OnInstrumentAdded(new DataEventArgs(instrument, ETimeFrame.None, null, false));
                instrument.DataChanged += HandleInstrumentDataChanged;
                break;

            case ListChg.ItemRemoved:
                OnInstrumentRemoved(new DataEventArgs(instrument, ETimeFrame.None, null, false));
                instrument.DataChanged -= HandleInstrumentDataChanged;
                instrument.Dispose();
                break;
            }
        }
Пример #12
0
        /// <summary>Handle the list of log entries changing</summary>
        private void HandleLogEntriesChanging(object sender, ListChgEventArgs <LogEntry> e)
        {
            if (!e.After || !e.IsDataChanged)
            {
                return;
            }

            // Auto tail
            var auto_tail = m_view.CurrentCell?.RowIndex == m_view.RowCount - 1 || m_view.RowCount == 0;

            // Update the row count to the number of log entries
            m_view.RowCount = Math.Min(MaxLines, LogEntries.Count);

            // Auto scroll to the last row
            if (auto_tail)
            {
                TailScroll();
            }

            // If a log entry was added, pop-out.
            if (e.ChangeType == ListChg.ItemAdded && DockControl?.DockContainer != null)
            {
                if (PopOutOnNewMessages)
                {
                    DockControl.DockContainer.FindAndShow(this);
                }
                else
                {
                    DockControl.TabColoursActive.Text = Color.Red;
                    DockControl.InvalidateTab();
                }
            }

            // Prevent the LogEntries collection getting too big
            if (e.ChangeType == ListChg.ItemAdded && LogEntries.Count > 2 * MaxLines)
            {
                LogEntries.RemoveRange(0, LogEntries.Count - MaxLines);
            }
        }
Пример #13
0
            protected override void OnListChanging(ListChgEventArgs <Element> args)
            {
                var elem = args.Item;

                if (elem != null && (elem.Chart != null && elem.Chart != m_chart))
                {
                    throw new ArgumentException("element belongs to another chart");
                }

                switch (args.ChangeType)
                {
                case ListChg.Reset:
                {
                    // Remove all elements from the chart
                    foreach (var e in this)
                    {
                        e.SetChartInternal(m_chart, false);
                    }

                    // Repopulate the IDs collection
                    Ids.Clear();
                    foreach (var e in this)
                    {
                        Ids.Add(e.Id, e);
                    }

                    Debug.Assert(m_chart.CheckConsistency());
                    break;
                }

                case ListChg.ItemAdded:
                {
                    // Remove from any previous chart
                    if (elem == null)
                    {
                        throw new Exception("ItemAdded should provide the added element");
                    }
                    elem.SetChartInternal(m_chart, false);

                    // Track the ID
                    Ids.Add(elem.Id, elem);

                    Debug.Assert(m_chart.CheckConsistency());
                    break;
                }

                case ListChg.ItemPreRemove:
                {
                    // Remove from selected or hovered sets before removing form the collection
                    if (elem == null)
                    {
                        throw new Exception("ItemPreRemove should provide the element to be removed");
                    }
                    elem.Selected = false;
                    elem.Hovered  = false;

                    Debug.Assert(m_chart.CheckConsistency());
                    break;
                }

                case ListChg.ItemRemoved:
                {
                    // Remove from the chart
                    if (elem == null)
                    {
                        throw new Exception("ItemRemoved should provide the removed element");
                    }
                    elem.SetChartInternal(null, false);

                    // Forget the ID
                    Ids.Remove(elem.Id);

                    Debug.Assert(m_chart.CheckConsistency());
                    break;
                }
                }
                base.OnListChanging(args);
            }
Пример #14
0
 /// <summary>When the list of elements changes, the data is modified</summary>
 private void HandleListChanged(object sender, ListChgEventArgs <XElement> e)
 {
     Modified = true;
 }
Пример #15
0
 private void HandleFileInfosListChanging(object sender, ListChgEventArgs <FileInfo> e)
 {
     m_btn_ok.Enabled = FileInfos.Count != 0;
 }