/// <summary> /// Check if order exists /// </summary> /// <param name="session"></param> /// <param name="sAccountID"></param> /// <param name="sOrderID"></param> /// <param name="responseListener"></param> /// <returns></returns> private static bool IsOrderExists(O2GSession session, string sAccountID, string sOrderID, ResponseListener responseListener) { bool bHasOrder = false; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } O2GRequest request = requestFactory.createRefreshTableRequestByAccount(O2GTableType.Orders, sAccountID); if (request == null) { throw new Exception("Cannot create request"); } responseListener.SetRequestID(request.RequestID); session.sendRequest(request); if (!responseListener.WaitEvents()) { throw new Exception("Response waiting timeout expired"); } O2GResponse response = responseListener.GetResponse(); O2GResponseReaderFactory responseReaderFactory = session.getResponseReaderFactory(); O2GOrdersTableResponseReader responseReader = responseReaderFactory.createOrdersTableReader(response); for (int i = 0; i < responseReader.Count; i++) { O2GOrderRow orderRow = responseReader.getRow(i); if (sOrderID.Equals(orderRow.OrderID)) { bHasOrder = true; break; } } return(bHasOrder); }
static void Main(string[] args) { O2GSession session = null; try { LoginParams loginParams = new LoginParams(ConfigurationManager.AppSettings); SampleParams sampleParams = new SampleParams(ConfigurationManager.AppSettings); PrintSampleParams("RemoveFromGroup", loginParams, sampleParams); session = O2GTransport.createSession(); SessionStatusListener statusListener = new SessionStatusListener(session, loginParams.SessionID, loginParams.Pin); session.subscribeSessionStatus(statusListener); session.login(loginParams.Login, loginParams.Password, loginParams.URL, loginParams.Connection); if (statusListener.WaitEvents() && statusListener.Connected) { ResponseListener responseListener = new ResponseListener(session); session.subscribeResponse(responseListener); O2GAccountRow account = GetAccount(session, sampleParams.AccountID); if (account == null) { if (string.IsNullOrEmpty(sampleParams.AccountID)) { throw new Exception("No valid accounts"); } else { throw new Exception(string.Format("The account '{0}' is not valid", sampleParams.AccountID)); } } sampleParams.AccountID = account.AccountID; O2GRequest request = RemoveOrderFromGroupRequest(session, sampleParams.AccountID, sampleParams.OrderID); if (request == null) { throw new Exception("Cannot create request"); } List <string> orderIDList = new List <string>(); orderIDList.Add(sampleParams.OrderID); foreach (string sOrderID in orderIDList) { if (!IsOrderExists(session, sampleParams.AccountID, sOrderID, responseListener)) { throw new Exception(string.Format("Order '{0}' does not exist", sOrderID)); } } responseListener.SetOrderIDs(orderIDList); session.sendRequest(request); if (responseListener.WaitEvents()) { Console.WriteLine("Done!"); } else { throw new Exception("Response waiting timeout expired"); } statusListener.Reset(); session.logout(); statusListener.WaitEvents(); session.unsubscribeResponse(responseListener); } session.unsubscribeSessionStatus(statusListener); } catch (Exception e) { Console.WriteLine("Exception: {0}", e.ToString()); } finally { if (session != null) { session.Dispose(); } } }