示例#1
0
        Guid ExecuteWf()
        {
            var result = Guid.NewGuid();

            DataObject.StartTime = DateTime.Now;
            var           wfappUtils = new WfApplicationUtils(_resourceCatalog);
            ErrorResultTO invokeErrors;
            var           executionId = DataObject.ExecutionID.ToString();

            try
            {
                IExecutionToken exeToken = new ExecutionToken {
                    IsUserCanceled = false
                };
                DataObject.ExecutionToken = exeToken;
                if (DataObject.IsDebugMode())
                {
                    wfappUtils.DispatchDebugState(DataObject, StateType.Start, out invokeErrors, true, false, false);
                }

                var resourceId = DataObject.ResourceID;
                if (CanExecute(resourceId, DataObject, AuthorizationContext.Execute))
                {
                    Eval(resourceId, DataObject);
                }

                if (DataObject.IsDebugMode())
                {
                    wfappUtils.DispatchDebugState(DataObject, StateType.End, out invokeErrors);
                }

                result = DataObject.DataListID;
            }
            catch (InvalidWorkflowException iwe)
            {
                Dev2Logger.Error(iwe, executionId);
                var msg = iwe.Message;

                var start        = msg.IndexOf("Flowchart ", StringComparison.Ordinal);
                var errorMessage = start > 0 ? GlobalConstants.NoStartNodeError : iwe.Message;
                DataObject.Environment.AddError(errorMessage);
                wfappUtils.DispatchDebugState(DataObject, StateType.End, out invokeErrors);
            }
            catch (Exception ex)
            {
                Dev2Logger.Error(ex, executionId);
                DataObject.Environment.AddError(ex.Message);
                DataObject.ExecutionException = ex;
                wfappUtils.DispatchDebugState(DataObject, StateType.End, out invokeErrors);
            }

            return(result);
        }
示例#2
0
        public void WfApplicationUtils_TryWriteDebug_WriteDebug_Environment_HasErrors_ShouldWriteUsingDebugDispactcher()
        {
            //---------------Set up test pack-------------------
            var wfApplicationUtils       = new WfApplicationUtils();
            var mockExecutionEnvironment = new Mock <IExecutionEnvironment>();
            var mockDebugDispatcher      = new Mock <IDebugDispatcher>();
            var mockDebugDispatcherFunc  = new Mock <Func <IDebugDispatcher> >();
            var mockDSFDataObject        = new Mock <IDSFDataObject>();

            var debugState = new DebugState {
                StateType = StateType.Start
            };

            mockDebugDispatcher.Setup(dispatcher => dispatcher.Write(new WriteArgs {
                debugState = debugState, isTestExecution = It.IsAny <bool>(), isDebugFromWeb = It.IsAny <bool>(), testName = It.IsAny <string>(), isRemoteInvoke = It.IsAny <bool>(), remoteInvokerId = It.IsAny <string>(), parentInstanceId = It.IsAny <string>(), remoteDebugItems = It.IsAny <IList <IDebugState> >()
            }));

            mockDebugDispatcherFunc.Setup(func => func()).Returns(() => mockDebugDispatcher.Object);

            mockDSFDataObject.Setup(o => o.Environment).Returns(mockExecutionEnvironment.Object);
            mockDSFDataObject.Setup(o => o.IsDebugMode()).Returns(true);
            mockDSFDataObject.Setup(o => o.ResourceID).Returns(new Guid("fa4b4786-67d9-414f-8c2e-17673fdcef48"));
            mockDSFDataObject.Setup(o => o.Environment.HasErrors()).Returns(true);

            var privateObject = new PrivateObject(wfApplicationUtils);

            privateObject.SetField("_getDebugDispatcher", mockDebugDispatcherFunc.Object);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                wfApplicationUtils.DispatchDebugState(mockDSFDataObject.Object, StateType.Start, out var error, false, false);
                var state = debugState;
                mockDebugDispatcher.Verify(dispatcher => dispatcher.Write(new WriteArgs {
                    debugState = state, isTestExecution = It.IsAny <bool>(), isDebugFromWeb = It.IsAny <bool>(), testName = It.IsAny <string>(), isRemoteInvoke = It.IsAny <bool>(), remoteInvokerId = It.IsAny <string>(), parentInstanceId = It.IsAny <string>(), remoteDebugItems = It.IsAny <IList <IDebugState> >()
                }));

                debugState = new DebugState {
                    StateType = StateType.End
                };
                wfApplicationUtils.DispatchDebugState(mockDSFDataObject.Object, StateType.End, out error, false, false);

                mockDebugDispatcher.Verify(dispatcher => dispatcher.Write(new WriteArgs {
                    debugState = debugState, isTestExecution = It.IsAny <bool>(), isDebugFromWeb = It.IsAny <bool>(), testName = It.IsAny <string>(), isRemoteInvoke = It.IsAny <bool>(), remoteInvokerId = It.IsAny <string>(), parentInstanceId = It.IsAny <string>(), remoteDebugItems = It.IsAny <IList <IDebugState> >()
                }));
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            //---------------Test Result -----------------------
        }
