/// <summary> /// Allows adding processing nodes to handle the Left case. /// </summary> /// <param name="processorNodes">Processor nodes</param> public EitherProcessor <TLeft, TRight, TSerializer> AddLeftProcessors(params IProcessorNode <TLeft, TSerializer>[] processorNodes) { foreach (var proc in processorNodes) { leftProcessorStructure.Add(proc); } return(this); }
/// <summary> /// Given a RestSharp response it returns the final value. /// </summary> public TResult GetResultFromResponse(IRestResponse response) { //It always adds the exception processor to the end of the processor list processor.Add(exProcesorCreator()); //The default processor is always added to the end of the list ProcessorUtilities.AddNeutralProcessorAtEndsForStructure <TResult, TSerializer>(processor); //It sets the error serializer to all processors ProcessorUtilities.SetErrorSerializerForStructure <TResult, TSerializer>(processor, errorSerializer); //Applies the post-processing to the response return(processor.Process(response, serializer)); }
/// <summary> /// Takes a processing structure from a REST response, and it adds a default processor to the end of each leaf. /// Because the default processor is the identity when composed on the right, it can be added without problems and it's only done so there exists at least one node to force the processing of a response. /// /// Ej: /// (P1 -> P2) goes to (P1 -> P2 -> DEF) /// (R1 * P1) -> P2 goes to (R1 * (P1 -> DEF)) -> P2 -> DEF /// </summary> /// <typeparam name="TResult">Type of the result</typeparam> /// <typeparam name="TSerializer">Type of the serializer</typeparam> /// <param name="processor">Processor structure</param> public static void AddNeutralProcessorAtEndsForStructure <TResult, TSerializer>( IProcessorStructure <TResult, TSerializer> processor) where TSerializer : ISerializer { //If it only has a single processor or it is one by default, then we don't do anything if (processor.Count == 1 && processor[0] is SuccessProcessor <TResult, TSerializer> ) { return; } //It adds the default processing node to all its nodes foreach (var node in processor) { if (!InheritsFromExceptionProcessor(node.GetType())) { ProcessNode <TResult, TSerializer>(node, "AddNeutralProcessorAtEndsForStructure"); } } //Then it adds it to the end of the structure itself processor.Add(new SuccessProcessor <TResult, TSerializer>().Default()); }