private static bool ProcessPipeline(ProcessingElement current, Stack <Splitter> stack) { if (current == null) { return(stack.Count == 0); } if (current is Splitter) { stack.Push((Splitter)current); } else if (current is Collector) { if (stack.Count == 0) { return(false); } var splitter = stack.Pop(); splitter.ConnectedCollector = (Collector)current; } else { if (current.IsAsync) { foreach (var splitter in stack) { splitter.IsAsync = true; } } } return(ProcessPipeline(current.Next, stack)); }
public override void ProcessElementEndNode(string name) { switch (name) { case specObjectNodeName: FinalizeIdentifiableElementUnderConstruction(); break; case alternativeIdNodeName: if (processingElement == ProcessingElement.AlternativeId) processingElement = ProcessingElement.SpecObject; break; case valuesNodeName: if (processingElement == ProcessingElement.Values) processingElement = ProcessingElement.SpecObject; break; case typeNodeName: if (processingElement == ProcessingElement.Type) processingElement = ProcessingElement.SpecObject; break; case specObjectTypeRefNodeName: if (processingElement == ProcessingElement.SpecObjectTypeRef) processingElement = ProcessingElement.Type; break; default: throw new ParserFailureException(unexpectedElementNodeErrorText + name + "'."); } }
private static List <object> PrepareParameters(ProcessingElement current, UnitContext octx, TransferingContext tctx) { List <object> parameters = new List <object>(); if (current.Method != null) { // TODO memoize me // TODO inject headers foreach (var parameterInfo in current.Method.GetParameters()) { if (parameterInfo.ParameterType.IsAssignableFrom(octx.GetUnitType())) { parameters.Add(octx.Unit); } else if (parameterInfo.ParameterType == typeof(TransferingContext)) { parameters.Add(tctx); } else if (parameterInfo.ParameterType == typeof(UnitContext)) { parameters.Add(octx); } else { throw new ParameterTypeMissmatchException(current.Carrier, current.Method.Name, octx.GetUnitType(), parameterInfo.ParameterType); } } } return(parameters); }
public ReqIfHeaderImporter(Package rootPackage) { if (rootPackage == null) throw new ArgumentNullException("rootPackage"); processingElement = ProcessingElement.Undefined; createPackage(rootPackage); }
public void Process(ProcessingElement element) { if (element == null || element.TaskId == Guid.Empty || element.Data == null) { throw new ArgumentException("element"); } _log.WriteMessage(MessageSeverity.Info, "New request: nuber size = {0}", element.Data.Length); _asyncBackGroundWorker.AddItemToQueue(() => ProcessInternal(element), exception => _log.WriteMessage(MessageSeverity.Error, exception)); }
public ReqIfHeaderImporter(Package rootPackage) { if (rootPackage == null) { throw new ArgumentNullException("rootPackage"); } processingElement = ProcessingElement.Undefined; createPackage(rootPackage); }
public void Send(ProcessingElement element) { var client = new RestClient(_baseApiAddress); var request = new RestRequest("api/calc/{id}", Method.PUT); request.AddUrlSegment("id", element.TaskId.ToString()); request.AddParameter("FibData", element.Data, ParameterType.RequestBody); var response = client.Execute(request); if (response.ErrorException != null) { throw response.ErrorException; } }
private void UpdateTail(ProcessingElement el) { el.Previous = Last; if (Last != null) { Last.Next = el; } Last = el; if (First == null) { First = el; } }
public override ProcessingElement Clone(ProcessingElement previous) { var np = new Splitter { Carrier = Carrier, ConcreteObject = ConcreteObject, ErrorProcessorMethod = ErrorProcessorMethod, IsAsync = IsAsync, Method = Method, Name = Name, Previous = previous }; np.Next = Next?.Clone(np); return(np); }
public override void ProcessElementStartNode(string name) { switch (name) { case specObjectNodeName: processingElement = ProcessingElement.SpecObject; identifiableElementUnderConstruction = new SpecObject(); break; case alternativeIdNodeName: if (processingElement == ProcessingElement.SpecObject) { processingElement = ProcessingElement.AlternativeId; } break; case valuesNodeName: if (processingElement == ProcessingElement.SpecObject) { processingElement = ProcessingElement.Values; } break; case typeNodeName: if (processingElement == ProcessingElement.SpecObject) { processingElement = ProcessingElement.Type; } break; case specObjectTypeRefNodeName: if (processingElement == ProcessingElement.Type) { processingElement = ProcessingElement.SpecObjectTypeRef; } break; default: throw new ParserFailureException(unexpectedElementNodeErrorText + name + "'."); } }
private static Exception ProcessException(ProcessingElement current, TransferingContext tctx, Exception exception, UnitContext octx, object obj, bool exceptionAllowed = false) { if (current?.ErrorProcessorMethod == null) { return(exception); } octx.Exception = exception; var errParams = new List <object>(); foreach (var param in current.ErrorProcessorMethod.GetParameters()) { if (param.ParameterType == typeof(Exception)) { errParams.Add(exception); } if (param.ParameterType == typeof(UnitContext)) { errParams.Add(octx); } if (param.ParameterType == typeof(TransferingContext)) { errParams.Add(tctx); } } try { var result = (bool)current.ErrorProcessorMethod.Invoke(obj, errParams.ToArray()) && exceptionAllowed; return(!result ? exception : null); } catch (Exception errorProcessingException) { var exceptions = new AggregateException(exception, errorProcessingException); tctx.Exception = exceptions; return(exceptions); } }
public override void ProcessElementStartNode(string name) { switch (name) { case commentElementName: processingElement = ProcessingElement.Comment; break; case creationTimeElementName: processingElement = ProcessingElement.CreationTime; break; case repositoryIdElementName: processingElement = ProcessingElement.RepositoryId; break; case reqIfTollIdElementName: processingElement = ProcessingElement.ReqIfToolId; break; case reqIfVersionElementName: processingElement = ProcessingElement.ReqIfVersion; break; case sourceToolIdElementName: processingElement = ProcessingElement.SourceToolId; break; case titleElementName: processingElement = ProcessingElement.Title; break; default: throw new ParserFailureException(unexpectedElementNodeErrorText + name + "."); } }
private void BuildPipelineAction(ProcessingElement current) { if (current == null) { return; } var obj = current.Carrier != null?Injection.InjectionProvider.Get(current.Carrier) : null; if (current is Processor) { PrepareProcessor((Processor)current, obj); } else if (current is Splitter) { PrepareSplitter((Splitter)current, obj); } else if (current is Collector) { PrepareCollector((Collector)current, obj); } BuildPipelineAction(current.Previous); }
public override void ProcessElementStartNode(string name) { switch (name) { case specificationNodeName: processingElement = ProcessingElement.Specification; identifiableElementUnderConstruction = new Specification(); break; case alternativeIdNodeName: if (processingElement == ProcessingElement.Specification) { processingElement = ProcessingElement.AlternativeId; } break; case valuesNodeName: if (processingElement == ProcessingElement.Specification) { processingElement = ProcessingElement.Values; } break; case typeNodeName: if (processingElement == ProcessingElement.Specification) { processingElement = ProcessingElement.Type; } break; case specificationTypeRefNodeName: if (processingElement == ProcessingElement.Type) { processingElement = ProcessingElement.SpecificationTypeRef; } break; case childrenNodeName: { if (HasSubImporter()) { SpecHierarchyImporter specHierarchySubImporter = (SpecHierarchyImporter)subImporter; if (!specHierarchySubImporter.IsImportCompleted()) { PassElementStartNodeToSubImporter(name); } } else { if (processingElement == ProcessingElement.Specification) { processingElement = ProcessingElement.Children; CreateSubImporterForChildElements(); } } } break; default: if (HasSubImporter()) { PassElementStartNodeToSubImporter(name); break; } else { throw new ParserFailureException(unexpectedElementNodeErrorText + name + "'."); } } }
public override void ProcessElementEndNode(string name) { switch (name) { case specificationNodeName: if (processingElement == ProcessingElement.Specification) { processingElement = ProcessingElement.Undefined; FinalizeIdentifiableElementUnderConstruction(); } break; case alternativeIdNodeName: if (processingElement == ProcessingElement.AlternativeId) processingElement = ProcessingElement.Specification; break; case valuesNodeName: if (processingElement == ProcessingElement.Values) processingElement = ProcessingElement.Specification; break; case typeNodeName: if (processingElement == ProcessingElement.Type) processingElement = ProcessingElement.Specification; break; case specificationTypeRefNodeName: if (processingElement == ProcessingElement.SpecificationTypeRef) processingElement = ProcessingElement.Type; break; case childrenNodeName: if (HasSubImporter()) { SpecHierarchyImporter specHierarchySubImporter = (SpecHierarchyImporter)subImporter; if (! specHierarchySubImporter.IsImportCompleted()) { PassElementEndNodeToSubImporter(name); } else { if (processingElement == ProcessingElement.Children) { processingElement = ProcessingElement.Specification; subImporter = null; } } } else { if (processingElement == ProcessingElement.Children) processingElement = ProcessingElement.Specification; } break; default: if (HasSubImporter()) { PassElementEndNodeToSubImporter(name); break; } else { throw new ParserFailureException(unexpectedElementNodeErrorText + name + "'."); } } }
public SpecificationsImporter(ref SortedList specifications) : base(ref specifications) { processingElement = ProcessingElement.Undefined; }
public override void ProcessElementEndNode(string name) { if (HasSubImporter()) { SpecHierarchyImporter specHierarchySubImporter = (SpecHierarchyImporter)subImporter; if (!specHierarchySubImporter.IsImportCompleted()) { PassElementEndNodeToSubImporter(name); return; } } switch (name) { case alternativeIdNodeName: if (processingElement == ProcessingElement.AlternativeId) { processingElement = ProcessingElement.SpecHierarchy; } break; case specObjectRefNodeName: if (processingElement == ProcessingElement.SpecObjectReference) { processingElement = ProcessingElement.Object; } break; case objectNodeName: if (processingElement == ProcessingElement.Object) { processingElement = ProcessingElement.SpecHierarchy; } break; case childrenNodeName: if (HasSubImporter()) { SpecHierarchyImporter specHierarchySubImporter = (SpecHierarchyImporter)subImporter; if (!specHierarchySubImporter.IsImportCompleted()) { PassElementEndNodeToSubImporter(name); } else { if (processingElement == ProcessingElement.Children) { processingElement = ProcessingElement.SpecHierarchy; subImporter = null; } } } else { if (processingElement == ProcessingElement.Children) { processingElement = ProcessingElement.SpecHierarchy; } } break; case specHierarchyNodeName: if (processingElement == ProcessingElement.SpecHierarchy) { processingElement = ProcessingElement.Undefined; FlagImportAsCompleted(); FinalizeIdentifiableElementUnderConstruction(); } break; default: throw new ParserFailureException(unexpectedElementNodeErrorText + name + "'."); } }
public SpecHierarchyImporter(ref SortedList specHierarchies) : base(ref specHierarchies) { processingElement = ProcessingElement.Undefined; isImportCompleted = false; }
public void Send(ProcessingElement message) { _bus.Publish(message); }
public override void ProcessElementEndNode(string name) { switch (name) { case specRelationNodeName: processingElement = ProcessingElement.Undefined; FinalizeIdentifiableElementUnderConstruction(); break; case alternativeIdNodeName: if (processingElement == ProcessingElement.AlternativeId) { processingElement = ProcessingElement.SpecRelation; } break; case valuesNodeName: if (processingElement == ProcessingElement.Values) { processingElement = ProcessingElement.SpecRelation; } break; case typeNodeName: if (processingElement == ProcessingElement.Type) { processingElement = ProcessingElement.SpecRelation; } break; case sourceNodeName: if (processingElement == ProcessingElement.Source) { processingElement = ProcessingElement.SpecRelation; } break; case targetNodeName: if (processingElement == ProcessingElement.Target) { processingElement = ProcessingElement.SpecRelation; } break; case specObjectRefNodeName: if (processingElement == ProcessingElement.SourceSpecObjectRef) { processingElement = ProcessingElement.Source; } else if (processingElement == ProcessingElement.TargetSpecObjectRef) { processingElement = ProcessingElement.Target; } break; case specRelationTypeRefNodeName: if (processingElement == ProcessingElement.SpecRelationTypeRef) { processingElement = ProcessingElement.Type; } break; default: throw new ParserFailureException(unexpectedElementNodeErrorText + name + "'."); } }
public override void ProcessElementStartNode(string name) { if (HasSubImporter()) { SpecHierarchyImporter specHierarchySubImporter = (SpecHierarchyImporter)subImporter; if (!specHierarchySubImporter.IsImportCompleted()) { PassElementStartNodeToSubImporter(name); return; } } switch (name) { case specHierarchyNodeName: processingElement = ProcessingElement.SpecHierarchy; identifiableElementUnderConstruction = new SpecHierarchy(); break; case childrenNodeName: if (HasSubImporter()) { SpecHierarchyImporter specHierarchySubImporter = (SpecHierarchyImporter)subImporter; if (!specHierarchySubImporter.IsImportCompleted()) { PassElementStartNodeToSubImporter(name); } } else { if (processingElement == ProcessingElement.SpecHierarchy) { processingElement = ProcessingElement.Children; CreateSubImporterForChildElements(); } } break; case objectNodeName: if (processingElement == ProcessingElement.SpecHierarchy) { processingElement = ProcessingElement.Object; } break; case specObjectRefNodeName: if (processingElement == ProcessingElement.Object) { processingElement = ProcessingElement.SpecObjectReference; } break; case alternativeIdNodeName: if (processingElement == ProcessingElement.SpecHierarchy) { processingElement = ProcessingElement.AlternativeId; } break; default: throw new ParserFailureException(unexpectedElementNodeErrorText + name + "'."); } }
private void PrepareSplitter(Splitter current, object obj) { var nextAction = current.Next?.ProcessAction; var afterSplitAction = current.ConnectedCollector?.Next?.ProcessAction; if (current.IsAsync) { var nextAsyncProcessor = ProcessingElement.NextAsyncProcessor(current.Next); var afterAsyncProcessor = ProcessingElement.NextAsyncProcessor(current.ConnectedCollector?.Next); current.ProcessTask = async(tctx, octx) => { try { var parameters = PrepareParameters(current, octx, tctx); var splitterInvokeResult = current.Method.Invoke(obj, parameters.ToArray()); var result = typeof(IEnumerable <UnitContext>).IsAssignableFrom(splitterInvokeResult.GetType()) ? ((IEnumerable <UnitContext>)splitterInvokeResult).GetEnumerator() : (IEnumerator <UnitContext>)splitterInvokeResult; var dict = new Dictionary <string, IList <UnitContext> >(); while (result.MoveNext()) { var soctx = result.Current; nextAction?.Invoke(tctx, soctx); if (tctx.Exception != null) { throw tctx.Exception; } if (nextAsyncProcessor != null) { await nextAsyncProcessor.ProcessTask(tctx, soctx); } current.ConnectedCollector.CollectAction(tctx, soctx, dict); } SetCollectedUnit(current, octx, dict); afterSplitAction?.Invoke(tctx, octx); if (afterAsyncProcessor != null) { await afterAsyncProcessor.ProcessTask(tctx, octx); } } catch (PipelineProcessingException) { throw; } catch (Exception exception) { var resultException = ProcessException(current, tctx, exception, octx, obj); throw new PipelineProcessingException(resultException); } }; } else { current.ProcessAction = (tctx, octx) => { try { var parameters = PrepareParameters(current, octx, tctx); var result = (IEnumerator <UnitContext>)current.Method.Invoke(obj, parameters.ToArray()); var dict = new Dictionary <string, IList <UnitContext> >(); while (result.MoveNext()) { var soctx = result.Current; nextAction?.Invoke(tctx, soctx); if (tctx.Exception != null) { throw tctx.Exception; } current.ConnectedCollector.CollectAction(tctx, soctx, dict); } SetCollectedUnit(current, octx, dict); afterSplitAction?.Invoke(tctx, octx); } catch (PipelineProcessingException) { throw; } catch (Exception exception) { var resultException = ProcessException(current, tctx, exception, octx, obj); throw new PipelineProcessingException(resultException); } }; } }
private static void PrepareProcessor(Processor current, object obj) { var nextAction = current.Next?.ProcessAction; if (current.IsAsync) { var nextAsyncProcessor = ProcessingElement.NextAsyncProcessor(current.Next); current.ProcessTask = async(tctx, octx) => { ProcessingInfo info = new ProcessingInfo { Started = DateTime.Now, StepName = !string.IsNullOrEmpty(current.Name) ? current.Name : current.Method.Name }; tctx.ProcessingHistory.Push(info); try { var parameters = PrepareParameters(current, octx, tctx); if (current.Method.ReturnType.IsGenericType && current.Method.ReturnType.GetGenericTypeDefinition() == typeof(Task <>)) { octx.Unit = await Wrap(current.Method.Invoke(obj ?? current.ConcreteObject, parameters.ToArray())); } if (current.Method.ReturnType == typeof(Task)) { await(Task) current.Method.Invoke(obj ?? current.ConcreteObject, parameters.ToArray()); } info.Finished = DateTime.Now; nextAction?.Invoke(tctx, octx); if (nextAsyncProcessor != null) { await nextAsyncProcessor.ProcessTask(tctx, octx); } } catch (PipelineProcessingException) { throw; } catch (Exception e) { Exception resultException = ProcessException(current, tctx, e, octx, obj, true); throw new PipelineProcessingException(resultException); } }; } else { current.ProcessAction = (tctx, octx) => { ProcessingInfo info = new ProcessingInfo { Started = DateTime.Now, StepName = !string.IsNullOrEmpty(current.Name) ? current.Name : current.Method.Name }; tctx.ProcessingHistory.Push(info); try { var parameters = PrepareParameters(current, octx, tctx); if (current.Method.ReturnType == typeof(void)) { current.Method.Invoke(obj ?? current.ConcreteObject, parameters.ToArray()); } else { octx.Unit = current.Method.Invoke(obj ?? current.ConcreteObject, parameters.ToArray()); } info.Finished = DateTime.Now; nextAction?.Invoke(tctx, octx); } catch (PipelineProcessingException) { throw; } catch (Exception e) { var resultException = ProcessException(current, tctx, e, octx, obj, true); if (resultException != null) { throw new PipelineProcessingException(resultException); } } finally { info.Finished = DateTime.Now; } }; } }
private void ProcessInternal(ProcessingElement element) { TryWhileNoSuccess(() => UpdateElementValue(element), 5); TryWhileNoSuccess(() => _resultSender.Send(element), 5); }
public override void ProcessElementStartNode(string name) { switch (name) { case specRelationNodeName: processingElement = ProcessingElement.SpecRelation; identifiableElementUnderConstruction = new SpecRelation(); break; case alternativeIdNodeName: if (processingElement == ProcessingElement.SpecRelation) processingElement = ProcessingElement.AlternativeId; break; case valuesNodeName: if (processingElement == ProcessingElement.SpecRelation) processingElement = ProcessingElement.Values; break; case typeNodeName: if (processingElement == ProcessingElement.SpecRelation) processingElement = ProcessingElement.Type; break; case sourceNodeName: if (processingElement == ProcessingElement.SpecRelation) processingElement = ProcessingElement.Source; break; case targetNodeName: if (processingElement == ProcessingElement.SpecRelation) processingElement = ProcessingElement.Target; break; case specObjectRefNodeName: if (processingElement == ProcessingElement.Source) processingElement = ProcessingElement.SourceSpecObjectRef; else if (processingElement == ProcessingElement.Target) processingElement = ProcessingElement.TargetSpecObjectRef; break; case specRelationTypeRefNodeName: if (processingElement == ProcessingElement.Type) processingElement = ProcessingElement.SpecRelationTypeRef; break; default: throw new ParserFailureException(unexpectedElementNodeErrorText + name + "'."); } }
private byte[] UpdateElementValue(ProcessingElement element) { return(element.Data = _elements.AddOrUpdate(element.TaskId, guid => _fiboCaculator.CalcNext(element.Data), (guid, curbytes) => _fiboCaculator.CalcNext(curbytes, element.Data))); }
public SpecRelationsImporter(ref SortedList specificationRelations) : base(ref specificationRelations) { processingElement = ProcessingElement.Undefined; }
public SpecObjectsImporter(ref SortedList specificationObjects) : base(ref specificationObjects) { processingElement = ProcessingElement.Undefined; }