示例#3
0
        public void WfApplicationUtils_DispatchDebugState_GivenValidParamsAndIsDebugMode_ShouldWriteUsingDebugDispactcher()
        {
            //---------------Set up test pack-------------------
            var wfApplicationUtils = new WfApplicationUtils();
            var envMock            = new Mock <IExecutionEnvironment>();
            var debugDispatcher    = new Mock <IDebugDispatcher>();
            var debugState         = new DebugState {
                StateType = StateType.Start
            };

            debugDispatcher.Setup(dispatcher => dispatcher.Write(new WriteArgs {
                debugState = debugState, isTestExecution = It.IsAny <bool>(), isDebugFromWeb = It.IsAny <bool>(), testName = It.IsAny <string>(), isRemoteInvoke = It.IsAny <bool>(), remoteInvokerId = It.IsAny <string>(), parentInstanceId = It.IsAny <string>(), remoteDebugItems = It.IsAny <IList <IDebugState> >()
            }));
            var mock = new Mock <Func <IDebugDispatcher> >();

            mock.Setup(func => func()).Returns(() => debugDispatcher.Object);
            var mockObj = new Mock <IDSFDataObject>();

            mockObj.Setup(o => o.Environment).Returns(envMock.Object);
            mockObj.Setup(o => o.IsDebugMode()).Returns(true);
            var privateObject = new PrivateObject(wfApplicationUtils);

            privateObject.SetField("_getDebugDispatcher", mock.Object);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                wfApplicationUtils.DispatchDebugState(mockObj.Object, StateType.Start, out var error, false, false);
                var state = debugState;
                debugDispatcher.Verify(dispatcher => dispatcher.Write(new WriteArgs {
                    debugState = state, isTestExecution = It.IsAny <bool>(), isDebugFromWeb = It.IsAny <bool>(), testName = It.IsAny <string>(), isRemoteInvoke = It.IsAny <bool>(), remoteInvokerId = It.IsAny <string>(), parentInstanceId = It.IsAny <string>(), remoteDebugItems = It.IsAny <IList <IDebugState> >()
                }));

                debugState = new DebugState {
                    StateType = StateType.End
                };
                wfApplicationUtils.DispatchDebugState(mockObj.Object, StateType.End, out error, false, false);

                debugDispatcher.Verify(dispatcher => dispatcher.Write(new WriteArgs {
                    debugState = debugState, isTestExecution = It.IsAny <bool>(), isDebugFromWeb = It.IsAny <bool>(), testName = It.IsAny <string>(), isRemoteInvoke = It.IsAny <bool>(), remoteInvokerId = It.IsAny <string>(), parentInstanceId = It.IsAny <string>(), remoteDebugItems = It.IsAny <IList <IDebugState> >()
                }));
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            //---------------Test Result -----------------------
        }
        public void DispatchDebugState_GivenValidParamsAndIntergoateInputs_ShouldWriteUsingDebugDispactcher()
        {
            //---------------Set up test pack-------------------
            var wfApplicationUtils = new WfApplicationUtils();
            var envMock            = new Mock <IExecutionEnvironment>();
            var debugDispatcher    = new Mock <IDebugDispatcher>();
            var debugState         = new DebugState {
                StateType = StateType.Start
            };

            debugDispatcher.Setup(dispatcher => dispatcher.Write(debugState, It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <string>()));
            var mock = new Mock <Func <IDebugDispatcher> >();

            mock.Setup(func => func()).Returns(() => debugDispatcher.Object);
            var mockObj = new Mock <IDSFDataObject>();

            mockObj.Setup(o => o.Environment).Returns(envMock.Object);
            mockObj.Setup(o => o.IsDebugMode()).Returns(true);
            var privateObject = new PrivateObject(wfApplicationUtils);

            privateObject.SetField("_getDebugDispatcher", mock.Object);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                wfApplicationUtils.DispatchDebugState(mockObj.Object, StateType.Start, false, string.Empty, out ErrorResultTO error, DateTime.Now, true, true);
                var state = debugState;
                debugDispatcher.Verify(dispatcher => dispatcher.Write(state, It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <string>()));
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            //---------------Test Result -----------------------
        }
