private void Shutdown(O2GSession session, StatusListener statusListener, TableListener tableListener, O2GTableManager tableManager) { if (tableListener != null) { tableListener.UnsubscribeEvents(tableManager); } if (statusListener != null) { if (session != null) { session.logout(); } statusListener.WaitEvents(); } }
static void Main(string[] args) { O2GSession session = null; try { LoginParams loginParams = new LoginParams(ConfigurationManager.AppSettings); SampleParams sampleParams = new SampleParams(ConfigurationManager.AppSettings); PrintSampleParams("GetOffers", loginParams, sampleParams); session = O2GTransport.createSession(); session.useTableManager(O2GTableManagerMode.Yes, null); SessionStatusListener statusListener = new SessionStatusListener(session, loginParams.SessionID, loginParams.Pin); session.subscribeSessionStatus(statusListener); statusListener.Reset(); session.login(loginParams.Login, loginParams.Password, loginParams.URL, loginParams.Connection); if (statusListener.WaitEvents() && statusListener.Connected) { TableListener tableListener = new TableListener(); O2GTableManager tableManager = session.getTableManager(); O2GTableManagerStatus managerStatus = tableManager.getStatus(); while (managerStatus == O2GTableManagerStatus.TablesLoading) { Thread.Sleep(50); managerStatus = tableManager.getStatus(); } if (managerStatus == O2GTableManagerStatus.TablesLoadFailed) { throw new Exception("Cannot refresh all tables of table manager"); } tableListener.SetInstrument(sampleParams.Instrument); tableListener.SubscribeEvents(tableManager); O2GOffersTable offers = null; offers = (O2GOffersTable)tableManager.getTable(O2GTableType.Offers); tableListener.PrintOffers(offers, null); // Do nothing 10 seconds, let offers print Thread.Sleep(10000); Console.WriteLine("Done!"); tableListener.UnsubscribeEvents(tableManager); statusListener.Reset(); session.logout(); statusListener.WaitEvents(); } session.unsubscribeSessionStatus(statusListener); } catch (Exception e) { Console.WriteLine("Exception: {0}", e.ToString()); } finally { if (session != null) { session.Dispose(); } } }
static void Main(string[] args) { O2GSession session = null; try { LoginParams loginParams = new LoginParams(ConfigurationManager.AppSettings); SampleParams sampleParams = new SampleParams(ConfigurationManager.AppSettings); PrintSampleParams("GetOffers", loginParams, sampleParams); session = O2GTransport.createSession(); session.useTableManager(O2GTableManagerMode.Yes, null); SessionStatusListener statusListener = new SessionStatusListener(session, loginParams.SessionID, loginParams.Pin); session.subscribeSessionStatus(statusListener); statusListener.Reset(); session.login(loginParams.Login, loginParams.Password, loginParams.URL, loginParams.Connection); if (statusListener.WaitEvents() && statusListener.Connected) { TableListener tableListener = new TableListener(); O2GTableManager tableManager = session.getTableManager(); O2GTableManagerStatus managerStatus = tableManager.getStatus(); while (managerStatus == O2GTableManagerStatus.TablesLoading) { Thread.Sleep(50); managerStatus = tableManager.getStatus(); } if (managerStatus == O2GTableManagerStatus.TablesLoadFailed) { throw new Exception("Cannot refresh all tables of table manager"); } tableListener.SetInstrument(sampleParams.Instrument); tableListener.SubscribeEvents(tableManager); O2GOffersTable offers = null; offers = (O2GOffersTable)tableManager.getTable(O2GTableType.Offers); tableListener.PrintOffers(offers, null); // Do nothing 10 seconds, let offers print Thread.Sleep(10000); Console.WriteLine("Done!"); tableListener.UnsubscribeEvents(tableManager); statusListener.Reset(); session.logout(); statusListener.WaitEvents(); } session.unsubscribeSessionStatus(statusListener); } catch (Exception e) { Console.WriteLine("Exception: {0}", e.ToString()); } finally { if (session != null) { session.Dispose(); } } }