Exemple #1
0
        public void Start(string[] args)
        {
            // Объект "соединение" и параметры соединения с приложением P2MQRouter
                m_conn = new CP2ConnectionClass();
                m_conn.Host = "localhost";
                m_conn.Port = 4001;
                m_conn.AppName = "p2clientgate_forts";

                IP2ConnectionEvent_ConnectionStatusChangedEventHandler connStatusHandler = new IP2ConnectionEvent_ConnectionStatusChangedEventHandler(ConnectionStatusChanged);
                m_conn.ConnectionStatusChanged += connStatusHandler;

                // создаем объект "входящий поток репликации"
                m_streamAggregates = new CP2DataStreamClass();
                m_streamAggregates.DBConnString = streamAggregatesDBConn;
                m_streamAggregates.type = TRequestType.RT_COMBINED_DYNAMIC;
                m_streamAggregates.StreamName = streamAggregatesID;
                m_streamAggregates.TableSet = new CP2TableSetClass();
                m_streamAggregates.TableSet.InitFromIni("orders_aggr.ini", "");

                m_streamTrades = new CP2DataStreamClass();
                m_streamTrades.DBConnString = streamTradesDBConn;
                m_streamTrades.type = TRequestType.RT_COMBINED_DYNAMIC;
                m_streamTrades.StreamName = streamTradesID;
                m_streamTrades.TableSet = new CP2TableSetClass();
                m_streamTrades.TableSet.InitFromIni("fut_trades.ini", "");

                m_streamMiscInfo = new CP2DataStreamClass();
                m_streamMiscInfo.DBConnString = streamMiscInfoDBConn;
                m_streamMiscInfo.type = TRequestType.RT_COMBINED_DYNAMIC;
                m_streamMiscInfo.StreamName = streamMiscInfoID;
                m_streamMiscInfo.TableSet = new CP2TableSetClass();
                m_streamMiscInfo.TableSet.InitFromIni("misc_info.ini", "");

                m_streamCommons = new CP2DataStreamClass();
                m_streamCommons.DBConnString = streamCommonsDBConn;
                m_streamCommons.type = TRequestType.RT_COMBINED_DYNAMIC;
                m_streamCommons.StreamName = streamCommonsID;
                m_streamCommons.TableSet = new CP2TableSetClass();
                m_streamCommons.TableSet.InitFromIni2("forts_scheme.ini", "FutCommon");

                // регистрируем интерфейсы обратного вызова для получения данных
                IP2DataStreamEvents_StreamStateChangedEventHandler StateHandler = new IP2DataStreamEvents_StreamStateChangedEventHandler(StreamStateChanged);
                m_streamAggregates.StreamStateChanged += StateHandler;
                m_streamTrades.StreamStateChanged += StateHandler;
                m_streamCommons.StreamStateChanged += StateHandler;
                m_streamMiscInfo.StreamStateChanged += StateHandler;

                IP2DataStreamEvents_StreamDataInsertedEventHandler InsHandler = new IP2DataStreamEvents_StreamDataInsertedEventHandler(StreamDataInserted);
                m_streamAggregates.StreamDataInserted += InsHandler;
                m_streamTrades.StreamDataInserted += InsHandler;
                m_streamCommons.StreamDataInserted += InsHandler;
                m_streamMiscInfo.StreamDataInserted += InsHandler;

                IP2DataStreamEvents_StreamDataUpdatedEventHandler UpdHandler = new IP2DataStreamEvents_StreamDataUpdatedEventHandler(StreamDataUpdated);
                m_streamAggregates.StreamDataUpdated += UpdHandler;
                m_streamTrades.StreamDataUpdated += UpdHandler;
                m_streamCommons.StreamDataUpdated += UpdHandler;
                m_streamMiscInfo.StreamDataUpdated += UpdHandler;

                IP2DataStreamEvents_StreamDataDeletedEventHandler DelHandler = new IP2DataStreamEvents_StreamDataDeletedEventHandler(StreamDataDeleted);
                m_streamAggregates.StreamDataDeleted += DelHandler;
                m_streamTrades.StreamDataDeleted += DelHandler;
                m_streamCommons.StreamDataDeleted += DelHandler;
                m_streamMiscInfo.StreamDataDeleted += DelHandler;

                // Добавляем обработчик события смены номера жизни потокам с клиентской схемой
                IP2DataStreamEvents_StreamLifeNumChangedEventHandler LifeNumHandler = new IP2DataStreamEvents_StreamLifeNumChangedEventHandler(StreamLifeNumChanged);
                m_streamAggregates.StreamLifeNumChanged += LifeNumHandler;
                m_streamTrades.StreamLifeNumChanged += LifeNumHandler;
                m_streamCommons.StreamLifeNumChanged += LifeNumHandler;
                m_streamMiscInfo.StreamLifeNumChanged += LifeNumHandler;

                for (int i = 0; i < args.Length; ++i)
                {
                    if (i == 0)
                    {
                        m_streamAggregates.DBConnString = args[i];
                        Console.WriteLine("Using DB connection string: {0}", m_streamAggregates.DBConnString);
                    }
                }
        }
Exemple #2
0
        public int Start(string[] args)
        {
            try
            {
                // Объект "соединение" и параметры соединения с приложением P2MQRouter
                m_conn = new CP2ConnectionClass();
                m_conn.Host = "localhost";
                m_conn.Port = 4001;
                m_conn.AppName = "p2clientgate_forts";

                IP2ConnectionEvent_ConnectionStatusChangedEventHandler connStatusHandler = new IP2ConnectionEvent_ConnectionStatusChangedEventHandler(ConnectionStatusChanged);
                m_conn.ConnectionStatusChanged += connStatusHandler;

                if (File.Exists(m_saveRev))
                {
                    using (StreamReader sr = new StreamReader(m_saveRev))
                    {
                        while (sr.Peek() >= 0)
                        {
                            curr_rev = Convert.ToInt64(sr.ReadLine());
                        }
                    }
                }

                if (File.Exists(m_saveDeal))
                {
                    using (StreamReader sr = new StreamReader(m_saveDeal))
                    {
                        while (sr.Peek() >= 0)
                        {
                            string buf = sr.ReadLine();
                            if (buf.StartsWith("replRev"))
                                curr_rev_deal = Int64.Parse(buf.Split('=')[1]);
                        }
                    }
                }

                // создаем объект "входящий поток репликации" для потока агрегированых заявок
                m_streamAggregates = new CP2DataStreamClass();
                m_streamAggregates.DBConnString = "";
                m_streamAggregates.type = TRequestType.RT_COMBINED_DYNAMIC;
                m_streamAggregates.StreamName = streamAggregatesID;
                m_streamAggregates.TableSet = new CP2TableSetClass();
                //m_streamAggregates.TableSet.InitFromIni2("orders_aggr.ini", "CustReplScheme");
                m_streamAggregates.TableSet.InitFromIni("orders_aggr.ini", "");
                m_streamAggregates.TableSet.set_rev("orders_aggr", curr_rev + 1);

                // создаем объект "входящий поток репликации" для потока агрегированых заявок
                m_streamTrades = new CP2DataStreamClass();
                m_streamTrades.DBConnString = "";
                m_streamTrades.type = TRequestType.RT_COMBINED_DYNAMIC;
                m_streamTrades.StreamName = streamTradesID;
                m_streamTrades.TableSet = new CP2TableSetClass();
                m_streamTrades.TableSet.InitFromIni2("forts_scheme.ini", "FutTrade");
                m_streamTrades.TableSet.set_rev("deal", curr_rev_deal + 1);

                // регистрируем интерфейсы обратного вызова для получения данных
                IP2DataStreamEvents_StreamStateChangedEventHandler StateHandler = new IP2DataStreamEvents_StreamStateChangedEventHandler(StreamStateChanged);
                m_streamAggregates.StreamStateChanged += StateHandler;
                m_streamTrades.StreamStateChanged += StateHandler;

                IP2DataStreamEvents_StreamDataInsertedEventHandler InsHandler = new IP2DataStreamEvents_StreamDataInsertedEventHandler(StreamDataInserted);
                m_streamAggregates.StreamDataInserted += InsHandler;
                m_streamTrades.StreamDataInserted += InsHandler;

                IP2DataStreamEvents_StreamDataDeletedEventHandler DelHandler = new IP2DataStreamEvents_StreamDataDeletedEventHandler(StreamDataDeleted);
                m_streamAggregates.StreamDataDeleted += DelHandler;
                m_streamTrades.StreamDataDeleted += DelHandler;

                IP2DataStreamEvents_StreamLifeNumChangedEventHandler LifeNumHandler = new IP2DataStreamEvents_StreamLifeNumChangedEventHandler(StreamLifeNumChanged);
                m_streamAggregates.StreamLifeNumChanged += LifeNumHandler;
                m_streamTrades.StreamLifeNumChanged += LifeNumHandler;

            }
            catch (Exception e)
            {
                int hRes = Marshal.GetHRForException(e);
                Console.WriteLine("Exception {0}", e.Message);
                LogWriteLine("Exception {0}", e.Message);
                if (hRes == -2147205116) // P2ERR_INI_FILE_NOT_FOUND
                {
                    string s = "Can't find one or both of ini file: P2ClientGate.ini, orders_aggr.ini";
                    Console.WriteLine("{0}", s);
                    LogWriteLine("{0}", s);
                }
                return (hRes);
            }
            return (0);
        }
Exemple #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                connect         = new CP2ConnectionClass();
                connect.Host    = "localhost";
                connect.Port    = 4001;
                connect.AppName = "myplazait";
                connect.ConnectionStatusChanged += delegate(CP2Connection _conn, TConnectionStatus _newStatus)
                {
                    //MessageBox.Show(_conn.Status.ToString() + " - newstatus: " + _newStatus);
                    MessageBox.Show("newstatus: " + _newStatus + " threadid: " + Thread.CurrentThread.ManagedThreadId);
                };

                if (File.Exists(m_saveRev))
                {
                    using (StreamReader sr = new StreamReader(m_saveRev))
                    {
                        while (sr.Peek() >= 0)
                        {
                            curr_rev = Convert.ToInt64(sr.ReadLine());
                        }
                    }
                }

                if (File.Exists(m_saveDeal))
                {
                    using (StreamReader sr = new StreamReader(m_saveDeal))
                    {
                        while (sr.Peek() >= 0)
                        {
                            string buf = sr.ReadLine();
                            if (buf.StartsWith("replRev"))
                            {
                                curr_rev_deal = Int64.Parse(buf.Split('=')[1]);
                            }
                        }
                    }
                }


                // создаем объект "входящий поток репликации" для потока агрегированых заявок
                m_streamAggregates = new CP2DataStreamClass();
                m_streamAggregates.DBConnString = "";
                m_streamAggregates.type         = TRequestType.RT_COMBINED_DYNAMIC; // RT_REMOTE_ONLINE
                m_streamAggregates.StreamName   = streamAggregatesID;
                m_streamAggregates.TableSet     = new CP2TableSetClass();
                m_streamAggregates.TableSet.InitFromIni("orders_aggr.ini", "");
                m_streamAggregates.TableSet.set_rev("orders_aggr", curr_rev + 1);

                // создаем объект "входящий поток репликации" для потока агрегированых заявок
                m_streamTrades = new CP2DataStreamClass();
                m_streamTrades.DBConnString = "";
                m_streamTrades.type         = TRequestType.RT_COMBINED_DYNAMIC; // RT_REMOTE_ONLINE
                m_streamTrades.StreamName   = streamTradesID;
                m_streamTrades.TableSet     = new CP2TableSetClass();
                m_streamTrades.TableSet.InitFromIni2("forts_scheme.ini", "FutTrade");
                m_streamTrades.TableSet.set_rev("deal", curr_rev_deal + 1);

                // регистрируем интерфейсы обратного вызова для получения данных
                IP2DataStreamEvents_StreamStateChangedEventHandler StateHandler = new IP2DataStreamEvents_StreamStateChangedEventHandler(StreamStateChanged);
                m_streamAggregates.StreamStateChanged += StateHandler;
                m_streamTrades.StreamStateChanged     += StateHandler;

                IP2DataStreamEvents_StreamDataInsertedEventHandler InsHandler = new IP2DataStreamEvents_StreamDataInsertedEventHandler(StreamDataInserted);
                m_streamAggregates.StreamDataInserted += InsHandler;
                m_streamTrades.StreamDataInserted     += InsHandler;

                IP2DataStreamEvents_StreamDataDeletedEventHandler DelHandler = new IP2DataStreamEvents_StreamDataDeletedEventHandler(StreamDataDeleted);
                m_streamAggregates.StreamDataDeleted += DelHandler;
                m_streamTrades.StreamDataDeleted     += DelHandler;

                IP2DataStreamEvents_StreamLifeNumChangedEventHandler LifeNumHandler = new IP2DataStreamEvents_StreamLifeNumChangedEventHandler(StreamLifeNumChanged);
                m_streamAggregates.StreamLifeNumChanged += LifeNumHandler;
                m_streamTrades.StreamLifeNumChanged     += LifeNumHandler;


                Run();
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }