Skip to content

Instantly share code, notes, and snippets.

@psethi1984 psethi1984/OrdersService.cs Secret
Last active Sep 18, 2017

Embed
What would you like to do?
private LiveDataService liveDataService;
private ObservableCollection<ProductOrder> _orders;
private void ServiceInit()
{
base.ServiceInit();
liveDataService.RegisterFor<ProductOrder>(
newOrder =>
{
_logService.Log("New order received");
_orders.Add(newOrder);
RaisePropertyChanged(() => AllOrders);
},
deletedOrder =>
{
_logService.Log("Order deleted");
_orders.Remove(deletedOrder);
RaisePropertyChanged(() => AllOrders);
},
error =>
{
_logService.Log("Service lost");
HandleError(error);
});
}
private void ServiceDeInit()
{
liveDataService.DeRegisterFor<ProductOrder>();
}
private LiveDataService liveDataService;
private CacheService cacheService;
private ObservableCollection<Product> _specialProducts;
private void ServiceInit()
{
base.ServiceInit();
liveDataService.RegisterFor<List<Product>>(
newProducts => {
_logService.Log("New specials received");
_specialProducts = new ObservableCollection<Product>(newProducts);
RaisePropertyChanged(() => SpecialProducts);
},
d =>
{
// Not required
},
error =>
{
_logService.Log("Service lost");
HandleError(error);
})
.CacheBy(cacheService) // Retrieves data from cache if still valid
.Scope(DiscountedProducts); // DiscountedProducts is synchronisation scope with live data
}
private void ServiceDeInit()
{
liveDataService.DeRegisterFor<List<Product>>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.