public Task Load(ResourceDocument fullResourceState) { if (!TryGetIdentity(fullResourceState, out var identity)) { throw new System.Exception("Identity field is required."); } if (!TryGetKindManager(fullResourceState, out var manager)) { throw new System.Exception("Valid kind required."); } var newState = new ResourceState( manager, identity, fullResourceState ); if (!Validate(newState)) { throw new System.Exception("Invalid resource parameters specified."); } CommitResourceState(newState); return(newState.Manager.Save(newState)); }
private ResourceState ApplyFields(ResourceDocument partialResourceState, ResourceState existingState) { return(new ResourceState( existingState.Manager, existingState.Identity, existingState.FullDocument.Patch(partialResourceState) )); }
public abstract Task Save(ResourceState resourceState);
public bool Validate(ResourceState resourceState) { return(true); }
private void CommitResourceState(ResourceState resourceState) { _resourceIdentityIndex[resourceState.Identity] = resourceState; }
private bool TryGetResourceState(string identity, out ResourceState fullResourceState) { return(_resourceIdentityIndex.TryGetValue(identity, out fullResourceState)); }