Esempio n. 1
0
        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));
        }
Esempio n. 2
0
 private ResourceState ApplyFields(ResourceDocument partialResourceState, ResourceState existingState)
 {
     return(new ResourceState(
                existingState.Manager,
                existingState.Identity,
                existingState.FullDocument.Patch(partialResourceState)
                ));
 }
Esempio n. 3
0
 public abstract Task Save(ResourceState resourceState);
Esempio n. 4
0
 public bool Validate(ResourceState resourceState)
 {
     return(true);
 }
Esempio n. 5
0
 private void CommitResourceState(ResourceState resourceState)
 {
     _resourceIdentityIndex[resourceState.Identity] = resourceState;
 }
Esempio n. 6
0
 private bool TryGetResourceState(string identity, out ResourceState fullResourceState)
 {
     return(_resourceIdentityIndex.TryGetValue(identity, out fullResourceState));
 }