示例#1
0
        /// <summary>
        /// Destroy the executions and destination orders on the shared data model.
        /// </summary>
        /// <param name="sender">The generic thread initialization parameter.</param>
        public static void DestroyOrders(object sender)
        {
            // This will establish an endpoint to the web services that support trading functions.
            TradingSupportClient tradingSupportClient = new TradingSupportClient(Properties.Settings.Default.TradingSupportEndpoint);

            lock (DataModel.SyncRoot)
            {
                // To prevent a buffer of an arbitrary size, the commands to delete orders are batched up and sent in chunks.
                int batchCounter = 0;

                // This will construct a list of references to the orders.  This list will be transmitted to the server where a web service will
                // pull it apart and
                List <DestinationOrderReference> destinationOrderReferences = new List <DestinationOrderReference>();
                foreach (DestinationOrderRow destinationOrderRow in DataModel.DestinationOrder)
                {
                    DestinationOrderReference destinationOrderReference = new DestinationOrderReference();
                    destinationOrderReference.DestinationId = destinationOrderRow.DestinationOrderId;
                    destinationOrderReference.RowVersion    = destinationOrderRow.RowVersion;
                    destinationOrderReferences.Add(destinationOrderReference);

                    if (batchCounter++ == batchSize)
                    {
                        batchCounter = 0;
                        tradingSupportClient.DestroyDestinationOrders(destinationOrderReferences.ToArray());
                        destinationOrderReferences = new List <DestinationOrderReference>();
                    }
                }

                if (destinationOrderReferences.Count != 0)
                {
                    tradingSupportClient.DestroyDestinationOrders(destinationOrderReferences.ToArray());
                }
            }

            tradingSupportClient.Close();
        }