#pragma warning restore CA1721 // Property names should not match get methods

            /// <summary>
            /// Get the <see cref="CloudRequestEngine"/> that will be making
            /// requests on behalf of this engine.
            /// </summary>
            public ICloudRequestEngine GetInstance()
            {
                if (_cloudRequestEngine == null)
                {
                    lock (_cloudRequestEngineLock)
                    {
                        if (_cloudRequestEngine == null)
                        {
                            if (_pipelinesAccessor().Count > 1)
                            {
                                throw new PipelineConfigurationException(
                                          $"'{_currentElement.GetType().Name}' does not support being " +
                                          $"added to multiple Pipelines.");
                            }
                            if (_pipelinesAccessor().Count == 0)
                            {
                                throw new PipelineConfigurationException(
                                          $"'{_currentElement.GetType().Name}' has not yet been added " +
                                          $"to a Pipeline.");
                            }

                            _cloudRequestEngine = _pipelinesAccessor()[0].GetElement <ICloudRequestEngine>();

                            if (_cloudRequestEngine == null)
                            {
                                throw new PipelineConfigurationException(
                                          $"The '{_currentElement.GetType().Name}' requires a 'CloudRequestEngine' " +
                                          $"before it in the Pipeline. This engine will be unable " +
                                          $"to produce results until this is corrected.");
                            }
                        }
                    }
                }
                return(_cloudRequestEngine);
            }
Пример #2
0
        /// <summary>
        /// Register an error that occurred while working with this
        /// instance.
        /// </summary>
        /// <param name="ex">
        /// The exception that occurred.
        /// </param>
        /// <param name="flowElement">
        /// The flow element that the exception occurred in.
        /// </param>
        /// <param name="shouldThrow">
        /// Set whether the pipeline should throw the exception.
        /// </param>
        /// <param name="shouldLog">
        /// Set whether the pipeline should log the exception as an error.
        /// </param>
        public void AddError(Exception ex, IFlowElement flowElement, bool shouldThrow, bool shouldLog)
        {
            if (_errors == null)
            {
                _errors = new List <IFlowError>();
            }
            if (_errorsLock == null)
            {
                _errorsLock = new object();
            }
            var error = new FlowError(ex, flowElement, shouldThrow);

            lock (_errorsLock)
            {
                _errors.Add(error);
            }

            if (_logger != null && _logger.IsEnabled(LogLevel.Error) && shouldLog)
            {
                string logMessage = "Error occurred during processing";
                if (flowElement != null)
                {
                    logMessage = logMessage + $" of {flowElement.GetType().Name}";
                }
                _logger.LogError(ex, logMessage);
            }
        }
        private void assertFlowElementIs(Type elementClass)
        {
            IBpmnModelInstance modelInstance = ModelExecutionContextExecutionListener.ModelInstance;

            Assert.NotNull(modelInstance);

            IModel model = modelInstance.Model;
            IEnumerable <IModelElementInstance> events = modelInstance.GetModelElementsByType(model.GetType(typeof(IEvent)));

            Assert.AreEqual(3, events.Count());
            IEnumerable <IModelElementInstance> gateways = modelInstance.GetModelElementsByType(model.GetType(typeof(IGateway)));

            Assert.AreEqual(1, gateways.Count());
            IEnumerable <IModelElementInstance> tasks = modelInstance.GetModelElementsByType(model.GetType(typeof(ITask)));

            Assert.AreEqual(1, tasks.Count());

            IFlowElement flowElement = ModelExecutionContextExecutionListener.FlowElement;

            Assert.NotNull(flowElement);
            Assert.True(elementClass.IsAssignableFrom(flowElement.GetType()));
        }
Пример #4
0
 private static Type getInterfaceType(IFlowElement element, string name)
 {
     Type[] interfaces = element.GetType().GetInterfaces();
     return(interfaces.FirstOrDefault((t) => { return t.Name.ToLower().StartsWith(name.ToLower()); }));
 }