Exemple #1
0
        /// <summary>Invokes the specified context resolver.</summary>
        /// <param name="contextResolver">The context resolver.</param>
        /// <returns></returns>
        public async Task Invoke(IApiRequestContextResolver contextResolver)
        {
            var context = contextResolver?.GetContext();

            if (context != null)
            {
                IPipelineComponent pipeline = null;

                try
                {
                    if (context.RequestServices != null)
                    {
                        pipeline = context.RequestServices.GetService(Type.GetType(PipelineType.AssemblyQualifiedName)) as IPipelineComponent;
                    }
                }
                catch { }

                if (pipeline == null)
                {
                    try
                    {
                        pipeline = Activator.CreateInstance(Type.GetType(PipelineType.AssemblyQualifiedName)) as IPipelineComponent;
                    }
                    catch { }
                }

                if (pipeline != null)
                {
                    await pipeline.Invoke(contextResolver).ConfigureAwait(false);
                }
            }
        }
Exemple #2
0
        /// <inheritdoc />
        public T Execute(T payload, CancellationToken cancellationToken)
        {
            IPipelineComponent current = null;

            try
            {
                foreach (var component in Components)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    current = component;
                    var currentPayload = ExecuteComponent(component, payload, cancellationToken);
                    if (currentPayload == null)
                    {
                        break;
                    }

                    payload = currentPayload;
                }

                return(payload);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception exception)
            {
                throw new PipelineExecutionException(current, exception);
            }
        }
        private void SetComponentProperties(IPipelineComponent component, string propertyName, object value)
        {
            var d = (PipelineComponentArgument)component.GetAllArguments().Single(a => a.Name.Equals(propertyName));

            d.SetValue(value);
            d.SaveToDatabase();
        }
Exemple #4
0
        private void DeleteSelectedComponent(object sender, EventArgs e)
        {
            if (SelectedComponent != null)
            {
                if (MessageBox.Show("Do you want to delete " + SelectedComponent.Class + "?", "Confirm Delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    //if they are deleting the destination
                    if (SelectedComponent.ID == _pipeline.DestinationPipelineComponent_ID)
                    {
                        _pipeline.DestinationPipelineComponent_ID = null;
                        _pipeline.SaveToDatabase();
                    }

                    //if they are deleting the source
                    if (SelectedComponent.ID == _pipeline.SourcePipelineComponent_ID)
                    {
                        _pipeline.SourcePipelineComponent_ID = null;
                        _pipeline.SaveToDatabase();
                    }

                    SelectedComponent.DeleteInDatabase();
                    RefreshUIFromDatabase();

                    SelectedComponent = null;
                    _deleteSelectedMenuItem.Enabled = false;
                }
            }
        }
Exemple #5
0
        private T ExecuteComponent(IPipelineComponent <T> component, T payload, CancellationToken cancellationToken)
        {
            if (_componentExecutionStatusReceiver == null)
            {
                return(component.Execute(payload, cancellationToken));
            }

            var executionStartingInfo = new PipelineComponentExecutionStartingInfo(component.Name, payload);

            _componentExecutionStatusReceiver.ReceiveExecutionStarting(
                executionStartingInfo);
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            try
            {
                var result = component.Execute(payload, cancellationToken);
                stopwatch.Stop();
                _componentExecutionStatusReceiver.ReceiveExecutionCompleted(
                    new PipelineComponentExecutionCompletedInfo(executionStartingInfo, stopwatch.Elapsed));
                return(result);
            }
            catch (Exception e)
            {
                stopwatch.Stop();
                _componentExecutionStatusReceiver.ReceiveExecutionCompleted(
                    new PipelineComponentExecutionCompletedInfo(executionStartingInfo, stopwatch.Elapsed, e));
                throw;
            }
        }
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="component">Type of <see cref="IPipelineComponent"/> that threw the exception.</param>
 /// <param name="innerException">The exception that was unhandled by <see cref="IPipelineComponent"/>.</param>
 protected PipelineComponentExceptionBase(
     IPipelineComponent component,
     Exception innerException = null)
     : base(null, innerException)
 {
     ThrowingComponent = component;
 }
        /// <inheritdoc />
        public async Task <T> ExecuteAsync(T payload, CancellationToken cancellationToken)
        {
            IPipelineComponent current = null;

            try
            {
                foreach (var component in Components)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    current = component;
                    var currentPayload = await ExecuteComponentAsync(component, payload, cancellationToken).ConfigureAwait(false);

                    if (currentPayload == null)
                    {
                        break;
                    }

                    payload = currentPayload;
                }

                return(payload);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception exception)
            {
                throw new PipelineExecutionException(current, exception);
            }
        }
 public DocumentResolution HandleException(IPipelineComponent component, ComponentException exception)
 {
     if (exception is PoisonComponentException)
     {
         return(DocumentResolution.PoisonComponentAndContinue);
     }
     return(DocumentResolution.CompleteSuccess);
 }
Exemple #9
0
 public static IPipelineComponent <string, string> AddConsole <PIn>(this IPipelineComponent <PIn, string> component)
 {
     return(component.AddStep((s, context) =>
     {
         Console.WriteLine(s);
         return s;
     }));
 }
Exemple #10
0
        private void AddInternal(IPipelineComponent component)
        {
            var key = component.GetType().Name;

            if (_components.ContainsKey(key))
            {
                throw new InvalidOperationException($"PipelineComponentResolver already contains an instance of type '{key}'");
            }

            _components.Add(key, component);
        }
Exemple #11
0
 public static IPipelineComponent <Log, Log> AddLogFilter <PIn>(this IPipelineComponent <PIn, Log> component, Severity severity)
 {
     return(component.AddStep((log, context) =>
     {
         if (log.Severity < severity)
         {
             context.Break();
         }
         return log;
     }));
 }
 /// <summary>
 /// Attempts to construct an instance of the class described by <see cref="IPipelineComponent.Class"/> and fulfil it's <see cref="DemandsInitializationAttribute"/>.
 /// Returns null and populates <paramref name="ex"/> if this is not possible/errors.
 /// </summary>
 /// <param name="component"></param>
 /// <param name="ex"></param>
 /// <returns></returns>
 public object TryCreateComponent(IPipelineComponent component, out Exception ex)
 {
     ex = null;
     try
     {
         return(CreateComponent(component));
     }
     catch (Exception e)
     {
         ex = e;
         return(null);
     }
 }
        void _pipelineDiagram_SelectedComponentChanged(object sender, IPipelineComponent selected)
        {
            gbArguments.Enabled = true;

            if (selected == null)
            {
                _arumentsCollection1.Setup(_activator, null, null, _catalogueRepository);
            }
            else
            {
                _arumentsCollection1.Setup(_activator, selected, selected.GetClassAsSystemType(), _catalogueRepository);
            }
        }
        /// <summary>
        /// Sets the value of a property on instance toReturn.
        /// </summary>
        /// <param name="toBuild">IPipelineComponent which is the persistence record - the template of what to build</param>
        /// <param name="toReturn">An instance of the Class referenced by IPipelineComponent.Class (or in the case of [DemandsNestedInitializationAttribute] a reference to the nested property)</param>
        /// <param name="propertyInfo">The specific property you are trying to populate on toBuild</param>
        /// <param name="arguments">IArguments of toBuild (the values to populate toReturn with)</param>
        /// <param name="nestedProperty">If you are populating a sub property of the class then pass the instance of the sub property as toBuild and pass the nesting property as nestedProperty</param>
        private void SetPropertyIfDemanded(IPipelineComponent toBuild, object toReturn, PropertyInfo propertyInfo, IArgument[] arguments, PropertyInfo nestedProperty = null)
        {
            //see if any demand initialization
            var initialization =
                (DemandsInitializationAttribute)
                System.Attribute.GetCustomAttributes(propertyInfo)
                .FirstOrDefault(a => a is DemandsInitializationAttribute);

            //this one does
            if (initialization != null)
            {
                try
                {
                    //look for 'DeleteUsers' if not nested
                    //look for 'Settings.DeleteUsers' if nested in a property called Settings on class
                    string expectedArgumentName = nestedProperty != null ?nestedProperty.Name + "." + propertyInfo.Name : propertyInfo.Name;

                    //get the appropriate value from arguments
                    var argument = arguments.SingleOrDefault(n => n.Name.Equals(expectedArgumentName));

                    //if there is no matching argument and no default value
                    if (argument == null)
                    {
                        if (initialization.DefaultValue == null && initialization.Mandatory)
                        {
                            string msg = string.Format("Class {0} has a property {1} marked with DemandsInitialization but no corresponding argument was found in the arguments (PipelineComponentArgument) of the PipelineComponent called {2}",
                                                       toReturn.GetType().Name,
                                                       propertyInfo.Name,
                                                       toBuild.Name);

                            throw new PropertyDemandNotMetException(msg, toBuild, propertyInfo);
                        }
                        else
                        {
                            //use reflection to set the value
                            propertyInfo.SetValue(toReturn, initialization.DefaultValue, null);
                        }
                    }
                    else
                    {
                        //use reflection to set the value
                        propertyInfo.SetValue(toReturn, argument.GetValueAsSystemType(), null);
                    }
                }
                catch (NotSupportedException e)
                {
                    throw new Exception("Class " + toReturn.GetType().Name + " has a property " + propertyInfo.Name +
                                        " but is of unexpected/unsupported type " + propertyInfo.GetType(), e);
                }
            }
        }
Exemple #15
0
        private void AddPipelineComponent(IPipelineComponent toRealize, DataFlowComponentVisualisation.Role role)
        {
            Exception exConstruction;

            //create the pipeline realization (might fail
            var value = _pipelineFactory.TryCreateComponent(toRealize, out exConstruction);

            if (role != DataFlowComponentVisualisation.Role.Source)
            {
                AddDividerIfReorderingAvailable();
            }

            //create the visualization
            var component = new PipelineComponentVisualisation(toRealize, role, value, exConstruction, component_shouldAllowDrop);

            component.DragDrop += component_DragDrop;
            flpPipelineDiagram.Controls.Add(component);//add the component

            //try to initialize the realization (we do this after creating visualization so that when the events come in we can record where on UI the consumption events happen and also because later on it might be that initialization takes ages and we want to use a Thread)
            if (value != null)
            {
                try
                {
                    if (!_useCase.IsDesignTime)
                    {
                        _useCase.GetContext().PreInitializeGeneric(new ThrowImmediatelyDataLoadEventListener(), value, _useCase.GetInitializationObjects().ToArray());
                        component.Check();
                    }

                    component.CheckMandatoryProperties();
                }
                catch (Exception exInit)
                {
                    //initialization failed
                    component.ExInitialization = exInit;
                }
            }

            component.AllowDrag = AllowReOrdering;

            if (AllowSelection)
            {
                component.AllowSelection     = true;
                component.ComponentSelected += component_Selected;
            }


            //PipelineComponents can never be locked because they are user setup things
            component.IsLocked = false;
        }
Exemple #16
0
        public void AddPipelineComponent(IEndpoint endpoint, IPipelineComponent pipelineComponent)
        {
            Queue <IPipelineComponent> pipeline;

            if (_pipelines.ContainsKey(endpoint))
            {
                pipeline = _pipelines[endpoint];
            }
            else
            {
                pipeline = new Queue <IPipelineComponent>();
                _pipelines.Add(endpoint, pipeline);
            }

            pipeline.Enqueue(pipelineComponent);
        }
Exemple #17
0
        public static ContainerBuilder AddLogging(this ContainerBuilder builder, Action <IPipelineComponent <Log, Log>, IComponentContext> configure)
        {
            builder.Register(context =>
            {
                IPipelineComponent <Log, Log> pipeline = PipelineComponent.CreateIdentity <Log>();

                configure?.Invoke(pipeline, context);

                return(new Logger(pipeline));
            }).As <ILogger>().SingleInstance();

            builder.RegisterGeneric(typeof(Logger <>))
            .As(typeof(ILogger <>))
            .InstancePerDependency();

            return(builder);
        }
        private object CreateComponent(IPipelineComponent toBuild)
        {
            var type = toBuild.GetClassAsSystemType();

            if (type == null)
            {
                throw new Exception("Could not find Type '" + toBuild.Class + "'");
            }

            object toReturn = _constructor.Construct(type);

            //all the IArguments we need to initialize the class
            var allArguments = toBuild.GetAllArguments().ToArray();

            //get all possible properties that we could set on the underlying class
            foreach (var propertyInfo in toReturn.GetType().GetProperties())
            {
                SetPropertyIfDemanded(toBuild, toReturn, propertyInfo, allArguments);

                //see if any demand nested initialization
                Attribute nestedInit =
                    System.Attribute.GetCustomAttributes(propertyInfo)
                    .FirstOrDefault(a => a is DemandsNestedInitializationAttribute);

                //this one does
                if (nestedInit != null)
                {
                    // initialise the container before nesting-setting all properties
                    var container = Activator.CreateInstance(propertyInfo.PropertyType);

                    foreach (var nestedProp in propertyInfo.PropertyType.GetProperties())
                    {
                        SetPropertyIfDemanded(toBuild, container, nestedProp, allArguments, propertyInfo);
                    }

                    //use reflection to set the container
                    propertyInfo.SetValue(toReturn, container, null);
                }
            }

            return(toReturn);
        }
Exemple #19
0
        public async Task <T> Process(T t)
        {
            IPipelineComponent <T> firstComponent = null;
            IPipelineComponent <T> prevComponent  = null;

            for (var i = Components.Count - 1; i >= 0; i--)
            {
                var currentComponent = Components[i]();
                var nextComponent    = prevComponent ?? new NoopComponent <T>();
                currentComponent.NextComponent = () => nextComponent;

                if (i == 0)
                {
                    firstComponent = currentComponent;
                }

                prevComponent = currentComponent;
            }

            await firstComponent.InvokeAsync(t).ConfigureAwait(false);

            return(t);
        }
Exemple #20
0
        void component_Selected(object sender, IPipelineComponent selected)
        {
            if (!AllowSelection)
            {
                return;
            }

            SelectedComponent = selected;

            //update the Del menu item
            _deleteSelectedMenuItem.Enabled = SelectedComponent != null;

            //clear old selections
            foreach (PipelineComponentVisualisation componentVisualisation in flpPipelineDiagram.Controls.OfType <PipelineComponentVisualisation>())
            {
                componentVisualisation.IsSelected = false;
            }

            ((PipelineComponentVisualisation)sender).IsSelected = true;
            SelectedComponentChanged?.Invoke(this, selected);

            this.Focus();
        }
        public PipelineComponentVisualisation(IPipelineComponent component, Role role, object valueOrNullIfBroken, Exception constructionExceptionIfAny, Func <DragEventArgs, DataFlowComponentVisualisation, DragDropEffects> shouldAllowDrop)
            : base(role, valueOrNullIfBroken, shouldAllowDrop)
        {
            PipelineComponent = component;

            if (constructionExceptionIfAny != null)
            {
                ragSmiley1.OnCheckPerformed(new CheckEventArgs("Failed to construct component", CheckResult.Fail, constructionExceptionIfAny));
            }

            _origFullPen = _fullPen;

            if (component == null)
            {
                return;
            }

            lblText.Text = component.GetClassNameLastPart();

            if (valueOrNullIfBroken == null)
            {
                ragSmiley1.OnCheckPerformed(new CheckEventArgs("Could not construct object", CheckResult.Fail));
            }

            this.Width = lblText.PreferredWidth + 80;

            _isEmpty = false;

            MouseDown             += Anywhere_MouseDown;
            lblText.MouseDown     += Anywhere_MouseDown;
            prongRight1.MouseDown += Anywhere_MouseDown;
            prongRight2.MouseDown += Anywhere_MouseDown;
            prongLeft1.MouseDown  += Anywhere_MouseDown;
            prongLeft2.MouseDown  += Anywhere_MouseDown;
            pComponent.MouseDown  += Anywhere_MouseDown;
        }
        private string MustHave(Type mustHaveType, IPipelineComponent component, string descriptionOfThingBeingChecked)
        {
            //it must have destination
            if (mustHaveType != null)
            {
                if (component == null)
                {
                    return("An explicit " + descriptionOfThingBeingChecked + " must be chosen");
                }
                else
                {
                    Type pipelineComponentType = component.GetClassAsSystemType();

                    if (pipelineComponentType == null)
                    {
                        return("PipelineComponent " + component.Class + " could not be created, check MEF assembly loading in the Diagnostics menu");
                    }

                    if (!mustHaveType.IsAssignableFrom(pipelineComponentType))
                    {
                        return("The pipeline requires a " + descriptionOfThingBeingChecked + " of type " + GetFullName(mustHaveType) +
                               " but the currently configured " + descriptionOfThingBeingChecked + GetFullName(pipelineComponentType) +
                               " is not of the same type or a derrived type");
                    }
                }
            }
            else
            //it cannot have destination
            if (component != null)
            {
                return("Context does not allow for an explicit (custom) " + descriptionOfThingBeingChecked);
            }


            return(null);
        }
Exemple #23
0
		public void AddPipelineComponent(IEndpoint endpoint, IPipelineComponent pipelineComponent)
		{
			Queue<IPipelineComponent> pipeline;

			if (_pipelines.ContainsKey(endpoint))
			{
				pipeline = _pipelines[endpoint];
			}
			else
			{
				pipeline = new Queue<IPipelineComponent>();
				_pipelines.Add(endpoint, pipeline);
			}

			pipeline.Enqueue(pipelineComponent);
		}
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="component">Type of <see cref="IPipelineComponent"/> that threw the exception.</param>
 /// <param name="componentException">The exception that was unhandled by <see cref="IPipelineComponent"/>.</param>
 // ReSharper disable once UnusedParameter.Local
 public PipelineExecutionException(
     IPipelineComponent component, Exception componentException)
     : base(component, componentException)
 {
 }
 public ControlOption(Func<Env, bool> shouldDo, IPipelineComponent handler) {
     ShouldDo = shouldDo;
     Handler = handler;
 }
 public void When(Func<Env, bool> shouldHandle, IPipelineComponent handler) {
     _options.Add(new ControlOption(shouldHandle, handler));
 }
Exemple #27
0
 internal PipelineComponentSettingNotFoundException(IPipelineComponent component, string settingName)
     : base(component)
 {
     SettingName = settingName;
 }
Exemple #28
0
 public static IPipelineComponent <POut, NOut> AddStep <PIn, POut, NOut>(this IPipelineComponent <PIn, POut> component, Func <POut, IPipelineContext, NOut> step)
 {
     return(component.AddStep(PipelineComponent.CreatePipeline(step)));
 }
 public Settings(IPipelineComponent component)
 {
     _component = component;
     _settings  = new Dictionary <string, string>();
 }
Exemple #30
0
 public static IPipelineComponent <Log, string> AddLogFormatter <PIn>(this IPipelineComponent <PIn, Log> component, ILogFormatter formatter)
 {
     return(component.AddStep(formatter));
 }
 public void When(Func <Env, bool> shouldHandle, IPipelineComponent handler)
 {
     _options.Add(new ControlOption(shouldHandle, handler));
 }
 public IPipeline Use(IPipelineComponent component) {
     _components.Add(component);
     return this;
 }
Exemple #33
0
 public IPipeline Use(IPipelineComponent component)
 {
     _components.Add(component);
     return(this);
 }
 public static void IsGet(this ControlComponent component, string pathRegex, IPipelineComponent handler) {
     component.When(BuildGetFilter(pathRegex), handler);
 }
 public ControlOption(Func <Env, bool> shouldDo, IPipelineComponent handler)
 {
     ShouldDo = shouldDo;
     Handler  = handler;
 }