示例#5
0
        public void WfApplicationUtils_DispatchDebugState_RunWorkflowAsyncIsFalse_WillNotDispatchDebugState()
        {
            //------------Setup for test--------------------------
            var wfUtils        = new WfApplicationUtils();
            var mockDispatcher = new Mock <Common.Interfaces.Diagnostics.Debug.IDebugDispatcher>();

            wfUtils.GetDebugDispatcher = () => mockDispatcher.Object;
            var mockDataObject = new Mock <IDSFDataObject>();

            mockDataObject.Setup(d => d.IsDebugMode()).Returns(false);
            mockDataObject.Setup(d => d.IsFromWebServer).Returns(false);
            mockDataObject.Setup(d => d.RunWorkflowAsync).Returns(false);
            mockDispatcher.Setup(m => m.Write(It.IsAny <Common.Interfaces.Diagnostics.Debug.IDebugState>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IList <Common.Interfaces.Diagnostics.Debug.IDebugState> >()))
            .Verifiable();
            var dataObject = mockDataObject.Object;
            const Common.Interfaces.Diagnostics.Debug.StateType StateType = Common.Interfaces.Diagnostics.Debug.StateType.All;
            // ReSharper disable RedundantAssignment
            ErrorResultTO errors = new ErrorResultTO();
            // ReSharper restore RedundantAssignment
            DateTime?workflowStartTime = DateTime.Now;

            //------------Execute Test---------------------------
            wfUtils.DispatchDebugState(dataObject, StateType, false, string.Empty, out errors, workflowStartTime);
            //------------Assert Results-------------------------
            mockDispatcher.Verify(m => m.Write(It.IsAny <Common.Interfaces.Diagnostics.Debug.IDebugState>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IList <Common.Interfaces.Diagnostics.Debug.IDebugState> >()), Times.Never());
            Assert.IsFalse(errors.HasErrors());
        }
示例#6
0
        Guid ExecuteWf(ErrorResultTO to)
        {
            Guid result = new Guid();

            try
            {
                // BUG 9304 - 2013.05.08 - TWR - Added CompileExpressions
                //_workflowHelper.CompileExpressions(theActivity,DataObject.ResourceID);

                //IDSFDataObject exeResult = wfFactor.InvokeWorkflow(activity.Value, DataObject,
                //                                                   new List<object> { EsbChannel, }, instanceId,
                //                                                   TheWorkspace, bookmark, out errors);
                var             wfappUtils = new WfApplicationUtils();
                IExecutionToken exeToken   = new ExecutionToken {
                    IsUserCanceled = false
                };
                DataObject.ExecutionToken = exeToken;
                ErrorResultTO invokeErrors;
                if (DataObject.IsDebugMode())
                {
                    wfappUtils.DispatchDebugState(DataObject, StateType.Start, DataObject.Environment.HasErrors(), DataObject.Environment.FetchErrors(), out invokeErrors, DateTime.Now, true, false, false);
                }
                Eval(DataObject.ResourceID, DataObject);
                if (DataObject.IsDebugMode())
                {
                    wfappUtils.DispatchDebugState(DataObject, StateType.End, DataObject.Environment.HasErrors(), DataObject.Environment.FetchErrors(), out invokeErrors, DataObject.StartTime, false, true);
                }
                result = DataObject.DataListID;
            }
            catch (InvalidWorkflowException iwe)
            {
                Dev2Logger.Log.Error(iwe);
                var msg = iwe.Message;

                int start = msg.IndexOf("Flowchart ", StringComparison.Ordinal);

                // trap the no start node error so we can replace it with something nicer ;)
                to.AddError(start > 0 ? GlobalConstants.NoStartNodeError : iwe.Message);
            }
            catch (Exception ex)
            {
                Dev2Logger.Log.Error(ex);
                to.AddError(ex.Message);
            }
            return(result);
        }
        Guid TryExecuteWf(ErrorResultTO to, IServiceTestModelTO test)
        {
            var result       = new Guid();
            var wfappUtils   = new WfApplicationUtils();
            var invokeErrors = new ErrorResultTO();
            var resourceId   = DataObject.ResourceID;

            if (test?.Inputs != null)
            {
                AddTestInputsToJsonOrRecordset(test);
            }

            var serializer = new Dev2JsonSerializer();

            try
            {
                result = _inner.ExecuteWf(new TestExecutionContext {
                    _test         = test,
                    _wfappUtils   = wfappUtils,
                    _invokeErrors = invokeErrors,
                    _serializer   = serializer,
                });
            }
            catch (InvalidWorkflowException iwe)
            {
                Dev2Logger.Error(iwe, DataObject.ExecutionID.ToString());
                var msg = iwe.Message;

                var start = msg.IndexOf("Flowchart ", StringComparison.Ordinal);
                to?.AddError(start > 0 ? GlobalConstants.NoStartNodeError : iwe.Message);
                var failureMessage = DataObject.Environment.FetchErrors();
                wfappUtils.DispatchDebugState(DataObject, StateType.End, out invokeErrors);

                SetTestRunResultAfterInvalidWorkflowException(test, resourceId, serializer, failureMessage);
            }
            catch (Exception ex)
            {
                Dev2Logger.Error(ex, GlobalConstants.WarewolfError);
                to.AddError(ex.Message);
                wfappUtils.DispatchDebugState(DataObject, StateType.End, out invokeErrors);

                SetTestRunResultAfterException(test, resourceId, serializer, ex);
            }
            return(result);
        }
