示例#1
0
        public async Task <ApplyResourceChange.Types.Response> ApplyResourceChange(ApplyResourceChange.Types.Request request)
        {
            var prior   = DeserializeDynamicValue(request.PriorState);
            var planned = DeserializeDynamicValue(request.PlannedState);

            if (planned == null)
            {
                // Delete
                await _resourceProvider.DeleteAsync(prior);

                return(new ApplyResourceChange.Types.Response());
            }
            else if (prior == null)
            {
                // Create
                var created = await _resourceProvider.CreateAsync(planned);

                var createdSerialized = SerializeDynamicValue(created);
                return(new ApplyResourceChange.Types.Response
                {
                    NewState = createdSerialized,
                });
            }
            else
            {
                // Update
                var updated = await _resourceProvider.UpdateAsync(prior, planned);

                var updatedSerialized = SerializeDynamicValue(updated);
                return(new ApplyResourceChange.Types.Response
                {
                    NewState = updatedSerialized,
                });
            }
        }