Exemple #1
0
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            ErrorResultTO allErrors = new ErrorResultTO();

            try
            {
                var activity = ExecuteDecision(dataObject);
                NextNodes = new List <IDev2Activity> {
                    activity
                };
            }
            catch (Exception e)
            {
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfDecision", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                }
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.After, update);
                    _debugOutputs = new List <DebugItem>();
                }
            }
        }
Exemple #2
0
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            _debugOutputs.Clear();
            _debugInputs.Clear();

            InitializeDebug(dataObject);
            var errors    = new ErrorResultTO();
            var allErrors = new ErrorResultTO();

            try
            {
                if (!errors.HasErrors())
                {
                    var innerCount = 1;
                    foreach (AssignObjectDTO t in FieldsCollection)
                    {
                        innerCount = TryExecute(dataObject, update, allErrors, innerCount, t);
                    }
                    dataObject.Environment.CommitAssign();
                    allErrors.MergeErrors(errors);
                }
            }
            catch (Exception e)
            {
                //Dev2Logger.Error(e, GlobalConstants.WarewolfError);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                HandleErrors(dataObject, update, allErrors);
            }
        }
Exemple #3
0
        void HandleErrors(IDSFDataObject dataObject, int update, ErrorResultTO allErrors)
        {
            var hasErrors = allErrors.HasErrors();

            if (hasErrors)
            {
                DisplayAndWriteError("DsfExecuteCommandLineActivity", allErrors);
                foreach (var error in allErrors.FetchErrors())
                {
                    dataObject.Environment.AddError(error);
                }
            }
            if (dataObject.IsDebugMode())
            {
                if (hasErrors)
                {
                    var innerCount = 1;
                    foreach (GatherSystemInformationTO item in SystemInformationCollection)
                    {
                        var itemToAdd = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), itemToAdd);
                        AddDebugItem(new DebugEvalResult(item.Result, "", dataObject.Environment, update), itemToAdd);
                        _debugOutputs.Add(itemToAdd);
                        innerCount++;
                    }
                }

                DispatchDebugState(dataObject, StateType.Before, update);
                DispatchDebugState(dataObject, StateType.After, update);
            }
        }
        private void UpdateDatalist(IDSFDataObject dataObject, int update, ErrorResultTO allErrors)
        {
            var colItr = new WarewolfListIterator();

            var dtItr = CreateDataListEvaluateIterator(string.IsNullOrEmpty(DateTime) ? GlobalConstants.CalcExpressionNow : DateTime, dataObject.Environment, update);

            colItr.AddVariableToIterateOn(dtItr);
            var ifItr = CreateDataListEvaluateIterator(InputFormat, dataObject.Environment, update);

            colItr.AddVariableToIterateOn(ifItr);
            var ofItr = CreateDataListEvaluateIterator(OutputFormat, dataObject.Environment, update);

            colItr.AddVariableToIterateOn(ofItr);
            var tmaItr = CreateDataListEvaluateIterator(TimeModifierAmountDisplay, dataObject.Environment, update);

            colItr.AddVariableToIterateOn(tmaItr);

            if (!allErrors.HasErrors())
            {
                while (colItr.HasMoreData())
                {
                    var transObj = ConvertToDateTimeTo(colItr.FetchNextValue(dtItr),
                                                       colItr.FetchNextValue(ifItr),
                                                       colItr.FetchNextValue(ofItr),
                                                       TimeModifierType,
                                                       colItr.FetchNextValue(tmaItr)
                                                       );

                    var    format = DateTimeConverterFactory.CreateFormatter();
                    string result;
                    string error;
                    if (format.TryFormat(transObj, out result, out error))
                    {
                        var expression = Result;
                        dataObject.Environment.Assign(expression, result, update);
                    }
                    else
                    {
                        allErrors.AddError(error);
                    }
                }
                if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                {
                    AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Resumed the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="bookmark">The bookmark.</param>
        /// <param name="value">The value.</param>
        /// <exception cref="System.Exception">
        /// Parent and Child DataList IDs are the same, aborting resumption!
        /// or
        /// Fatal Error : Cannot merge resumed data
        /// or
        /// Fatal Error : Cannot locate Root DataList for resumption!
        /// </exception>
        public virtual void Resumed(NativeActivityContext context, Bookmark bookmark, object value)
        {
            IDSFDataObject    myDO          = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler      = DataListFactory.CreateDataListCompiler();
            ErrorResultTO     errorResultTO = new ErrorResultTO();
            Guid executionID = myDO.DataListID;

            if (value != null)
            {
                Guid rootID;
                Guid.TryParse(value.ToString(), out rootID);

                if (executionID == rootID)
                {
                    throw new Exception("Parent and Child DataList IDs are the same, aborting resumption!");
                }

                try
                {
                    /* Now perform the shape.... */

                    // First set the parentID on executionID to rootID.. so the shape happens correctly ;)
                    compiler.SetParentID(rootID, executionID);
                    // Next shape the execution result into the root datalist ;)
                    ErrorResultTO tmpErrors;
                    Guid          shapeID = compiler.Shape(rootID, enDev2ArgumentType.Output, OutputMapping, out tmpErrors);
                    errorResultTO.MergeErrors(tmpErrors);

                    // set parent instanceID
                    myDO.DataListID = executionID; // reset the DataListID accordingly

                    if (shapeID != executionID)
                    {
                        throw new Exception("Fatal Error : Cannot merge resumed data");
                    }


                    compiler.ConditionalMerge(DataListMergeFrequency.Always | DataListMergeFrequency.OnResumption,
                                              myDO.DatalistOutMergeID, myDO.DataListID, myDO.DatalistOutMergeFrequency, myDO.DatalistOutMergeType, myDO.DatalistOutMergeDepth);
                    ExecutionStatusCallbackDispatcher.Instance.Post(myDO.BookmarkExecutionCallbackID, ExecutionStatusCallbackMessageType.ResumedCallback);
                }
                finally
                {
                    // At resumption this is the root dl entry ;)

                    // Handle Errors
                    if (errorResultTO.HasErrors())
                    {
                        DisplayAndWriteError("Resumption", errorResultTO);
                        var errorString = errorResultTO.MakeDataListReady();
                        myDO.Environment.AddError(errorString);
                    }
                }
            }
            else
            {
                throw new Exception("Fatal Error : Cannot locate Root DataList for resumption!");
            }
        }
Exemple #6
0
        List <DebugItem> CreateDebugInputs(IExecutionEnvironment env)
        {
            var result = new List <IDebugItem>();

            var allErrors = new ErrorResultTO();

            try
            {
                var dds       = Conditions;
                var userModel = dds.GenerateToolLabel(env, dds.Mode, out ErrorResultTO error);
                allErrors.MergeErrors(error);

                foreach (Dev2Decision dev2Decision in dds.TheStack)
                {
                    AddInputDebugItemResultsAfterEvaluate(result, ref userModel, env, dev2Decision.Col1, out error);
                    allErrors.MergeErrors(error);
                    AddInputDebugItemResultsAfterEvaluate(result, ref userModel, env, dev2Decision.Col2, out error);
                    allErrors.MergeErrors(error);
                    AddInputDebugItemResultsAfterEvaluate(result, ref userModel, env, dev2Decision.Col3, out error);
                    allErrors.MergeErrors(error);
                }

                var itemToAdd = new DebugItem();

                userModel = userModel.Replace("OR", " OR\r\n")
                            .Replace("AND", " AND\r\n")
                            .Replace("\r\n ", "\r\n")
                            .Replace("\r\n\r\n", "\r\n")
                            .Replace("  ", " ");

                AddDebugItem(new DebugItemStaticDataParams(userModel, "Statement"), itemToAdd);
                result.Add(itemToAdd);

                itemToAdd = new DebugItem();
                AddDebugItem(new DebugItemStaticDataParams(dds.Mode == Dev2DecisionMode.AND ? "YES" : "NO", "Require all decisions to be true"), itemToAdd);
                result.Add(itemToAdd);
            }
            catch (JsonSerializationException e)
            {
                Dev2Logger.Warn(e.Message, "Warewolf Warn");
            }
            catch (Exception e)
            {
                allErrors.AddError(e.Message);
            }
            finally
            {
                if (allErrors.HasErrors())
                {
                    var serviceName = GetType().Name;
                    DisplayAndWriteError(serviceName, allErrors);
                }
            }

            var val = result.Select(a => a as DebugItem).ToList();

            _inner?.SetDebugInputs(val);
            return(val);
        }
        /// <summary>
        /// Executes the sub request.
        /// </summary>
        /// <param name="dataObject">The data object.</param>
        /// <param name="workspaceId">The workspace unique identifier.</param>
        /// <param name="inputDefs">The input defs.</param>
        /// <param name="outputDefs">The output defs.</param>
        /// <param name="errors">The errors.</param>
        /// <param name="update"></param>
        /// <param name="handleErrors"> buble up errors or not</param>
        /// <returns></returns>
        public IExecutionEnvironment ExecuteSubRequest(IDSFDataObject dataObject, Guid workspaceId, string inputDefs, string outputDefs, out ErrorResultTO errors, int update, bool handleErrors)
        {
            var           theWorkspace = WorkspaceRepository.Instance.Get(workspaceId);
            var           invoker      = CreateEsbServicesInvoker(theWorkspace);
            ErrorResultTO invokeErrors;
            var           oldID = dataObject.DataListID;

            errors = new ErrorResultTO();

            // local non-scoped execution ;)
            var isLocal = !dataObject.IsRemoteWorkflow();

            var principle = Thread.CurrentPrincipal;

            Dev2Logger.Log.Info("SUB-EXECUTION USER CONTEXT IS [ " + principle.Identity.Name + " ] FOR SERVICE  [ " + dataObject.ServiceName + " ]");

            if (dataObject.RunWorkflowAsync)
            {
                ExecuteRequestAsync(dataObject, inputDefs, invoker, isLocal, oldID, out invokeErrors, update);
                errors.MergeErrors(invokeErrors);
            }
            else
            {
                if (isLocal)
                {
                    if (GetResource(workspaceId, dataObject.ResourceID) == null && GetResource(workspaceId, dataObject.ServiceName) == null)
                    {
                        errors.AddError(string.Format("Resource {0} not found.", dataObject.ServiceName));
                        return(null);
                    }
                }

                var executionContainer = invoker.GenerateInvokeContainer(dataObject, dataObject.ServiceName, isLocal, oldID);
                if (executionContainer != null)
                {
                    CreateNewEnvironmentFromInputMappings(dataObject, inputDefs, update);
                    if (!isLocal)
                    {
                        SetRemoteExecutionDataList(dataObject, executionContainer, errors);
                    }
                    if (!errors.HasErrors())
                    {
                        executionContainer.InstanceInputDefinition  = inputDefs;
                        executionContainer.InstanceOutputDefinition = outputDefs;
                        executionContainer.Execute(out invokeErrors, update);
                        var env = UpdatePreviousEnvironmentWithSubExecutionResultUsingOutputMappings(dataObject, outputDefs, update, handleErrors, errors);

                        errors.MergeErrors(invokeErrors);
                        string errorString = dataObject.Environment.FetchErrors();
                        invokeErrors = ErrorResultTO.MakeErrorResultFromDataListString(errorString);
                        errors.MergeErrors(invokeErrors);
                        return(env);
                    }
                    errors.AddError(string.Format("Resource {0} not found.", dataObject.ServiceName));
                }
            }
            return(new ExecutionEnvironment());
        }
Exemple #8
0
        private (IEnumerable <INameValue> head, string query, string data, IEnumerable <IFormDataParameters> conditions) GetEnvironmentInputVariables(IExecutionEnvironment environment, int update)
        {
            IEnumerable <INameValue> head = null;

            if (Headers != null)
            {
                head = Headers.Select(a => new NameValue(ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval(a.Name, update)), ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval(a.Value, update))));
                if (IsFormDataChecked)
                {
                    var headersHelper = new WebRequestHeadersHelper(notEvaluatedHeaders: Headers, evaluatedHeaders: head);
                    head = headersHelper.CalculateFormDataContentType();
                }
            }
            var query = string.Empty;

            if (QueryString != null)
            {
                query = ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval(QueryString, update));
            }
            var postData = string.Empty;

            if (PostData != null && IsManualChecked)
            {
                postData = ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval(PostData, update, true));
            }
            var conditions = new List <IFormDataParameters>();

            if ((Conditions ?? (Conditions = new List <FormDataConditionExpression>())).Any() && IsFormDataChecked)
            {
                _errorsTo  = new ErrorResultTO();
                conditions = Conditions.SelectMany(o => o.Eval(GetArgumentsFunc, _errorsTo.HasErrors())).ToList();
            }

            IEnumerable <string[]> GetArgumentsFunc(string col1s, string col2s, string col3s)
            {
                var col1 = environment.EvalAsList(col1s, 0, true);
                var col2 = environment.EvalAsList(col2s ?? "", 0, true);
                var col3 = environment.EvalAsList(col3s ?? "", 0, true);

                var iter = new WarewolfListIterator();
                var c1   = new WarewolfAtomIterator(col1);
                var c2   = new WarewolfAtomIterator(col2);
                var c3   = new WarewolfAtomIterator(col3);

                iter.AddVariableToIterateOn(c1);
                iter.AddVariableToIterateOn(c2);
                iter.AddVariableToIterateOn(c3);

                while (iter.HasMoreData())
                {
                    var item = new[] { iter.FetchNextValue(c1), iter.FetchNextValue(c2), iter.FetchNextValue(c3) };
                    yield return(item);
                }
                yield break;
            }

            return(head, query, postData, conditions);
        }
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            ErrorResultTO allErrors     = new ErrorResultTO();
            ErrorResultTO errorResultTo = new ErrorResultTO();

            allErrors.MergeErrors(errorResultTo);

            try
            {
                if (!errorResultTo.HasErrors())
                {
                    if (allErrors.HasErrors())
                    {
                        return;
                    }
                    allErrors.MergeErrors(errorResultTo);
                    if (allErrors.HasErrors())
                    {
                        return;
                    }

                    if (dataObject.IsDebugMode())
                    {
                        AddDebugInputItem(Script, dataObject.Environment, update);
                    }



                    allErrors.MergeErrors(errorResultTo);
                }
            }
            catch (Exception e)
            {
                allErrors.AddError(e.GetType() == typeof(NullReferenceException) ? "There was an error when returning a value from the javascript, remember to use the 'Return' keyword when returning the result" : e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfScriptingJavaScriptActivity", allErrors);
                    dataObject.Environment.AddError(allErrors.MakeDataListReady());
                    dataObject.Environment.Assign(Result, null, update);
                }

                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }

                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
