Ejemplo n.º 1
0
        protected override void AddItemsToIterator(Guid executionId, IDataListCompiler compiler, List <ErrorResultTO> errors)
        {
            ErrorResultTO        error;
            IBinaryDataListEntry archPassEntry = compiler.Evaluate(executionId, enActionType.User, ArchivePassword, false,
                                                                   out error);

            errors.Add(error);
            _archPassItr = Dev2ValueObjectFactory.CreateEvaluateIterator(archPassEntry);
            ColItr.AddIterator(_archPassItr);
        }
Ejemplo n.º 2
0
        IDev2DataListEvaluateIterator CreateDataListEvaluateIterator(string expression, Guid executionId, IDataListCompiler compiler, IDev2IteratorCollection iteratorCollection, ErrorResultTO allErrors)
        {
            ErrorResultTO errors;

            IBinaryDataListEntry expressionEntry = compiler.Evaluate(executionId, enActionType.User, expression, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator expressionIterator = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionEntry);

            iteratorCollection.AddIterator(expressionIterator);

            return(expressionIterator);
        }
Ejemplo n.º 3
0
 void GetBatchSize(IDev2DataListEvaluateIterator batchItr, IDev2IteratorCollection parametersIteratorCollection, ref int batchSize)
 {
     if (batchItr != null)
     {
         var batchSizeString = parametersIteratorCollection.FetchNextRow(batchItr).TheValue;
         if (!String.IsNullOrEmpty(batchSizeString))
         {
             int parsedValue;
             if (int.TryParse(batchSizeString, out parsedValue))
             {
                 batchSize = parsedValue;
             }
         }
     }
     else
     {
         Int32.TryParse(BatchSize, out batchSize);
     }
 }
Ejemplo n.º 4
0
 void GetTimeOut(IDev2IteratorCollection parametersIteratorCollection, IDev2DataListEvaluateIterator timeoutItr, ref int timeout)
 {
     if (timeoutItr != null)
     {
         var timeoutString = parametersIteratorCollection.FetchNextRow(timeoutItr).TheValue;
         if (!String.IsNullOrEmpty(timeoutString))
         {
             int parsedValue;
             if (int.TryParse(timeoutString, out parsedValue))
             {
                 timeout = parsedValue;
             }
         }
     }
     else
     {
         Int32.TryParse(Timeout, out timeout);
     }
 }
