Exemplo n.º 1
0
 public void Dispose()
 {
     inner_data.Clear();
     categories.Clear();
     inner_data = null;
     categories = null;
 }
Exemplo n.º 2
0
 public bool EnumTypes()
 {
     ResourceItems.Clear();
     Types.Clear();
     table_data.Clear();
     return(EnumResourceTypes(hModule, (EnumResTypeLpProc)EnumTypeProc, IntPtr.Zero));
 }
    public void Dispose()
    {
        _serverCallbacks = null;
        _clientCallbacks = null;

        for (int i = 0; i < 2; ++i)
        {
            if (_serverSock[i] != null)
            {
                try {
                    _serverSock[i].Close();
                } catch (Exception) { }
                _serverSock[i] = null;
            }

            var connections = new List <SocketNetDriverConnection>(_tcpConnections.Values);
            foreach (var c in connections)
            {
                c.Dispose();
            }

            _tcpConnections.Clear();
            _udpConnections.Clear();
        }
    }
        public void TestClear()
        {
            var newList = new List<string>()
                {
                    "A", "B", "C", "D",
                };

            var dictList = new DictionaryList<string>(newList);

            Assert.AreEqual(4, dictList.Count);
            Assert.AreEqual("A", dictList[0]);
            Assert.AreEqual("B", dictList[1]);
            Assert.AreEqual("C", dictList[2]);
            Assert.AreEqual("D", dictList[3]);

            dictList.Clear();

            Assert.AreEqual(0, dictList.Count);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adjusts the amount of available units for every transaction
        /// </summary>
        /// <param name="newEntry">New entry</param>
        private void AdjustAvailableUnits(ITransactionBookEntry newEntry)
        {
            var id = newEntry.StockId;

            if (newEntry is ISellingTransactionBookEntry && newEntry.Shares > GetOrAddOpenPosition(id).Shares)
            {
                throw new InvalidOperationException("Cannot sell more units than available.");
            }

            _changedEntries.Clear(id);

            if (newEntry is IBuyingTransactionBookEntry)
            {
                UpdateOpenPosition(id);
                return;
            }

            if (newEntry is ISplitTransactionBookEntry split)
            {
                var buys = _entries.GetOrAdd(id).Where(e => e is IBuyingTransactionBookEntry).ToList();

                buys.ForEach(t => _entries.Delete(id, t));
                _entries.Add(id, split.CreatePositionAfterSplit(buys));

                UpdateOpenPosition(id);
                return;
            }

            var newUnitsToSell = newEntry.Shares;

            var deletes = new List <ITransactionBookEntry>();

            foreach (var entry in _entries.GetOrAdd(id).OrderBy(e => e.OrderDate))
            {
                if (entry is IBuyingTransactionBookEntry)
                {
                    var changed = entry.Copy();

                    //Complete buying transaction filled
                    if (entry.Shares <= newUnitsToSell)
                    {
                        newUnitsToSell -= entry.Shares;

                        if (!(newEntry is IDividendTransactionBookEntry))
                        {
                            entry.Shares = 0;
                        }
                    }
                    //Partly filled
                    else
                    {
                        changed.Shares     = newUnitsToSell;
                        changed.OrderCosts = (entry.OrderCosts / entry.Shares) * newUnitsToSell;

                        if (!(newEntry is IDividendTransactionBookEntry))
                        {
                            entry.OrderCosts = (entry.OrderCosts / entry.Shares) * (entry.Shares - newUnitsToSell);
                            entry.Shares    -= newUnitsToSell;
                        }

                        newUnitsToSell = 0;
                    }

                    _changedEntries.Add(id, changed);

                    if (entry.Shares == 0 && !(newEntry is IDividendTransactionBookEntry))
                    {
                        deletes.Add(entry);
                    }

                    if (newUnitsToSell == 0)
                    {
                        break;
                    }
                }
            }

            _changedEntries.Add(id, newEntry);
            _entries.Delete(id, newEntry);

            if (!(newEntry is IDividendTransactionBookEntry))
            {
                deletes.ForEach(t => _entries.Delete(id, t));
            }

            UpdateOpenPosition(id);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Deletes all positions.
 /// </summary>
 public void DeleteAll()
 {
     _positions.Clear();
     _changedEntries.Clear();
     _entries.Clear();
 }
        public void ClearWorksFine()
        {
            var sample = new DictionaryList<string, object>
            {
                { "key1", "value1" },
                { "key2", "value2" },
                { "key3", 33 }
            };

            Assert.AreEqual(3, sample.Count);

            sample.Clear();

            Assert.AreEqual(0, sample.Count);
        }