public Guid OrderTicket(Order newOrder, SeatIndex[] seats) { ITicketingServiceOneWay prox = null; Guid callId = Guid.NewGuid(); try { // TODO: Ex2 - Add code to call the one-way service // Find a proxy to the ticketing service (one-way) prox = TicketingServiceOneWayProxyFactory.GetProxy(false); AutoResetEvent arrived = new AutoResetEvent(false); // Create a ResultPackage with a wait handle to wait on until a response arrives (on another channel) ResultPackage pack = new ResultPackage() { ResultArrived = arrived }; ResultsCache.Current.SetPackage(callId, pack); // Call the pricing service on MSMQ channel on another thread. Action<ITicketingServiceOneWay> del = (p => p.OrderTicket(newOrder, seats, callId)); del.BeginInvoke(prox, null, null); //Wait until result arrives arrived.WaitOne(timeout); Guid result = (Guid)ResultsCache.Current.GetResult(callId); ResultsCache.Current.ClearResult(callId); return result; } catch (Exception ex) { LoggingManager.Logger.Log(LoggingCategory.Error, StringsResource.FailedToContactTicketing + " " + ex.Message); throw new TicketingException(StringsResource.TicketingFailed + " " + ex.Message, ex); } finally { if ((prox != null) && ((prox as ICommunicationObject).State == CommunicationState.Opened)) (prox as ICommunicationObject).Close(); } }
public Payment PayForTicket(Guid orderID, Guid payingCustomerID, double amount, PaymentType methodOfPayment, Currencies? currency, string creditCard) { ITicketingServiceOneWay prox = null; Guid callId = Guid.NewGuid(); try { // Find a proxy to the ticketing service (one way) prox = TicketingServiceOneWayProxyFactory.GetProxy(false); AutoResetEvent arrived = new AutoResetEvent(false); // Create a ResultPackage with a wait handle to wait on until a response arrives (on another channel) ResultPackage pack = new ResultPackage() { ResultArrived = arrived }; ResultsCache.Current.SetPackage(callId, pack); // Call the ticketing service via MSMQ channel on another thread. Action<ITicketingServiceOneWay> del = (p => p.PayForTicket(orderID, payingCustomerID, amount, methodOfPayment, currency, callId, creditCard)); del.BeginInvoke(prox, null, null); //Wait until result arrives arrived.WaitOne(timeout); Payment result = (Payment)ResultsCache.Current.GetResult(callId); ResultsCache.Current.ClearResult(callId); return result; } catch (Exception ex) { LoggingManager.Logger.Log(LoggingCategory.Error, StringsResource.FailedToContactTicketing + " " + ex.Message); throw new TicketingException(StringsResource.TicketingFailed + " " + ex.Message, ex); } finally { if ((prox != null) && ((prox as ICommunicationObject).State == CommunicationState.Opened)) (prox as ICommunicationObject).Close(); } }
public void SetPackage(Guid id, ResultPackage package) { Results[id] = package; }
public void SaveResult(Guid Id, ResultPackage result) { Results.Add(Id, result); }