示例#1
0
        /// <summary>
        /// Sets the simulation parameters.
        /// </summary>
        /// <param name="simulationParameters">The simulator parameters.</param>
        void SetSimulatorParameter(Object state)
        {
            // Extract the simulator parameters from the generic argument.
            SimulatorParameters simulatorParameters = state as SimulatorParameters;

            // This pushes the simulation parameters to the simulator.
            using (MarketServiceClient marketServiceClient = new MarketServiceClient())
                marketServiceClient.SetSimulatorParameters(simulatorParameters);
        }
示例#2
0
        /// <summary>
        /// Extracts orders from the queue and passes them on to the market service to be executed.
        /// </summary>
        static void MarketThread()
        {
            // This provides a connection to a destination that will simulate the execution of orders.
            MarketServiceClient marketServiceClient = new MarketServiceClient();

            while (true)
            {
                // The thread will wait here until there is an order to process.
                MarketEngine.orderEvent.WaitOne();

                // The general idea is to pull messages out of the queue until either the queue is empty or we've got a chunk big enough to send to the
                // destination.  When the queue has been emptied, we're going to put the thread in a wait until more orders arrive.
                List <Message> messages = new List <Message>();
                lock (MarketEngine.syncRoot)
                {
                    while (MarketEngine.messageQueue.Count != 0 && messages.Count < MarketEngine.chunkSize)
                    {
                        messages.Add(MarketEngine.messageQueue.Dequeue());
                    }
                    if (MarketEngine.messageQueue.Count == 0)
                    {
                        MarketEngine.orderEvent.Reset();
                    }
                }

                // This will guarantee the delivery of the block of messages.  This loop will continue to try to send execute the web method until until the market
                // service either accepts it or the thread is killed externally.  If the client finds itself in the faulted state after any exception, we'll try
                // to create it again.  Note that we give the thread a little time to sleep when we do run into a fault so as to keep this loop from eating up the
                // CPU when the market service isn't around to process the web service request.
                while (true)
                {
                    try
                    {
                        marketServiceClient.ExecuteOrder(messages.ToArray());
                        break;
                    }
                    catch
                    {
                        if (marketServiceClient.State != CommunicationState.Opened)
                        {
                            marketServiceClient = new MarketServiceClient();
                            Thread.Sleep(MarketEngine.retryTime);
                        }
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Clears the orders and executions from the server.
        /// </summary>
        void ClearOrders(Object state)
        {
            // The simulator needs to be cleaned of orders so it doesn't generate an execution on an order that's been deleted by the server.
            using (MarketServiceClient marketServiceClient = new MarketServiceClient())
                marketServiceClient.ClearOrders();

            // This will clear any of the orders on the server.  The main idea is to allow a replay of a demo scenario.  This is never intended to be part of an
            // actual production environment.
            foreach (TenantInfo tenantInfo in MainWindow.Tenants)
            {
                if (tenantInfo.Status == Status.Running)
                {
                    WebServiceClient webServiceClient = new WebServiceClient(tenantInfo.EndpointConfigurationName);
                    webServiceClient.ClientCredentials.UserName.UserName = tenantInfo.UserName;
                    webServiceClient.ClientCredentials.UserName.Password = tenantInfo.Password;
                    webServiceClient.ClearOrders();
                }
            }
        }
示例#4
0
        /// <summary>
        /// Initializes the simulation parameters.
        /// </summary>
        /// <param name="state">The generic thread start parameter.</param>
        void InitializeData(Object state)
        {
            SimulatorParameters simulatorParameters = null;

            // This will ask the simulator for the current set of operating parameters
            using (MarketServiceClient marketServiceClient = new MarketServiceClient())
            {
                try
                {
                    simulatorParameters = marketServiceClient.GetSimulatorParameters();
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, "Market Console Error");
                    Application.Current.Shutdown();
                }
            }

            // Pass the simulator parameters to the foreground to be used as the initialization settings for the management dialog.
            this.Dispatcher.BeginInvoke(
                DispatcherPriority.SystemIdle,
                new SetSimulatorParametersHandler(this.OnSetSimulatorParameters),
                simulatorParameters);
        }