Exemple #10
0
        void TryExecute(IDSFDataObject dataObject, int update, ErrorResultTO allErrors)
        {
            var indexCounter = 0;

            CleanArgs();

            foreach (GatherSystemInformationTO item in SystemInformationCollection)
            {
                try
                {
                    if (dataObject.IsDebugMode())
                    {
                        var inputToAdd = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams("", (++indexCounter).ToString(CultureInfo.InvariantCulture)), inputToAdd);
                        AddDebugItem(new DebugItemStaticDataParams("", dataObject.Environment.EvalToExpression(item.Result, update), "", "="), inputToAdd);
                        AddDebugItem(new DebugItemStaticDataParams(item.EnTypeOfSystemInformation.GetDescription(), ""), inputToAdd);
                        _debugInputs.Add(inputToAdd);
                    }

                    var hasErrors = allErrors.HasErrors();
                    if (!hasErrors)
                    {
                        ExecuteForTO(dataObject, update, allErrors, item);
                    }
                }
                catch (Exception err)
                {
                    dataObject.Environment.Assign(item.Result, null, update);
                    allErrors.AddError(err.Message);
                }
            }
            dataObject.Environment.CommitAssign();
            if (dataObject.IsDebugMode() && !allErrors.HasErrors())
            {
                var innerCount = 1;
                foreach (GatherSystemInformationTO item in SystemInformationCollection)
                {
                    var itemToAdd = new DebugItem();
                    AddDebugItem(new DebugItemStaticDataParams("", "", innerCount.ToString(CultureInfo.InvariantCulture)), itemToAdd);
                    AddDebugItem(new DebugEvalResult(item.Result, "", dataObject.Environment, update), itemToAdd);
                    _debugOutputs.Add(itemToAdd);
                    innerCount++;
                }
            }
        }
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            var  errorResultTo           = new ErrorResultTO();
            var  allErrors               = new ErrorResultTO();
            bool addExceptionToErrorList = true;

            InitializeDebug(dataObject);
            try
            {
                IWarewolfIterator batchItr;
                IWarewolfIterator timeoutItr;
                var parametersIteratorCollection = BuildParametersIteratorCollection(dataObject.Environment, out batchItr, out timeoutItr, update);

                var currentOptions  = BuildSqlBulkCopyOptions();
                var runtimeDatabase = ResourceCatalog.Instance.GetResource <DbSource>(dataObject.WorkspaceID, Database.ResourceID);
                if (runtimeDatabase.ServerType == enSourceType.MySqlDatabase)
                {
                    DoInsertForMySql(runtimeDatabase, currentOptions, parametersIteratorCollection, batchItr, timeoutItr, dataObject, errorResultTo, allErrors, ref addExceptionToErrorList, update);
                }
                else
                {
                    DoInsertForSqlServer(runtimeDatabase, currentOptions, dataObject, allErrors, batchItr, parametersIteratorCollection, timeoutItr, ref errorResultTo, ref addExceptionToErrorList, update);
                }

                allErrors.MergeErrors(errorResultTo);
            }
            catch (Exception e)
            {
                if (addExceptionToErrorList)
                {
                    allErrors.AddError(e.Message);
                }
                // ReSharper disable InvokeAsExtensionMethod
                Dev2Logger.Log.Error(this, e);
                // ReSharper restore InvokeAsExtensionMethod
            }
            finally
            {
                // Handle Errors
                if (allErrors.HasErrors())
                {
                    DisplayAndWriteError("DsfSqlBulkInsertActivity", allErrors);
                    dataObject.Environment.Assign(Result, null, update);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("Failure", Result, "", "="));
                    }
                }
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
Exemple #12
0
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            var searchQuery = new SearchQuery(this, Result, RequireAllFieldsToMatch, RequireAllTrue);

            var allErrors = new ErrorResultTO();

            try
            {
                InitializeDebug(dataObject);
                var searchContext = new SearchContext(this);
                if (dataObject.IsDebugMode())
                {
                    TryAddDebugInputValues(dataObject, searchContext.ToSearch, ref allErrors, update);
                }

                searchQuery.Execute(searchContext, allErrors, dataObject, update);

                if (dataObject.IsDebugMode())
                {
                    if (DataListUtil.IsValueRecordset(Result))
                    {
                        var recVar = DataListUtil.ReplaceRecordsetBlankWithStar(Result);
                        AddDebugOutputItem(new DebugEvalResult(recVar, "", dataObject.Environment, update));
                    }
                    else
                    {
                        AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
                    }
                }
            }
            catch (Exception exception)
            {
                Dev2Logger.Error("DSFRecordsMultipleCriteria", exception, GlobalConstants.WarewolfError);
                allErrors.AddError(exception.Message);
            }
            finally
            {
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfFindRecordsMultipleCriteriaActivity", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                    dataObject.Environment.Assign(Result, "-1", update);
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
                    }
                }

                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
        public void ErrorResultsTOMakeErrorResultFromDataListStringWithMultipleErrorsExpectedCorrectErrorResultTO()
        {
            ErrorResultTO makeErrorResultFromDataListString = ErrorResultTO.MakeErrorResultFromDataListString("<InnerError>First Error</InnerError><InnerError>Second Error</InnerError>");

            Assert.IsTrue(makeErrorResultFromDataListString.HasErrors());
            Assert.AreEqual(2, makeErrorResultFromDataListString.FetchErrors().Count);
            Assert.AreEqual("First Error", makeErrorResultFromDataListString.FetchErrors()[0]);
            Assert.AreEqual("Second Error", makeErrorResultFromDataListString.FetchErrors()[1]);
        }
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            var allErrors = new ErrorResultTO();
            var errors    = new ErrorResultTO();

            allErrors.MergeErrors(errors);
            InitializeDebug(dataObject);
            // Process if no errors
            try
            {
                ValidateRecordsetName(RecordsetName, errors);
                allErrors.MergeErrors(errors);
                if (!allErrors.HasErrors())
                {
                    try
                    {
                        TryExecuteTool(dataObject, update, allErrors);
                    }
                    catch (Exception e)
                    {
                        AddDebugInputItem(new DebugItemStaticDataParams("", RecordsetName, "Recordset", "="));
                        allErrors.AddError(e.Message);
                        dataObject.Environment.Assign(CountNumber, "0", update);
                        AddDebugOutputItem(new DebugItemStaticDataParams("0", CountNumber, "", "="));
                    }
                }
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    var errorString = allErrors.MakeDataListReady();
                    dataObject.Environment.AddError(errorString);
                    DisplayAndWriteError(dataObject, DisplayName, allErrors);
                }
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
Exemple #15
0
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            AddScriptSourcePathsToList();
            var allErrors = new ErrorResultTO();
            var env       = dataObject.Environment;

            InitializeDebug(dataObject);
            try
            {
                TryExecute(dataObject, update, allErrors, env);
            }
            catch (NullReferenceException)
            {
                allErrors.AddError(ErrorResource.ScriptingErrorReturningValue);
            }
            catch (RuntimeBinderException e)
            {
                allErrors.AddError(e.Message.Replace(" for main:Object", string.Empty));
            }
            catch (Exception e)
            {
                allErrors.AddError(e.Message);
            }
            finally
            {
                if (allErrors.HasErrors())
                {
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                    DisplayAndWriteError(dataObject, DisplayName, allErrors);
                }

                if (dataObject.IsDebugMode())
                {
                    if (allErrors.HasErrors())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }

                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            AddScriptSourcePathsToList();
            var allErrors = new ErrorResultTO();
            var errors    = new ErrorResultTO();

            allErrors.MergeErrors(errors);
            var env = dataObject.Environment;

            InitializeDebug(dataObject);
            try
            {
                if (!errors.HasErrors())
                {
                    if (dataObject.IsDebugMode())
                    {
                        var language = ScriptType.GetDescription();
                        AddDebugInputItem(new DebugItemStaticDataParams(language, "Language"));
                        AddDebugInputItem(new DebugEvalResult(Script, "Script", env, update));
                    }

                    allErrors.MergeErrors(errors);

                    if (allErrors.HasErrors())
                    {
                        return;
                    }

                    TryExecute(dataObject, update, allErrors, env);
                }
            }
            catch (Exception e) when(e is NullReferenceException || e is RuntimeBinderException)
            {
                allErrors.AddError(e.GetType() == typeof(NullReferenceException) || e.GetType() == typeof(RuntimeBinderException) ? ErrorResource.ScriptingErrorReturningValue : e.Message.Replace(" for main:Object", string.Empty));
            }
            finally
            {
                // Handle Errors
                if (allErrors.HasErrors())
                {
                    DisplayAndWriteError("DsfScriptingPythonActivity", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                }

                if (dataObject.IsDebugMode())
                {
                    if (allErrors.HasErrors())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
        private void AddToErrorsToDebugOutput(IDSFDataObject dataObject, int update, IDev2MergeOperations mergeOperations, ErrorResultTO allErrors, ErrorResultTO errorResultTo)
        {
            dataObject.Environment.Assign(Result, mergeOperations.MergeData.ToString(), update);
            allErrors.MergeErrors(errorResultTo);

            if (dataObject.IsDebugMode() && !allErrors.HasErrors())
            {
                AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
            }
        }
        private void TryExecute(IDSFDataObject dataObject, int update, ErrorResultTO allErrors, ErrorResultTO errors, IExecutionEnvironment env)
        {
            CleanArgs();

            allErrors.MergeErrors(errors);

            var inputIndex  = 1;
            var outputIndex = 1;

            foreach (ICaseConvertTO item in ConvertCollection.Where(a => !String.IsNullOrEmpty(a.StringToConvert)))
            {
                IsSingleValueRule.ApplyIsSingleValueRule(item.ExpressionToConvert, allErrors);
                if (dataObject.IsDebugMode())
                {
                    var debugItem = new DebugItem();
                    AddDebugItem(new DebugItemStaticDataParams("", inputIndex.ToString(CultureInfo.InvariantCulture)), debugItem);
                    AddDebugItem(new DebugEvalResult(item.StringToConvert, "Convert", env, update), debugItem);
                    AddDebugItem(new DebugItemStaticDataParams(item.ConvertType, "To"), debugItem);
                    _debugInputs.Add(debugItem);
                    inputIndex++;
                }
                if (!allErrors.HasErrors())
                {
                    try
                    {
                        env.ApplyUpdate(item.StringToConvert, TryConvertFunc(item, env, update), update);
                    }
                    catch (Exception e)
                    {
                        allErrors.AddError(e.Message);
                    }

                    if (!allErrors.HasErrors() && dataObject.IsDebugMode())
                    {
                        var debugItem = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams("", outputIndex.ToString(CultureInfo.InvariantCulture)), debugItem);
                        AddDebugItem(new DebugEvalResult(item.StringToConvert, "", env, update), debugItem);
                        _debugOutputs.Add(debugItem);
                        outputIndex++;
                    }
                }
            }
        }
Exemple #19
0
        /// <summary>
        /// Creates a binary data list from XML data.
        /// </summary>
        /// <param name="xmlDataList">The XML data list.</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        private IBinaryDataList CreateBinaryDataListFromXmlData(string xmlDataList, out ErrorResultTO errors)
        {
            IBinaryDataList result    = null;
            ErrorResultTO   allErrors = new ErrorResultTO();

            errors = new ErrorResultTO();
            Guid dlGuid = _compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._Studio_XML), xmlDataList, xmlDataList, out errors);

            if (!errors.HasErrors())
            {
                result = _compiler.FetchBinaryDataList(dlGuid, out errors);
                if (errors.HasErrors())
                {
                    allErrors.MergeErrors(errors);
                }
            }
            _compiler.ForceDeleteDataListByID(dlGuid);
            return(result);
        }
Exemple #20
0
        private void DebugOutput(IDSFDataObject dataObject, int update, ErrorResultTO allErrors, string parentServiceName, string serviceName, Guid oldResourceId)
        {
            if (!dataObject.WorkflowResumeable || !dataObject.IsDataListScoped)
            {
                // Handle Errors
                if (allErrors.HasErrors())
                {
                    var env = dataObject.Environment;
                    foreach (var allError in allErrors.FetchErrors())
                    {
                        env.AddError(allError);
                    }

                    // add to datalist in variable specified
                    if (!String.IsNullOrEmpty(OnErrorVariable))
                    {
                        var errorString    = env.FetchErrors();
                        var errors         = ErrorResultTO.MakeErrorResultFromDataListString(errorString, true);
                        var upsertVariable = DataListUtil.AddBracketsToValueIfNotExist(OnErrorVariable);
                        if (errors.HasErrors())
                        {
                            foreach (var error in errors.FetchErrors())
                            {
                                //TODO: duplicate check on the Recordset might hide the real issue,
                                //of multiple execution calls passing here which seems not to be the same on F7
                                env.Assign(upsertVariable, error, update);
                            }
                        }
                        else
                        {
                            env.Assign(upsertVariable, errorString, update);
                        }
                    }
                    DisplayAndWriteError(dataObject, serviceName, allErrors);
                }
            }

            if (dataObject.IsDebugMode() || dataObject.RunWorkflowAsync && !dataObject.IsFromWebServer)
            {
                var dt = DateTime.Now;
                DispatchDebugState(dataObject, StateType.After, update, dt);
                ChildDebugStateDispatch(dataObject);
                _debugOutputs = new List <DebugItem>();
                DispatchDebugState(dataObject, StateType.Duration, update, dt);
            }

            dataObject.ParentInstanceID        = _previousInstanceId;
            dataObject.ParentServiceName       = parentServiceName;
            dataObject.ServiceName             = serviceName;
            dataObject.RemoteInvokeResultShape = new StringBuilder(); // reset targnet shape ;)
            dataObject.RunWorkflowAsync        = false;
            dataObject.RemoteInvokerID         = Guid.Empty.ToString();
            dataObject.EnvironmentID           = Guid.Empty;
            dataObject.ResourceID = oldResourceId;
        }
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            _debugOutputs.Clear();

            _isDebugMode = dataObject.IsDebugMode();
            var errors    = new ErrorResultTO();
            var allErrors = new ErrorResultTO();
            var parser    = new XPathParser();
            var i         = 0;

            InitializeDebug(dataObject);
            try
            {
                if (!string.IsNullOrEmpty(SourceString))
                {
                    if (_isDebugMode)
                    {
                        AddSourceStringDebugInputItem(SourceString, dataObject.Environment, update);
                        AddResultDebugInputs(ResultsCollection, out errors);
                        allErrors.MergeErrors(errors);
                    }
                    if (!allErrors.HasErrors())
                    {
                        i = Process(dataObject, update, i, parser, allErrors, errors);
                    }
                    DoDebug(dataObject, update, allErrors);
                }
            }
            catch (Exception ex)
            {
                allErrors.AddError(ex.Message);
            }
            finally
            {
                var actualIndex = i - 1;
                var hasErrors   = allErrors.HasErrors();
                ProcessErrors(dataObject, update, hasErrors, allErrors, actualIndex);

                DispatchDebugState(dataObject, StateType.Before, update);
                DispatchDebugState(dataObject, StateType.After, update);
            }
        }
Exemple #22
0
        private void HandleErrors(IDSFDataObject dataObject, ErrorResultTO allErrors)
        {
            if (allErrors.HasErrors())
            {
                dataObject.ParentInstanceID = _previousParentId;
                dataObject.ForEachNestingLevel--;
                dataObject.IsDebugNested = false;
                // Handle Errors
                if (allErrors.HasErrors())
                {
                    DisplayAndWriteError("DsfForEachActivity", allErrors);
                    foreach (var fetchError in allErrors.FetchErrors())
                    {
                        dataObject.Environment.AddError(fetchError);
                    }

                    dataObject.ParentInstanceID = _previousParentId;
                }
            }
        }
Exemple #23
0
        public void ErrorResultTO_AddError_NullMessage()
        {
            var resultTo = new ErrorResultTO();

            resultTo.AddError(null, true);

            Assert.IsFalse(resultTo.HasErrors());
            // Shouldn't this be passing?
            Assert.AreEqual(0, resultTo.FetchErrors().Count);
            Assert.AreEqual("", resultTo.MakeDataListReady());
        }
Exemple #24
0
        void TryExecute(IDSFDataObject dataObject, int update, ErrorResultTO allErrors)
        {
            IsSingleValueRule.ApplyIsSingleValueRule(Result, allErrors);

            AddValidationErrors(allErrors);

            if (!allErrors.HasErrors())
            {
                UpdateEnvironmentAndDebugOutput(dataObject, update, allErrors);
            }
        }
Exemple #25
0
        /// <summary>
        ///     Creates a binary data list from XML data.
        /// </summary>
        /// <param name="xmlDataList">The XML data list.</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        private IBinaryDataList CreateBinaryDataListFromXmlData(string xmlDataList, out ErrorResultTO errors)
        {
            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();
            IBinaryDataList   result   = null;
            var  allErrors             = new ErrorResultTO();
            Guid dlGuid = compiler.ConvertTo(
                DataListFormat.CreateFormat(GlobalConstants._Studio_XML), xmlDataList.ToStringBuilder(), xmlDataList.ToStringBuilder(), out errors);

            if (!errors.HasErrors())
            {
                result = compiler.FetchBinaryDataList(dlGuid, out errors);
                if (errors.HasErrors())
                {
                    allErrors.MergeErrors(errors);
                }
            }

            compiler.ForceDeleteDataListByID(dlGuid);
            return(result);
        }
Exemple #26
0
        /// <summary>
        /// this method exist for the datalist server port
        /// it is a crap way to upserting since it replicates all the existing functionality of the server, but it is the quickest
        /// and with an activity re-write coming, it is as good as it needs to be...
        /// </summary>
        /// <param name="outputs">The outputs.</param>
        /// <param name="dataListID">The data list unique identifier.</param>
        /// <param name="compiler">The compiler.</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        public Guid UpsertOutputs(IList <OutputTO> outputs, Guid dataListID, IDataListCompiler compiler, out ErrorResultTO errors)
        {
            ErrorResultTO    allErrors = new ErrorResultTO();
            ActivityUpsertTO toUpsert  = BinaryDataListEntryBuilder.CreateEntriesFromOutputTOs(outputs, compiler, dataListID, out errors);

            if (errors.HasErrors())
            {
                allErrors.MergeErrors(errors);
            }
            Guid result = compiler.Upsert(dataListID, toUpsert.FetchExpressions(), toUpsert.FetchBinaryEntries(), out errors);

            if (errors.HasErrors())
            {
                allErrors.MergeErrors(errors);
            }

            errors = allErrors;

            return(result);
        }
