public void OrderTicket(Order newOrder, SeatIndex[] seats, Guid callID) { try { callback_prox = CallBackChannelFactory.GetProxy(false); Guid result; // Do the job and call back the ticketing bridge result = generalTicketing.OrderTicket(newOrder, seats); //Call back the bridge callback_prox.IDArrived(result, callID); } catch (TicketingException tex) { LoggingManager.Logger.Log(LoggingCategory.Error, StringsResource.TicketingFailed + " " + tex.Message); throw new TicketingException(StringsResource.TicketingFailed + " " + tex.Message, tex); } catch (Exception ex) { LoggingManager.Logger.Log(LoggingCategory.Error, StringsResource.FailedToContactTicketingBridge + " " + ex.Message); throw new TicketingException(StringsResource.TicketingFailed + " " + ex.Message, ex); } finally { if ((callback_prox != null) && ((callback_prox as ICommunicationObject).State == CommunicationState.Opened)) (callback_prox as ICommunicationObject).Close(); } }
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 string Print(Order order) { string result; switch (order.State) { case OrderState.Created: result = "The order is not approved please pay the bill"; break; case OrderState.Approved: result = order.ToString(); break; case OrderState.Canceled: result = "The order was canceled"; break; default: result = "Error: Order is in an undefined state"; break; } Console.WriteLine(result); return result; }
private void btnOrderTicket_Click(object sender, RoutedEventArgs e) { if (_seats.Count == 0) { MessageBox.Show(Properties.Resources.OrderTicketWindow_NoSeatSelected); } else if (SelectedCustomer == null) { MessageBox.Show(Properties.Resources.OrderTicketWindow_NoCustomerSelected); } else { Order newOrder = new Order(); // Create an order newOrder.ReservationID = Guid.NewGuid(); newOrder.CustomerInfo = new Customer() { ID = SelectedCustomer.ID }; newOrder.EventInfo = SelectedEvent; btnOrderTicket.IsEnabled = false; statusText.Text = "Waiting for the service to complete"; BackgroundWorker backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += BackgroundTicketOrderWork; backgroundWorker.RunWorkerCompleted += BackgroundTicketOrderCompleted; backgroundWorker.RunWorkerAsync(newOrder); } }
public void OrdersArrived(Order[] result, Guid callID) { HandleResult(result, callID); }
/// <summary> /// call the payment service to fill in the payments info /// </summary> /// <param name="order"></param> private void FillPaymentInfo(Order order) { IPaymentService paymentProx = null; lock (this) { if (paymentChf == null) paymentChf = new ChannelFactory<IPaymentService>("CertPaymentEP"); } try { paymentProx = paymentChf.CreateChannel(); var payments = paymentProx.FindPayments(new PaymentCriteria() { OrderID = order.ID }); order.PaymentsInfo = payments.ToList(); } catch (Exception ex) { LoggingManager.Logger.Log(LoggingCategory.Error, ex.Message); throw new TicketingException(StringsResource.FailedToContactPayment + " " + ex.Message, ex); } finally { var channel = paymentProx as ICommunicationObject; if ((channel != null) && (channel.State == CommunicationState.Opened)) channel.Close(); } }
/// <summary> /// call the shows service to fill in the Event info /// </summary> /// <param name="ord"></param> private void FillEventInfo(Order ord) { IShowsService showsProx = null; lock (this) { if (showsChf == null) showsChf = new ChannelFactory<IShowsService>("ShowEP"); } try { showsProx = showsChf.CreateChannel(); ord.EventInfo = showsProx.FindEventByID(ord.EventInfo.EventID); } catch (Exception ex) { LoggingManager.Logger.Log(LoggingCategory.Error, ex.Message); throw new TicketingException(StringsResource.FailedToContactPayment + " " + ex.Message, ex); } finally { var channel = showsProx as ICommunicationObject; if ((channel != null) && (channel.State == CommunicationState.Opened)) channel.Close(); } }
/// <summary> /// Call the crm service to fill the customer info. In the orders DB only the ID is saved. /// The order data contract includes a full customer record so the crm service is called to get that info. /// </summary> /// <param name="ord"></param> private void FillCustomerInfo(Order ord) { ICrmBase crmProx = null; lock (this) { if (crmChf == null) crmChf = new ChannelFactory<ICrmBase>("CrmCertEP"); } try { crmProx = crmChf.CreateChannel(); var crm_cust = crmProx.GetCustomerByID(ord.CustomerInfo.ID); if (crm_cust == null) throw new TicketingException(string.Format(StringsResource.CustomerNotFound, ord.CustomerInfo.ID)); ord.CustomerInfo = CustomerMapper.MapToTicketingCustomer(crm_cust); } catch (Exception ex) { LoggingManager.Logger.Log(LoggingCategory.Error, ex.Message); throw new TicketingException(StringsResource.FailedToContactCrm + " " + ex.Message, ex); } finally { var channel = crmProx as ICommunicationObject; if ((channel != null) && (channel.State == CommunicationState.Opened)) channel.Close(); } }