Пример #1
0
        public Guid Invoke(IDSFDataObject dataObject, out ErrorResultTO errors)
        {
            var result = GlobalConstants.NullDataListID;
            var time   = new Stopwatch();

            time.Start();
            errors = new ErrorResultTO();
            if (dataObject.Environment.HasErrors())
            {
                errors.AddError(dataObject.Environment.FetchErrors());
                DispatchDebugErrors(errors, dataObject, StateType.Before);
            }
            errors.ClearErrors();
            try
            {
                errors = TryInvokeService(dataObject, errors);
            }
            finally
            {
                time.Stop();
                ServerStats.IncrementTotalRequests();
                ServerStats.IncrementTotalTime(time.ElapsedMilliseconds);
                DispatchDebugErrors(errors, dataObject, StateType.End);
            }
            return(result);
        }
Пример #2
0
        void TryExecute(IDSFDataObject dataObject, int update, IDev2IndexFinder indexFinder, ErrorResultTO allErrors, ErrorResultTO errors)
        {
            var outerIteratorCollection = new WarewolfListIterator();
            var innerIteratorCollection = new WarewolfListIterator();

            allErrors.MergeErrors(errors);

            #region Iterate and Find Index

            if (dataObject.IsDebugMode())
            {
                AddDebugInputItem(new DebugEvalResult(InField, "In Field", dataObject.Environment, update));
                AddDebugInputItem(new DebugItemStaticDataParams(Index, "Index"));
                AddDebugInputItem(new DebugEvalResult(Characters, "Characters", dataObject.Environment, update));
                AddDebugInputItem(new DebugItemStaticDataParams(Direction, "Direction"));
            }

            var itrChar = new WarewolfIterator(dataObject.Environment.Eval(Characters, update));
            outerIteratorCollection.AddVariableToIterateOn(itrChar);

            var completeResultList = new List <string>();
            if (String.IsNullOrEmpty(InField))
            {
                allErrors.AddError(string.Format(ErrorResource.IsBlank, "'In Field'"));
            }
            else if (String.IsNullOrEmpty(Characters))
            {
                allErrors.AddError(string.Format(ErrorResource.IsBlank, "'Characters'"));
            }
            else
            {
                while (outerIteratorCollection.HasMoreData())
                {
                    allErrors.MergeErrors(errors);
                    errors.ClearErrors();
                    var itrInField = new WarewolfIterator(dataObject.Environment.Eval(InField, update));
                    innerIteratorCollection.AddVariableToIterateOn(itrInField);

                    var chars = outerIteratorCollection.FetchNextValue(itrChar);
                    while (innerIteratorCollection.HasMoreData())
                    {
                        CheckForErrors(dataObject, update, indexFinder, allErrors, errors, innerIteratorCollection, completeResultList, itrInField, chars);
                        completeResultList = new List <string>();
                    }
                }
                if (!allErrors.HasErrors() && dataObject.IsDebugMode())
                {
                    AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
                }
            }

            #endregion
        }
Пример #3
0
        public void ErrorResultTO_Clear_ShouldEmptyTheErrorCollection()
        {
            var errorResultTo = new ErrorResultTO();

            errorResultTo.AddError("SomeError");
            errorResultTo.AddError("AnotherError");

            Assert.AreEqual(2, errorResultTo.FetchErrors().Count);

            errorResultTo.ClearErrors();

            Assert.AreEqual(0, errorResultTo.FetchErrors().Count);
        }
        protected override void ExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out ErrorResultTO tmpErrors, int update)
        {
            var execErrors = new ErrorResultTO();

            tmpErrors = new ErrorResultTO();
            tmpErrors.MergeErrors(execErrors);
            try
            {
                if (string.IsNullOrEmpty(ProcedureName))
                {
                    tmpErrors.AddError(ErrorResource.NoActionsInSelectedDB);
                    DisplayAndWriteError(dataObject, DisplayName, tmpErrors);
                    return;
                }

                if (ServiceExecution is DatabaseServiceExecution databaseServiceExecution)
                {
                    if (databaseServiceExecution.SourceIsNull())
                    {
                        databaseServiceExecution.GetSource(SourceId);
                    }

                    databaseServiceExecution.Inputs = Inputs.Select(a => new ServiceInput {
                        EmptyIsNull = a.EmptyIsNull, Name = a.Name, RequiredField = a.RequiredField, Value = a.Value, TypeName = a.TypeName
                    } as IServiceInput).ToList();
                    databaseServiceExecution.Outputs = Outputs;
                }

                ServiceExecution.Execute(out execErrors, update);
            }
            catch (Exception ex)
            {
                execErrors.AddError(ex.Message);
            }
            finally
            {
                if (execErrors.HasErrors())
                {
                    var fetchErrors = execErrors.FetchErrors();
                    foreach (var error in fetchErrors)
                    {
                        dataObject.Environment.Errors.Add(error);
                    }
                }

                tmpErrors.MergeErrors(execErrors);
                execErrors.ClearErrors();
            }
        }
Пример #5
0
        protected Mock <IEsbChannel> ExecuteForEachProcess(out IDSFDataObject dataObject, bool isDebug = false, int nestingLevel = 0)
        {
            using (ServiceAction svc = new ServiceAction {
                Name = "ForEachTestAction", ServiceName = "UnitTestService"
            })
            {
                var mockChannel = new Mock <IEsbChannel>();
                svc.SetActivity(FlowchartProcess);

                if (CurrentDl == null)
                {
                    CurrentDl = TestData;
                }

                var errors = new ErrorResultTO();


                if (errors.HasErrors())
                {
                    var errorString = errors.FetchErrors().Aggregate(string.Empty, (current, item) => current + item);

                    throw new Exception(errorString);
                }

                dataObject = new DsfDataObject(CurrentDl, new Guid())
                {
                    // NOTE: WorkflowApplicationFactory.InvokeWorkflowImpl() will use HostSecurityProvider.Instance.ServerID
                    //       if this is NOT provided which will cause the tests to fail!
                    ServerID            = Guid.NewGuid(),
                    IsDebug             = isDebug,
                    ForEachNestingLevel = nestingLevel,
                    ParentThreadID      = 1
                };


                // we need to set this now ;)

                mockChannel.Setup(c => c.ExecuteSubRequest(It.IsAny <IDSFDataObject>(), It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), out errors, 0, false)).Verifiable();
                CustomContainer.Register <IActivityParser>(new ActivityParser());
                var wfec = new WfExecutionContainer(svc, dataObject, WorkspaceRepository.Instance.ServerWorkspace, mockChannel.Object);

                errors.ClearErrors();
                wfec.Eval(FlowchartProcess, dataObject, 0);

                return(mockChannel);
            }
        }
        public void ErrorResultTO_Clear_ShouldEmptyTheErrorCollection()
        {
            var errorResultTo = new ErrorResultTO();

            Assert.IsNotNull(errorResultTo);
            var prObj  = new PrivateObject(errorResultTo);
            var errors = prObj.GetField("_errorList") as IList <string>;

            Assert.IsNotNull(errors);
            Assert.AreEqual(0, errors.Count);
            errorResultTo.AddError("SomeError");
            errorResultTo.AddError("AnotherError");
            errors = prObj.GetField("_errorList") as IList <string>;
            if (errors != null)
            {
                Assert.AreEqual(2, errors.Count);
            }
            errorResultTo.ClearErrors();
            if (errors != null)
            {
                Assert.AreEqual(0, errors.Count);
            }
        }
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            IDev2IndexFinder indexFinder = new Dev2IndexFinder();
            ErrorResultTO    allErrors   = new ErrorResultTO();
            ErrorResultTO    errors      = new ErrorResultTO();

            InitializeDebug(dataObject);

            try
            {
                var outerIteratorCollection = new WarewolfListIterator();
                var innerIteratorCollection = new WarewolfListIterator();

                allErrors.MergeErrors(errors);

                #region Iterate and Find Index

                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(new DebugEvalResult(InField, "In Field", dataObject.Environment, update));
                    AddDebugInputItem(new DebugItemStaticDataParams(Index, "Index"));
                    AddDebugInputItem(new DebugEvalResult(Characters, "Characters", dataObject.Environment, update));
                    AddDebugInputItem(new DebugItemStaticDataParams(Direction, "Direction"));
                }

                var itrChar = new WarewolfIterator(dataObject.Environment.Eval(Characters, update));
                outerIteratorCollection.AddVariableToIterateOn(itrChar);

                var completeResultList = new List <string>();
                if (String.IsNullOrEmpty(InField))
                {
                    allErrors.AddError(string.Format(ErrorResource.IsBlank, "'In Field'"));
                }
                else if (String.IsNullOrEmpty(Characters))
                {
                    allErrors.AddError(string.Format(ErrorResource.IsBlank, "'Characters'"));
                }
                else
                {
                    while (outerIteratorCollection.HasMoreData())
                    {
                        allErrors.MergeErrors(errors);
                        errors.ClearErrors();
                        var itrInField = new WarewolfIterator(dataObject.Environment.Eval(InField, update));
                        innerIteratorCollection.AddVariableToIterateOn(itrInField);

                        string chars = outerIteratorCollection.FetchNextValue(itrChar);
                        while (innerIteratorCollection.HasMoreData())
                        {
                            if (!string.IsNullOrEmpty(InField) && !string.IsNullOrEmpty(Characters))
                            {
                                var val = innerIteratorCollection.FetchNextValue(itrInField);
                                if (val != null)
                                {
                                    IEnumerable <int> returedData = indexFinder.FindIndex(val, Index, chars, Direction, MatchCase, StartIndex);
                                    completeResultList.AddRange(returedData.Select(value => value.ToString(CultureInfo.InvariantCulture)).ToList());
                                    var rule   = new IsSingleValueRule(() => Result);
                                    var single = rule.Check();
                                    if (single != null)
                                    {
                                        allErrors.AddError(single.Message);
                                    }
                                    else
                                    {
                                        dataObject.Environment.Assign(Result, string.Join(",", completeResultList), update);
                                        allErrors.MergeErrors(errors);
                                    }
                                }
                            }
                            completeResultList = new List <string>();
                        }
                    }
                    if (!allErrors.HasErrors() && dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
                    }
                }

                #endregion
            }
            catch (Exception e)
            {
                Dev2Logger.Error("DSFFindActivity", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                #region Handle Errors

                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfIndexActivity", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                }

                #endregion

                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
                    }
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
Пример #8
0
        protected IDSFDataObject ExecuteProcess(IDSFDataObject dataObject = null, bool isDebug = false, IEsbChannel channel = null, bool isRemoteInvoke = false, bool throwException = true, bool isDebugMode = false, Guid currentEnvironmentId = default(Guid), bool overrideRemote = false)
        {
            using (ServiceAction svc = new ServiceAction {
                Name = "TestAction", ServiceName = "UnitTestService"
            })
            {
                svc.SetActivity(FlowchartProcess);
                var mockChannel = new Mock <IEsbChannel>();

                if (CurrentDl == null)
                {
                    CurrentDl = TestData;
                }

                var errors = new ErrorResultTO();
                if (ExecutionId == Guid.Empty)
                {
                    if (dataObject != null)
                    {
                        dataObject.ExecutingUser = User;
                        dataObject.DataList      = new StringBuilder(CurrentDl);
                    }
                }

                if (errors.HasErrors())
                {
                    var errorString = errors.FetchErrors().Aggregate(string.Empty, (current, item) => current + item);

                    if (throwException)
                    {
                        throw new Exception(errorString);
                    }
                }

                if (dataObject == null)
                {
                    dataObject = new DsfDataObject(CurrentDl, ExecutionId)
                    {
                        // NOTE: WorkflowApplicationFactory.InvokeWorkflowImpl() will use HostSecurityProvider.Instance.ServerID
                        //       if this is NOT provided which will cause the tests to fail!
                        ServerID                 = Guid.NewGuid(),
                        ExecutingUser            = User,
                        IsDebug                  = isDebugMode,
                        EnvironmentID            = currentEnvironmentId,
                        IsRemoteInvokeOverridden = overrideRemote,
                        DataList                 = new StringBuilder(CurrentDl)
                    };
                }
                if (!string.IsNullOrEmpty(TestData))
                {
                    ExecutionEnvironmentUtils.UpdateEnvironmentFromXmlPayload(DataObject, new StringBuilder(TestData), CurrentDl, 0);
                }
                dataObject.IsDebug = isDebug;

                // we now need to set a thread ID ;)
                dataObject.ParentThreadID = 1;

                if (isRemoteInvoke)
                {
                    dataObject.RemoteInvoke    = true;
                    dataObject.RemoteInvokerID = Guid.NewGuid().ToString();
                }

                var esbChannel = mockChannel.Object;
                if (channel != null)
                {
                    esbChannel = channel;
                }
                dataObject.ExecutionToken = new ExecutionToken();
                var wfec = new WfExecutionContainer(svc, dataObject, WorkspaceRepository.Instance.ServerWorkspace, esbChannel);

                errors.ClearErrors();
                CustomContainer.Register <IActivityParser>(new ActivityParser());
                if (dataObject.ResourceID == Guid.Empty)
                {
                    dataObject.ResourceID = Guid.NewGuid();
                }
                dataObject.Environment = DataObject.Environment;
                wfec.Eval(FlowchartProcess, dataObject, 0);
                DataObject = dataObject;
                return(dataObject);
            }
        }
Пример #9
0
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            IDev2IndexFinder indexFinder = new Dev2IndexFinder();
            ErrorResultTO    allErrors   = new ErrorResultTO();
            ErrorResultTO    errors      = new ErrorResultTO();

            InitializeDebug(dataObject);

            try
            {
                var outerIteratorCollection = new WarewolfListIterator();
                var innerIteratorCollection = new WarewolfListIterator();

                allErrors.MergeErrors(errors);

                #region Iterate and Find Index

                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(new DebugEvalResult(InField, "In Field", dataObject.Environment, update));
                    AddDebugInputItem(new DebugItemStaticDataParams(Index, "Index"));
                    AddDebugInputItem(new DebugEvalResult(Characters, "Characters", dataObject.Environment, update));
                    AddDebugInputItem(new DebugItemStaticDataParams(Direction, "Direction"));
                }

                var itrChar = new WarewolfIterator(dataObject.Environment.Eval(Characters, update));
                outerIteratorCollection.AddVariableToIterateOn(itrChar);

                var completeResultList = new List <string>();
                if (String.IsNullOrEmpty(InField))
                {
                    allErrors.AddError("'In Field' is blank");
                }
                else if (String.IsNullOrEmpty(Characters))
                {
                    allErrors.AddError("'Characters' is blank");
                }
                else
                {
                    while (outerIteratorCollection.HasMoreData())
                    {
                        allErrors.MergeErrors(errors);
                        errors.ClearErrors();
                        var itrInField = new WarewolfIterator(dataObject.Environment.Eval(InField, update));
                        innerIteratorCollection.AddVariableToIterateOn(itrInField);

                        string chars = outerIteratorCollection.FetchNextValue(itrChar);
                        while (innerIteratorCollection.HasMoreData())
                        {
                            if (!string.IsNullOrEmpty(InField) && !string.IsNullOrEmpty(Characters))
                            {
                                var val = innerIteratorCollection.FetchNextValue(itrInField);
                                if (val != null)
                                {
                                    IEnumerable <int> returedData = indexFinder.FindIndex(val, Index, chars, Direction, MatchCase, StartIndex);
                                    completeResultList.AddRange(returedData.Select(value => value.ToString(CultureInfo.InvariantCulture)).ToList());
                                    //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result
                                }
                            }
                        }
                    }
                    var rule   = new IsSingleValueRule(() => Result);
                    var single = rule.Check();
                    if (single != null)
                    {
                        allErrors.AddError(single.Message);
                    }
                    else
                    {
                        if (DataListUtil.IsValueRecordset(Result))
                        {
                            var rsType = DataListUtil.GetRecordsetIndexType(Result);
                            if (rsType == enRecordsetIndexType.Numeric)
                            {
                                dataObject.Environment.Assign(Result, string.Join(",", completeResultList), update);
                                allErrors.MergeErrors(errors);
                            }
                            else
                            {
                                var idx = 1;
                                foreach (var res in completeResultList)
                                {
                                    if (rsType == enRecordsetIndexType.Blank)
                                    {
                                        dataObject.Environment.Assign(Result, res, update);
                                    }
                                    if (rsType == enRecordsetIndexType.Star)
                                    {
                                        var expression = DataListUtil.CreateRecordsetDisplayValue(DataListUtil.ExtractRecordsetNameFromValue(Result), DataListUtil.ExtractFieldNameFromValue(Result), idx.ToString());
                                        dataObject.Environment.Assign(DataListUtil.AddBracketsToValueIfNotExist(expression), res, update);
                                        idx++;
                                    }
                                }
                            }
                        }
                        else
                        {
                            dataObject.Environment.Assign(Result, string.Join(",", completeResultList), update);
                        }
                        allErrors.MergeErrors(errors);
                        if (!allErrors.HasErrors() && dataObject.IsDebugMode())
                        {
                            AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
                        }
                    }
                }

                #endregion
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFFindActivity", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                #region Handle Errors

                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfIndexActivity", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                }

                #endregion

                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
                    }
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
Пример #10
0
        public dynamic ExecuteProcess(IDSFDataObject dataObject = null, bool isDebug = false, IEsbChannel channel = null, bool isRemoteInvoke = false, bool throwException = true, bool isDebugMode = false, Guid currentEnvironmentId = default(Guid), bool overrideRemote = false)
        {
            var svc = new ServiceAction {
                Name = "TestAction", ServiceName = "UnitTestService"
            };

            svc.SetActivity(FlowchartProcess);
            Mock <IEsbChannel> mockChannel = new Mock <IEsbChannel>();

            if (CurrentDl == null)
            {
                CurrentDl = TestData;
            }

            var errors = new ErrorResultTO();

            if (ExecutionId == Guid.Empty)
            {
                Compiler = DataListFactory.CreateDataListCompiler();

                ExecutionId = Compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), new StringBuilder(TestData), new StringBuilder(CurrentDl), out errors);
                if (dataObject != null)
                {
                    dataObject.DataListID    = ExecutionId;
                    dataObject.ExecutingUser = User;
                    dataObject.DataList      = new StringBuilder(CurrentDl);
                }
            }

            if (errors.HasErrors())
            {
                string errorString = errors.FetchErrors().Aggregate(string.Empty, (current, item) => current + item);

                if (throwException)
                {
                    throw new Exception(errorString);
                }
            }

            if (dataObject == null)
            {
                dataObject = new DsfDataObject(CurrentDl, ExecutionId)
                {
                    // NOTE: WorkflowApplicationFactory.InvokeWorkflowImpl() will use HostSecurityProvider.Instance.ServerID
                    //       if this is NOT provided which will cause the tests to fail!
                    ServerID                 = Guid.NewGuid(),
                    ExecutingUser            = User,
                    IsDebug                  = isDebugMode,
                    EnvironmentID            = currentEnvironmentId,
                    IsRemoteInvokeOverridden = overrideRemote,
                    DataList                 = new StringBuilder(CurrentDl)
                };
            }
            dataObject.IsDebug = isDebug;

            // we now need to set a thread ID ;)
            dataObject.ParentThreadID = 1;

            if (isRemoteInvoke)
            {
                dataObject.RemoteInvoke    = true;
                dataObject.RemoteInvokerID = Guid.NewGuid().ToString();
            }

            var esbChannel = mockChannel.Object;

            if (channel != null)
            {
                esbChannel = channel;
            }
            WfExecutionContainer wfec = new WfExecutionContainer(svc, dataObject, Dev2.Workspaces.WorkspaceRepository.Instance.ServerWorkspace, esbChannel);

            errors.ClearErrors();
            dataObject.DataListID = wfec.Execute(out errors);


            return(dataObject);
        }