Exemple #27
0
        public void ErrorResultTO_AddError_CheckForDuplicates_True_AddSameError_ExpectLstToBeSame()
        {
            var resultTo = new ErrorResultTO();

            resultTo.AddError("some message", true);
            resultTo.AddError("some message", true);

            Assert.IsTrue(resultTo.HasErrors());
            Assert.AreEqual(1, resultTo.FetchErrors().Count);
            Assert.AreEqual("some message", resultTo.FetchErrors()[0]);
            Assert.AreEqual("<InnerError>some message</InnerError>", resultTo.MakeDataListReady());
        }
#pragma warning disable S1541 // Methods and properties should not be too complex
        private void TryExecute(IDSFDataObject dataObject, int update, ErrorResultTO allErrors, ErrorResultTO errors)
#pragma warning restore S1541 // Methods and properties should not be too complex
        {
            IsSingleValueRule.ApplyIsSingleValueRule(Result, allErrors);

            var colItr = new WarewolfListIterator();
            var iteratorPropertyDictionary = new Dictionary <string, IWarewolfIterator>();

            foreach (var propertyInfo in GetType().GetProperties().Where(info => info.IsDefined(typeof(Inputs))))
            {
                var attributes    = (Inputs[])propertyInfo.GetCustomAttributes(typeof(Inputs), false);
                var variableValue = propertyInfo.GetValue(this) as string;
                if (!string.IsNullOrEmpty(variableValue))
                {
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugInputItem(new DebugEvalResult(variableValue, attributes[0].UserVisibleName, dataObject.Environment, update));
                    }

                    var dtItr = CreateDataListEvaluateIterator(variableValue, dataObject.Environment, update);
                    colItr.AddVariableToIterateOn(dtItr);
                    iteratorPropertyDictionary.Add(propertyInfo.Name, dtItr);
                }
            }
            if (colItr.FieldCount <= 0)
            {
                var evaluatedValues = new Dictionary <string, string>();
                _executionResult = PerformExecution(evaluatedValues);
                AssignResult(dataObject, update);
            }
            else
            {
                while (colItr.HasMoreData())
                {
                    var evaluatedValues = new Dictionary <string, string>();
                    foreach (var dev2DataListEvaluateIterator in iteratorPropertyDictionary)
                    {
                        var binaryDataListItem = colItr.FetchNextValue(dev2DataListEvaluateIterator.Value);
                        evaluatedValues.Add(dev2DataListEvaluateIterator.Key, binaryDataListItem);
                    }
                    _executionResult = PerformExecution(evaluatedValues);
                    AssignResult(dataObject, update);
                }
            }

            if (dataObject.IsDebugMode() && !allErrors.HasErrors() && !string.IsNullOrWhiteSpace(Result) && dataObject.IsDebugMode() && !allErrors.HasErrors() && !string.IsNullOrEmpty(Result))
            {
                AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
            }


            allErrors.MergeErrors(errors);
        }
Exemple #29
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
        }
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            var allErrors = new ErrorResultTO();

            InitializeDebug(dataObject);
            try
            {
                AddValidationErrors(allErrors);
                if (!allErrors.HasErrors())
                {
                    if (dataObject.IsDebugMode())
                    {
                        ExecuteToolAddDebugItems(dataObject, update);
                    }
                    ExecuteRecordset(dataObject, update);
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Error("AdvancedRecordset", e, GlobalConstants.WarewolfError);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();

                if (hasErrors)
                {
                    DisplayAndWriteError("AdvancedRecordset", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                }
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }