public Market(PriceChanged priceChanged) { this.mile_Price = null; this.business_Price = null; this.volume_Price = null; this.speed_Price = null; this._priceChanged = priceChanged; var rootPath = System.IO.Directory.GetCurrentDirectory(); Console.WriteLine($"path:{rootPath}"); //Console.WriteLine($"IPPath:{rootPath}"); if (File.Exists($"{rootPath}\\config\\MarketIP.txt")) { var text = File.ReadAllText($"{rootPath}\\config\\MarketIP.txt"); var ipAndPort = text.Split(':'); this.IP = ipAndPort[0]; this.port = int.Parse(ipAndPort[1]); } else { Console.WriteLine($"请market输入IP"); this.IP = Console.ReadLine(); Console.WriteLine("请market输入端口"); this.port = int.Parse(Console.ReadLine()); var text = $"{this.IP}:{this.port}"; File.WriteAllText($"{rootPath}\\config\\MarketIP.txt", text); } }
public async Task SimilarEventWithDifferentTimeStampIsNotIdempotent() { var product = new Product { ProductCode = "MN2400" }; var customer = new Customer { CustomerCode = "0000010367" }; var firstOccurrence = DateTime.UtcNow.Subtract(new TimeSpan(3, 0, 0)); var secondOccurrence = DateTime.UtcNow.Subtract(new TimeSpan(2, 0, 0)); var evt1 = new PriceChanged { Product = product, Customer = customer, TimeStamp = firstOccurrence }; var evt2 = new PriceChanged { Product = product, Customer = customer, TimeStamp = secondOccurrence }; var streamName = $"IdempotentTestStream-{Guid.NewGuid()}"; await eventStore.PublishAsync(evt1, streamName).ConfigureAwait(false); await eventStore.PublishAsync(evt2, streamName).ConfigureAwait(false); var streamEvents = await eventStore.ReadSliceFromStreamAsync(streamName, ReadDirection.Forwards, StreamPosition.Start, 200).ConfigureAwait(false); streamEvents.Count().Should().Be(2); testOutput.WriteLine($"2 events succesfully written to {streamName}"); }
protected virtual void OnPriceChanged(PriceChangedEventArgs e) { if (e.NewPrice > 200) { PriceChanged.Invoke(this, e); // removed null check because the object is already initialized. } }
protected virtual void OnPriceChanged(EventArgs e) { if (PriceChanged != null) { PriceChanged.Invoke(this, e); } }
public async void UpdatePriceAsync(PriceChanged newPrice) { if (newPrice == null) { throw new ArgumentNullException("newPrice"); } if (newPrice.Price <= 0) { throw new ArgumentException("Price must be > 0 (zero)", "newPrice"); } var currentPrice = GetCurrentPrice(); if (newPrice.Price == currentPrice) { return; } _state = _stateProvider.CalculateState(newPrice.Price, GetCurrentSellPoint()); if (newPrice.Price > currentPrice) { await UpdateSellPoint(newPrice.Price); } else if (newPrice.Price < currentPrice) { await StopLoss(newPrice.Price); } }
private void OnPriceUpdate() { PriceChanged?.Invoke(this, new PriceUpdateEventArgs() { Row = Row, AlertId = Alerts.IndexOf(this) }); }
//методы public void ChangePrice(int value) { Price = value; var args = new PriceChangedEventArgs(); args.NewPrice = value; PriceChanged?.Invoke(this, args); }
private void RecalculatePrice() { CafeItemInfo.TotalPrice = ItemCheckbox.Checked ? CafeItemInfo.Price * CafeItemInfo.Count : 0; PriceChanged?.Invoke(this, CafeItemInfo.TotalPrice); }
public void OnPriceChange(PriceChangedEventAgrs e) { PriceChanged?.Invoke(this, e); //if (PriceChanged != null) //{ // PriceChanged(this, e); //} }
protected virtual void OnPriceChanged(PriceChangedEventArgs e) { //when there is method is added to PriceChanged event delegate if (PriceChanged != null) { //invoke the method: // stock_PriceChanged(object sender, PriceChangedEventArgs e) PriceChanged.Invoke(this, e); } }
static async Task Main(string[] args) { var builder = ConnectionSettings.Create() .EnableVerboseLogging() .UseConsoleLogger(); var connection = EventStoreConnection.Create("ConnectTo=tcp://admin:changeit@localhost:1113", builder); await connection.ConnectAsync(); const string streamName = "e-commerce-stream"; var orders = Enumerable .Range(1, 10) .Select(i => new OrderSubmitted ( Guid.NewGuid(), $"Order {DateTime.Now} - {i + 1}", (decimal)Rnd.NextDouble() * 100, (OrderCategory)Rnd.Next(Enum.GetValues(typeof(OrderCategory)).Length) )) .ToList(); for (int i = 0; i < 10; i++) { var data = JsonHelper.Serialize(orders[i]); var meta = JsonHelper.Serialize(new { Index = i }); var eventData = new EventData(Guid.NewGuid(), nameof(OrderSubmitted), true, data, meta); await connection.AppendToStreamAsync(streamName, ExpectedVersion.Any, eventData); } var ordersToChange = orders .OrderBy(_ => Guid.NewGuid()) .Take(5); foreach (var order in ordersToChange) { var priceChanged = new PriceChanged ( order.Id, order.Price, (decimal)Rnd.NextDouble() * 100, DateTime.UtcNow ); var data = JsonHelper.Serialize(priceChanged); var eventData = new EventData(Guid.NewGuid(), nameof(PriceChanged), true, data, null); await connection.AppendToStreamAsync(streamName, ExpectedVersion.Any, eventData); } }
public void Handle(PriceChanged priceChanged) { _correlationId += 1; if (priceChanged.NewPrice < _limit) { var id = _correlationId; _bus.Publish(new Timeout(30, () => PriceDrop(id))); } if (priceChanged.NewPrice > _currentPrice) { var id = _correlationId; _bus.Publish(new Timeout(15, () => SetNewLimit(id, priceChanged.NewPrice))); } _currentPrice = priceChanged.NewPrice; }
public async Task ShouldRaisePriceChangedEvent() { var productID = Guid.NewGuid(); var amount = 5m; var currency = "EUR"; PriceChanged e = null; repoMock.Setup(x => x.GetByID(productID)).Returns(new Product(productID) { Price = new Price(1m, "EUR") }); mediatorMock.Setup(x => x.Publish(It.IsAny <PriceChanged>(), It.IsAny <CancellationToken>())).Callback <object, CancellationToken>((o, ct) => e = (PriceChanged)o); await handler.Handle(new SetPriceCommand { ProductID = productID, ProductPrice = new SetPriceCommand.Price { Amount = amount, Currency = currency } }, CancellationToken.None); e.ProductID.Should().Be(productID); }
/// <summary> /// Simulates a change in stock price. Rules are: /// 1) New price is within -/+ 10 % of the current price. /// 2) New price must be at most equal to upper limit. /// 3) New price must be at least equal to lower limit. /// </summary> public void GenerateNewPrice() { int percentChange = 10 - _generator.Next(21); double factor = 1 + (percentChange / 100.0); double newPrice = _price * factor; if (newPrice > _upperLimit) { newPrice = _upperLimit; } if (newPrice < _lowerLimit) { newPrice = _lowerLimit; } Price = newPrice; PriceChanged?.Invoke(ID, Price); }
public event EventHandler <PriceChangedEventArgs> PriceChanged; // 2 & 3 Use Framework define generic delegate protected virtual void OnPriceChanged(PriceChangedEventArgs e) // Protected Virtual Method that fires the event { PriceChanged?.Invoke(this, e); }
protected virtual void OnPriceChanged(PriceChangedEventArgs e) { PriceChanged?.Invoke(this, e); }
// The Standard Event Pattern requires a protected virtual method that fires the event. // The name has to match the name of the event, prefixed with the word "On". // It has to accept a single EventArgs argument protected virtual void OnPriceChanged(PriceChangedEventArgs e) { // This is a thread-safe and succint way to envoke the event. PriceChanged?.Invoke(this, e); }
private void OnMatch(object sender, RealtimeMatch e) { this.Price = e.Price.Value; PriceChanged?.Invoke(this, e.Price.Value); }
private void OnPriceChanged(decimal pretVechi, decimal pretNou) //functie care aplica delegatul cand trebuie { PriceChanged?.Invoke(this, new PriceChangedArgs { PretNou = pretNou, PretVechi = pretVechi }); }
void OnPriceChanged(int priceChange) { PriceChanged?.Invoke(this, priceChange); }
public event EventHandler <PriceChangedEventArgs> PriceChanged; // "Po zdefiniowaniu podklasy klasy EventArgs jest wybór lub zdefiniowanie delegatu dla zdarzenia" //public event EventHandler PriceChanged; protected virtual void OnPriceChanged(PriceChangedEventArgs e) // "I w końcu wzorzec zakłada napisanie chronionej metody wirtualnej uruchamiającej zdarzenie." { PriceChanged?.Invoke(this, e); }
public void ChangePrice(float price) { Price = price; PriceChanged?.Invoke(this, price); }
// any method inside of Stock class can call the event, which then triggers subscribers protected virtual void OnPriceChanged(PriceChangedEventArgs e) { PriceChanged?.Invoke(this, e); // null propagation, will check for null before invocation }
public void Test() { PriceChanged?.Invoke(this, new PriceChangedEventArgs(1, 1)); }