Ejemplo n.º 5
0
        public SqlBulkCopy SetupSqlBulkCopy(IDev2DataListEvaluateIterator batchItr, IDev2IteratorCollection parametersIteratorCollection, IDev2DataListEvaluateIterator timeoutItr, DbSource runtimeDatabase, SqlBulkCopyOptions copyOptions)
        {
            var batchSize = -1;
            var timeout   = -1;

            GetParameterValuesForBatchSizeAndTimeOut(batchItr, parametersIteratorCollection, timeoutItr, ref batchSize, ref timeout);
            var sqlBulkCopy = new SqlBulkCopy(runtimeDatabase.ConnectionString, copyOptions)
            {
                DestinationTableName = TableName
            };

            if (batchSize != -1)
            {
                sqlBulkCopy.BatchSize = batchSize;
            }
            if (timeout != -1)
            {
                sqlBulkCopy.BulkCopyTimeout = timeout;
            }
            return(sqlBulkCopy);
        }
        public IBinaryDataListItem FetchNextRow(IDev2DataListEvaluateIterator itr)
        {
            IBinaryDataListItem         result = null;
            IList <IBinaryDataListItem> tmp;

            int idx = _itrCollection.IndexOf(itr);

            if (idx >= 0)
            {
                if (_itrCollection[idx].HasMoreRecords())
                {
                    tmp = _itrCollection[idx].FetchNextRowData();
                    if (tmp != null)
                    {
                        if (tmp.Count == 1)
                        {
                            result = tmp[0];
                        }
                        else if (tmp.Count == 0)
                        {
                            result = Dev2BinaryDataListFactory.CreateBinaryItem(string.Empty, string.Empty);
                        }
                        else if (tmp.Count > 1)
                        {
                            throw new Exception("Invalid use, iterator collection may only return a single column per row");
                        }
                    }
                }
                else
                {
                    tmp = _itrCollection[idx].FetchNextRowData();
                    if (tmp != null)
                    {
                        result = tmp[0];
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 7
0
        protected override IList <OutputTO> ExecuteConcreteAction(NativeActivityContext context, out ErrorResultTO allErrors)
        {
            IList <OutputTO>  outputs    = new List <OutputTO>();
            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();

            allErrors = new ErrorResultTO();
            ErrorResultTO           errors;
            Guid                    executionId = dataObject.DataListID;
            IDev2IteratorCollection colItr      = Dev2ValueObjectFactory.CreateIteratorCollection();

            //get all the possible paths for all the string variables
            IBinaryDataListEntry inputPathEntry = compiler.Evaluate(executionId, enActionType.User, InputPath, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator inputItr = Dev2ValueObjectFactory.CreateEvaluateIterator(inputPathEntry);

            colItr.AddIterator(inputItr);

            IBinaryDataListEntry usernameEntry = compiler.Evaluate(executionId, enActionType.User, Username, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator unameItr = Dev2ValueObjectFactory.CreateEvaluateIterator(usernameEntry);

            colItr.AddIterator(unameItr);

            IBinaryDataListEntry passwordEntry = compiler.Evaluate(executionId, enActionType.User, Password, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator passItr = Dev2ValueObjectFactory.CreateEvaluateIterator(passwordEntry);

            colItr.AddIterator(passItr);

            outputs.Add(DataListFactory.CreateOutputTO(Result));

            if (dataObject.IsDebugMode())
            {
                AddDebugInputItem(InputPath, "Input Path", inputPathEntry, executionId);
                AddDebugInputItemUserNamePassword(executionId, usernameEntry);
            }

            while (colItr.HasMoreData())
            {
                IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker();
                IActivityIOPath           IOpath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextRow(inputItr).TheValue,
                                                                                          colItr.FetchNextRow(unameItr).TheValue,
                                                                                          colItr.FetchNextRow(passItr).TheValue,
                                                                                          true);

                IActivityIOOperationsEndPoint endpoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(IOpath);
                try
                {
                    string result = broker.Get(endpoint);
                    outputs[0].OutputStrings.Add(result);
                }
                catch (Exception e)
                {
                    outputs[0].OutputStrings.Add(null);
                    allErrors.AddError(e.Message);
                    break;
                }
            }

            return(outputs);
        }
Ejemplo n.º 8
0
        protected override IList <OutputTO> ExecuteConcreteAction(NativeActivityContext context, out ErrorResultTO allErrors)
        {
            IsNotCertVerifiable = true;

            allErrors = new ErrorResultTO();
            IList <OutputTO> outputs    = new List <OutputTO>();
            IDSFDataObject   dataObject = context.GetExtension <IDSFDataObject>();

            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();

            ErrorResultTO           errors;
            Guid                    executionId = dataObject.DataListID;
            IDev2IteratorCollection colItr      = Dev2ValueObjectFactory.CreateIteratorCollection();

            //get all the possible paths for all the string variables
            IBinaryDataListEntry inputPathEntry = compiler.Evaluate(executionId, enActionType.User, InputPath, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator inputItr = Dev2ValueObjectFactory.CreateEvaluateIterator(inputPathEntry);

            colItr.AddIterator(inputItr);

            IBinaryDataListEntry usernameEntry = compiler.Evaluate(executionId, enActionType.User, Username, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator unameItr = Dev2ValueObjectFactory.CreateEvaluateIterator(usernameEntry);

            colItr.AddIterator(unameItr);

            IBinaryDataListEntry passwordEntry = compiler.Evaluate(executionId, enActionType.User, Password, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator passItr = Dev2ValueObjectFactory.CreateEvaluateIterator(passwordEntry);

            colItr.AddIterator(passItr);

            if (dataObject.IsDebugMode())
            {
                AddDebugInputItem(InputPath, "Input Path", inputPathEntry, executionId);
                AddDebugInputItem(new DebugItemStaticDataParams(GetReadType().GetDescription(), "Read"));
                AddDebugInputItemUserNamePassword(executionId, usernameEntry);
            }

            while (colItr.HasMoreData())
            {
                IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker();
                IActivityIOPath           ioPath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextRow(inputItr).TheValue,
                                                                                          colItr.FetchNextRow(unameItr).TheValue,
                                                                                          colItr.FetchNextRow(passItr).TheValue,
                                                                                          true);
                IActivityIOOperationsEndPoint endPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(ioPath);

                try
                {
                    IList <IActivityIOPath> listOfDir = broker.ListDirectory(endPoint, GetReadType());
                    if (DataListUtil.IsValueRecordset(Result) && DataListUtil.GetRecordsetIndexType(Result) != enRecordsetIndexType.Numeric)
                    {
                        if (DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Star)
                        {
                            string recsetName = DataListUtil.ExtractRecordsetNameFromValue(Result);
                            string fieldName  = DataListUtil.ExtractFieldNameFromValue(Result);

                            int indexToUpsertTo = 1;
                            if (listOfDir != null)
                            {
                                foreach (IActivityIOPath pa in listOfDir)
                                {
                                    string fullRecsetName = DataListUtil.CreateRecordsetDisplayValue(recsetName, fieldName,
                                                                                                     indexToUpsertTo.ToString(CultureInfo.InvariantCulture));
                                    outputs.Add(DataListFactory.CreateOutputTO(DataListUtil.AddBracketsToValueIfNotExist(fullRecsetName), pa.Path));
                                    indexToUpsertTo++;
                                }
                            }
                        }
                        else if (DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Blank)
                        {
                            if (listOfDir != null)
                            {
                                foreach (IActivityIOPath pa in listOfDir)
                                {
                                    outputs.Add(DataListFactory.CreateOutputTO(Result, pa.Path));
                                }
                            }
                        }
                    }
                    else
                    {
                        if (listOfDir != null)
                        {
                            string xmlList = string.Join(",", listOfDir.Select(c => c.Path));
                            outputs.Add(DataListFactory.CreateOutputTO(Result));
                            outputs.Last().OutputStrings.Add(xmlList);
                        }
                    }
                }
                catch (Exception e)
                {
                    outputs.Add(DataListFactory.CreateOutputTO(null));
                    allErrors.AddError(e.Message);
                    break;
                }
            }

            return(outputs);
        }
        Dev2DecisionStack ResolveAllRecords(Guid id, Dev2DecisionStack stack, Dev2Decision decision, bool[] effectedCols, out ErrorResultTO errors)
        {
            if (effectedCols == null)
            {
                throw new ArgumentNullException("effectedCols");
            }
            int stackIndex = stack.TheStack.IndexOf(decision);

            stack.TheStack.Remove(decision);
            errors = new ErrorResultTO();
            if (effectedCols[0])
            {
                IDev2IteratorCollection       colItr       = Dev2ValueObjectFactory.CreateIteratorCollection();
                IBinaryDataListEntry          col1Entry    = Compiler.Evaluate(id, enActionType.User, decision.Col1, false, out errors);
                IDev2DataListEvaluateIterator col1Iterator = Dev2ValueObjectFactory.CreateEvaluateIterator(col1Entry);
                colItr.AddIterator(col1Iterator);
                int reStackIndex = stackIndex;

                while (colItr.HasMoreData())
                {
                    var newDecision = new Dev2Decision {
                        Col1 = colItr.FetchNextRow(col1Iterator).TheValue, Col2 = decision.Col2, Col3 = decision.Col3, EvaluationFn = decision.EvaluationFn
                    };
                    stack.TheStack.Insert(reStackIndex++, newDecision);
                }
            }
            if (effectedCols[1])
            {
                IDev2IteratorCollection       colItr       = Dev2ValueObjectFactory.CreateIteratorCollection();
                IBinaryDataListEntry          col2Entry    = Compiler.Evaluate(id, enActionType.User, decision.Col2, false, out errors);
                IDev2DataListEvaluateIterator col2Iterator = Dev2ValueObjectFactory.CreateEvaluateIterator(col2Entry);
                colItr.AddIterator(col2Iterator);
                int reStackIndex = stackIndex;

                while (colItr.HasMoreData())
                {
                    var newDecision = new Dev2Decision {
                        Col1 = FetchStackValue(stack, reStackIndex, 1), Col2 = colItr.FetchNextRow(col2Iterator).TheValue, Col3 = decision.Col3, EvaluationFn = decision.EvaluationFn
                    };
                    if (effectedCols[0])
                    {
                        // ensure we have the correct indexing ;)
                        if (reStackIndex < stack.TheStack.Count)
                        {
                            stack.TheStack[reStackIndex++] = newDecision;
                        }
                        else
                        {
                            stack.TheStack.Insert(reStackIndex++, newDecision);
                        }
                    }
                    else
                    {
                        stack.TheStack.Insert(reStackIndex++, newDecision);
                    }
                }
            }
            if (effectedCols[2])
            {
                IDev2IteratorCollection       colItr       = Dev2ValueObjectFactory.CreateIteratorCollection();
                IBinaryDataListEntry          col3Entry    = Compiler.Evaluate(id, enActionType.User, decision.Col3, false, out errors);
                IDev2DataListEvaluateIterator col3Iterator = Dev2ValueObjectFactory.CreateEvaluateIterator(col3Entry);
                colItr.AddIterator(col3Iterator);
                int reStackIndex = stackIndex;

                while (colItr.HasMoreData())
                {
                    var newDecision = new Dev2Decision {
                        Col1 = FetchStackValue(stack, reStackIndex, 1), Col2 = FetchStackValue(stack, reStackIndex, 2), Col3 = colItr.FetchNextRow(col3Iterator).TheValue, EvaluationFn = decision.EvaluationFn
                    };
                    if (effectedCols[0] || effectedCols[1])
                    {
                        // ensure we have the correct indexing ;)
                        if (reStackIndex < stack.TheStack.Count)
                        {
                            stack.TheStack[reStackIndex++] = newDecision;
                        }
                        else
                        {
                            stack.TheStack.Insert(reStackIndex++, newDecision);
                        }
                    }
                    else
                    {
                        stack.TheStack.Insert(reStackIndex++, newDecision);
                    }
                }
            }
            return(stack);
        }
Ejemplo n.º 10
0
        public IDev2DataListUpsertPayloadBuilder <string> Replace(Guid exIdx, string expression, string oldString, string newString, bool caseMatch, IDev2DataListUpsertPayloadBuilder <string> payloadBuilder, out ErrorResultTO errors, out int ReplaceCount, out IBinaryDataListEntry entryToReplaceIn)
        {
            ReplaceCount = 0;
            oldString    = oldString.Replace("\\", "\\\\");
            // ReSharper disable RedundantAssignment
            ErrorResultTO allErrors = new ErrorResultTO();

            errors = new ErrorResultTO();
            // ReSharper restore RedundantAssignment
            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();

            entryToReplaceIn = compiler.Evaluate(exIdx, enActionType.User, expression, false, out errors);
            allErrors.MergeErrors(errors);

            if (entryToReplaceIn != null)
            {
                RegexOptions regexOptions;
                if (caseMatch)
                {
                    regexOptions = NoneCompiled;
                }
                else
                {
                    regexOptions = IgnoreCaseCompiled;
                }

                //Massimo Guerrera -  Added the Regex.Escape to escape certain characters - Bug 9937
                Regex regex = new Regex(Regex.Escape(oldString), regexOptions);

                IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(entryToReplaceIn);
                while (itr.HasMoreRecords())
                {
                    IList <IBinaryDataListItem> rowList = itr.FetchNextRowData();
                    if (rowList != null)
                    {
                        foreach (IBinaryDataListItem binaryDataListItem in rowList)
                        {
                            int    tmpCount = ReplaceCount;
                            string tmpVal   = binaryDataListItem.TheValue;
                            if (tmpVal.Contains("\\") && oldString.Contains("\\"))
                            {
                                tmpVal = tmpVal.Replace("\\", "\\\\");
                            }

                            ReplaceCount += regex.Matches(tmpVal).Count;
                            if (ReplaceCount > tmpCount)
                            {
                                if (entryToReplaceIn.IsRecordset)
                                {
                                    string recsetDisplayValue =
                                        DataListUtil.CreateRecordsetDisplayValue(entryToReplaceIn.Namespace, binaryDataListItem.FieldName, binaryDataListItem.ItemCollectionIndex.ToString());
                                    expression = string.Concat("[[", recsetDisplayValue, "]]");
                                }

                                var replaceValue = regex.Replace(tmpVal, newString);
                                payloadBuilder.Add(expression, replaceValue);
                            }
                        }
                    }
                }
                payloadBuilder.FlushIterationFrame();
            }
            else
            {
                allErrors.AddError("DataList entry is null.");
            }

            errors = allErrors;

            return(payloadBuilder);
        }
Ejemplo n.º 11
0
        // ReSharper restore RedundantOverridenMember

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

            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();

            IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);

            toUpsert.IsDebug = dataObject.IsDebugMode();
            toUpsert.ReplaceStarWithFixedIndex = true;

            ErrorResultTO allErrors   = new ErrorResultTO();
            ErrorResultTO errors      = new ErrorResultTO();
            Guid          executionId = DataListExecutionID.Get(context);

            InitializeDebug(dataObject);
            try
            {
                CleanArgs();
                ICaseConverter converter = CaseConverterFactory.CreateCaseConverter();

                allErrors.MergeErrors(errors);

                int index    = 1;
                int outIndex = 0;
                foreach (ICaseConvertTO item in ConvertCollection)
                {
                    outIndex++;
                    IBinaryDataListEntry tmp = compiler.Evaluate(executionId, enActionType.User, item.StringToConvert, false, out errors);
                    allErrors.MergeErrors(errors);
                    ValidateVariable(item.Result, compiler, dataObject, out errors);
                    allErrors.MergeErrors(errors);
                    IsSingleValueRule.ApplyIsSingleValueRule(item.ExpressionToConvert, allErrors);
                    if (dataObject.IsDebugMode())
                    {
                        var debugItem = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams("", index.ToString(CultureInfo.InvariantCulture)), debugItem);
                        AddDebugItem(new DebugItemVariableParams(item.StringToConvert, "Convert", tmp, executionId), debugItem);
                        AddDebugItem(new DebugItemStaticDataParams(item.ConvertType, "To"), debugItem);
                        _debugInputs.Add(debugItem);
                        index++;
                    }

                    if (tmp != null)
                    {
                        IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(tmp);

                        while (itr.HasMoreRecords())
                        {
                            foreach (IBinaryDataListItem itm in itr.FetchNextRowData())
                            {
                                try
                                {
                                    IBinaryDataListItem res = converter.TryConvert(item.ConvertType, itm);
                                    string expression       = item.Result;

                                    // 27.08.2013
                                    // NOTE : The result must remain [ as this is how the fliping studio generates the result when using (*) notation
                                    // There is a proper bug in to fix this issue, but since the studio is spaghetti I will leave this to the experts ;)
                                    // This is a tmp fix to the issue
                                    if (expression == "[" || DataListUtil.GetRecordsetIndexType(expression) == enRecordsetIndexType.Star)
                                    {
                                        expression = DataListUtil.AddBracketsToValueIfNotExist(res.DisplayValue);
                                    }
                                    //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result
                                    IsSingleValueRule rule = new IsSingleValueRule(() => expression);
                                    var singleresError     = rule.Check();
                                    if (singleresError != null)
                                    {
                                        allErrors.AddError(singleresError.Message);
                                    }
                                    else
                                    {
                                        toUpsert.Add(expression, res.TheValue);
                                        // Upsert the entire payload
                                    }
                                    allErrors.MergeErrors(errors);
                                }
                                catch (Exception e)
                                {
                                    allErrors.AddError(e.Message);
                                    toUpsert.Add(item.Result, null);
                                }
                            }
                        }
                        compiler.Upsert(executionId, toUpsert, out errors);
                        if (!allErrors.HasErrors() && dataObject.IsDebugMode())
                        {
                            foreach (var debugOutputTo in toUpsert.DebugOutputs)
                            {
                                var debugItem = new DebugItem();
                                AddDebugItem(new DebugItemStaticDataParams("", outIndex.ToString(CultureInfo.InvariantCulture)), debugItem);
                                AddDebugItem(new DebugItemVariableParams(debugOutputTo), debugItem);
                                _debugOutputs.Add(debugItem);
                            }
                            toUpsert.DebugOutputs.Clear();
                        }
                    }
                }
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfCaseConvertActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                }
                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        int outIndex = 1;
                        foreach (ICaseConvertTO item in ConvertCollection)
                        {
                            IBinaryDataListEntry tmp = compiler.Evaluate(executionId, enActionType.User, item.StringToConvert, false, out errors);
                            var debugItem            = new DebugItem();
                            AddDebugItem(new DebugItemStaticDataParams("", outIndex.ToString(CultureInfo.InvariantCulture)), debugItem);
                            AddDebugItem(new DebugItemVariableParams(item.Result, "", tmp, executionId), debugItem);
                            _debugOutputs.Add(debugItem);
                            outIndex++;
                        }
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
Ejemplo n.º 12
0
        IDev2IteratorCollection BuildParametersIteratorCollection(IDataListCompiler compiler, Guid executionId, out IDev2DataListEvaluateIterator batchIterator, out IDev2DataListEvaluateIterator timeOutIterator)
        {
            ErrorResultTO errorResultTo;
            var           parametersIteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection();

            batchIterator   = null;
            timeOutIterator = null;
            if (!String.IsNullOrEmpty(BatchSize))
            {
                var batchSizeEntry = compiler.Evaluate(executionId, enActionType.User, BatchSize, false, out errorResultTo);
                var batchItr       = Dev2ValueObjectFactory.CreateEvaluateIterator(batchSizeEntry);
                parametersIteratorCollection.AddIterator(batchItr);
                batchIterator = batchItr;
            }
            if (!String.IsNullOrEmpty(Timeout))
            {
                var timeoutEntry = compiler.Evaluate(executionId, enActionType.User, Timeout, false, out errorResultTo);
                var timeoutItr   = Dev2ValueObjectFactory.CreateEvaluateIterator(timeoutEntry);
                parametersIteratorCollection.AddIterator(timeoutItr);
                timeOutIterator = timeoutItr;
            }
            return(parametersIteratorCollection);
        }
Ejemplo n.º 13
0
 void GetParameterValuesForBatchSizeAndTimeOut(IDev2DataListEvaluateIterator batchItr, IDev2IteratorCollection parametersIteratorCollection, IDev2DataListEvaluateIterator timeoutItr, ref int batchSize, ref int timeout)
 {
     GetBatchSize(batchItr, parametersIteratorCollection, ref batchSize);
     GetTimeOut(parametersIteratorCollection, timeoutItr, ref timeout);
 }
Ejemplo n.º 14
0
        protected override IList <OutputTO> ExecuteConcreteAction(NativeActivityContext context,
                                                                  out ErrorResultTO allErrors)
        {
            IList <OutputTO>  outputs    = new List <OutputTO>();
            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();

            allErrors = new ErrorResultTO();
            ErrorResultTO errors;
            Guid          executionId = dataObject.DataListID;

            ColItr = Dev2ValueObjectFactory.CreateIteratorCollection();

            //get all the possible paths for all the string variables
            IBinaryDataListEntry inputPathEntry = compiler.Evaluate(executionId, enActionType.User, InputPath, false,
                                                                    out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator inputItr = Dev2ValueObjectFactory.CreateEvaluateIterator(inputPathEntry);

            ColItr.AddIterator(inputItr);

            IBinaryDataListEntry outputPathEntry = compiler.Evaluate(executionId, enActionType.User, OutputPath, false,
                                                                     out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator outputItr = Dev2ValueObjectFactory.CreateEvaluateIterator(outputPathEntry);

            ColItr.AddIterator(outputItr);

            IBinaryDataListEntry usernameEntry = compiler.Evaluate(executionId, enActionType.User, Username, false,
                                                                   out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator unameItr = Dev2ValueObjectFactory.CreateEvaluateIterator(usernameEntry);

            ColItr.AddIterator(unameItr);

            IBinaryDataListEntry passwordEntry = compiler.Evaluate(executionId, enActionType.User, Password, false,
                                                                   out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator passItr = Dev2ValueObjectFactory.CreateEvaluateIterator(passwordEntry);

            ColItr.AddIterator(passItr);

            IBinaryDataListEntry destinationUsernameEntry = compiler.Evaluate(executionId, enActionType.User, DestinationUsername, false,
                                                                              out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator desunameItr = Dev2ValueObjectFactory.CreateEvaluateIterator(destinationUsernameEntry);

            ColItr.AddIterator(desunameItr);

            IBinaryDataListEntry destinationPasswordEntry = compiler.Evaluate(executionId, enActionType.User, DestinationPassword, false,
                                                                              out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator despassItr = Dev2ValueObjectFactory.CreateEvaluateIterator(destinationPasswordEntry);

            ColItr.AddIterator(despassItr);

            var iteratorsErrors = new List <ErrorResultTO>();

            AddItemsToIterator(executionId, compiler, iteratorsErrors);
            ErrorResultTO to = allErrors;

            iteratorsErrors.ForEach(to.MergeErrors);

            outputs.Add(DataListFactory.CreateOutputTO(Result));

            if (dataObject.IsDebugMode())
            {
                AddDebugInputItem(new DebugItemVariableParams(InputPath, "Source Path", inputPathEntry, executionId));
                AddDebugInputItemUserNamePassword(executionId, usernameEntry);
                AddDebugInputItem(new DebugItemVariableParams(OutputPath, "Destination Path", outputPathEntry, executionId));
                AddDebugInputItemDestinationUsernamePassword(executionId, destinationUsernameEntry, DestinationPassword, DestinationUsername);
                AddDebugInputItem(new DebugItemStaticDataParams(Overwrite.ToString(), "Overwrite"));
                AddDebugInputItems(executionId);
            }

            while (ColItr.HasMoreData())
            {
                var             hasError = false;
                IActivityIOPath src      = null;
                IActivityIOPath dst      = null;
                try
                {
                    src = ActivityIOFactory.CreatePathFromString(ColItr.FetchNextRow(inputItr).TheValue,
                                                                 ColItr.FetchNextRow(unameItr).TheValue,
                                                                 ColItr.FetchNextRow(passItr).TheValue,
                                                                 true);
                }
                catch (IOException ioException)
                {
                    allErrors.AddError("Source: " + ioException.Message);
                    hasError = true;
                }
                try
                {
                    dst = ActivityIOFactory.CreatePathFromString(ColItr.FetchNextRow(outputItr).TheValue,
                                                                 ColItr.FetchNextRow(desunameItr).TheValue,
                                                                 ColItr.FetchNextRow(despassItr).TheValue,
                                                                 true);
                }
                catch (IOException ioException)
                {
                    allErrors.AddError("Destination:" + ioException.Message);
                    hasError = true;
                }

                if (hasError)
                {
                    outputs[0].OutputStrings.Add(null);
                    MoveRemainingIterators();
                    continue;
                }
                IActivityIOOperationsEndPoint scrEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(src);
                IActivityIOOperationsEndPoint dstEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(dst);

                try
                {
                    IActivityOperationsBroker broker = GetOperationBroker();
                    var result = ExecuteBroker(broker, scrEndPoint, dstEndPoint);
                    outputs[0].OutputStrings.Add(result);
                }
                catch (Exception e)
                {
                    allErrors.AddError(e.Message);
                    outputs[0].OutputStrings.Add(null);
                }
            }

            return(outputs);
        }
Ejemplo n.º 15
0
        // ReSharper restore RedundantOverridenMember

        /// <summary>
        /// Executes the logic of the activity and calls the backend code to do the work
        /// Also responsible for adding the results to the data list
        /// </summary>
        /// <param name="context"></param>
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();
            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            ErrorResultTO     errors;
            ErrorResultTO     allErrors = new ErrorResultTO();
            Guid executionId            = dataObject.DataListID;

            InitializeDebug(dataObject);
            try
            {
                IsSingleValueRule.ApplyIsSingleValueRule(Result, allErrors);
                // Fetch all fields to search....
                IList <string> toSearch = FieldsToSearch.Split(',');
                // now process each field for entire evaluated Where expression....
                IBinaryDataListEntry bdle = compiler.Evaluate(executionId, enActionType.User, SearchCriteria, false, out errors);
                if (dataObject.IsDebugMode())
                {
                    var itemToAdd = new DebugItem();
                    itemToAdd.Add(new DebugItemResult {
                        Type = DebugItemResultType.Label, Value = "Fields To Search"
                    });
                    _debugInputs.Add(itemToAdd);
                }
                allErrors.MergeErrors(errors);

                if (bdle != null)
                {
                    IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(bdle);
                    IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);
                    int idx;
                    if (!Int32.TryParse(StartIndex, out idx))
                    {
                        idx = 1;
                    }
                    IBinaryDataList toSearchList = compiler.FetchBinaryDataList(executionId, out errors);
                    allErrors.MergeErrors(errors);
                    int iterationIndex = 0;
                    foreach (string s in toSearch)
                    {
                        if (dataObject.IsDebugMode())
                        {
                            IBinaryDataListEntry tmpEntry = compiler.Evaluate(executionId, enActionType.User, s, false, out errors);
                            AddDebugInputItem(s, string.Empty, tmpEntry, executionId);
                        }
                        // each entry in the recordset
                        while (itr.HasMoreRecords())
                        {
                            IList <IBinaryDataListItem> cols = itr.FetchNextRowData();
                            foreach (IBinaryDataListItem c in cols)
                            {
                                IRecsetSearch  searchTo = ConvertToSearchTo(c.TheValue, idx.ToString(CultureInfo.InvariantCulture));
                                IList <string> results  = RecordsetInterrogator.FindRecords(toSearchList, searchTo, out errors);
                                allErrors.MergeErrors(errors);
                                string concatRes = string.Empty;

                                // ReSharper disable LoopCanBeConvertedToQuery
                                foreach (string r in results)
                                // ReSharper restore LoopCanBeConvertedToQuery
                                {
                                    concatRes = string.Concat(concatRes, r, ",");
                                }

                                if (concatRes.EndsWith(","))
                                {
                                    concatRes = concatRes.Remove(concatRes.Length - 1);
                                }
                                //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result
                                DataListCleaningUtils.SplitIntoRegions(Result);
                                //2013.06.07: Massimo Guerrera for BUG 9497 - To handle putting out to a scalar as a CSV

                                if (!DataListUtil.IsValueRecordset(Result))
                                {
                                    toUpsert.Add(Result, concatRes);
                                    toUpsert.FlushIterationFrame();
                                    if (dataObject.IsDebugMode())
                                    {
                                        AddDebugOutputItem(new DebugOutputParams(Result, concatRes, executionId, iterationIndex));
                                    }
                                }
                                else
                                {
                                    iterationIndex = 0;

                                    foreach (string r in results)
                                    {
                                        toUpsert.Add(Result, r);
                                        toUpsert.FlushIterationFrame();
                                        if (dataObject.IsDebugMode())
                                        {
                                            AddDebugOutputItem(new DebugOutputParams(Result, r, executionId, iterationIndex));
                                        }

                                        iterationIndex++;
                                    }
                                }
                            }
                        }
                    }

                    if (dataObject.IsDebugMode())
                    {
                        AddDebugInputItem(SearchCriteria, "Where", bdle, executionId);
                    }

                    // now push the result to the server
                    compiler.Upsert(executionId, toUpsert, out errors);
                    allErrors.MergeErrors(errors);
                }
            }
            finally
            {
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfFindRecordsActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                    compiler.Upsert(executionId, Result, (string)null, out errors);
                }

                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
Ejemplo n.º 16
0
        private string EvaluateExpressiomToStringValue(string expression, Dev2DecisionMode mode, IBinaryDataList dataList)
        {
            string            result = string.Empty;
            IDataListCompiler c      = DataListFactory.CreateDataListCompiler();

            ErrorResultTO errors;
            var           dlEntry = c.Evaluate(dataList.UID, enActionType.User, expression, false, out errors);

            if (dlEntry != null && dlEntry.IsRecordset)
            {
                if (DataListUtil.GetRecordsetIndexType(expression) == enRecordsetIndexType.Numeric)
                {
                    int index;
                    if (int.TryParse(DataListUtil.ExtractIndexRegionFromRecordset(expression), out index))
                    {
                        string error;
                        IList <IBinaryDataListItem> listOfCols = dlEntry.FetchRecordAt(index, out error);
                        if (listOfCols != null)
                        {
                            foreach (IBinaryDataListItem binaryDataListItem in listOfCols)
                            {
                                result = binaryDataListItem.TheValue;
                            }
                        }
                    }
                }
                else
                {
                    if (DataListUtil.GetRecordsetIndexType(expression) == enRecordsetIndexType.Star)
                    {
                        IDev2IteratorCollection       colItr       = Dev2ValueObjectFactory.CreateIteratorCollection();
                        IBinaryDataListEntry          entry        = c.Evaluate(dataList.UID, enActionType.User, expression, false, out errors);
                        IDev2DataListEvaluateIterator col1Iterator = Dev2ValueObjectFactory.CreateEvaluateIterator(entry);
                        colItr.AddIterator(col1Iterator);

                        bool firstTime = true;
                        while (colItr.HasMoreData())
                        {
                            if (firstTime)
                            {
                                result    = colItr.FetchNextRow(col1Iterator).TheValue;
                                firstTime = false;
                            }
                            else
                            {
                                result += " " + mode + " " + colItr.FetchNextRow(col1Iterator).TheValue;
                            }
                        }
                    }
                    else
                    {
                        result = string.Empty;
                    }
                }
            }
            else
            {
                if (dlEntry != null)
                {
                    var scalarItem = dlEntry.FetchScalar();
                    result = scalarItem.TheValue;
                }
            }


            return(result);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Executes the logic of the activity and calls the backend code to do the work
        /// Also responsible for adding the results to the data list
        /// </summary>
        /// <param name="context"></param>
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            IDataListCompiler     compiler         = DataListFactory.CreateDataListCompiler();
            IDSFDataObject        dataObject       = context.GetExtension <IDSFDataObject>();
            IDev2ReplaceOperation replaceOperation = Dev2OperationsFactory.CreateReplaceOperation();
            IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(false);

            toUpsert.IsDebug = dataObject.IsDebugMode();
            ErrorResultTO errors;
            ErrorResultTO allErrors   = new ErrorResultTO();
            Guid          executionId = DataListExecutionID.Get(context);

            IDev2IteratorCollection iteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection();

            IBinaryDataListEntry expressionsEntryFind = compiler.Evaluate(executionId, enActionType.User, Find, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator itrFind = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntryFind);

            iteratorCollection.AddIterator(itrFind);

            IBinaryDataListEntry expressionsEntryReplaceWith = compiler.Evaluate(executionId, enActionType.User, ReplaceWith, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator itrReplace = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntryReplaceWith);

            iteratorCollection.AddIterator(itrReplace);
            int replacementCount = 0;
            int replacementTotal = 0;

            InitializeDebug(dataObject);
            try
            {
                IList <string> toSearch = FieldsToSearch.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var s in toSearch)
                {
                    if (dataObject.IsDebugMode())
                    {
                        IBinaryDataListEntry inFieldsEntry = compiler.Evaluate(executionId, enActionType.User, s, false, out errors);
                        AddDebugInputItem(new DebugItemVariableParams(s, "In Field(s)", inFieldsEntry, executionId));
                    }
                }
                var rule   = new IsSingleValueRule(() => Result);
                var single = rule.Check();
                if (single != null)
                {
                    allErrors.AddError(single.Message);
                }
                else
                {
                    while (iteratorCollection.HasMoreData())
                    {
                        // now process each field for entire evaluated Where expression....
                        var findValue        = iteratorCollection.FetchNextRow(itrFind).TheValue;
                        var replaceWithValue = iteratorCollection.FetchNextRow(itrReplace).TheValue;
                        foreach (string s in toSearch)
                        {
                            if (!DataListUtil.IsEvaluated(s))
                            {
                                allErrors.AddError("Please insert only variables into Fields To Search");
                                return;
                            }
                            if (!string.IsNullOrEmpty(findValue))
                            {
                                IBinaryDataListEntry entryToReplaceIn;
                                toUpsert = replaceOperation.Replace(executionId, s.Trim(), findValue, replaceWithValue, CaseMatch, toUpsert, out errors, out replacementCount, out entryToReplaceIn);
                            }

                            replacementTotal += replacementCount;

                            allErrors.MergeErrors(errors);
                        }
                    }
                }
                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(new DebugItemVariableParams(Find, "Find", expressionsEntryFind, executionId));
                    AddDebugInputItem(new DebugItemVariableParams(ReplaceWith, "Replace With", expressionsEntryReplaceWith, executionId));
                }

                toUpsert.Add(Result, replacementTotal.ToString(CultureInfo.InvariantCulture));


                // now push the result to the server
                compiler.Upsert(executionId, toUpsert, out errors);
                allErrors.MergeErrors(errors);
                if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                {
                    foreach (var debugOutputTo in toUpsert.DebugOutputs)
                    {
                        AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                    }
                }
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch (Exception ex)
            {
                Dev2Logger.Log.Error("DSFReplace", ex);
                allErrors.AddError(ex.Message);
            }
            finally
            {
                if (allErrors.HasErrors())
                {
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DisplayAndWriteError("DsfReplaceActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                    compiler.Upsert(executionId, Result, (string)null, out errors);
                }

                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// When overridden runs the activity's execution logic
        /// </summary>
        /// <param name="context">The context to be used.</param>
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>();

            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();

            Guid          dlId        = dataObject.DataListID;
            ErrorResultTO allErrors   = new ErrorResultTO();
            ErrorResultTO errors      = new ErrorResultTO();
            Guid          executionId = dlId;

            allErrors.MergeErrors(errors);

            IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);

            toUpsert.IsDebug    = dataObject.IsDebugMode();
            toUpsert.ResourceID = dataObject.ResourceID;

            InitializeDebug(dataObject);

            try
            {
                if (!errors.HasErrors())
                {
                    IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection();

                    IDev2DataListEvaluateIterator lengthItr   = CreateDataListEvaluateIterator(Length, executionId, compiler, colItr, allErrors);
                    IBinaryDataListEntry          lengthEntry = compiler.Evaluate(executionId, enActionType.User, Length, false, out errors);

                    IDev2DataListEvaluateIterator fromItr   = CreateDataListEvaluateIterator(From, executionId, compiler, colItr, allErrors);
                    IBinaryDataListEntry          fromEntry = compiler.Evaluate(executionId, enActionType.User, From, false, out errors);

                    IDev2DataListEvaluateIterator toItr   = CreateDataListEvaluateIterator(To, executionId, compiler, colItr, allErrors);
                    IBinaryDataListEntry          toEntry = compiler.Evaluate(executionId, enActionType.User, To, false, out errors);

                    if (dataObject.IsDebugMode())
                    {
                        AddDebugInputItem(Length, From, To, fromEntry, toEntry, lengthEntry, executionId, RandomType);
                    }
                    Dev2Random dev2Random = new Dev2Random();
                    while (colItr.HasMoreData())
                    {
                        int lengthNum = -1;
                        int fromNum   = -1;
                        int toNum     = -1;

                        string fromValue   = colItr.FetchNextRow(fromItr).TheValue;
                        string toValue     = colItr.FetchNextRow(toItr).TheValue;
                        string lengthValue = colItr.FetchNextRow(lengthItr).TheValue;

                        if (RandomType != enRandomType.Guid)
                        {
                            if (RandomType == enRandomType.Numbers)
                            {
                                #region Getting the From

                                fromNum = GetFromValue(fromValue, out errors);
                                if (errors.HasErrors())
                                {
                                    allErrors.MergeErrors(errors);
                                    continue;
                                }

                                #endregion

                                #region Getting the To

                                toNum = GetToValue(toValue, out errors);
                                if (errors.HasErrors())
                                {
                                    allErrors.MergeErrors(errors);
                                    continue;
                                }

                                #endregion
                            }
                            else
                            {
                                #region Getting the Length

                                lengthNum = GetLengthValue(lengthValue, out errors);
                                if (errors.HasErrors())
                                {
                                    allErrors.MergeErrors(errors);
                                    continue;
                                }

                                #endregion
                            }
                        }
                        string value = dev2Random.GetRandom(RandomType, lengthNum, fromNum, toNum);

                        //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result
                        var rule   = new IsSingleValueRule(() => Result);
                        var single = rule.Check();
                        if (single != null)
                        {
                            allErrors.AddError(single.Message);
                        }
                        else
                        {
                            toUpsert.Add(Result, value);
                            toUpsert.FlushIterationFrame();
                        }
                    }
                    compiler.Upsert(executionId, toUpsert, out errors);

                    if (dataObject.IsDebugMode())
                    {
                        if (string.IsNullOrEmpty(Result))
                        {
                            AddDebugOutputItem(new DebugItemStaticDataParams("", "Result"));
                        }
                        else
                        {
                            foreach (var debugOutputTo in toUpsert.DebugOutputs)
                            {
                                AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                            }
                        }
                    }
                    allErrors.MergeErrors(errors);
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFRandomActivity", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfRandomActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                    compiler.Upsert(executionId, Result, (string)null, out errors);
                }
                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
Ejemplo n.º 19
0
        protected override IList <OutputTO> ExecuteConcreteAction(NativeActivityContext context, out ErrorResultTO allErrors)
        {
            IList <OutputTO> outputs    = new List <OutputTO>();
            IDSFDataObject   dataObject = context.GetExtension <IDSFDataObject>();

            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();

            allErrors = new ErrorResultTO();
            ErrorResultTO           errors;
            Guid                    executionId = dataObject.DataListID;
            IDev2IteratorCollection colItr      = Dev2ValueObjectFactory.CreateIteratorCollection();

            //get all the possible paths for all the string variables
            IBinaryDataListEntry outputPathEntry = compiler.Evaluate(executionId, enActionType.User, OutputPath, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator outputItr = Dev2ValueObjectFactory.CreateEvaluateIterator(outputPathEntry);

            colItr.AddIterator(outputItr);

            IBinaryDataListEntry usernameEntry = compiler.Evaluate(executionId, enActionType.User, Username, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator unameItr = Dev2ValueObjectFactory.CreateEvaluateIterator(usernameEntry);

            colItr.AddIterator(unameItr);

            IBinaryDataListEntry passwordEntry = compiler.Evaluate(executionId, enActionType.User, Password, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator passItr = Dev2ValueObjectFactory.CreateEvaluateIterator(passwordEntry);

            colItr.AddIterator(passItr);

            if (dataObject.IsDebugMode())
            {
                AddDebugInputItem(new DebugItemVariableParams(OutputPath, "File or Folder", outputPathEntry, executionId));
                AddDebugInputItem(new DebugItemStaticDataParams(Overwrite.ToString(), "Overwrite"));
                AddDebugInputItemUserNamePassword(executionId, usernameEntry);
            }

            while (colItr.HasMoreData())
            {
                IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker();
                Dev2CRUDOperationTO       opTo   = new Dev2CRUDOperationTO(Overwrite);

                try
                {
                    IActivityIOPath dst = ActivityIOFactory.CreatePathFromString(colItr.FetchNextRow(outputItr).TheValue,
                                                                                 colItr.FetchNextRow(unameItr).TheValue,
                                                                                 colItr.FetchNextRow(passItr).TheValue,
                                                                                 true);

                    IActivityIOOperationsEndPoint dstEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(dst);
                    string result = broker.Create(dstEndPoint, opTo, true);
                    outputs.Add(DataListFactory.CreateOutputTO(Result, result));
                }
                catch (Exception e)
                {
                    outputs.Add(DataListFactory.CreateOutputTO(Result, (string)null));
                    allErrors.AddError(e.Message);
                    break;
                }
            }

            return(outputs);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// When overridden runs the activity's execution logic
        /// </summary>
        /// <param name="context">The context to be used.</param>
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs           = new List <DebugItem>();
            _debugOutputs          = new List <DebugItem>();
            _nativeActivityContext = context;
            var dataObject = _nativeActivityContext.GetExtension <IDSFDataObject>();
            var compiler   = DataListFactory.CreateDataListCompiler();

            var           dlId      = dataObject.DataListID;
            var           allErrors = new ErrorResultTO();
            ErrorResultTO errors;


            var exeToken = _nativeActivityContext.GetExtension <IExecutionToken>();

            InitializeDebug(dataObject);
            try
            {
                IBinaryDataListEntry expressionsEntry = compiler.Evaluate(dlId, enActionType.User, CommandFileName, false, out errors);
                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(new DebugItemVariableParams(CommandFileName, "Command", expressionsEntry, dlId));
                }
                allErrors.MergeErrors(errors);
                IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry);
                IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);
                toUpsert.IsDebug = dataObject.IsDebugMode();
                if (!allErrors.HasErrors())
                {
                    while (itr.HasMoreRecords())
                    {
                        IList <IBinaryDataListItem> cols = itr.FetchNextRowData();
                        foreach (IBinaryDataListItem c in cols)
                        {
                            if (c.IsDeferredRead)
                            {
                                if (toUpsert != null)
                                {
                                    toUpsert.HasLiveFlushing      = true;
                                    toUpsert.LiveFlushingLocation = dlId;
                                }
                            }

                            if (string.IsNullOrEmpty(c.TheValue))
                            {
                                throw new Exception("Empty script to execute");
                            }

                            string        val = c.TheValue;
                            StreamReader  errorReader;
                            StringBuilder outputReader;
                            if (!ExecuteProcess(val, exeToken, out errorReader, out outputReader))
                            {
                                return;
                            }

                            allErrors.AddError(errorReader.ReadToEnd());
                            var    bytes     = Encoding.Default.GetBytes(outputReader.ToString().Trim());
                            string readValue = Encoding.ASCII.GetString(bytes).Replace("?", " ");

                            //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result
                            foreach (var region in DataListCleaningUtils.SplitIntoRegions(CommandResult))
                            {
                                if (toUpsert != null)
                                {
                                    toUpsert.Add(region, readValue);
                                }
                            }

                            errorReader.Close();

                            if (toUpsert != null && toUpsert.HasLiveFlushing)
                            {
                                try
                                {
                                    toUpsert.FlushIterationFrame();
                                    toUpsert = null;
                                }
                                catch (Exception e)
                                {
                                    Dev2Logger.Log.Error("DSFExecuteCommandLine", e);
                                    allErrors.AddError(e.Message);
                                }
                            }
                            else
                            {
                                compiler.Upsert(dlId, toUpsert, out errors);
                                allErrors.MergeErrors(errors);
                            }
                        }
                    }

                    if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                    {
                        if (toUpsert == null)
                        {
                            return;
                        }
                        foreach (var debugOutputTo in toUpsert.DebugOutputs)
                        {
                            AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFCommandLine", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfExecuteCommandLineActivity", allErrors);
                    compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                    compiler.Upsert(dlId, CommandResult, (string)null, out errors);
                }
                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", CommandResult, ""));
                    }
                    DispatchDebugState(_nativeActivityContext, StateType.Before);
                    DispatchDebugState(_nativeActivityContext, StateType.After);
                }

                if (!string.IsNullOrEmpty(_fullPath))
                {
                    File.Delete(_fullPath);
                }
            }
        }
Ejemplo n.º 21
0
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugOutputs.Clear();

            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();
            IDev2DataListUpsertPayloadBuilder <List <string> > toUpsert = Dev2DataListBuilderFactory.CreateStringListDataListUpsertBuilder();

            _isDebugMode        = dataObject.IsDebugMode();
            toUpsert.IsDebug    = _isDebugMode;
            toUpsert.ResourceID = dataObject.ResourceID;
            ErrorResultTO errors      = new ErrorResultTO();
            ErrorResultTO allErrors   = new ErrorResultTO();
            Guid          executionId = DataListExecutionID.Get(context);
            XPathParser   parser      = new XPathParser();
            int           i           = 0;

            InitializeDebug(dataObject);
            try
            {
                if (!errors.HasErrors())
                {
                    IBinaryDataListEntry expressionsEntry = compiler.Evaluate(executionId, enActionType.User, SourceString, false, out errors);

                    if (_isDebugMode)
                    {
                        AddSourceStringDebugInputItem(SourceString, expressionsEntry, executionId);
                        AddResultDebugInputs(ResultsCollection, executionId, compiler, out errors);
                        allErrors.MergeErrors(errors);
                    }
                    if (!allErrors.HasErrors())
                    {
                        IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry);
                        while (itr.HasMoreRecords())
                        {
                            IList <IBinaryDataListItem> cols = itr.FetchNextRowData();
                            foreach (IBinaryDataListItem c in cols)
                            {
                                for (i = 0; i < ResultsCollection.Count; i++)
                                {
                                    if (!string.IsNullOrEmpty(ResultsCollection[i].OutputVariable))
                                    {
                                        IBinaryDataListEntry          xpathEntry = compiler.Evaluate(executionId, enActionType.User, ResultsCollection[i].XPath, false, out errors);
                                        IDev2DataListEvaluateIterator xpathItr   = Dev2ValueObjectFactory.CreateEvaluateIterator(xpathEntry);
                                        while (xpathItr.HasMoreRecords())
                                        {
                                            IList <IBinaryDataListItem> xpathCols = xpathItr.FetchNextRowData();
                                            foreach (IBinaryDataListItem xPathCol in xpathCols)
                                            {
                                                try
                                                {
                                                    List <string> eval = parser.ExecuteXPath(c.TheValue, xPathCol.TheValue).ToList();

                                                    //2013.06.03: Ashley Lewis for bug 9498 - handle line breaks in multi assign
                                                    string[] openParts  = Regex.Split(ResultsCollection[i].OutputVariable, @"\[\[");
                                                    string[] closeParts = Regex.Split(ResultsCollection[i].OutputVariable, @"\]\]");
                                                    if (openParts.Count() == closeParts.Count() && openParts.Count() > 2 && closeParts.Count() > 2)
                                                    {
                                                        foreach (var newFieldName in openParts)
                                                        {
                                                            if (!string.IsNullOrEmpty(newFieldName))
                                                            {
                                                                string cleanFieldName;
                                                                if (newFieldName.IndexOf("]]", StringComparison.Ordinal) + 2 < newFieldName.Length)
                                                                {
                                                                    cleanFieldName = "[[" + newFieldName.Remove(newFieldName.IndexOf("]]", StringComparison.Ordinal) + 2);
                                                                }
                                                                else
                                                                {
                                                                    cleanFieldName = "[[" + newFieldName;
                                                                }
                                                                toUpsert.Add(cleanFieldName, eval);
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        toUpsert.Add(ResultsCollection[i].OutputVariable, eval);
                                                    }
                                                }
                                                catch (Exception)
                                                {
                                                    toUpsert.Add(ResultsCollection[i].OutputVariable, null);
                                                }
                                            }
                                        }
                                    }
                                }
                                compiler.Upsert(executionId, toUpsert, out errors);
                            }

                            allErrors.MergeErrors(errors);
                        }
                    }
                    if (_isDebugMode && !allErrors.HasErrors())
                    {
                        var innerCount = 1;
                        foreach (var debugOutputTo in toUpsert.DebugOutputs)
                        {
                            var itemToAdd = new DebugItem();
                            AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), itemToAdd);
                            AddDebugItem(new DebugItemVariableParams(debugOutputTo), itemToAdd);
                            _debugOutputs.Add(itemToAdd);
                            innerCount++;
                        }
                        toUpsert.DebugOutputs.Clear();
                    }
                }
            }
            catch (Exception ex)
            {
                allErrors.AddError(ex.Message);
            }
            finally
            {
                // Handle Errors

                var actualIndex = i - 1;
                var hasErrors   = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfXPathActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                    compiler.Upsert(executionId, ResultsCollection[actualIndex].OutputVariable, (string)null, out errors);
                }
                if (_isDebugMode)
                {
                    if (hasErrors)
                    {
                        if (_isDebugMode)
                        {
                            ResultsCollection[actualIndex].XPath = "";
                            var itemToAdd = new DebugItem();
                            AddDebugItem(new DebugItemStaticDataParams("", (actualIndex + 1).ToString(CultureInfo.InvariantCulture)), itemToAdd);
                            AddDebugItem(new DebugOutputParams(ResultsCollection[actualIndex].OutputVariable, "", executionId, actualIndex + 1), itemToAdd);
                            _debugOutputs.Add(itemToAdd);
                        }
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
Ejemplo n.º 22
0
        // ReSharper restore RedundantOverridenMember

        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            _indexCounter = 1;
            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();
            Guid          dlId           = dataObject.DataListID;
            ErrorResultTO allErrors      = new ErrorResultTO();
            ErrorResultTO errors;

            _datalistString = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), Dev2.DataList.Contract.enTranslationDepth.Shape, out errors).ToString();

            InitializeDebug(dataObject);
            try
            {
                var sourceString = SourceString ?? "";
                IBinaryDataListEntry expressionsEntry = compiler.Evaluate(dlId, enActionType.User, sourceString, false, out errors);

                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(new DebugItemVariableParams(sourceString, "String to Split", expressionsEntry, dlId));
                    AddDebugInputItem(new DebugItemStaticDataParams(ReverseOrder ? "Backward" : "Forward", "Process Direction"));
                    AddDebugInputItem(new DebugItemStaticDataParams(SkipBlankRows ? "Yes" : "No", "Skip blank rows"));
                }
                CleanArguments(ResultsCollection);
                ResultsCollection.ToList().ForEach(a => IsSingleValueRule.ApplyIsSingleValueRule(a.OutputVariable, allErrors));
                if (ResultsCollection.Count > 0)
                {
                    if (dataObject.IsDebugMode())
                    {
                        AddDebug(ResultsCollection, compiler, dlId);
                    }

                    CheckIndex(sourceString);
                    allErrors.MergeErrors(errors);
                    IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry);
                    IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);
                    bool singleInnerIteration = ArePureScalarTargets(ResultsCollection);
                    bool exit = false;
                    while (itr.HasMoreRecords())
                    {
                        IList <IBinaryDataListItem> cols = itr.FetchNextRowData();
                        foreach (IBinaryDataListItem c in cols)
                        {
                            // set up live flushing iterator details
                            toUpsert.HasLiveFlushing      = true;
                            toUpsert.LiveFlushingLocation = dlId;

#pragma warning disable 219
                            int opCnt = 0;
#pragma warning restore 219
                            if (!string.IsNullOrEmpty(c.TheValue))
                            {
                                string val       = c.TheValue;
                                var    blankRows = new List <int>();
                                if (SkipBlankRows)
                                {
                                    var strings         = val.Split(new[] { Environment.NewLine, "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                                    var newSourceString = string.Join(Environment.NewLine, strings);
                                    val = newSourceString;
                                }
                                else
                                {
                                    var strings = val.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
                                    for (int blankRow = 0; blankRow < strings.Length; blankRow++)
                                    {
                                        if (String.IsNullOrEmpty(strings[blankRow]))
                                        {
                                            blankRows.Add(blankRow);
                                        }
                                    }
                                }

                                IDev2Tokenizer tokenizer = CreateSplitPattern(ref val, ResultsCollection, compiler, dlId, out errors);
                                allErrors.MergeErrors(errors);

                                if (!allErrors.HasErrors())
                                {
                                    if (tokenizer != null)
                                    {
                                        int pos = 0;
                                        int end = (ResultsCollection.Count - 1);

                                        // track used tokens so we can adjust flushing ;)
                                        HashSet <string> usedTokens = new HashSet <string>();

                                        while (tokenizer.HasMoreOps() && !exit)
                                        {
                                            string tmp = tokenizer.NextToken();
                                            if (blankRows.Contains(opCnt) && blankRows.Count != 0)
                                            {
                                                tmp = tmp.Replace(Environment.NewLine, "");
                                                while (pos != end + 1)
                                                {
                                                    UpdateOutputVariableWithValue(pos, usedTokens, toUpsert, "");
                                                    pos++;
                                                }
                                                pos = CompletedRow(usedTokens, toUpsert, singleInnerIteration, ref opCnt, ref exit);
                                            }
                                            UpdateOutputVariableWithValue(pos, usedTokens, toUpsert, tmp);

                                            // Per pass
                                            if (pos == end)
                                            {
                                                //row has been processed
                                                pos = CompletedRow(usedTokens, toUpsert, singleInnerIteration, ref opCnt, ref exit);
                                            }
                                            else
                                            {
                                                pos++;
                                            }
                                        }

                                        // flush the final frame ;)

                                        toUpsert.FlushIterationFrame();
                                        toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);
                                    }
                                }
                            }
                        }
                    }
                    if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                    {
                        AddResultToDebug(compiler, dlId);
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFDataSplit", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfDataSplitActivity", allErrors);
                    compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                }

                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        AddResultToDebug(compiler, dlId);
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
Ejemplo n.º 23
0
        // ReSharper restore RedundantOverridenMember


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

            ErrorResultTO allErrors = new ErrorResultTO();
            ErrorResultTO errors;
            Guid          executionId = DataListExecutionID.Get(context);
            IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(false);

            InitializeDebug(dataObject);

            try
            {
                CleanArgs();

                toUpsert.IsDebug = dataObject.IsDebugMode();

                foreach (var item in ConvertCollection)
                {
                    try
                    {
                        _indexCounter++;
                        // Travis.Frisinger - This needs to be in the ViewModel not here ;)
                        if (item.ToExpression == string.Empty)
                        {
                            item.ToExpression = item.FromExpression;
                        }
                        IsSingleValueRule.ApplyIsSingleValueRule(item.FromExpression, allErrors);
                        var fieldName = item.FromExpression;
                        fieldName = DataListUtil.IsValueRecordset(fieldName) ? DataListUtil.ReplaceRecordsetIndexWithBlank(fieldName) : fieldName;
                        var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), Dev2.DataList.Contract.enTranslationDepth.Shape, out errors);
                        if (!datalist.IsNullOrEmpty())
                        {
                            var isValidExpr = new IsValidExpressionRule(() => fieldName, datalist.ToString())
                            {
                                LabelText = fieldName
                            };

                            var errorInfo = isValidExpr.Check();
                            if (errorInfo != null)
                            {
                                item.FromExpression = "";
                                errors.AddError(errorInfo.Message);
                            }
                            allErrors.MergeErrors(errors);
                        }

                        IBinaryDataListEntry tmp = compiler.Evaluate(executionId, enActionType.User, item.FromExpression, false, out errors);
                        if (dataObject.IsDebugMode())
                        {
                            AddDebugInputItem(item.FromExpression, tmp, executionId, item.FromType, item.ToType);
                        }
                        allErrors.MergeErrors(errors);
                        if (tmp != null)
                        {
                            IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(tmp);

                            IBaseConverter        from   = _fac.CreateConverter((enDev2BaseConvertType)Dev2EnumConverter.GetEnumFromStringDiscription(item.FromType, typeof(enDev2BaseConvertType)));
                            IBaseConverter        to     = _fac.CreateConverter((enDev2BaseConvertType)Dev2EnumConverter.GetEnumFromStringDiscription(item.ToType, typeof(enDev2BaseConvertType)));
                            IBaseConversionBroker broker = _fac.CreateBroker(from, to);

                            // process result information
                            while (itr.HasMoreRecords())
                            {
                                IList <IBinaryDataListItem> cols = itr.FetchNextRowData();
                                foreach (IBinaryDataListItem c in cols)
                                {
                                    // set up live flushing iterator details
                                    if (c.IsDeferredRead)
                                    {
                                        if (toUpsert != null)
                                        {
                                            toUpsert.HasLiveFlushing      = true;
                                            toUpsert.LiveFlushingLocation = executionId;
                                        }
                                    }

                                    int indexToUpsertTo = c.ItemCollectionIndex;

                                    string val        = string.IsNullOrEmpty(c.TheValue) ? "" : broker.Convert(c.TheValue);
                                    string expression = item.ToExpression;

                                    if (DataListUtil.IsValueRecordset(item.ToExpression) && DataListUtil.GetRecordsetIndexType(item.ToExpression) == enRecordsetIndexType.Star)
                                    {
                                        expression = item.ToExpression.Replace(GlobalConstants.StarExpression, indexToUpsertTo.ToString(CultureInfo.InvariantCulture));
                                    }
                                    toUpsert.Add(expression, val);
                                    if (toUpsert != null && toUpsert.HasLiveFlushing)
                                    {
                                        toUpsert.FlushIterationFrame();
                                        toUpsert = null;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Dev2Logger.Log.Error("DSFBaseConvert", e);
                        allErrors.AddError(e.Message);
                    }
                    finally
                    {
                        if (allErrors.HasErrors())
                        {
                            toUpsert.Add(item.ToExpression, null);
                        }
                    }
                }

                if (toUpsert != null && toUpsert.HasLiveFlushing)
                {
                    try
                    {
                        toUpsert.FlushIterationFrame();
                    }
                    catch (Exception e)
                    {
                        Dev2Logger.Log.Error("DSFBaseConvert", e);
                        allErrors.AddError(e.Message);
                    }
                }
                else
                {
                    compiler.Upsert(executionId, toUpsert, out errors);
                    allErrors.MergeErrors(errors);
                }

                if (!allErrors.HasErrors() && toUpsert != null)
                {
                    var outIndex = 1;
                    foreach (var debugOutputTo in toUpsert.DebugOutputs)
                    {
                        var debugItem = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams("", outIndex.ToString(CultureInfo.InvariantCulture)), debugItem);
                        AddDebugItem(new DebugItemVariableParams(debugOutputTo), debugItem);
                        _debugOutputs.Add(debugItem);
                        outIndex++;
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFBaseConvert", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfBaseConvertActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                }
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
Ejemplo n.º 24
0
        // ReSharper restore RedundantOverridenMember

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

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

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

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

                allErrors.MergeErrors(errors);


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

                outerIteratorCollection.AddIterator(itrChar);

                #region Iterate and Find Index

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

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

                var completeResultList = new List <string>();

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

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

                #endregion

                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        foreach (var debugOutputTo in toUpsert.DebugOutputs)
                        {
                            AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                        }
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
 public void AddIterator(IDev2DataListEvaluateIterator itr)
 {
     _itrCollection.Add(itr);
 }
Ejemplo n.º 26
0
        protected override IList <OutputTO> ExecuteConcreteAction(NativeActivityContext context, out ErrorResultTO allErrors)
        {
            IList <OutputTO> outputs    = new List <OutputTO>();
            IDSFDataObject   dataObject = context.GetExtension <IDSFDataObject>();

            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();

            allErrors = new ErrorResultTO();
            ErrorResultTO           errors;
            Guid                    executionId = dataObject.DataListID;
            IDev2IteratorCollection colItr      = Dev2ValueObjectFactory.CreateIteratorCollection();

            //get all the possible paths for all the string variables
            IBinaryDataListEntry inputPathEntry = compiler.Evaluate(executionId, enActionType.User, OutputPath, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator inputItr = Dev2ValueObjectFactory.CreateEvaluateIterator(inputPathEntry);

            colItr.AddIterator(inputItr);

            IBinaryDataListEntry usernameEntry = compiler.Evaluate(executionId, enActionType.User, Username, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator unameItr = Dev2ValueObjectFactory.CreateEvaluateIterator(usernameEntry);

            colItr.AddIterator(unameItr);

            IBinaryDataListEntry passwordEntry = compiler.Evaluate(executionId, enActionType.User, Password, false, out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator passItr = Dev2ValueObjectFactory.CreateEvaluateIterator(passwordEntry);

            colItr.AddIterator(passItr);

            IBinaryDataListEntry contentsEntry = compiler.Evaluate(executionId, enActionType.User, FileContents, false, out errors);

            if (contentsEntry == null)
            {
                errors.AddError("Contents could not be evaluated");
            }

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator contentItr = Dev2ValueObjectFactory.CreateEvaluateIterator(contentsEntry);

            colItr.AddIterator(contentItr);

            outputs.Add(DataListFactory.CreateOutputTO(Result));

            if (dataObject.IsDebugMode())
            {
                AddDebugInputItem(OutputPath, "Output Path", inputPathEntry, executionId);
                AddDebugInputItem(new DebugItemStaticDataParams(GetMethod(), "Method"));
                AddDebugInputItemUserNamePassword(executionId, usernameEntry);
                AddDebugInputItem(FileContents, "File Contents", contentsEntry, executionId);
            }

            while (colItr.HasMoreData())
            {
                IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker();
                var writeType = GetCorrectWriteType();
                Dev2PutRawOperationTO putTo = ActivityIOFactory.CreatePutRawOperationTO(writeType, TextUtils.ReplaceWorkflowNewLinesWithEnvironmentNewLines(colItr.FetchNextRow(contentItr).TheValue));
                IActivityIOPath       opath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextRow(inputItr).TheValue,
                                                                                     colItr.FetchNextRow(unameItr).TheValue,
                                                                                     colItr.FetchNextRow(passItr).TheValue,
                                                                                     true);
                IActivityIOOperationsEndPoint endPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(opath);

                try
                {
                    if (allErrors.HasErrors())
                    {
                        outputs[0].OutputStrings.Add(null);
                    }
                    else
                    {
                        string result = broker.PutRaw(endPoint, putTo);
                        outputs[0].OutputStrings.Add(result);
                    }
                }
                catch (Exception e)
                {
                    outputs[0].OutputStrings.Add(null);
                    allErrors.AddError(e.Message);
                    break;
                }
            }

            return(outputs);
        }
Ejemplo n.º 27
0
        // ReSharper restore RedundantOverridenMember

        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            IDSFDataObject       dataObject      = context.GetExtension <IDSFDataObject>();
            IDataListCompiler    compiler        = DataListFactory.CreateDataListCompiler();
            IDev2MergeOperations mergeOperations = new Dev2MergeOperations();
            ErrorResultTO        allErrors       = new ErrorResultTO();
            ErrorResultTO        errorResultTo   = new ErrorResultTO();
            Guid executionId = DataListExecutionID.Get(context);
            IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);

            toUpsert.IsDebug    = dataObject.IsDebugMode();
            toUpsert.ResourceID = dataObject.ResourceID;

            InitializeDebug(dataObject);
            try
            {
                CleanArguments(MergeCollection);

                if (MergeCollection.Count <= 0)
                {
                    return;
                }

                IDev2IteratorCollection iteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection();


                allErrors.MergeErrors(errorResultTo);
                Dictionary <int, List <IDev2DataListEvaluateIterator> > listOfIterators = new Dictionary <int, List <IDev2DataListEvaluateIterator> >();

                #region Create a iterator for each row in the data grid in the designer so that the right iteration happen on the data

                int dictionaryKey = 0;
                foreach (DataMergeDTO row in MergeCollection)
                {
                    IBinaryDataListEntry inputVariableExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.InputVariable, false, out errorResultTo);
                    allErrors.MergeErrors(errorResultTo);

                    IBinaryDataListEntry atExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.At, false, out errorResultTo);
                    allErrors.MergeErrors(errorResultTo);

                    IBinaryDataListEntry paddingExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.Padding, false, out errorResultTo);
                    allErrors.MergeErrors(errorResultTo);

                    var fieldName        = row.InputVariable;
                    var splitIntoRegions = DataListCleaningUtils.FindAllLanguagePieces(fieldName);
                    var datalist         = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errorResultTo).ToString();
                    if (!string.IsNullOrEmpty(datalist))
                    {
                        foreach (var region in splitIntoRegions)
                        {
                            var r           = DataListUtil.IsValueRecordset(region) ? DataListUtil.ReplaceRecordsetIndexWithBlank(region) : region;
                            var isValidExpr = new IsValidExpressionRule(() => r, datalist)
                            {
                                LabelText = fieldName
                            };

                            var errorInfo = isValidExpr.Check();
                            if (errorInfo != null)
                            {
                                row.InputVariable = "";
                                errorResultTo.AddError(errorInfo.Message);
                            }
                            allErrors.MergeErrors(errorResultTo);
                        }
                    }

                    allErrors.MergeErrors(errorResultTo);

                    if (dataObject.IsDebugMode())
                    {
                        DebugItem debugItem = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams("", (MergeCollection.IndexOf(row) + 1).ToString(CultureInfo.InvariantCulture)), debugItem);
                        AddDebugItem(new DebugItemVariableParams(row.InputVariable, "", inputVariableExpressionEntry, executionId), debugItem);
                        AddDebugItem(new DebugItemStaticDataParams(row.MergeType, "With"), debugItem);
                        AddDebugItem(new DebugItemVariableParams(row.At, "Using", atExpressionEntry, executionId), debugItem);
                        AddDebugItem(new DebugItemVariableParams(row.Padding, "Pad", paddingExpressionEntry, executionId), debugItem);

                        //Old workflows don't have this set.
                        if (row.Alignment == null)
                        {
                            row.Alignment = string.Empty;
                        }

                        AddDebugItem(DataListUtil.IsEvaluated(row.Alignment) ? new DebugItemStaticDataParams("", row.Alignment, "Align") : new DebugItemStaticDataParams(row.Alignment, "Align"), debugItem);

                        _debugInputs.Add(debugItem);
                    }

                    IDev2DataListEvaluateIterator itr    = Dev2ValueObjectFactory.CreateEvaluateIterator(inputVariableExpressionEntry);
                    IDev2DataListEvaluateIterator atItr  = Dev2ValueObjectFactory.CreateEvaluateIterator(atExpressionEntry);
                    IDev2DataListEvaluateIterator padItr = Dev2ValueObjectFactory.CreateEvaluateIterator(paddingExpressionEntry);

                    iteratorCollection.AddIterator(itr);
                    iteratorCollection.AddIterator(atItr);
                    iteratorCollection.AddIterator(padItr);

                    listOfIterators.Add(dictionaryKey, new List <IDev2DataListEvaluateIterator> {
                        itr, atItr, padItr
                    });
                    dictionaryKey++;
                }

                #endregion

                #region Iterate and Merge Data
                if (!allErrors.HasErrors())
                {
                    while (iteratorCollection.HasMoreData())
                    {
                        int pos = 0;
                        foreach (var iterator in listOfIterators)
                        {
                            var val = iteratorCollection.FetchNextRow(iterator.Value[0]);
                            var at  = iteratorCollection.FetchNextRow(iterator.Value[1]);
                            var pad = iteratorCollection.FetchNextRow(iterator.Value[2]);

                            if (val != null)
                            {
                                if (at != null)
                                {
                                    if (pad != null)
                                    {
                                        if (MergeCollection[pos].MergeType == "Index")
                                        {
                                            if (string.IsNullOrEmpty(at.TheValue))
                                            {
                                                allErrors.AddError("The 'Using' value cannot be blank.");
                                            }

                                            int atValue;
                                            if (!Int32.TryParse(at.TheValue, out atValue) || atValue < 0)
                                            {
                                                allErrors.AddError("The 'Using' value must be a real number.");
                                            }
                                            if (pad.TheValue.Length > 1)
                                            {
                                                allErrors.AddError("'Padding' must be a single character");
                                            }
                                        }
                                        else
                                        {
                                            if (MergeCollection[pos].MergeType == "Chars" && string.IsNullOrEmpty(at.TheValue))
                                            {
                                                allErrors.AddError("The 'Using' value cannot be blank.");
                                            }
                                        }
                                        mergeOperations.Merge(val.TheValue, MergeCollection[pos].MergeType, at.TheValue, pad.TheValue, MergeCollection[pos].Alignment);
                                        pos++;
                                    }
                                }
                            }
                        }
                    }
                    if (!allErrors.HasErrors())
                    {
                        if (string.IsNullOrEmpty(Result))
                        {
                            AddDebugOutputItem(new DebugItemStaticDataParams("", ""));
                        }
                        else
                        {
                            var rule   = new IsSingleValueRule(() => Result);
                            var single = rule.Check();
                            if (single != null)
                            {
                                allErrors.AddError(single.Message);
                            }
                            else
                            {
                                toUpsert.Add(Result, mergeOperations.MergeData.ToString());
                                toUpsert.FlushIterationFrame();
                                compiler.Upsert(executionId, toUpsert, out errorResultTo);
                                allErrors.MergeErrors(errorResultTo);

                                if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                                {
                                    foreach (var debugOutputTo in toUpsert.DebugOutputs)
                                    {
                                        if (debugOutputTo.LeftEntry != null && debugOutputTo.TargetEntry != null)
                                        {
                                            AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion Iterate and Merge Data
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFDataMerge", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                #region Handle Errors

                if (allErrors.HasErrors())
                {
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DisplayAndWriteError("DsfDataMergeActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errorResultTo);
                    compiler.Upsert(executionId, Result, (string)null, out errorResultTo);
                }

                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }

                #endregion
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// When overridden runs the activity's execution logic
        /// </summary>
        /// <param name="context">The context to be used.</param>
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>();

            _dataObject = dataObject;
            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();
            Guid          dlId         = dataObject.DataListID;
            ErrorResultTO allErrors    = new ErrorResultTO();
            ErrorResultTO errors;
            Guid          executionId     = DataListExecutionID.Get(context);
            int           indexToUpsertTo = 0;
            IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);

            toUpsert.IsDebug = dataObject.IsDebugMode();

            InitializeDebug(dataObject);
            try
            {
                var colItr = Dev2ValueObjectFactory.CreateIteratorCollection();

                IBinaryDataListEntry fromAccountEntry = compiler.Evaluate(dlId, enActionType.User, FromAccount ?? string.Empty, false, out errors);

                allErrors.MergeErrors(errors);
                IDev2DataListEvaluateIterator fromAccountItr = Dev2ValueObjectFactory.CreateEvaluateIterator(fromAccountEntry);
                colItr.AddIterator(fromAccountItr);

                IBinaryDataListEntry passwordEntry = compiler.Evaluate(dlId, enActionType.User, Password, false, out errors);
                allErrors.MergeErrors(errors);
                IDev2DataListEvaluateIterator passwordItr = Dev2ValueObjectFactory.CreateEvaluateIterator(passwordEntry);
                colItr.AddIterator(passwordItr);

                IBinaryDataListEntry toEntry = compiler.Evaluate(dlId, enActionType.User, To, false, out errors);
                allErrors.MergeErrors(errors);
                IDev2DataListEvaluateIterator toItr = Dev2ValueObjectFactory.CreateEvaluateIterator(toEntry);
                colItr.AddIterator(toItr);

                IBinaryDataListEntry ccEntry = compiler.Evaluate(dlId, enActionType.User, Cc ?? string.Empty, false, out errors);
                allErrors.MergeErrors(errors);
                IDev2DataListEvaluateIterator ccItr = Dev2ValueObjectFactory.CreateEvaluateIterator(ccEntry);
                colItr.AddIterator(ccItr);

                IBinaryDataListEntry bccEntry = compiler.Evaluate(dlId, enActionType.User, Bcc ?? string.Empty, false, out errors);
                allErrors.MergeErrors(errors);
                IDev2DataListEvaluateIterator bccItr = Dev2ValueObjectFactory.CreateEvaluateIterator(bccEntry);
                colItr.AddIterator(bccItr);

                IBinaryDataListEntry subjectEntry = compiler.Evaluate(dlId, enActionType.User, Subject ?? string.Empty, false, out errors);
                allErrors.MergeErrors(errors);
                IDev2DataListEvaluateIterator subjectItr = Dev2ValueObjectFactory.CreateEvaluateIterator(subjectEntry);
                colItr.AddIterator(subjectItr);

                IBinaryDataListEntry bodyEntry = compiler.Evaluate(dlId, enActionType.User, Body ?? string.Empty, false, out errors);
                allErrors.MergeErrors(errors);
                IDev2DataListEvaluateIterator bodyItr = Dev2ValueObjectFactory.CreateEvaluateIterator(bodyEntry);
                colItr.AddIterator(bodyItr);

                IBinaryDataListEntry attachmentsEntry = compiler.Evaluate(dlId, enActionType.User, Attachments ?? string.Empty, false, out errors);
                allErrors.MergeErrors(errors);
                IDev2DataListEvaluateIterator attachmentsItr = Dev2ValueObjectFactory.CreateEvaluateIterator(attachmentsEntry);
                colItr.AddIterator(attachmentsItr);

                var runtimeSource = ResourceCatalog.Instance.GetResource <EmailSource>(dataObject.WorkspaceID, SelectedEmailSource.ResourceID);

                if (!allErrors.HasErrors())
                {
                    while (colItr.HasMoreData())
                    {
                        if (IsDebug)
                        {
                            var fromAccount = FromAccount;
                            if (String.IsNullOrEmpty(fromAccount))
                            {
                                fromAccount = runtimeSource.UserName;
                                AddDebugInputItem(fromAccount, "From Account");
                            }
                            else
                            {
                                AddDebugInputItem(new DebugItemVariableParams(FromAccount, "From Account", fromAccountEntry, executionId));
                            }
                            AddDebugInputItem(new DebugItemVariableParams(To, "To", toEntry, executionId));
                            AddDebugInputItem(new DebugItemVariableParams(Subject, "Subject", subjectEntry, executionId));
                            AddDebugInputItem(new DebugItemVariableParams(Body, "Body", bodyEntry, executionId));
                        }

                        var result = SendEmail(runtimeSource, colItr, fromAccountItr, passwordItr, toItr, ccItr, bccItr, subjectItr, bodyItr, attachmentsItr, out errors);
                        allErrors.MergeErrors(errors);
                        if (!allErrors.HasErrors())
                        {
                            indexToUpsertTo = UpsertResult(indexToUpsertTo, toUpsert, result);
                        }
                    }
                    compiler.Upsert(executionId, toUpsert, out errors);
                    allErrors.MergeErrors(errors);
                    if (IsDebug && !allErrors.HasErrors())
                    {
                        foreach (var debugOutputTo in toUpsert.DebugOutputs)
                        {
                            AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                        }
                    }
                }
                else
                {
                    if (IsDebug)
                    {
                        AddDebugInputItem(FromAccount, "From Account");
                        AddDebugInputItem(To, "To");
                        AddDebugInputItem(Subject, "Subject");
                        AddDebugInputItem(Body, "Body");
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFEmail", e);
                allErrors.AddError(e.Message);
            }

            finally
            {
                // Handle Errors

                if (allErrors.HasErrors())
                {
                    UpsertResult(indexToUpsertTo, toUpsert, null);
                    compiler.Upsert(executionId, toUpsert, out errors);
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DisplayAndWriteError("DsfSendEmailActivity", allErrors);
                    compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                }
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
Ejemplo n.º 29
0
        string SendEmail(EmailSource runtimeSource, IDev2IteratorCollection colItr, IDev2DataListEvaluateIterator fromAccountItr, IDev2DataListEvaluateIterator passwordItr, IDev2DataListEvaluateIterator toItr, IDev2DataListEvaluateIterator ccItr, IDev2DataListEvaluateIterator bccItr, IDev2DataListEvaluateIterator subjectItr, IDev2DataListEvaluateIterator bodyItr, IDev2DataListEvaluateIterator attachmentsItr, out ErrorResultTO errors)
        {
            errors = new ErrorResultTO();
            var          fromAccountValue = colItr.FetchNextRow(fromAccountItr).TheValue;
            var          passwordValue    = colItr.FetchNextRow(passwordItr).TheValue;
            var          toValue          = colItr.FetchNextRow(toItr).TheValue;
            var          ccValue          = colItr.FetchNextRow(ccItr).TheValue;
            var          bccValue         = colItr.FetchNextRow(bccItr).TheValue;
            var          subjectValue     = colItr.FetchNextRow(subjectItr).TheValue;
            var          bodyValue        = colItr.FetchNextRow(bodyItr).TheValue;
            var          attachmentsValue = colItr.FetchNextRow(attachmentsItr).TheValue;
            MailMessage  mailMessage      = new MailMessage();
            MailPriority priority;

            if (Enum.TryParse(Priority.ToString(), true, out priority))
            {
                mailMessage.Priority = priority;
            }
            mailMessage.Subject = subjectValue;
            AddToAddresses(toValue, mailMessage);
            try
            {
                // Always use source account unless specifically overridden by From Account
                if (!string.IsNullOrEmpty(fromAccountValue))
                {
                    runtimeSource.UserName = fromAccountValue;
                    runtimeSource.Password = passwordValue;
                }
                mailMessage.From = new MailAddress(runtimeSource.UserName);
            }
            catch (Exception)
            {
                errors.AddError(string.Format("From address is not in the valid format: {0}", fromAccountValue));
                return("Failure");
            }
            mailMessage.Body = bodyValue;
            if (!String.IsNullOrEmpty(ccValue))
            {
                AddCcAddresses(ccValue, mailMessage);
            }
            if (!String.IsNullOrEmpty(bccValue))
            {
                AddBccAddresses(bccValue, mailMessage);
            }
            if (!String.IsNullOrEmpty(attachmentsValue))
            {
                AddAttachmentsValue(attachmentsValue, mailMessage);
            }
            string result;

            try
            {
                EmailSender.Send(runtimeSource, mailMessage);
                result = "Success";
            }
            catch (Exception e)
            {
                result = "Failure";
                errors.AddError(e.Message);
            }

            return(result);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// When overridden runs the activity's execution logic
        /// </summary>
        /// <param name="context">The context to be used.</param>
        protected override void OnExecute(NativeActivityContext context)
        {
            IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>();

            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();

            Guid          dlID        = dataObject.DataListID;
            ErrorResultTO allErrors   = new ErrorResultTO();
            ErrorResultTO errors      = new ErrorResultTO();
            Guid          executionId = dlID;

            allErrors.MergeErrors(errors);
            IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder();

            toUpsert.IsDebug    = (dataObject.IsDebugMode());
            toUpsert.ResourceID = dataObject.ResourceID;

            InitializeDebug(dataObject);
            try
            {
                if (!errors.HasErrors())
                {
                    IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection();

                    IDev2DataListEvaluateIterator scriptItr = CreateDataListEvaluateIterator(Script, executionId, compiler, colItr, allErrors);

                    IBinaryDataListEntry scriptEntry = compiler.Evaluate(executionId, enActionType.User, Script, false, out errors);
                    allErrors.MergeErrors(errors);

                    if (dataObject.IsDebugMode())
                    {
                        var language = ScriptType.GetDescription();
                        AddDebugInputItem(new DebugItemStaticDataParams(language, "Language"));
                        AddDebugInputItem(new DebugItemVariableParams(Script, "Script", scriptEntry, executionId));
                    }
                    if (allErrors.HasErrors())
                    {
                        return;
                    }

                    while (colItr.HasMoreData())
                    {
                        string scriptValue = colItr.FetchNextRow(scriptItr).TheValue;

                        var engine = new ScriptingEngineRepo().CreateEngine(ScriptType);
                        var value  = engine.Execute(scriptValue);

                        //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result
                        foreach (var region in DataListCleaningUtils.SplitIntoRegions(Result))
                        {
                            toUpsert.Add(region, value);
                            toUpsert.FlushIterationFrame();
                        }
                    }
                    compiler.Upsert(executionId, toUpsert, out errors);
                    allErrors.MergeErrors(errors);
                    if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                    {
                        foreach (var debugOutputTo in toUpsert.DebugOutputs)
                        {
                            AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof(NullReferenceException) || e.GetType() == typeof(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException))
                {
                    allErrors.AddError("There was an error when returning a value from your script, remember to use the 'Return' keyword when returning the result");
                }
                else
                {
                    allErrors.AddError(e.Message.Replace(" for main:Object", string.Empty));
                }
            }
            finally
            {
                // Handle Errors
                if (allErrors.HasErrors())
                {
                    DisplayAndWriteError("DsfScriptingJavaScriptActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                }

                if (dataObject.IsDebugMode())
                {
                    if (allErrors.HasErrors())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }