/// <summary> /// Deletes the data structure from the reposiotry and tells all (subscribing) clients about it /// /// Override to implement custom logic /// </summary> /// <param name="model"></param> public virtual async Task Delete(DataSyncStructure model) { model = Repository <Guid, DataSyncStructure> .GetById(model.Id); if (model != null) { Repository <Guid, DataSyncStructure> .Remove(model.Id); await Sync(DataSyncCommand.Delete, model); } }
/// <summary> /// Adds/Updates the data structure from in reposiotry and tells all (subscribing) clients about it. /// /// Override to implement custom logic /// </summary> /// <param name="model"></param> public virtual async Task Update(DataSyncStructure model) { var command = DataSyncCommand.Update; if (model.Id == Guid.Empty) { model.Id = Guid.NewGuid(); command = DataSyncCommand.Add; } model = Repository <Guid, DataSyncStructure> .AddOrUpdate(model.Id, model); await Sync(command, model); }
/// <summary> /// Will do a PUBLISH of changes by default, override to implement specific logic and/or RPC /// </summary> /// <param name="command"></param> /// <param name="model"></param> protected virtual async Task Sync(string command, DataSyncStructure model) { await Controller.PublishToAll(model, string.Format("{0}:{1}", command, model.Topic)); }