示例#8
0
        public void WfApplicationUtils_DispatchDebugState_GivenValidParamsAndIntergoateOutputs_ShouldWriteUsingDebugDispactcher_GetResourceForDatalist()
        {
            //---------------Set up test pack-------------------
            var catLog = new Mock <IResourceCatalog>();

            catLog.Setup(catalog => catalog.GetResource(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(new Resource
            {
                DataList = new StringBuilder()
            });

            IResource dropBoxSource = new DropBoxSource
            {
                AppKey      = "Key",
                AccessToken = "token",
                DataList    = new StringBuilder("<DataList></DataList>")
            };

            catLog.Setup(catalog => catalog.GetResource(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(dropBoxSource);

            var wfApplicationUtils = new WfApplicationUtils();
            var envMock            = new Mock <IExecutionEnvironment>();
            var debugDispatcher    = new Mock <IDebugDispatcher>();
            var debugState         = new DebugState {
                StateType = StateType.Start
            };

            debugDispatcher.Setup(dispatcher => dispatcher.Write(new WriteArgs {
                debugState = debugState, isTestExecution = It.IsAny <bool>(), isDebugFromWeb = It.IsAny <bool>(), testName = It.IsAny <string>(), isRemoteInvoke = It.IsAny <bool>(), remoteInvokerId = It.IsAny <string>(), parentInstanceId = It.IsAny <string>(), remoteDebugItems = It.IsAny <IList <IDebugState> >()
            }));
            var mock = new Mock <Func <IDebugDispatcher> >();

            mock.Setup(func => func()).Returns(() => debugDispatcher.Object);
            var mockObj = new Mock <IDSFDataObject>();

            mockObj.Setup(o => o.Environment).Returns(envMock.Object);
            mockObj.Setup(o => o.IsDebugMode()).Returns(true);
            var privateObject = new PrivateObject(wfApplicationUtils);

            privateObject.SetField("_getDebugDispatcher", mock.Object);
            privateObject.SetField("_lazyCat", catLog.Object);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                wfApplicationUtils.DispatchDebugState(mockObj.Object, StateType.Start, out var error);
                var state = debugState;
                debugDispatcher.Verify(dispatcher => dispatcher.Write(new WriteArgs {
                    debugState = state, isTestExecution = It.IsAny <bool>(), isDebugFromWeb = It.IsAny <bool>(), testName = It.IsAny <string>(), isRemoteInvoke = It.IsAny <bool>(), remoteInvokerId = It.IsAny <string>(), parentInstanceId = It.IsAny <string>(), remoteDebugItems = It.IsAny <IList <IDebugState> >()
                }));
                catLog.Verify(catalog => catalog.GetResource(It.IsAny <Guid>(), It.IsAny <Guid>()));
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        public void DispatchDebugState_GivenValidParamsAndIntergoateOutputs_ShouldWriteUsingDebugDispactcher_GetResourceForDatalist()
        {
            //---------------Set up test pack-------------------
            var catLog = new Mock <IResourceCatalog>();

            catLog.Setup(catalog => catalog.GetResource(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(new Resource()
            {
                DataList = new StringBuilder()
            });

            IResource dropBoxSource = new DropBoxSource()
            {
                AppKey = "Key", AccessToken = "token"
            };

            dropBoxSource.DataList = new StringBuilder("<DataList></DataList>");
            catLog.Setup(catalog => catalog.GetResource(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(dropBoxSource);

            var wfApplicationUtils = new WfApplicationUtils();
            var envMock            = new Mock <IExecutionEnvironment>();
            var debugDispatcher    = new Mock <IDebugDispatcher>();
            var debugState         = new DebugState {
                StateType = StateType.Start
            };

            debugDispatcher.Setup(dispatcher => dispatcher.Write(debugState, It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <string>()));
            var mock = new Mock <Func <IDebugDispatcher> >();

            mock.Setup(func => func()).Returns(() => debugDispatcher.Object);
            var mockObj = new Mock <IDSFDataObject>();

            mockObj.Setup(o => o.Environment).Returns(envMock.Object);
            mockObj.Setup(o => o.IsDebugMode()).Returns(true);
            var privateObject = new PrivateObject(wfApplicationUtils);

            privateObject.SetField("_getDebugDispatcher", mock.Object);
            privateObject.SetField("_lazyCat", catLog.Object);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                wfApplicationUtils.DispatchDebugState(mockObj.Object, StateType.Start, false, string.Empty, out ErrorResultTO error, DateTime.Now, false, true);
                var state = debugState;
                debugDispatcher.Verify(dispatcher => dispatcher.Write(state, It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <string>()));
                catLog.Verify(catalog => catalog.GetResource(It.IsAny <Guid>(), It.IsAny <Guid>()));
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            //---------------Test Result -----------------------
        }
示例#10
0
        public void WfApplicationUtils_DispatchDebugState_GetDebugState_HasRemote_ShouldNotThrowException()
        {
            //---------------Set up test pack-------------------
            var wfApplicationUtils       = new WfApplicationUtils();
            var mockExecutionEnvironment = new Mock <IExecutionEnvironment>();
            var mockDSFDataObject        = new Mock <IDSFDataObject>();

            mockDSFDataObject.Setup(o => o.Environment).Returns(mockExecutionEnvironment.Object);
            mockDSFDataObject.Setup(o => o.RemoteInvokerID).Returns("fa4b4786-67d9-414f-8c2e-17673fdcef48");
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                wfApplicationUtils.DispatchDebugState(mockDSFDataObject.Object, StateType.Start, out ErrorResultTO error, false, false);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            //---------------Test Result -----------------------
        }
示例#11
0
        public void WfApplicationUtils_DispatchDebugState_GivenValidParams_ShouldNotThrowException()
        {
            //---------------Set up test pack-------------------
            var wfApplicationUtils = new WfApplicationUtils();
            var envMock            = new Mock <IExecutionEnvironment>();

            var mockObj = new Mock <IDSFDataObject>();

            mockObj.Setup(o => o.Environment).Returns(envMock.Object);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                wfApplicationUtils.DispatchDebugState(mockObj.Object, StateType.Start, out ErrorResultTO error, false, false);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            //---------------Test Result -----------------------
        }
示例#12
0
        // ReSharper disable InconsistentNaming
        public void DebugDispatcher_Write_WhenRemoteInvokeItemsPresentAfterEndMessage_ExpectRemoteItemsDispatchedBeforeEndMessage()
        // ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var workspaceID = Guid.NewGuid();
            var writer      = new Mock <IDebugWriter>();

            writer.Setup(s => s.Write(It.IsAny <IDebugState>())).Verifiable();
            var writerList = new List <IDebugState>();

            // .Callback<ISqlBulkCopy, DataTable>((sqlBulkCopy, dataTable) => returnedDataTable = dataTable);
            // ReSharper disable ConvertClosureToMethodGroup
            writer.Setup(w => w.Write(It.IsAny <IDebugState>())).Callback <IDebugState>(ds =>
            {
                writerList.Add(ds);
            });
            // ReSharper restore ConvertClosureToMethodGroup

            DebugDispatcher.Instance.Add(workspaceID, writer.Object);

            var origResourceID = Guid.NewGuid();
            var server         = Guid.NewGuid();

            var state2 = new Mock <IDebugState>();

            state2.Setup(s => s.WorkspaceID).Returns(workspaceID);
            state2.Setup(s => s.OriginatingResourceID).Returns(origResourceID);
            state2.Setup(s => s.Server).Returns(server.ToString);
            state2.Setup(s => s.StateType).Returns(StateType.Message);

            var state1 = new Mock <IDebugState>();

            state1.Setup(s => s.WorkspaceID).Returns(workspaceID);
            state1.Setup(s => s.OriginatingResourceID).Returns(origResourceID);
            state1.Setup(s => s.Server).Returns(server.ToString);
            state1.Setup(s => s.StateType).Returns(StateType.Message);

            var utils      = new WfApplicationUtils();
            var dataObject = new Mock <IDSFDataObject>();

            dataObject.Setup(d => d.RemoteDebugItems).Returns(new List <IDebugState> {
                state1.Object, state2.Object
            });
            dataObject.Setup(d => d.IsDebugMode()).Returns(true);
            dataObject.Setup(d => d.WorkspaceID).Returns(workspaceID);
            dataObject.Setup(d => d.Environment).Returns(new ExecutionEnvironment());

            //------------Execute Test---------------------------

            ErrorResultTO errors;

            utils.DispatchDebugState(dataObject.Object, StateType.End, false, string.Empty, out errors);

            //------------Assert Results-------------------------

            // Write happens asynchronously on a separate thread
            Thread.Sleep(50);
            writer.Verify(s => s.Write(It.IsAny <IDebugState>()), Times.Exactly(3));

            Assert.AreEqual(3, writerList.Count);
            // Now ensure ordering is correct ;)
            Assert.AreEqual(state1.Object, writerList[0]);
            Assert.AreEqual(state2.Object, writerList[1]);
            // ensure end state last to dispatch ;)
            Assert.AreEqual(StateType.End, writerList[2].StateType);
        }
示例#13
0
        /// <summary>
        /// Executes the specified errors.
        /// </summary>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        public override Guid Execute(out ErrorResultTO errors)
        {
            errors = new ErrorResultTO();
            // WorkflowApplicationFactory wfFactor = new WorkflowApplicationFactory();
            Guid result = GlobalConstants.NullDataListID;



            // Set Service Name
            DataObject.ServiceName = ServiceAction.ServiceName;

            // Set server ID, only if not set yet - original server;
            if (DataObject.ServerID == Guid.Empty)
            {
                DataObject.ServerID = HostSecurityProvider.Instance.ServerID;
            }

            // Set resource ID, only if not set yet - original resource;
            if (DataObject.ResourceID == Guid.Empty && ServiceAction != null && ServiceAction.Service != null)
            {
                DataObject.ResourceID = ServiceAction.Service.ID;
            }

            // Travis : Now set Data List
            DataObject.DataList = ServiceAction.DataListSpecification;
            // Set original instance ID, only if not set yet - original resource;
            if (DataObject.OriginalInstanceID == Guid.Empty)
            {
                DataObject.OriginalInstanceID = DataObject.DataListID;
            }
            Dev2Logger.Log.Info(String.Format("Started Execution for Service Name:{0} Resource Id:{1} Mode:{2}", DataObject.ServiceName, DataObject.ResourceID, DataObject.IsDebug?"Debug":"Execute"));
            //Set execution origin
            if (!string.IsNullOrWhiteSpace(DataObject.ParentServiceName))
            {
                DataObject.ExecutionOrigin            = ExecutionOrigin.Workflow;
                DataObject.ExecutionOriginDescription = DataObject.ParentServiceName;
            }
            else if (DataObject.IsDebug)
            {
                DataObject.ExecutionOrigin = ExecutionOrigin.Debug;
            }
            else
            {
                DataObject.ExecutionOrigin = ExecutionOrigin.External;
            }

            try
            {
                // BUG 9304 - 2013.05.08 - TWR - Added CompileExpressions
                //_workflowHelper.CompileExpressions(theActivity,DataObject.ResourceID);

                //IDSFDataObject exeResult = wfFactor.InvokeWorkflow(activity.Value, DataObject,
                //                                                   new List<object> { EsbChannel, }, instanceId,
                //                                                   TheWorkspace, bookmark, out errors);
                var             wfappUtils = new WfApplicationUtils();
                IExecutionToken exeToken   = new ExecutionToken {
                    IsUserCanceled = false
                };
                DataObject.ExecutionToken = exeToken;
                ErrorResultTO invokeErrors;
                if (DataObject.IsDebugMode())
                {
                    wfappUtils.DispatchDebugState(DataObject, StateType.Start, DataObject.Environment.HasErrors(), DataObject.Environment.FetchErrors(), out invokeErrors, null, true);
                }
                Eval(DataObject.ResourceID, DataObject);
                if (DataObject.IsDebugMode())
                {
                    wfappUtils.DispatchDebugState(DataObject, StateType.End, DataObject.Environment.HasErrors(), DataObject.Environment.FetchErrors(), out invokeErrors, DateTime.Now, false, true);
                }
                result = DataObject.DataListID;
            }
            catch (InvalidWorkflowException iwe)
            {
                Dev2Logger.Log.Error(iwe);
                var msg = iwe.Message;

                int start = msg.IndexOf("Flowchart ", StringComparison.Ordinal);

                // trap the no start node error so we can replace it with something nicer ;)
                errors.AddError(start > 0 ? GlobalConstants.NoStartNodeError : iwe.Message);
            }
            catch (Exception ex)
            {
                Dev2Logger.Log.Error(ex);
                errors.AddError(ex.Message);
            }
            finally
            {
                //ServiceAction.PushActivity(activity);
            }
            Dev2Logger.Log.Info(String.Format("Completed Execution for Service Name:{0} Resource Id: {1} Mode:{2}", DataObject.ServiceName, DataObject.ResourceID, DataObject.IsDebug?"Debug":"Execute"));
            return(result);
        }
示例#14
0
        Guid ExecuteWf(ErrorResultTO to, IServiceTestModelTO test)
        {
            Guid          result       = new Guid();
            var           wfappUtils   = new WfApplicationUtils();
            ErrorResultTO invokeErrors = new ErrorResultTO();
            var           resourceId   = DataObject.ResourceID;

            if (test?.Inputs != null)
            {
                AddRecordsetsInputs(test.Inputs.Where(input => DataListUtil.IsValueRecordset(input.Variable) && !input.Variable.Contains("@")), DataObject.Environment);
                foreach (var input in test.Inputs)
                {
                    var variable = DataListUtil.AddBracketsToValueIfNotExist(input.Variable);
                    var value    = input.Value;
                    if (variable.StartsWith("[[@"))
                    {
                        var jContainer = JsonConvert.DeserializeObject(value) as JObject;
                        DataObject.Environment.AddToJsonObjects(variable, jContainer);
                    }
                    else if (!DataListUtil.IsValueRecordset(input.Variable))
                    {
                        string errorMessage;
                        if (ExecutionEnvironment.IsValidVariableExpression(input.Value, out errorMessage, 0))
                        {
                            DataObject.Environment.AllErrors.Add("Cannot use variables as input value.");
                        }
                        else
                        {
                            if (!input.EmptyIsNull || !string.IsNullOrEmpty(value))
                            {
                                DataObject.Environment.Assign(variable, value, 0);
                            }
                        }
                    }
                }
            }
            Dev2JsonSerializer serializer = new Dev2JsonSerializer();

            try
            {
                IExecutionToken exeToken = new ExecutionToken {
                    IsUserCanceled = false
                };
                DataObject.ExecutionToken = exeToken;

                if (DataObject.IsDebugMode())
                {
                    var debugState = wfappUtils.GetDebugState(DataObject, StateType.Start, DataObject.Environment.HasErrors(), DataObject.Environment.FetchErrors(), invokeErrors, DateTime.Now, true, false, false);
                    wfappUtils.WriteDebug(DataObject, debugState);
                }

                var testRunResult = Eval(resourceId, DataObject, test);

                if (DataObject.IsDebugMode())
                {
                    if (!DataObject.StopExecution)
                    {
                        var       debugState      = wfappUtils.GetDebugState(DataObject, StateType.End, DataObject.Environment.HasErrors(), DataObject.Environment.FetchErrors(), invokeErrors, DataObject.StartTime, false, true, true);
                        DebugItem outputDebugItem = new DebugItem();
                        if (test != null)
                        {
                            var msg = test.FailureMessage;
                            if (test.TestPassed)
                            {
                                msg = Warewolf.Resource.Messages.Messages.Test_PassedResult;
                            }
                            outputDebugItem.AddRange(new DebugItemServiceTestStaticDataParams(msg, test.TestFailing).GetDebugItemResult());
                        }
                        debugState.AssertResultList.Add(outputDebugItem);
                        wfappUtils.WriteDebug(DataObject, debugState);
                    }
                    var testAggregateDebugState = wfappUtils.GetDebugState(DataObject, StateType.TestAggregate, false, string.Empty, new ErrorResultTO(), DataObject.StartTime, false, false, false);
                    AggregateTestResult(resourceId, test);

                    DebugItem itemToAdd = new DebugItem();
                    if (test != null)
                    {
                        var msg = test.FailureMessage;
                        if (test.TestPassed)
                        {
                            msg = Warewolf.Resource.Messages.Messages.Test_PassedResult;
                        }
                        itemToAdd.AddRange(new DebugItemServiceTestStaticDataParams(msg, test.TestFailing).GetDebugItemResult());
                    }
                    testAggregateDebugState.AssertResultList.Add(itemToAdd);
                    wfappUtils.WriteDebug(DataObject, testAggregateDebugState);

                    if (testRunResult != null)
                    {
                        if (test != null)
                        {
                            test.Result.DebugForTest = TestDebugMessageRepo.Instance.FetchDebugItems(resourceId, test.TestName);
                        }
                        _request.ExecuteResult = serializer.SerializeToBuilder(testRunResult);
                    }
                }
                else
                {
                    AggregateTestResult(resourceId, test);
                    if (test != null)
                    {
                        _request.ExecuteResult = serializer.SerializeToBuilder(test);
                    }
                }
                result = DataObject.DataListID;
            }
            catch (InvalidWorkflowException iwe)
            {
                Dev2Logger.Error(iwe);
                var msg = iwe.Message;

                int start = msg.IndexOf("Flowchart ", StringComparison.Ordinal);
                to?.AddError(start > 0 ? GlobalConstants.NoStartNodeError : iwe.Message);
                var failureMessage = DataObject.Environment.FetchErrors();
                wfappUtils.DispatchDebugState(DataObject, StateType.End, DataObject.Environment.HasErrors(), failureMessage, out invokeErrors, DataObject.StartTime, false, true);

                // ReSharper disable once PossibleNullReferenceException
                test.TestFailing = false;
                test.TestPassed  = false;
                test.TestPending = false;
                test.TestInvalid = true;
                test.LastRunDate = DateTime.Now;


                Common.Utilities.PerformActionInsideImpersonatedContext(Common.Utilities.ServerUser, () => { TestCatalog.Instance.SaveTest(resourceId, test); });

                var testRunResult = new TestRunResult {
                    TestName = test.TestName
                };
                if (test.TestInvalid)
                {
                    testRunResult.RunTestResult = RunResult.TestInvalid;
                    testRunResult.Message       = failureMessage;
                    Dev2Logger.Error($"Test {DataObject.TestName} for Resource {DataObject.ServiceName} ID {DataObject.ResourceID} marked invalid in exception for no start node");
                }
                testRunResult.DebugForTest = TestDebugMessageRepo.Instance.FetchDebugItems(resourceId, test.TestName);
                if (_request != null)
                {
                    _request.ExecuteResult = serializer.SerializeToBuilder(testRunResult);
                }
            }
            catch (Exception ex)
            {
                Dev2Logger.Error(ex);
                to.AddError(ex.Message);
                var failureMessage = DataObject.Environment.FetchErrors();
                wfappUtils.DispatchDebugState(DataObject, StateType.End, DataObject.Environment.HasErrors(), failureMessage, out invokeErrors, DataObject.StartTime, false, true);
                // ReSharper disable once PossibleNullReferenceException
                test.TestFailing = false;
                test.TestPassed  = false;
                test.TestPending = false;
                test.TestInvalid = true;
                test.LastRunDate = DateTime.Now;


                Common.Utilities.PerformActionInsideImpersonatedContext(Common.Utilities.ServerUser, () => { TestCatalog.Instance.SaveTest(resourceId, test); });

                var testRunResult = new TestRunResult {
                    TestName = test.TestName
                };
                if (test.TestInvalid)
                {
                    testRunResult.RunTestResult = RunResult.TestInvalid;
                    testRunResult.Message       = ex.Message;
                    Dev2Logger.Error($"Test {DataObject.TestName} for Resource {DataObject.ServiceName} ID {DataObject.ResourceID} marked invalid in general exception");
                }
                testRunResult.DebugForTest = TestDebugMessageRepo.Instance.FetchDebugItems(resourceId, test.TestName);
                _request.ExecuteResult     = serializer.SerializeToBuilder(testRunResult);
            }
            return(result);
        }
示例#15
0
        Guid TryExecuteWf(ErrorResultTO to, IServiceTestModelTO test)
        {
            var result       = new Guid();
            var wfappUtils   = new WfApplicationUtils();
            var invokeErrors = new ErrorResultTO();
            var resourceId   = DataObject.ResourceID;

            if (test?.Inputs != null)
            {
                AddRecordsetsInputs(test.Inputs.Where(input => DataListUtil.IsValueRecordset(input.Variable) && !input.Variable.Contains("@")), DataObject.Environment);
                foreach (var input in test.Inputs)
                {
                    var variable = DataListUtil.AddBracketsToValueIfNotExist(input.Variable);
                    var value    = input.Value;
                    if (variable.StartsWith("[[@"))
                    {
                        var jContainer = JsonConvert.DeserializeObject(value) as JObject;
                        DataObject.Environment.AddToJsonObjects(variable, jContainer);
                    }
                    else
                    {
                        AddToRecordsetObjects(input, variable, value);
                    }
                }
            }
            var serializer = new Dev2JsonSerializer();

            try
            {
                result = ExecuteWf(test, wfappUtils, invokeErrors, resourceId, serializer);
            }
            catch (InvalidWorkflowException iwe)
            {
                Dev2Logger.Error(iwe, DataObject.ExecutionID.ToString());
                var msg = iwe.Message;

                var start = msg.IndexOf("Flowchart ", StringComparison.Ordinal);
                to?.AddError(start > 0 ? GlobalConstants.NoStartNodeError : iwe.Message);
                var failureMessage = DataObject.Environment.FetchErrors();
                wfappUtils.DispatchDebugState(DataObject, StateType.End, DataObject.Environment.HasErrors(), failureMessage, out invokeErrors, DataObject.StartTime, false, true);


                test.TestFailing = false;
                test.TestPassed  = false;
                test.TestPending = false;
                test.TestInvalid = true;
                test.LastRunDate = DateTime.Now;


                Common.Utilities.PerformActionInsideImpersonatedContext(Common.Utilities.ServerUser, () => { TestCatalog.Instance.SaveTest(resourceId, test); });

                var testRunResult = new TestRunResult {
                    TestName = test.TestName
                };
                if (test.TestInvalid)
                {
                    testRunResult.RunTestResult = RunResult.TestInvalid;
                    testRunResult.Message       = failureMessage;
                    Dev2Logger.Error($"Test {DataObject.TestName} for Resource {DataObject.ServiceName} ID {DataObject.ResourceID} marked invalid in exception for no start node", DataObject.ExecutionID.ToString());
                }
                testRunResult.DebugForTest = TestDebugMessageRepo.Instance.FetchDebugItems(resourceId, test.TestName);
                if (_request != null)
                {
                    _request.ExecuteResult = serializer.SerializeToBuilder(testRunResult);
                }
            }
            catch (Exception ex)
            {
                Dev2Logger.Error(ex, GlobalConstants.WarewolfError);
                to.AddError(ex.Message);
                var failureMessage = DataObject.Environment.FetchErrors();
                wfappUtils.DispatchDebugState(DataObject, StateType.End, DataObject.Environment.HasErrors(), failureMessage, out invokeErrors, DataObject.StartTime, false, true);

                test.TestFailing = false;
                test.TestPassed  = false;
                test.TestPending = false;
                test.TestInvalid = true;
                test.LastRunDate = DateTime.Now;


                Common.Utilities.PerformActionInsideImpersonatedContext(Common.Utilities.ServerUser, () => { TestCatalog.Instance.SaveTest(resourceId, test); });

                var testRunResult = new TestRunResult {
                    TestName = test.TestName
                };
                if (test.TestInvalid)
                {
                    testRunResult.RunTestResult = RunResult.TestInvalid;
                    testRunResult.Message       = ex.Message;
                    Dev2Logger.Error($"Test {DataObject.TestName} for Resource {DataObject.ServiceName} ID {DataObject.ResourceID} marked invalid in general exception", GlobalConstants.WarewolfError);
                }
                testRunResult.DebugForTest = TestDebugMessageRepo.Instance.FetchDebugItems(resourceId, test.TestName);
                _request.ExecuteResult     = serializer.SerializeToBuilder(testRunResult);
            }
            return(result);
        }