/// <summary> /// When we receive a event from DbMongoManager when the db is modified. /// </summary> /// <param name="operationType"></param> /// <param name="type"></param> /// <param name="obj"></param> public override void OnDbModified(ChangeStreamOperationType operationType, Type type, BaseType obj) { log.Debug($"UpdatesHubHandler.OnDbModified() called with operation {operationType}"); EventNotifierOperation?notifierOperationType = null; switch (operationType) { case ChangeStreamOperationType.Delete: notifierOperationType = EventNotifierOperation.Delete; break; case ChangeStreamOperationType.Insert: notifierOperationType = EventNotifierOperation.Create; break; case ChangeStreamOperationType.Update: case ChangeStreamOperationType.Replace: notifierOperationType = EventNotifierOperation.Update; break; } if (notifierOperationType == null) { return; } // Users connection updates. if (type == typeof(Users)) { UpdateUsers(obj as Users); } // Events based Tasks. else if (type == typeof(Ingredients)) { Ingredients ingredient = obj as Ingredients; if (notifierOperationType.Value == EventNotifierOperation.Delete) { HandleDeletedIngredient(ingredient); } else { ingredient.Price = IngredientPrices.Get(ingredient._id); } SendMessage(notifierOperationType.Value, ingredient); } else if (type == typeof(IngredientPrices)) { IngredientPrices price = obj as IngredientPrices; Ingredients ingredient = Ingredients.Get(price.IngredientId, price.UserId); SendMessage(notifierOperationType.Value, ingredient); } else if (type == typeof(Recipes)) { Recipes recipe = obj as Recipes; if (notifierOperationType.Value == EventNotifierOperation.Delete) { HandleDeletedRecipe(recipe); } else { recipe = Recipes.Get(obj._id); } SendMessage(notifierOperationType.Value, recipe); } else if (type == typeof(Weeks)) { Weeks week = obj as Weeks; week = Weeks.GetWeek(week.UserId); SendMessage(notifierOperationType.Value, week); } else if (type == typeof(WeekIngredients)) { WeekIngredients weekIngredients = obj as WeekIngredients; weekIngredients = WeekIngredients.Get(weekIngredients.UserId); SendMessage(notifierOperationType.Value, weekIngredients); } }