protected ActivityAPI.Models.ProviderEvent ParseExecEvent(Entities.ActivityProviderEvent providerEventEntity) { var result = this.Mapper.Map <GolemClientMockAPI.ActivityAPI.Models.ExecProviderEvent>(providerEventEntity); result.ExeScript = new ActivityAPI.Models.ExeScriptBatch() { Commands = new List <ActivityAPI.Models.ExeScriptCommand>() }; // TODO more sophisticated syntax parser required here! var lines = providerEventEntity.ExeScript.Text.Replace("\r", "").Split("\n"); foreach (var line in lines) { var tokens = SplitCommandLine(line); if (tokens.Count() > 0) { result.ExeScript.Commands.Add(new ActivityAPI.Models.ExeScriptCommand() { Command = tokens.First(), Params = tokens.Skip(1).ToList() }); } } return(result); }
public GolemClientMockAPI.Entities.Activity Run(string agreementId) { var agreement = this.AgreementRepository.GetAgreement(agreementId); if (agreement == null) { throw new Exception($"Agreement {agreementId} does not exist..."); } else { var requestorNodeId = agreement.DemandProposal.Demand.NodeId; var providerNodeId = agreement.OfferProposal.Offer.NodeId; // 1. Create the activity record var activity = this.ActivityRepository.CreateActivity(agreementId, requestorNodeId, providerNodeId); // 2. Send the CreateActivity event to the Provider var providerEvent = new Entities.ActivityProviderEvent() { EventType = Entities.ActivityProviderEvent.ActivityProviderEventType.CreateActivity, ActivityId = activity.Id, AgreementId = agreementId }; this.EnsureProviderQueueExists(providerNodeId); this.ProviderEventQueues[providerNodeId].Add(providerEvent); // TODO: consider the activity states here - what should the activity state be at this point...??? return(activity); } }
public void Run(string activityId, ActivityProviderEvent.ActivityProviderEventType eventType) { var activity = this.ActivityRepository.GetActivity(activityId); if (activity == null) { throw new Exception($"Activity {activityId} does not exist..."); } else { var requestorNodeId = activity.RequestorNodeId; var providerNodeId = activity.ProviderNodeId; // 1. Send the event to Provider var providerEvent = new Entities.ActivityProviderEvent() { EventType = eventType, ActivityId = activity.Id }; if (this.ProviderEventQueues.ContainsKey(providerNodeId)) { this.ProviderEventQueues[providerNodeId].Add(providerEvent); } else { throw new Exception($"Unable to find provider node id {providerNodeId} in ProviderEventQueues..."); } } }
public GolemClientMockAPI.ActivityAPI.Models.ProviderEvent Map(Entities.ActivityProviderEvent providerEventEntity) { switch (providerEventEntity.EventType) { case Entities.ActivityProviderEvent.ActivityProviderEventType.CreateActivity: return(this.Mapper.Map <GolemClientMockAPI.ActivityAPI.Models.CreateActivityProviderEvent>(providerEventEntity)); case Entities.ActivityProviderEvent.ActivityProviderEventType.DestroyActivity: return(this.Mapper.Map <GolemClientMockAPI.ActivityAPI.Models.ProviderEvent>(providerEventEntity)); case Entities.ActivityProviderEvent.ActivityProviderEventType.Exec: return(this.ParseExecEvent(providerEventEntity)); case Entities.ActivityProviderEvent.ActivityProviderEventType.GetState: return(this.Mapper.Map <GolemClientMockAPI.ActivityAPI.Models.ProviderEvent>(providerEventEntity)); default: throw new Exception($"Unknown ProviderEventType {providerEventEntity.EventType} "); } }
public string Run(string activityId, ExeScript exeScript) { var activity = this.ActivityRepository.GetActivity(activityId); if (activity == null) { throw new Exception($"Activity {activityId} does not exist..."); } else { var requestorNodeId = activity.RequestorNodeId; var providerNodeId = activity.ProviderNodeId; // 1. Create the exeScript batch record var exeScriptBatch = this.ActivityRepository.CreateExeScriptBatch(activityId, exeScript); // 2. Send the Exec event to the Provider var providerEvent = new Entities.ActivityProviderEvent() { EventType = Entities.ActivityProviderEvent.ActivityProviderEventType.Exec, ActivityId = activity.Id, ExeScript = exeScriptBatch }; if (this.ProviderEventQueues.ContainsKey(providerNodeId)) { this.ProviderEventQueues[providerNodeId].Add(providerEvent); } else { throw new Exception($"Unable to find provider node id {providerNodeId} in ProviderEventQueues..."); } return(exeScriptBatch.BatchId); } }
public GolemClientMockAPI.Entities.Activity Run(string activityId) { var activity = this.ActivityRepository.GetActivity(activityId); if (activity == null) { throw new Exception($"Activity {activityId} does not exist..."); } else { var requestorNodeId = activity.RequestorNodeId; var providerNodeId = activity.ProviderNodeId; // 1. TODO Update state of the activity record // this.ActivityRepository.SetActivityState(activityId, ActivityState.) // 2. Send the DestroyActivity event to the Provider var providerEvent = new Entities.ActivityProviderEvent() { EventType = Entities.ActivityProviderEvent.ActivityProviderEventType.DestroyActivity, ActivityId = activity.Id }; if (this.ProviderEventQueues.ContainsKey(providerNodeId)) { this.ProviderEventQueues[providerNodeId].Add(providerEvent); } else { throw new Exception($"Unable to find provider node id {providerNodeId} in ProviderEventQueues..."); } return(activity); } }