Пример #11
0
        /// <summary>
        /// Invokes the specified service as per the dataObject against theHost
        /// </summary>
        /// <param name="dataObject">The data object.</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Can only execute workflows from web browser</exception>
        public Guid Invoke(IDSFDataObject dataObject, out ErrorResultTO errors)
        {
            var result = GlobalConstants.NullDataListID;
            var time   = new Stopwatch();

            time.Start();
            errors = new ErrorResultTO();
            int update = 0;

            // BUG 9706 - 2013.06.22 - TWR : added pre debug dispatch
            if (dataObject.Environment.HasErrors())
            {
                errors.AddError(dataObject.Environment.FetchErrors());
                DispatchDebugErrors(errors, dataObject, StateType.Before);
            }
            errors.ClearErrors();
            try
            {
                var serviceId = dataObject.ResourceID;

                // we need to get better at getting this ;)

                var serviceName = dataObject.ServiceName;
                if (serviceId == Guid.Empty && string.IsNullOrEmpty(serviceName))
                {
                    errors.AddError(Resources.DynamicServiceError_ServiceNotSpecified);
                }
                else
                {
                    try
                    {
                        var sl = new ServiceLocator();
                        Dev2Logger.Log.Debug("Finding service");
                        var theService = serviceId == Guid.Empty ? sl.FindService(serviceName, _workspace.ID) : sl.FindService(serviceId, _workspace.ID);

                        if (theService == null)
                        {
                            errors.AddError("Service [ " + serviceName + " ] not found.");
                        }
                        else if (theService.Actions.Count <= 1)
                        {
                            #region Execute ESB container

                            var theStart = theService.Actions.FirstOrDefault();
                            if (theStart != null && theStart.ActionType != Common.Interfaces.Core.DynamicServices.enActionType.InvokeManagementDynamicService && theStart.ActionType != Common.Interfaces.Core.DynamicServices.enActionType.Workflow && dataObject.IsFromWebServer)
                            {
                                throw new Exception("Can only execute workflows from web browser");
                            }
                            Dev2Logger.Log.Debug("Mapping Action Dependencies");
                            MapServiceActionDependencies(theStart, sl);

                            // Invoke based upon type ;)
                            if (theStart != null)
                            {
                                theStart.DataListSpecification = theService.DataListSpecification;
                                Dev2Logger.Log.Debug("Getting container");
                                var           container = GenerateContainer(theStart, dataObject, _workspace);
                                ErrorResultTO invokeErrors;
                                result = container.Execute(out invokeErrors, update);
                                errors.MergeErrors(invokeErrors);
                            }
                            #endregion
                        }
                        else
                        {
                            errors.AddError("Malformed Service [ " + serviceId + " ] it contains multiple actions");
                        }
                    }
                    catch (Exception e)
                    {
                        errors.AddError(e.Message);
                    }
                    finally
                    {
                        if (dataObject.Environment.HasErrors())
                        {
                            var errorString     = dataObject.Environment.FetchErrors();
                            var executionErrors = ErrorResultTO.MakeErrorResultFromDataListString(errorString);
                            errors.MergeErrors(executionErrors);
                        }

                        dataObject.Environment.AddError(errors.MakeDataListReady());

                        if (errors.HasErrors())
                        {
                            Dev2Logger.Log.Error(errors.MakeDisplayReady());
                        }
                    }
                }
            }
            finally
            {
                time.Stop();
                ServerStats.IncrementTotalRequests();
                ServerStats.IncrementTotalTime(time.ElapsedMilliseconds);
                // BUG 9706 - 2013.06.22 - TWR : added
                DispatchDebugErrors(errors, dataObject, StateType.End);
            }
            return(result);
        }
Пример #12
0
        /// <summary>
        /// Invokes the specified service as per the dataObject against theHost
        /// </summary>
        /// <param name="dataObject">The data object.</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Can only execute workflows from web browser</exception>
        public Guid Invoke(IDSFDataObject dataObject, out ErrorResultTO errors)
        {
            var result = GlobalConstants.NullDataListID;
            var time   = new Stopwatch();

            time.Start();
            errors = new ErrorResultTO();
            const int Update = 0;

            if (dataObject.Environment.HasErrors())
            {
                errors.AddError(dataObject.Environment.FetchErrors());
                DispatchDebugErrors(errors, dataObject, StateType.Before);
            }
            errors.ClearErrors();
            try
            {
                var serviceId = dataObject.ResourceID;

                var serviceName = dataObject.ServiceName;
                if (serviceId == Guid.Empty && string.IsNullOrEmpty(serviceName))
                {
                    errors.AddError(Resources.DynamicServiceError_ServiceNotSpecified);
                }
                else
                {
                    try
                    {
                        Dev2Logger.Debug("Finding service");
                        var theService = serviceId == Guid.Empty ? _serviceLocator.FindService(serviceName, _workspace.ID) : _serviceLocator.FindService(serviceId, _workspace.ID);

                        if (theService == null)
                        {
                            if (!dataObject.IsServiceTestExecution)
                            {
                                theService = _serviceLocator.FindService(serviceName, GlobalConstants.ServerWorkspaceID);
                            }
                            if (theService == null)
                            {
                                if (dataObject.IsServiceTestExecution)
                                {
                                    var testResult = new ServiceTestModelTO
                                    {
                                        Result = new TestRunResult
                                        {
                                            RunTestResult = RunResult.TestResourceDeleted,
                                            Message       = "Resource has been deleted",
                                            DebugForTest  = new List <IDebugState>(),
                                            TestName      = dataObject.TestName
                                        },
                                        TestPassed     = false,
                                        TestInvalid    = true,
                                        FailureMessage = "Resource has been deleted",
                                        TestName       = dataObject.TestName,
                                    };
                                    var ser = new Dev2JsonSerializer();
                                    _request.ExecuteResult = ser.SerializeToBuilder(testResult);
                                }

                                errors.AddError(string.Format(ErrorResource.ServiceNotFound, serviceName));
                            }
                        }
                        else if (theService.Actions.Count <= 1)
                        {
                            #region Execute ESB container

                            var theStart = theService.Actions.FirstOrDefault();
                            if (theStart != null && theStart.ActionType != enActionType.InvokeManagementDynamicService && theStart.ActionType != enActionType.Workflow && dataObject.IsFromWebServer)
                            {
                                throw new Exception(ErrorResource.CanOnlyExecuteWorkflowsFromWebBrowser);
                            }
                            Dev2Logger.Debug("Mapping Action Dependencies");
                            MapServiceActionDependencies(theStart);

                            if (theStart != null)
                            {
                                theStart.Service = theService;
                                theStart.DataListSpecification = theService.DataListSpecification;
                                Dev2Logger.Debug("Getting container");
                                var           container = GenerateContainer(theStart, dataObject, _workspace);
                                ErrorResultTO invokeErrors;
                                result = container.Execute(out invokeErrors, Update);

                                errors.MergeErrors(invokeErrors);
                            }
                            #endregion
                        }
                        else
                        {
                            errors.AddError(string.Format(ErrorResource.MalformedService, serviceId));
                        }
                    }
                    catch (Exception e)
                    {
                        errors.AddError(e.Message);
                    }
                    finally
                    {
                        if (dataObject.Environment.HasErrors())
                        {
                            var errorString     = dataObject.Environment.FetchErrors();
                            var executionErrors = ErrorResultTO.MakeErrorResultFromDataListString(errorString);
                            errors.MergeErrors(executionErrors);
                        }

                        dataObject.Environment.AddError(errors.MakeDataListReady());

                        if (errors.HasErrors())
                        {
                            Dev2Logger.Error(errors.MakeDisplayReady());
                        }
                    }
                }
            }
            finally
            {
                time.Stop();
                ServerStats.IncrementTotalRequests();
                ServerStats.IncrementTotalTime(time.ElapsedMilliseconds);
                DispatchDebugErrors(errors, dataObject, StateType.End);
            }
            return(result);
        }
Пример #13
0
        // ReSharper restore RedundantOverridenMember

        /// <summary>
        /// The execute method that is called when the activity is executed at run time and will hold all the logic of the activity
        /// </summary>
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>();

            IDataListCompiler compiler    = DataListFactory.CreateDataListCompiler();
            IDev2IndexFinder  indexFinder = new Dev2IndexFinder();
            ErrorResultTO     allErrors   = new ErrorResultTO();
            ErrorResultTO     errors      = new ErrorResultTO();
            Guid executionId = DataListExecutionID.Get(context);

            InitializeDebug(dataObject);
            IDev2DataListUpsertPayloadBuilder <List <string> > toUpsert       = Dev2DataListBuilderFactory.CreateStringListDataListUpsertBuilder();
            IDev2DataListUpsertPayloadBuilder <string>         toUpsertScalar = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder();

            toUpsert.IsDebug       = dataObject.IsDebugMode();
            toUpsertScalar.IsDebug = dataObject.IsDebugMode();
            try
            {
                IDev2IteratorCollection outerIteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection();
                IDev2IteratorCollection innerIteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection();

                allErrors.MergeErrors(errors);


                IBinaryDataListEntry expressionsEntry = compiler.Evaluate(executionId, enActionType.User, Characters, false, out errors);
                allErrors.MergeErrors(errors);
                IDev2DataListEvaluateIterator itrChar = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry);

                outerIteratorCollection.AddIterator(itrChar);

                #region Iterate and Find Index

                expressionsEntry = compiler.Evaluate(executionId, enActionType.User, InField, false, out errors);

                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(new DebugItemVariableParams(InField, "In Field", expressionsEntry, executionId));
                    AddDebugInputItem(new DebugItemStaticDataParams(Index, "Index"));
                    AddDebugInputItem(new DebugItemVariableParams(Characters, "Characters", itrChar.FetchEntry(), executionId));
                    AddDebugInputItem(new DebugItemStaticDataParams(Direction, "Direction"));
                }

                var completeResultList = new List <string>();

                while (outerIteratorCollection.HasMoreData())
                {
                    allErrors.MergeErrors(errors);
                    errors.ClearErrors();
                    IDev2DataListEvaluateIterator itrInField = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry);
                    innerIteratorCollection.AddIterator(itrInField);

                    string chars = outerIteratorCollection.FetchNextRow(itrChar).TheValue;
                    while (innerIteratorCollection.HasMoreData())
                    {
                        if (!string.IsNullOrEmpty(InField) && !string.IsNullOrEmpty(Characters))
                        {
                            var val = innerIteratorCollection.FetchNextRow(itrInField);
                            if (val != null)
                            {
                                IEnumerable <int> returedData = indexFinder.FindIndex(val.TheValue, Index, chars, Direction, MatchCase, StartIndex);
                                completeResultList.AddRange(returedData.Select(value => value.ToString(CultureInfo.InvariantCulture)).ToList());
                                //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result
                            }
                        }
                    }
                }
                var rule   = new IsSingleValueRule(() => Result);
                var single = rule.Check();
                if (single != null)
                {
                    allErrors.AddError(single.Message);
                }
                else
                {
                    var rsType = DataListUtil.GetRecordsetIndexType(Result);
                    if (rsType == enRecordsetIndexType.Numeric)
                    {
                        toUpsertScalar.Add(Result, string.Join(",", completeResultList));
                        compiler.Upsert(executionId, toUpsertScalar, out errors);
                        allErrors.MergeErrors(errors);
                        if (!allErrors.HasErrors() && dataObject.IsDebugMode())
                        {
                            foreach (var debugOutputTo in toUpsertScalar.DebugOutputs)
                            {
                                AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                            }
                            toUpsert.DebugOutputs.Clear();
                        }
                    }
                    else
                    {
                        toUpsert.Add(Result, completeResultList);
                        compiler.Upsert(executionId, toUpsert, out errors);
                        allErrors.MergeErrors(errors);
                        if (!allErrors.HasErrors() && dataObject.IsDebugMode())
                        {
                            foreach (var debugOutputTo in toUpsert.DebugOutputs)
                            {
                                AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                            }
                            toUpsert.DebugOutputs.Clear();
                        }
                    }
                }
                #endregion
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFFindActivity", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                #region Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfIndexActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                    compiler.Upsert(executionId, Result, (string)null, out errors);
                }

                #endregion

                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        foreach (var debugOutputTo in toUpsert.DebugOutputs)
                        {
                            AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                        }
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }