//вставка записи void StreamDataInserted(CP2DataStream stream, String tableName, CP2Record rec) { try { LogWriteLine(DateTime.Now.ToString() + " Insert " + tableName + " StreamName: " + stream.StreamName + "; TableSet.Count = " + stream.TableSet.Count.ToString()); // Пришел поток FORTS_FUTAGGR20_REPL if (stream.StreamName == streamAggregatesID) { SaveRev(rec.GetValAsVariantByIndex(1)); curr_rev = rec.GetValAsLongByIndex(1); uint count = rec.Count; for (uint i = 0; i < count; ++i) { if (i != count - 1) { LogWrite(rec.GetValAsStringByIndex(i) + ";"); } else { LogWriteLine(rec.GetValAsStringByIndex(i)); } } } // Пришел поток FORTS_FUTTRADE_REPL if (stream.StreamName == streamTradesID) { string Fields = m_streamTrades.TableSet.get_FieldList("deal"); curr_rev_deal = rec.GetValAsLongByIndex(1); for (uint i = 0; i < Fields.Split(',').Length; i++) { string Field = Fields.Split(',')[i]; string Value = ""; try { Value = rec.GetValAsString(Field); SaveDeal(DateTime.Now.ToString() + " " + Fields.Split(',')[i], Value); } catch (System.Exception e) { } } m_saveDealFile.WriteLine(""); m_saveDealFile.Flush(); } } catch (System.Exception e) { LogWriteLine("!!!" + e.Message + "!!!" + e.Source); } }
void StreamLifeNumChanged(CP2DataStream stream, int lifeNum) { if (stream.StreamName == "FORTS_FUTAGGR20_REPL") { m_streamAggregates.TableSet.LifeNum = lifeNum; m_streamAggregates.TableSet.SetLifeNumToIni("orders_aggr.ini"); } if (stream.StreamName == "FORTS_FUTTRADE_REPL") { m_streamTrades.TableSet.LifeNum = lifeNum; m_streamTrades.TableSet.SetLifeNumToIni("forts_scheme.ini"); } }
void StreamStateChanged(CP2DataStream stream, TDataStreamState newState) { String state = DateTime.Now.ToString() + " Stream " + stream.StreamName + " state: "; switch (newState) { case TDataStreamState.DS_STATE_CLOSE: state += "CLOSE"; //m_opened = false; break; case TDataStreamState.DS_STATE_CLOSE_COMPLETE: state += "CLOSE_COMPLETE"; break; case TDataStreamState.DS_STATE_ERROR: state += "ERROR"; //m_opened = false; break; case TDataStreamState.DS_STATE_LOCAL_SNAPSHOT: state += "LOCAL_SNAPSHOT"; break; case TDataStreamState.DS_STATE_ONLINE: state += "ONLINE"; break; case TDataStreamState.DS_STATE_REMOTE_SNAPSHOT: state += "REMOTE_SNAPSHOT"; break; case TDataStreamState.DS_STATE_REOPEN: state += "REOPEN"; break; } LogWriteLine(state); }
//удаление записи void StreamDataDeleted(CP2DataStream stream, String tableName, Int64 Id, CP2Record rec) { SaveRev(rec.GetValAsVariantByIndex(1)); LogWriteLine("Delete " + tableName + " " + Id); }
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); }
// Функция обработки смены номера жизни void StreamLifeNumChanged(CP2DataStream stream, int lifeNum) { if (stream.StreamName == "FORTS_FUTTRADE_REPL") { m_streamTrades.TableSet.LifeNum = lifeNum; m_streamTrades.TableSet.SetLifeNumToIni("fut_trades.ini"); } if (stream.StreamName == "FORTS_FUTCOMMON_REPL") { m_streamCommons.TableSet.LifeNum = lifeNum; m_streamCommons.TableSet.SetLifeNumToIni("forts_scheme.ini"); } if (stream.StreamName == "FORTS_MISCINFO_REPL") { m_streamMiscInfo.TableSet.LifeNum = lifeNum; m_streamMiscInfo.TableSet.SetLifeNumToIni("misc_info.ini"); } if (stream.StreamName == "FORTS_FUTAGGR20_REPL") { m_streamAggregates.TableSet.LifeNum = lifeNum; m_streamAggregates.TableSet.SetLifeNumToIni("orders_aggr.ini"); } }
//апдейт записи void StreamDataUpdated(CP2DataStream stream, String tableName, Int64 Id, CP2Record rec) { LogWriteLine("Update " + tableName + " " + Id); try { uint count = rec.Count; for( uint i = 0; i < count; ++i ) { if( i != count - 1) { LogWrite(rec.GetValAsStringByIndex(i) + ";"); } else { LogWriteLine(rec.GetValAsStringByIndex(i)); } } } catch (System.Exception e) { LogWriteLine("!!!" + e.Message + "!!!" + e.Source); } }
//удаление записи void StreamDataDeleted(CP2DataStream stream, String tableName, Int64 Id, CP2Record rec) { LogWriteLine("Delete " + tableName + " " + Id); }
private void DU(CP2DataStream stream, string tableName, long id, CP2Record rec) { Hashtable hashtable = new Hashtable(); TableBaseInfo tb = (this.buffer.tables[tableName] as TableBaseInfo); if (tb != null) { for (int i = 0; i < tb.fieldsArr.Length; i++) { hashtable.Add(tb.fieldsArr[i],rec.GetValAsString(tb.fieldsArr[i])); } recordContainer r = new recordContainer(tableName, hashtable, "update", id); buffer.insertRecord(r); } }
// Обработка состояния потока репликации void StreamStateChanged(CP2DataStream stream, TDataStreamState newState) { String state = "Stream " + stream.StreamName + " state: "; switch( newState ) { case TDataStreamState.DS_STATE_CLOSE: state += "CLOSE"; //m_opened = false; break; case TDataStreamState.DS_STATE_CLOSE_COMPLETE: state += "CLOSE_COMPLETE"; break; case TDataStreamState.DS_STATE_ERROR: state += "ERROR"; //m_opened = false; break; case TDataStreamState.DS_STATE_LOCAL_SNAPSHOT: state += "LOCAL_SNAPSHOT"; break; case TDataStreamState.DS_STATE_ONLINE: state += "ONLINE"; break; case TDataStreamState.DS_STATE_REMOTE_SNAPSHOT: state += "REMOTE_SNAPSHOT"; break; case TDataStreamState.DS_STATE_REOPEN: state += "REOPEN"; break; } LogWriteLine(state); }
void StreamDataDeleted(CP2DataStream stream, String tableName, Int64 Id, CP2Record rec) { SaveRev(rec.GetValAsVariantByIndex(1)); LogWriteLine(DateTime.Now.ToString() + " Delete " + tableName + " " + Id); }
private void lifeNumChanged(CP2DataStream stream, int Life) { this.parent.parent.logService("Life num value change in " + Life.ToString() + ", trying reopen stream " + stream.StreamName); stream.TableSet.LifeNum = Life; stream.TableSet.SetLifeNumToIni("Config\\scheme.ini"); foreach (TableBaseInfo tb in buffer.tables) { if ((tb.saveRev==1) && (tb.resetRevOnChangeLiveNum==1)) { this.parent.parent.logService("Set revision 0 for table " + tb.name + " on stream " + this.full_name); this.parent.mRevHash.setRevision(this.full_name + ":" + tb.name, 0L); long rev = this.parent.mRevHash.getRevision(this.full_name + ":" + tb.name); this.TableSet.set_rev(tb.name,rev); } } }
private void DUD(CP2DataStream stream, string tableName, long id) { Hashtable hashtable = new Hashtable(); TableBaseInfo tb = (this.buffer.tables[tableName] as TableBaseInfo); if (tb != null) { recordContainer r = new recordContainer(tableName, null, "delete_less", id); this.buffer.insertRecord(r); } }
//вставка записи void StreamDataInserted(CP2DataStream stream, String tableName, CP2Record rec) { try { LogWriteLine("Insert " + tableName); // Пришел поток FORTS_FUTAGGR20_REPL if (stream.StreamName == streamAggregatesID) { SaveRev(rec.GetValAsVariantByIndex(1)); curr_rev = rec.GetValAsLongByIndex(1); uint count = rec.Count; for (uint i = 0; i < count; ++i) { if (i != count - 1) { LogWrite(rec.GetValAsStringByIndex(i) + ";"); } else { LogWriteLine(rec.GetValAsStringByIndex(i)); } } } // Пришел поток FORTS_FUTTRADE_REPL if (stream.StreamName == streamTradesID) { string Fields = m_streamTrades.TableSet.get_FieldList("deal"); curr_rev_deal = rec.GetValAsLongByIndex(1); for (uint i = 0; i < Fields.Split(',').Length; i++) { string Field = Fields.Split(',')[i]; string Value = ""; try { Value = rec.GetValAsString(Field); SaveDeal(Fields.Split(',')[i], Value); } catch (System.Exception e) { } } m_saveDealFile.WriteLine(""); m_saveDealFile.Flush(); } } catch (System.Exception e) { LogWriteLine("!!!" + e.Message + "!!!" + e.Source); } }
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); } }
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); } } }
private void StreamStateChanged(CP2DataStream stream, TDataStreamState newState) { string str = "Stream " + stream.StreamName + " state: " + newState.ToString(); this.parent.logService(str); this.parent.listSteams_SetState(stream.StreamName, newState.ToString().Replace("DS_STATE_","")); }
private void DI(CP2DataStream stream, string tableName, CP2Record rec) { /*if (tableName == "common") { string t = rec.GetValAsVariant("isin_id").ToString(); if (t == "194834") parent.parent.logMsg("to queue :" + rec.GetValAsVariant("best_buy").ToString()); }*/ Hashtable hashtable = new Hashtable(); TableBaseInfo tb = (this.buffer.tables[tableName] as TableBaseInfo); if (tb != null) { for (int i = 0; i < tb.fieldsArr.Length; i++) { hashtable.Add(tb.fieldsArr[i],rec.GetValAsString(tb.fieldsArr[i])); } recordContainer r = new recordContainer(tableName, hashtable, "insert", 0); this.buffer.insertRecord(r); } }