// Hoare Partition Scheme // https://en.wikipedia.org/wiki/Quicksort#Hoare_partition_scheme protected override async Task <int> Split(IList list, int low, int high) { // Select a pivot var pivot = list[(high + low) / 2]; // Get initial index of smaller side var ii = low; var jj = high; // Begin swapping elements to ensure those less than the pivot are to the left // and those greater than or equal to the pivot are on the right while (true) { await Task.Delay(1); while (AbstractOrder.LessThan(list[ii], pivot)) { ii++; } while (AbstractOrder.GreaterThan(list[jj], pivot)) { jj--; } if (ii >= jj) { return(jj + 1); // +1 to account for base Sorter using -1 instead of +1 for the recursive calls } Swap(list, ii, jj); ii++; jj--; } }
protected override async Task Join(IList list, int low, int splitIndex, int high) { // Find sizes of two subarrays to be merged int n1 = splitIndex - low; int n2 = high - splitIndex + 1; // Create temp arrays var left = new object[n1]; var right = new object[n2]; // Copy data to temp arrays to prevent overriding data in array for (var ii = 0; ii < n1; ++ii) { left[ii] = list[low + ii]; } for (var jj = 0; jj < n2; ++jj) { right[jj] = list[splitIndex + jj]; } // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of 'array' where first and second will merge to var k = low; // Begin merging the two temp arrays into 'array' starting at index k while (i < n1 && j < n2) { await Task.Delay(1); if (AbstractOrder.LessThanOrEqual(left[i], right[j])) { list[k] = left[i]; i++; } else { list[k] = right[j]; j++; } k++; } // Copy remaining elements of left[] if any while (i < n1) { list[k] = left[i]; i++; k++; } // Copy remaining elements of right[] if any while (j < n2) { list[k] = right[j]; j++; k++; } }
private void onDeleteOrderClicked(object sender, System.Windows.RoutedEventArgs e) { Button b = sender as Button; AbstractOrder data = b.DataContext as AbstractOrder; data.Source.mapModel.model.removeOrder(data); // TODO: Add event handler implementation here. }
public override void Validate(AbstractOrder order) { double total = order.getTotal(); CreditData creditData = order.Contributor.CreditData; double newBalance = creditData.Balance + total; if (newBalance > creditData.CreditLimit) { throw new ValidationException("The amount of the order " + "exceeds the available credit limit"); } }
public void EnqueueOrder(AbstractOrder order) { if (order == null) { throw new ArgumentNullException(nameof(order), "Parameter is null."); } _hangingOrders.Enqueue(order); OrderAdded(this, new OrderAddedEventArgs(order)); }
/// <summary> /// Validates the Order object fields /// Sends the order to riskified server endpoint as configured in the ctor /// </summary> /// <param name="order">The order checkout object to send</param> /// <param name="riskifiedEndpointUrl">the endpoint to which the order should be sent</param> /// <returns>The order tranaction result containing status and order id in riskified servers (for followup only - not used latter) in case of successful transfer</returns> /// <exception cref="OrderFieldBadFormatException">On bad format of the order (missing fields data or invalid data)</exception> /// <exception cref="RiskifiedTransactionException">On errors with the transaction itself (network errors, bad response data)</exception> private OrderNotification SendOrderCheckout(AbstractOrder orderCheckout, Uri riskifiedEndpointUrl) { if (_validationMode != Validations.Skip) { orderCheckout.Validate(_validationMode); } var wrappedOrder = new OrderCheckoutWrapper <AbstractOrder>(orderCheckout); var transactionResult = HttpUtils.JsonPostAndParseResponseToObject <OrderCheckoutWrapper <Notification>, OrderCheckoutWrapper <AbstractOrder> >(riskifiedEndpointUrl, wrappedOrder, _authToken, _shopDomain); return(new OrderNotification(transactionResult)); }
public override void Validate(AbstractOrder order) { if (!(order.GetType() == typeof(SalesOrder))) { throw new ValidationException("A sales order was expected"); } foreach (AbstractOrderValidator validator in Validators) { validator.Validate(order); } }
public override void Validate(AbstractOrder order) { foreach (AbstractOrderValidator validator in Validators) { validator.Validate(order); } //if (c.GetType() == typeof(TForm)) if (!(order.Contributor.GetType() == typeof(Customer))) { throw new ValidationException("The taxpayer is not a client"); } }
public override void Validate(AbstractOrder order) { foreach (AbstractOrderValidator validator in Validators) { validator.Validate(order); } Contributor contributor = order.Contributor; if (Status.ACTIVO != contributor.Status) { throw new ValidationException("The taxpayer is not active"); } }
private async Task CompleteOrder(AbstractOrder order) { AbstractCompletedOrder completedOrder = await PreparedOrder(order); // Будем считать, что выбирает ближайшее окно.. или наименее загруженное var productDeliveryWindow = Restaurant.ProductDeliveryWindowsByNumber.ElementAt( _random.Next(Restaurant.ProductDeliveryWindowsByNumber.Count())).Value; productDeliveryWindow.AddCompletedOrder(completedOrder); OrderCompleted(this, new OrderCompletedEventArgs(new CompletdOrderInfo(order.Number, productDeliveryWindow.WindowNumber))); _isFree = true; }
protected override async Task <int> Split(IList list, int low, int high) { // Bubble the largest element in the array up to the last position for (var ii = low; ii < high; ii++) { await Task.Delay(1); if (!AbstractOrder.GreaterThan(list[ii], list[ii + 1])) { continue; } Swap(list, ii, ii + 1); } return(high); }
protected override async Task Join(IList list, int low, int splitIndex, int high) { int jj; var key = list[high]; // Pick the last element in the array to insert // Begin shuffling any elements larger than the key over to the right for (jj = high; low < jj && AbstractOrder.LessThan(key, list[jj - 1]); jj--) { await Task.Delay(1); list[jj] = list[jj - 1]; } list[jj] = key; // Insert the key at it's final position }
public override void Validate(AbstractOrder order) { Address address = order.Contributor.Address; if (address.Address1 == null || address.Address1.Length == 0) { throw new ValidationException("Address 1 is mandatory"); } else if (address.CP == null || address.CP.Length != 4) { throw new ValidationException("ZIP code must be 4 digits"); } else if (address.Country == null || address.Country.Length == 0) { throw new ValidationException("The country is mandatory"); } }
private async Task <AbstractCompletedOrder> PreparedOrder(AbstractOrder order) { int allCoocingTime = order.ProductTypes.Sum(productType => ProductsCookingTimeInformator.GetCookingTime(productType)); var cookingEmulator = Task.Delay(TimeSpan.FromSeconds(allCoocingTime)); // Моделирует приготовление заказа LinkedList <AbstractProduct> completedProducts = new LinkedList <AbstractProduct>(); foreach (var productType in order.ProductTypes) { completedProducts.AddLast(AbstractProductCreator.GetCreator(productType).Create()); } AbstractCompletedOrder completedOrder = new CompletedOrder(order.Number, completedProducts); await cookingEmulator; return(completedOrder); }
public override void Validate(AbstractOrder order) { Telephone tel = order.Contributor.Telephone; if (null == tel) { throw new ValidationException("The taxpayer's phone is required"); } else if (tel.Number.Length != 7) { throw new ValidationException("Invalid phone number"); } else if (tel.Lada.Length != 3) { throw new ValidationException("Invalid lada"); } }
public override void Validate(AbstractOrder order) { List <OrderItem> orderItems = order.OrderItems; foreach (OrderItem item in orderItems) { Product product = item.Product; if (item.Quantity <= 0) { throw new ValidationException("The product '" + product.Name + "' has no amount"); } double listPrice = item.Product.ListPrice; double price = item.Price; double priceLimit = listPrice - (listPrice * 0.20d); if (price < priceLimit) { throw new ValidationException("The price of the product '" + product.Name + "' exceeds the allowed limit"); } } }
private async Task MaxHeapify(IList list, int n, int ii) { await Task.Delay(1); // Animation purposes var largest = ii; var leftChild = ii * 2 + 1; var rightChild = ii * 2 + 2; if (leftChild <= n && AbstractOrder.GreaterThan(list[leftChild], list[largest])) { largest = leftChild; } if (rightChild <= n && AbstractOrder.GreaterThan(list[rightChild], list[largest])) { largest = rightChild; } if (largest != ii) { Swap(list, ii, largest); await MaxHeapify(list, n, largest); } }
private async Task TakeNewOrder() { if (!Restaurant.ProductDeliveryWindowsByNumber.Any()) { throw new KeyNotFoundException("Restaurant doesn't contain at least one product delivery window."); } while (_isFree) { AbstractOrder order = null; lock (_locker) { if (!_isFree) { return; } if (Restaurant.OrdersController == null) { throw new NullReferenceException($"{nameof(Restaurant.OrdersController)} is null."); } order = Restaurant.OrdersController.DequeueOrder(); if (order == null) { return; } _isFree = false; } await CompleteOrder(order); } }
public BubbleSort(AbstractOrder abstractOrder) : base(abstractOrder) { }
public OrderAddedEventArgs(AbstractOrder order) { Order = order; }
public abstract void Validate(AbstractOrder order);
public OrderAcceptedEventArgs(AbstractOrder order) { Order = order ?? throw new ArgumentNullException(nameof(order), "Argument is null."); }
public PercentageOrderDecorator(AbstractOrder order, decimal percentage) : base(order) { this.percentage = percentage; }
public FixedOrderDecorator(AbstractOrder order, decimal amount) : base(order) { this.amount = amount; }
public HeapSort(AbstractOrder abstractOrder) : base(abstractOrder) { }
public QuickSort(AbstractOrder abstractOrder) : base(abstractOrder) { }
public MergeSort(AbstractOrder abstractOrder) : base(abstractOrder) { }
protected OrderDecorator(AbstractOrder order) { this.order = order; }
public InsertionSort(AbstractOrder abstractOrder) : base(abstractOrder) { }