public void createRequest(Good[] itemIDAndCount, DateTime time) { try { ChannelServices.RegisterChannel(chnl, false); } catch (Exception) { } // 1 Tuple<int, int> resultSupplierSystem = SupplierSystemsSurvey(itemIDAndCount); // 2 Tuple<int, int> resultDeliveryService = DeliveryServicesSurvey(time); // 3 { // оплата } // 4 Session["ResultSupplierSystem"] = resultSupplierSystem; Session["ResultDeliveryService"] = resultDeliveryService; //SupplierSystemConfirm(resultSupplierSystem.Item1, resultSupplierSystem.Item2); // 5 //DeliveryServiceConfirm(resultDeliveryService.Item1, resultDeliveryService.Item2); }
public void Test_DeliverySystemConfirmFail() { ShoppingCart sc = new ShoppingCart(); Good[] itemIDAndCount = new Good[1]; for (int i = 0, count = itemIDAndCount.Length; i < count; ++i) { itemIDAndCount[i].ItemID = i + 1; itemIDAndCount[i].Count = 5; } string dateString = "5/1/2008 5:01:52 PM"; DateTime time = DateTime.Parse(dateString, System.Globalization.CultureInfo.InvariantCulture); sc.createRequest(itemIDAndCount, time, 7); }
public void Test_DeliveryServiceWrongTime() { ShoppingCart sc = new ShoppingCart(); Good[] itemIDAndCount = new Good[3]; for (int i = 0, count = itemIDAndCount.Length; i < count; ++i) { itemIDAndCount[i].ItemID = i + 1; itemIDAndCount[i].Count = 10; } string dateString = "5/1/2008 5:30:52 AM"; DateTime time = DateTime.Parse(dateString, System.Globalization.CultureInfo.InvariantCulture); sc.createRequest(itemIDAndCount, time, 5); }
public void Test_SupplierSystemGoodNotFound() { ShoppingCart sc = new ShoppingCart(); Good[] itemIDAndCount = new Good[3]; for (int i = 0, count = itemIDAndCount.Length; i < count; ++i) { itemIDAndCount[i].ItemID = 10; itemIDAndCount[i].Count = 5; } string dateString = "5/1/2008 5:30:52 PM"; DateTime time = DateTime.Parse(dateString, System.Globalization.CultureInfo.InvariantCulture); sc.createRequest(itemIDAndCount, time, 2); }
public void createRequest(Good[] itemIDAndCount, DateTime time, int id) { try { ChannelServices.RegisterChannel(chnl, false); } catch (Exception) { } offSupplierSystem = true; offDeliveryService = true; switch (id) { case 1: { object[] parameters = new object[] { 1, "http://localhost:5671/SupplierSystem.RPC", itemIDAndCount }; SupplierSystemSurvey(parameters); if (offSupplierSystem) { throw new ExceptionSupplierSystemOff(); } } break; case 2: { object[] parameters = new object[] { 1, "http://localhost:5671/SupplierSystem.RPC", itemIDAndCount }; SupplierSystemSurvey(parameters); if (offSupplierSystem) { throw new ExceptionSupplierSystemOff(); } else { throw new ExceptionSupplierSystemNotGood(); } } break; case 3: { object[] parameters = new object[] { 1, "http://localhost:5671/SupplierSystem.RPC", itemIDAndCount }; SupplierSystemSurvey(parameters); if (offSupplierSystem) { throw new ExceptionSupplierSystemOff(); } else { throw new ExceptionSupplierSystemNotGood(); } } break; case 4: { object[] parameters = new object[] { 1, "http://localhost:5671/SupplierSystem.RPC", itemIDAndCount }; SupplierSystemSurvey(parameters); if (offSupplierSystem) { throw new ExceptionSupplierSystemOff(); } parameters = new object[] { 1, "http://localhost:5681/DeliveryService.RPC", time }; DeliveryServiceSurvey(parameters); if (offDeliveryService) { throw new ExceptionDeliveryServiceOff(); } } break; case 5: { object[] parameters = new object[] { 1, "http://localhost:5671/SupplierSystem.RPC", itemIDAndCount }; SupplierSystemSurvey(parameters); if (offSupplierSystem) { throw new ExceptionSupplierSystemOff(); } parameters = new object[] { 1, "http://localhost:5681/DeliveryService.RPC", time }; DeliveryServiceSurvey(parameters); if (offDeliveryService) { throw new ExceptionDeliveryServiceOff(); } else { throw new ExceptionDeliveryServiceWrongTime(); } } break; case 6: { object[] parameters = new object[] { 1, "http://localhost:5671/SupplierSystem.RPC", itemIDAndCount }; SupplierSystemSurvey(parameters); if (offSupplierSystem) { throw new ExceptionSupplierSystemOff(); } parameters = new object[] { 1, "http://localhost:5681/DeliveryService.RPC", time }; DeliveryServiceSurvey(parameters); if (offDeliveryService) { throw new ExceptionDeliveryServiceOff(); } throw new ExceptionSupplierSystemConfirmFail(); } break; case 7: { object[] parameters = new object[] { 1, "http://localhost:5671/SupplierSystem.RPC", itemIDAndCount }; SupplierSystemSurvey(parameters); if (offSupplierSystem) { throw new ExceptionSupplierSystemOff(); } parameters = new object[] { 1, "http://localhost:5681/DeliveryService.RPC", time }; DeliveryServiceSurvey(parameters); if (offDeliveryService) { throw new ExceptionDeliveryServiceOff(); } SupplierSystemConfirm("http://localhost:5671/SupplierSystem.RPC", 1); throw new ExceptionDeliveryServiceConfirmFail(); } break; case 8: { object[] parameters = new object[] { 1, "http://localhost:5671/SupplierSystem.RPC", itemIDAndCount }; SupplierSystemSurvey(parameters); if (offSupplierSystem) { throw new ExceptionSupplierSystemOff(); } parameters = new object[] { 1, "http://localhost:5681/DeliveryService.RPC", time }; DeliveryServiceSurvey(parameters); if (offDeliveryService) { throw new ExceptionDeliveryServiceOff(); } SupplierSystemConfirm("http://localhost:5671/SupplierSystem.RPC", 1); DeliveryServiceConfirm("http://localhost:5681/DeliveryService.RPC", 1); } break; } }
Tuple<int, int> SupplierSystemsSurvey(Good[] itemIDAndCount) { int timeOut = 100; offSupplierSystem = true; Tuple<int, int> result = null; resultSupplierSystemGlobal = null; using (ProductContext _db = new ProductContext()) { foreach (var system in _db.SupplierSystems) { object[] parameters = new object[] { system.ID, system.ConnectionString, itemIDAndCount }; Thread thread = new Thread(SupplierSystemSurvey); thread.Start(parameters); } } for (int i = 0; i < 20 && null == result; ++i) { Thread.Sleep(timeOut); lock (lockSupplierSystem) { result = resultSupplierSystemGlobal; } } if (null == result) { if (offSupplierSystem) { throw new ExceptionSupplierSystemOff(); } else { throw new ExceptionSupplierSystemNotGood(); } } Console.WriteLine(" resultSupplierSystem={0}:{1}", result.Item1, result.Item2); return result; }
protected void CheckoutBtn_Click(object sender, EventArgs e) { Good[] itemIDAndCount = null; using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) { Session["payment_amt"] = usersShoppingCart.GetTotal(); List<CartItem> items = usersShoppingCart.GetCartItems(); int count = items.Count; itemIDAndCount = new Good[count]; for (int i = 0; i < count; ++i) { itemIDAndCount[i].ItemID = items[i].ProductId; itemIDAndCount[i].Count = items[i].Quantity; } } int indexDate = DropDownListDate.SelectedIndex; int indexTime = DropDownListTime.SelectedIndex; DateTime now = DateTime.Now; DateTime time = new DateTime(now.Year, now.Month, now.Day + indexDate, 4 * indexTime, 0, 0); bool allRight = false; try { createRequest(itemIDAndCount, time); allRight = true; //Response.Redirect("http://localhost:24019/Checkout/CheckoutReview.aspx"); } catch (ExceptionSupplierSystemOff) { LabelError.Text = "Поставщики не отвечают."; LabelError.Visible = true; } catch (ExceptionSupplierSystemNotGood) { LabelError.Text = "Запрос не может быть удовлетворён."; LabelError.Visible = true; } catch (ExceptionSupplierSystemConfirmFail) { LabelError.Text = "Проблема связи с поставщиками."; LabelError.Visible = true; } catch (ExceptionDeliveryServiceOff) { LabelError.Text = "Службы доставки не отвечают."; LabelError.Visible = true; } catch (ExceptionDeliveryServiceWrongTime) { LabelError.Text = "Запрос на доставку не может быть удовлетворён."; LabelError.Visible = true; } catch (ExceptionDeliveryServiceConfirmFail) { LabelError.Text = "Проблема связи со службой доставки."; LabelError.Visible = true; } catch (Exception exception) { Console.WriteLine("Exception: {0}", exception); Response.Redirect("http://localhost:24019/Checkout/CheckoutCancel.aspx"); } // //Response.Redirect("Checkout/CheckoutStart.aspx"); if (allRight) { Response.Redirect("Checkout/CheckoutInformation.aspx"); } }