public async Task OnAbortExecutionAsync(IPipelineExecutionContext context) { // aborts of the full pipeline indicate we do not calculate but we still want to capture the frame // if we have one context.Request.AdrRequest.PerformADRCalculation = false; context.Result.AdrResult = await this.HandleADRRequest(context.DevEUI, context.Request.AdrRequest); }
public async Task <FunctionBundlerExecutionState> ExecuteAsync(IPipelineExecutionContext context) { context.Result.AdrResult = await this.HandleADRRequest(context.DevEUI, context.Request.AdrRequest); context.Result.NextFCntDown = context.Result.AdrResult != null && context.Result.AdrResult.FCntDown > 0 ? context.Result.AdrResult.FCntDown : (uint?)null; return(FunctionBundlerExecutionState.Continue); }
protected BasePipelinePlugin(IPipelineExecutionContext context) { Context = context; RequestContractInUri = ((ContractAttribute)GetType().GetCustomAttribute(typeof(RequestContractInAttribute)))?.Uri; RequestContractOutUri = ((ContractAttribute)GetType().GetCustomAttribute(typeof(RequestContractOutAttribute)))?.Uri; ResponseContractInUri = ((ContractAttribute)GetType().GetCustomAttribute(typeof(ResponseContractInAttribute)))?.Uri; ResponseContractOutUri = ((ContractAttribute)GetType().GetCustomAttribute(typeof(ResponseContractOutAttribute)))?.Uri; }
private Policy InvokePolicy(IPipelineExecutionContext context, Type policyType) { var getPolicyMethod = context.GetType().GetMethod("GetPolicy"); var genericMethod = getPolicyMethod.MakeGenericMethod(new Type[] { policyType }); var policy = genericMethod.Invoke(context, null) as Policy; return(policy); }
public async Task OnAbortExecutionAsync(IPipelineExecutionContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } await ComputeAndSetPreferredGateway(context); }
public async Task Handle(IPipelineExecutionContext executionContext, CancellationToken cancellationToken, Func <CancellationToken, Task> next) { await next(cancellationToken); if (executionContext.CurrentStep is Step1) { Assert.Equal(Step1.Parameter.Value, executionContext.Get <string>(Step1.Parameter.Key)); } }
public Task <FunctionBundlerExecutionState> ExecuteAsync(IPipelineExecutionContext context) { if (!context.Result.NextFCntDown.HasValue) { var next = this.fCntCacheCheck.GetNextFCntDown(context.DevEUI, context.Request.GatewayId, context.Request.ClientFCntUp, context.Request.ClientFCntDown); context.Result.NextFCntDown = next > 0 ? next : (uint?)null; } return(Task.FromResult(FunctionBundlerExecutionState.Continue)); }
public PipelineProcessor(IPipelineExecutionContext pipelineExecutionContext, WorkflowAction workflowAction) { _dbContext = new OrationiDatabaseContext(); _pipelineExecutionContext = pipelineExecutionContext; _messageId = pipelineExecutionContext.MessageId; _workflowId = workflowAction.WorkflowId; InitializeStepsDescriptions(workflowAction); }
public async Task <FunctionBundlerExecutionState> ExecuteAsync(IPipelineExecutionContext context) { if (context is null) { throw new System.ArgumentNullException(nameof(context)); } context.Result.DeduplicationResult = await GetDuplicateMessageResultAsync(context.DevEUI, context.Request.GatewayId, context.Request.ClientFCntUp, context.Request.ClientFCntDown, context.Logger); return(context.Result.DeduplicationResult.IsDuplicate ? FunctionBundlerExecutionState.Abort : FunctionBundlerExecutionState.Continue); }
public async Task <FunctionBundlerExecutionState> ExecuteAsync(IPipelineExecutionContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } await ComputeAndSetPreferredGateway(context); return(FunctionBundlerExecutionState.Continue); }
public async Task <FunctionBundlerExecutionState> ExecuteAsync(IPipelineExecutionContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } context.Result.AdrResult = await HandleADRRequest(context.DevEUI, context.Request.AdrRequest); context.Result.NextFCntDown = context.Result.AdrResult != null && context.Result.AdrResult.FCntDown > 0 ? context.Result.AdrResult.FCntDown : null; return(FunctionBundlerExecutionState.Continue); }
public async Task OnAbortExecutionAsync(IPipelineExecutionContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } // aborts of the full pipeline indicate we do not calculate but we still want to capture the frame // if we have one context.Request.AdrRequest.PerformADRCalculation = false; context.Result.AdrResult = await HandleADRRequest(context.DevEUI, context.Request.AdrRequest); }
public async Task <IPipelineExecutionContext> Execute(IPipelineExecutionContext executionContext, CancellationToken cancellationToken = default) { if (executionContext == null) { throw new ArgumentNullException(nameof(executionContext)); } var behaviors = ResolveBehaviors(); foreach (var step in _stepDescriptors) { ExecuteStepDelegate @delegate = s_boundDelegates.GetOrAdd(step.Id, _ => step.CreateDelegate()); await ExecuteStep(step, executionContext, cancellationToken, @delegate, behaviors); } return(executionContext); }
private Task ExecuteStep(StepDescriptor step, IPipelineExecutionContext executionContext, CancellationToken cancellationToken, ExecuteStepDelegate @delegate, IPipelineBehavior[] behaviors) { var stepInstance = _factory(step.TypeInfo); executionContext.CurrentStep = stepInstance; Func <CancellationToken, Task> currentFunc = token => @delegate(stepInstance, executionContext, _namingStrategy, _unknownParameterBehavior, token); for (var i = behaviors.Length - 1; i >= 0; i--) { var behavior = behaviors[i]; var previousFunc = currentFunc; currentFunc = token => behavior.Handle(executionContext, cancellationToken, previousFunc); } return(currentFunc(cancellationToken)); }
public async Task <FunctionBundlerExecutionState> ExecuteAsync(IPipelineExecutionContext context) { if (context.Result.AdrResult?.FCntDown != null) { // adr already processed the next fcnt down check context.Result.NextFCntDown = context.Result.AdrResult.FCntDown; return(FunctionBundlerExecutionState.Continue); } if (!context.Result.NextFCntDown.HasValue) { var next = await this.fCntCacheCheck.GetNextFCntDownAsync(context.DevEUI, context.Request.GatewayId, context.Request.ClientFCntUp, context.Request.ClientFCntDown); context.Result.NextFCntDown = next; } return(FunctionBundlerExecutionState.Continue); }
public async Task <FunctionBundlerExecutionState> ExecuteAsync(IPipelineExecutionContext context) { await this.ComputeAndSetPreferredGateway(context); return(FunctionBundlerExecutionState.Continue); }
public async Task <FunctionBundlerExecutionState> ExecuteAsync(IPipelineExecutionContext context) { context.Result.DeduplicationResult = await this.GetDuplicateMessageResultAsync(context.DevEUI, context.Request.GatewayId, context.Request.ClientFCntUp, context.Request.ClientFCntDown, context.Logger); return(context.Result.DeduplicationResult.IsDuplicate ? FunctionBundlerExecutionState.Abort : FunctionBundlerExecutionState.Continue); }
public void ComingTogether(string param1Version1, string param1Version2, IPipelineExecutionContext context) { Param1Version1 = param1Version1; Param1Version2 = param1Version2; }
private async Task <PreferredGatewayResult> ComputePreferredGateway(IPipelineExecutionContext context) { var computationId = Guid.NewGuid().ToString(); var fcntUp = context.Request.ClientFCntUp; var devEUI = context.DevEUI; var rssi = context.Request.Rssi.Value; // 1. Add request to list `preferred_gateway:deviceID:fcnt`, timeout: 5min // List item: gatewayid, rssi, insertTime var item = new PreferredGatewayTableItem(context.Request.GatewayId, rssi); var listCacheKey = LoRaDevicePreferredGateway.PreferredGatewayFcntUpItemListCacheKey(devEUI, fcntUp); this.cacheStore.ListAdd(listCacheKey, item.ToCachedString(), TimeSpan.FromMinutes(REQUEST_LIST_CACHE_DURATION_IN_MINUTES)); this.log.LogInformation("Preferred gateway {devEUI}/{fcnt}: added {gateway} with {rssi}", devEUI, fcntUp, context.Request.GatewayId, rssi); // 2. Wait for the time specified in receiveInterval (default 200ms). Optional: wait less if another requests already started await Task.Delay(this.receiveInterval); // 3. Check if value was already calculated var preferredGateway = LoRaDevicePreferredGateway.LoadFromCache(this.cacheStore, devEUI); if (preferredGateway != null) { if (preferredGateway.FcntUp >= fcntUp) { return(new PreferredGatewayResult(devEUI, fcntUp, preferredGateway)); } } // 4. To calculated need to adquire a lock var preferredGatewayLockKey = $"preferredGateway:{devEUI}:lock"; for (var i = 0; i < MAX_ATTEMPTS_TO_RESOLVE_PREFERRED_GATEWAY; i++) { if (await this.cacheStore.LockTakeAsync(preferredGatewayLockKey, computationId, TimeSpan.FromMilliseconds(200), block: false)) { try { preferredGateway = LoRaDevicePreferredGateway.LoadFromCache(this.cacheStore, devEUI); if (preferredGateway == null || preferredGateway.FcntUp < fcntUp) { var items = this.cacheStore.ListGet(listCacheKey).Select(x => PreferredGatewayTableItem.CreateFromCachedString(x)); // if no table item was found (redis restarted, or delayed processing)? // Return error, we don't want to save a value for each gateway or overwrite with a delayed request var winner = items?.OrderByDescending(x => x.Rssi).FirstOrDefault(); if (winner == null) { this.log.LogError("Could not resolve closest gateway in {devEUI} and {fcntUp}", devEUI, fcntUp); return(new PreferredGatewayResult(devEUI, fcntUp, "Could not resolve closest gateway")); } preferredGateway = new LoRaDevicePreferredGateway(winner.GatewayID, fcntUp); LoRaDevicePreferredGateway.SaveToCache(this.cacheStore, context.DevEUI, preferredGateway); this.log.LogInformation("Resolved preferred gateway {devEUI}/{fcnt}: {gateway} with {rssi}", devEUI, fcntUp, context.Request.GatewayId, rssi); } } finally { this.cacheStore.LockRelease(preferredGatewayLockKey, computationId); } } else { // We couldn't get lock // wait a bit and try to get result await Task.Delay(Math.Max(50, this.receiveInterval / 4)); preferredGateway = LoRaDevicePreferredGateway.LoadFromCache(this.cacheStore, context.DevEUI); } if (preferredGateway != null) { if (preferredGateway.FcntUp >= fcntUp) { return(new PreferredGatewayResult(devEUI, fcntUp, preferredGateway)); } } } this.log.LogError("Could not resolve closest gateway in {devEUI} and {fcntUp}", devEUI, fcntUp); return(new PreferredGatewayResult(devEUI, fcntUp, "Could not resolve closest gateway")); }
public Task Execute(string param1, IPipelineExecutionContext context) { context.Add(Parameter.Key, Parameter.Value); return(Task.CompletedTask); }
public void Execute(IPipelineExecutionContext context) { Assert.NotNull(context); context.Add(Parameter.Key, Parameter.Value); }
public Task Handle(IPipelineExecutionContext executionContext, CancellationToken token, Func <CancellationToken, Task> next) { throw new NotImplementedException(); }
public Task Execute(string PARAM1, IPipelineExecutionContext context) { Assert.NotNull(context); context.Add(Parameter.Key, Parameter.Value); return(Task.CompletedTask); }
public async Task OnAbortExecutionAsync(IPipelineExecutionContext context) { await this.ComputeAndSetPreferredGateway(context); }
private async Task ComputeAndSetPreferredGateway(IPipelineExecutionContext context) { context.Result.PreferredGatewayResult = await this.ComputePreferredGateway(context); }
public void Do(IPipelineExecutionContext context) { context.Add("param1Version1", $"Hello from {nameof(Step1Version1)}"); }
public Task Execute(string unknownParam1, int unknownParam2, IPipelineExecutionContext context) { Assert.NotNull(context); Assert.Null(unknownParam1); Assert.Equal(default, unknownParam2);
public Task Do(IPipelineExecutionContext context) { context.Add("param1Version2", $"Hello from {nameof(Step1Version2)}"); return(Task.CompletedTask); }
public Task OnAbortExecutionAsync(IPipelineExecutionContext context) { return(Task.CompletedTask); }
public void Execute(IPipelineExecutionContext context) { context.Add(Parameter.Key, Parameter.Value); }