示例#1
0
        /// <summary>
        /// 
        /// </summary>
        /// <exception cref="AggregateException"></exception>
        public void PreloadMagicNumbers()
        {
            var gates = new AutoResetEvent[6];
            var g1 = new AutoResetEvent(false);
            var agex = new AggregateException("Exceptions occured resolving magic numbers");
            gates[0] = g1;
            _client.Messaging.BeginGetSystemLookup(MagicNumberKeys.ApiOrderResponseDTO_StatusReason, 69, a =>
                {

                    try
                    {
                        MagicNumbers[MagicNumberKeys.ApiOrderResponseDTO_StatusReason] = _client.EndRequest<ApiLookupResponseDTO>(a);
                    }
                    catch (Exception ex)
                    {
                        
                        agex.Exceptions.Add(ex);
                    }
                    finally
                    {
                        g1.Set();    
                    }
                    
                }, null);

            var g2 = new AutoResetEvent(false);
            gates[1] = g2;
            _client.Messaging.BeginGetSystemLookup(MagicNumberKeys.ApiOrderResponseDTO_Status, 69, a =>
                {
                    try
                    {
                        MagicNumbers[MagicNumberKeys.ApiOrderResponseDTO_Status] = _client.EndRequest<ApiLookupResponseDTO>(a);
                    }
                    catch (Exception ex)
                    {

                        agex.Exceptions.Add(ex);
                    }
                    finally
                    {
                        g2.Set();
                    }
                }, null);

            var g3 = new AutoResetEvent(false);
            gates[2] = g3;
            _client.Messaging.BeginGetSystemLookup(MagicNumberKeys.ApiTradeOrderResponseDTO_StatusReason, 69, a =>
                {
                    try
                    {
                        MagicNumbers[MagicNumberKeys.ApiTradeOrderResponseDTO_StatusReason] = _client.EndRequest<ApiLookupResponseDTO>(a);

                    }
                    catch (Exception ex)
                    {

                        agex.Exceptions.Add(ex);
                    }
                    finally
                    {
                        g3.Set();
                    }
                }, null);

            var g4 = new AutoResetEvent(false);
            gates[3] = g4;
            _client.Messaging.BeginGetSystemLookup(MagicNumberKeys.ApiTradeOrderResponseDTO_Status, 69, a =>
                {
                    try
                    {
                        MagicNumbers[MagicNumberKeys.ApiTradeOrderResponseDTO_Status] = _client.EndRequest<ApiLookupResponseDTO>(a);
                    }
                    catch (Exception ex)
                    {

                        agex.Exceptions.Add(ex);
                    }
                    finally
                    {
                        g4.Set();
                    }
                }, null);

            var g5 = new AutoResetEvent(false);
            gates[4] = g5;
            _client.Messaging.BeginGetSystemLookup(MagicNumberKeys.ApiActiveStopLimitOrderDTO_Applicability, 69, a =>
                {
                    try
                    {
                        MagicNumbers[MagicNumberKeys.ApiActiveStopLimitOrderDTO_Applicability] = _client.EndRequest<ApiLookupResponseDTO>(a);
                    }
                    catch (Exception ex)
                    {

                        agex.Exceptions.Add(ex);
                    }
                    finally
                    {
                        g5.Set();
                    }
                }, null);

            var g6 = new AutoResetEvent(false);
            gates[5] = g6;


            _client.Messaging.BeginGetSystemLookup(MagicNumberKeys.ApiOpenPositionDTO_Status, 69, a =>
                {
                    try
                    {
                        MagicNumbers[MagicNumberKeys.ApiOpenPositionDTO_Status] = _client.EndRequest<ApiLookupResponseDTO>(a);
                    }
                    catch (Exception ex)
                    {

                        agex.Exceptions.Add(ex);
                    }
                    finally
                    {
                        g6.Set();
                    }
                }, null);

            // System.Threading.WaitHandle.WaitAll API is not supported is silverlight/phone
            // WaitHandle.WaitAll(gates);

            g1.WaitOne();
            g2.WaitOne();
            g3.WaitOne();
            g4.WaitOne();
            g5.WaitOne();
            g6.WaitOne();

            
            if (agex.Exceptions.Count!=0)
            {
                throw agex;
            }
#if SILVERLIGHT
            _preloaded = true;
#endif
            _logger.Debug("PreloadMagicNumbersAsync complete");
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="AggregateException"></exception>
        public void PreloadMagicNumbers()
        {
            var gates = new AutoResetEvent[6];
            var g1    = new AutoResetEvent(false);
            var agex  = new AggregateException("Exceptions occured resolving magic numbers");

            gates[0] = g1;
            _client.Messaging.BeginGetSystemLookup(MagicNumberKeys.ApiOrderResponseDTO_StatusReason, 69, a =>
            {
                try
                {
                    MagicNumbers[MagicNumberKeys.ApiOrderResponseDTO_StatusReason] = _client.EndRequest <ApiLookupResponseDTO>(a);
                }
                catch (Exception ex)
                {
                    agex.Exceptions.Add(ex);
                }
                finally
                {
                    g1.Set();
                }
            }, null);

            var g2 = new AutoResetEvent(false);

            gates[1] = g2;
            _client.Messaging.BeginGetSystemLookup(MagicNumberKeys.ApiOrderResponseDTO_Status, 69, a =>
            {
                try
                {
                    MagicNumbers[MagicNumberKeys.ApiOrderResponseDTO_Status] = _client.EndRequest <ApiLookupResponseDTO>(a);
                }
                catch (Exception ex)
                {
                    agex.Exceptions.Add(ex);
                }
                finally
                {
                    g2.Set();
                }
            }, null);

            var g3 = new AutoResetEvent(false);

            gates[2] = g3;
            _client.Messaging.BeginGetSystemLookup(MagicNumberKeys.ApiTradeOrderResponseDTO_StatusReason, 69, a =>
            {
                try
                {
                    MagicNumbers[MagicNumberKeys.ApiTradeOrderResponseDTO_StatusReason] = _client.EndRequest <ApiLookupResponseDTO>(a);
                }
                catch (Exception ex)
                {
                    agex.Exceptions.Add(ex);
                }
                finally
                {
                    g3.Set();
                }
            }, null);

            var g4 = new AutoResetEvent(false);

            gates[3] = g4;
            _client.Messaging.BeginGetSystemLookup(MagicNumberKeys.ApiTradeOrderResponseDTO_Status, 69, a =>
            {
                try
                {
                    MagicNumbers[MagicNumberKeys.ApiTradeOrderResponseDTO_Status] = _client.EndRequest <ApiLookupResponseDTO>(a);
                }
                catch (Exception ex)
                {
                    agex.Exceptions.Add(ex);
                }
                finally
                {
                    g4.Set();
                }
            }, null);

            var g5 = new AutoResetEvent(false);

            gates[4] = g5;
            _client.Messaging.BeginGetSystemLookup(MagicNumberKeys.ApiActiveStopLimitOrderDTO_Applicability, 69, a =>
            {
                try
                {
                    MagicNumbers[MagicNumberKeys.ApiActiveStopLimitOrderDTO_Applicability] = _client.EndRequest <ApiLookupResponseDTO>(a);
                }
                catch (Exception ex)
                {
                    agex.Exceptions.Add(ex);
                }
                finally
                {
                    g5.Set();
                }
            }, null);

            var g6 = new AutoResetEvent(false);

            gates[5] = g6;


            _client.Messaging.BeginGetSystemLookup(MagicNumberKeys.ApiOpenPositionDTO_Status, 69, a =>
            {
                try
                {
                    MagicNumbers[MagicNumberKeys.ApiOpenPositionDTO_Status] = _client.EndRequest <ApiLookupResponseDTO>(a);
                }
                catch (Exception ex)
                {
                    agex.Exceptions.Add(ex);
                }
                finally
                {
                    g6.Set();
                }
            }, null);

            // System.Threading.WaitHandle.WaitAll API is not supported is silverlight/phone
            // WaitHandle.WaitAll(gates);

            g1.WaitOne();
            g2.WaitOne();
            g3.WaitOne();
            g4.WaitOne();
            g5.WaitOne();
            g6.WaitOne();


            if (agex.Exceptions.Count != 0)
            {
                throw agex;
            }
#if SILVERLIGHT
            _preloaded = true;
#endif
            _logger.Debug("PreloadMagicNumbersAsync complete");
        }