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