public Agreement Run(string agreementId, AgreementResultEnum response) { // 0. Validate the agreement var agreement = this.AgreementRepository.GetAgreement(agreementId); if (agreement != null) { if (agreement.State != AgreementState.Proposed) { throw new Exception($"Agreement {agreementId} must be in Proposed state, is in {agreement.State}!"); } // 1. Set agreement state to Proposed and persist this.AgreementRepository.UpdateAgreementState(agreementId, this.DecodeIntendedAgreementState(response)); // 2. Send the Agreement response to the Requestor if (this.AgreementResultPipelines.ContainsKey(agreementId)) { this.AgreementResultPipelines[agreementId].Add(response); } else { throw new Exception($"AgreementId {agreementId} not found in AgreementResultPipelines..."); } return(agreement); } else { throw new Exception($"Agreement Id {agreementId} does not exist..."); } }
protected Agreement SendAgreementResponse(string agreementId, AgreementResultEnum response) { return(new SendAgreementResponseOperation( this.SubscriptionRepository, this.ProposalRepository, this.AgreementRepository, this.RequestorEventPipelines, this.DemandSubscriptions, this.ProviderEventPipelines, this.OfferSubscriptions, this.AgreementResultPipelines ).Run(agreementId, response)); }
private AgreementState DecodeIntendedAgreementState(AgreementResultEnum response) { switch (response) { case AgreementResultEnum.Approved: return(AgreementState.Approved); case AgreementResultEnum.Rejected: return(AgreementState.Rejected); default: throw new Exception($"Unknown repsonse: {response}"); } }
public Agreement Run(string agreementId, AgreementResultEnum response) { // 0. Validate the agreement var agreement = this.AgreementRepository.GetAgreement(agreementId); if (agreement != null) { switch (agreement.State) { case AgreementState.Pending: // 1. Set agreement state according to Provider's decision and persist this.AgreementRepository.UpdateAgreementState(agreementId, this.DecodeIntendedAgreementState(response)); // 2. Send the Agreement response to the Requestor if (this.AgreementResultPipelines.ContainsKey(agreementId)) { this.AgreementResultPipelines[agreementId].Add(response); } else { throw new Exception($"AgreementId {agreementId} not found in AgreementResultPipelines..."); } break; case AgreementState.Cancelled: // Agreement has been cancelled in between // break; default: throw new Exception($"Agreement {agreementId} must be in Proposed state, is in {agreement.State}!"); } return(agreement); } else { throw new Exception($"Agreement Id {agreementId} does not exist..."); } }