public async Task <IActionResult> PutAsync(string id, [FromBody] UpdateProduct command) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var toBeUpdatedProduct = _productRepository.GetAsync(id); if (toBeUpdatedProduct == null) { return(NotFound()); } else if (command.Id == null) { command.Id = id; } Product product = Mapper.Map <Product>(command); await _productRepository.UpdateAsync(product); // send event ProductUpdated e = Mapper.Map <ProductUpdated>(product); await _messagePublisher.PublishMessageAsync(e.MessageType, e, ""); return(NoContent()); }
/** * Modify selected product using data form passed product */ public bool Edit(Product responseProduct) { if (string.IsNullOrEmpty(responseProduct.Name) || responseProduct.Price == 0 || responseProduct.Category == 0 || responseProduct.Id == 0) { Debug.WriteLine("Product name, price and category cannot be null"); return(false); } using (var context = new ShopDbContext()) { //Get product. If it doesn't exist return null Product oldProduct = context.Products.Find(responseProduct.Id); if (oldProduct == null) { Debug.WriteLine("Product of given id doesn't exist in database"); return(false); } var config = new MapperConfiguration(cfg => cfg.CreateMap <Product, ProductUpdated>()); var mapper = config.CreateMapper(); ProductUpdated updatedProduct = mapper.Map <ProductUpdated>(responseProduct); context.Entry(oldProduct).CurrentValues.SetValues(updatedProduct); context.SaveChanges(); return(true); } }
public async Task Handle( ProductUpdated notification, CancellationToken cancellationToken) { _logger.LogInformation($"We publish the message {nameof(notification)}: {JsonSerializer.Serialize(notification)}"); await _daprClient.PublishEventAsync("product-updated", notification); }
public void Handle(ProductUpdated @event, CommerceInstance instance) { var product = CommerceInstance.Current.Database.Repository <Product>().Find(@event.ProductId); if (product.IsPublished) { Index(product, GetAllCultures()); } }
public void Handle(ProductUpdated evt) { if (productPrices.ContainsKey(evt.ProductId)) { productPrices.Remove(evt.ProductId); Model.ProductUpdated(evt.ProductId, evt.Price, evt.Description, evt.Timestamp); } productPrices.Add(evt.ProductId, evt); }
public XNodeEventService(ILogger <SystemService> logger, string agentId, XNodeConfiguration nodeConfig, DataStorageConfiguration dataStorageConfig, AgentConfiguration agentConfiguration, IXNodeConnectionRepository xNodeConnectionRepository, TenantIOService tenantIOService, ProducerIOService producerIOService, ConsumerIOService consumerIOService, MessageIOService messageIOService) { this.logger = logger; this.xNodeConnectionRepository = xNodeConnectionRepository; this.tenantIOService = tenantIOService; this.producerIOService = producerIOService; this.consumerIOService = consumerIOService; this.messageIOService = messageIOService; this.agentId = agentId; this.nodeConfig = nodeConfig; var provider = new XNodeConnectionProvider(nodeConfig, dataStorageConfig, agentConfiguration, agentId); _connection = provider.GetHubConnection(); _connection.On <AgentConnectedArgs>("StorageConnected", connectedArgs => StorageConnected?.Invoke(connectedArgs)); _connection.On <AgentDisconnectedArgs>("StorageDisconnected", disconnectedArgs => StorageDisconnected?.Invoke(disconnectedArgs)); _connection.On <TenantCreatedArgs>("TenantCreated", tenantCreated => TenantCreated?.Invoke(tenantCreated)); _connection.On <TenantUpdatedArgs>("TenantUpdated", tenantUpdated => TenantUpdated?.Invoke(tenantUpdated)); _connection.On <ProductCreatedArgs>("ProductCreated", productCreated => ProductCreated?.Invoke(productCreated)); _connection.On <ProductUpdatedArgs>("ProductUpdated", productUpdated => ProductUpdated?.Invoke(productUpdated)); _connection.On <ComponentCreatedArgs>("ComponentCreated", componentCreated => ComponentCreated?.Invoke(componentCreated)); _connection.On <ComponentUpdatedArgs>("ComponentUpdated", componentUpdated => ComponentUpdated?.Invoke(componentUpdated)); _connection.On <TopicCreatedArgs>("TopicCreated", topicCreated => TopicCreated?.Invoke(topicCreated)); _connection.On <TopicUpdatedArgs>("TopicUpdated", topicUpdated => TopicUpdated?.Invoke(topicUpdated)); _connection.On <ProducerConnectedArgs>("ProducerConnected", producerConnected => ProducerConnected?.Invoke(producerConnected)); _connection.On <ProducerDisconnectedArgs>("ProducerDisconnected", producerDisconnected => ProducerDisconnected?.Invoke(producerDisconnected)); _connection.On <ConsumerConnectedArgs>("ConsumerConnected", consumerConnected => ConsumerConnected?.Invoke(consumerConnected)); _connection.On <ConsumerDisconnectedArgs>("ConsumerDisconnected", consumerDisconnected => ConsumerDisconnected?.Invoke(consumerDisconnected)); _connection.On <ConsumerConnectedArgs>("ConsumerUnacknowledgedMessagesRequested", consumerConnected => ConsumerUnacknowledgedMessagesRequested?.Invoke(consumerConnected)); _connection.On <MessageAcknowledgedArgs>("MessageAcknowledged", messageAcked => MessageAcknowledged?.Invoke(messageAcked)); _connection.On <MessageStoredArgs>("MessageStored", msgStored => MessageStored?.Invoke(msgStored)); InitializeEventHandlers(); ConnectAsync(); xNodeConnectionRepository.AddService(nodeConfig.ServiceUrl, agentId, this); }
private async Task <bool> HandleAsync(ProductUpdated e) { using (var dbContext = GetDbContext()) { if (e != null) { var product = await dbContext.Products.FirstOrDefaultAsync(p => p.ProductId == e.Id); product.Name = e.Name; product.Weight = e.WeightKg; await dbContext.SaveChangesAsync(); } } return(true); }
/// <summary> /// Notify that the product is updated /// </summary> public void Update() { ProductUpdated?.Invoke(); }
void Apply(ProductUpdated e) { _quantity = e.Quantity; _productCode = e.ProductCode; _allowComment = e.AllowComment; }
public async Task Handle(ProductUpdated @event) { await Task.Delay(1000); await Mediator.Send(@event); }
public Task HandleAsync(ProductUpdated @event) { return(RemoveCacheAsync()); }
private void Apply(ProductUpdated @event) { Name = @event.Name; Description = @event.Description; Price = @event.Price; }
public void Consume(ProductUpdated message) { _eventHandlers.Handle(message); }
public void Handle(ProductUpdated @event) { AddActivityLog(AdminActivityLogCategory.Product, @event); }
private void Apply(ProductUpdated evt) { this.productId = evt.ProductId; this.description = evt.Description; this.price = evt.Price; }
public SensiConnection() { Trace.WriteLine("SensiConnection ctor"); this._cookieJar = new CookieContainer(); this._hubConnection = new HubConnection(_urlBase + "realtime", false); this._hubConnection.CookieContainer = this._cookieJar; this._hubProxy = this._hubConnection.CreateHubProxy("thermostat-v1"); this._subscriptions = new List <string>(); this._hubConnection.StateChanged += (state) => { Debug.WriteLine($"State Changed from {state.OldState} to {state.NewState}"); }; this._hubConnection.ConnectionSlow += () => { Debug.WriteLine("Connection Slow"); }; this._hubConnection.Reconnected += () => { Debug.WriteLine("Reconnected"); }; this._hubConnection.Reconnecting += () => { Debug.WriteLine("Reconnecting"); }; this._hubConnection.Error += async(ex) => { Trace.WriteLine(ex, "HubConnection Error"); if (ex is System.Net.WebException) { if (((System.Net.WebException)ex).Status == WebExceptionStatus.ProtocolError) { var response = ((System.Net.WebException)ex).Response as HttpWebResponse; if (response != null && ( response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.InternalServerError) ) { Trace.WriteLine("Restarting Realtime due to WebExpection"); while (await this.BeginRealtime() == false) { Trace.WriteLine("Not Connected, Delaying..."); this.StopRealtime(); await Task.Delay(5000); } foreach (var sub in _subscriptions) { Trace.WriteLine("Attempt Re-Subscription for " + sub); this.Subscribe(sub).Wait(); } return; } } } else if (ex is System.Net.Sockets.SocketException) { Trace.WriteLine("Restarting Realtime due to SocketException"); while (await this.BeginRealtime() == false) { Trace.WriteLine("Not Connected, Delaying..."); this.StopRealtime(); await Task.Delay(5000); } foreach (var sub in _subscriptions) { Trace.WriteLine("Attempt Re-Subscription for " + sub); this.Subscribe(sub).Wait(); } return; } }; this._hubConnection.Received += (data) => { Debug.WriteLine("Data Received"); }; this._hubProxy.On <object>("initalized", (data) => { Trace.WriteLine(data, "Initalized"); }); this._hubProxy.On <object, object>("online", (icd, data) => { //Trace.WriteLine(Environment.NewLine + data, $"Received Online Message for ICD [{icd}]"); Trace.WriteLine($"Received Online Message for ICD [{icd}]"); this.LastUpdateReceived = DateTime.Now; try { var msg = JsonConvert.DeserializeObject <OnlineResponse>(data.ToString()); var args = (ThermostatOnlineEventArgs)msg; args.Icd = icd.ToString(); ThermostatOnline?.Invoke(this, args); } catch (Exception ex) { Trace.WriteLine(ex); } }); this._hubProxy.On <object, object>("update", (icd, data) => { //Trace.WriteLine(Environment.NewLine + data, $"Received Update Message for ICD [{icd}]"); Trace.WriteLine($"Received Update Message for ICD [{icd}]"); this.LastUpdateReceived = DateTime.Now; OnlineResponse msg = null; try { msg = JsonConvert.DeserializeObject <OnlineResponse>(data.ToString()); } catch (Exception ex) { Trace.WriteLine(ex); } if (msg != null) { if (msg != null && msg.OperationalStatus != null) { OperationalStatusUpdated?.Invoke(this, new OperationalStatusUpdatedEventArgs { Icd = icd.ToString(), OperationalStatus = msg.OperationalStatus }); } if (msg != null && msg.EnvironmentControls != null) { EnvironmentalControlsUpdated?.Invoke(this, new EnvironmentalControlsUpdatedEventArgs { Icd = icd.ToString(), EnvironmentControls = msg.EnvironmentControls }); } if (msg != null && msg.Capabilities != null) { CapabilitiesUpdated?.Invoke(this, new CapabilitiesUpdatedEventArgs { Icd = icd.ToString(), Capabilities = msg.Capabilities }); } if (msg != null && msg.Settings != null) { SettingsUpdated?.Invoke(this, new SettingsUpdatedEventArgs { Icd = icd.ToString(), Settings = msg.Settings }); } if (msg != null && msg.Product != null) { ProductUpdated?.Invoke(this, new ProductUpdatedEventArgs { Icd = icd.ToString(), Product = msg.Product }); } } }); this._hubProxy.On <object, object>("offline", (icd, data) => { //Trace.WriteLine(Environment.NewLine + data, $"Received Offline Message for ICD [{icd}]"); Trace.WriteLine($"Received Offline Message for ICD [{icd}]"); this.LastUpdateReceived = DateTime.Now; }); }