Inheritance: IErrorResultTO
Example #1
0
        public string GenerateUserFriendlyModel(IExecutionEnvironment env, Dev2DecisionMode mode, out ErrorResultTO errors)
        {
            StringBuilder result = new StringBuilder("");

            int cnt = 0;

            errors = new ErrorResultTO();
            // build the output for decisions
            foreach(Dev2Decision dd in TheStack)
            {
                result.Append(dd.GenerateUserFriendlyModel(env, Mode, out errors));
                // append mode if not at end
                if((cnt + 1) < TheStack.Count)
                {
                    result.Append(Mode);
                }
                result.AppendLine();
                cnt++;
            }

            // append the arms
            result.Append("THEN " + TrueArmText);
            result.AppendLine();
            result.Append("ELSE " + FalseArmText);

            return result.ToString();
        }
 public System.Guid MockExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out DataList.Contract.ErrorResultTO tmpErrors)
 {
     
     tmpErrors = new ErrorResultTO();
     tmpErrors.AddError("Something bad happened");
     return Guid.Empty;
 }
        public void Webservice_Test_WhenRequestShouldTimeout_ExpectTimeoutMessage()
        {
            //------------Setup for test--------------------------
            var serviceXml = XmlResource.Fetch("WebService");
            var sourceXml = XmlResource.Fetch("WebSource");
            var response = JsonResource.Fetch("cryptsy_all_markets");

            var service = new WebService(serviceXml) { Source = new WebSource(sourceXml) };

            foreach(var parameter in service.Method.Parameters)
            {
                parameter.Value = parameter.DefaultValue;
            }

            var webExecuteHitCount = 0;
            var resourceCatalog = new Mock<IResourceCatalog>();
            var services = new WebServicesMock(resourceCatalog.Object,
                (WebSource source, WebRequestMethod method, string uri, string data, bool error, out ErrorResultTO errors, string[] headers) =>
                {
                    webExecuteHitCount++;
                    errors = new ErrorResultTO();
                    return response;
                });

            //------------Execute Test---------------------------
            var result = services.Test(service.ToString(), Guid.Empty, Guid.Empty);

            //------------Assert Results-------------------------
            Assert.AreEqual(1, webExecuteHitCount);
            Assert.AreEqual(GlobalConstants.WebServiceTimeoutMessage, result.RequestMessage);
        }
Example #4
0
        protected override Guid ExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out ErrorResultTO errors, int update)
        {
            var execErrors = new ErrorResultTO();

            errors = new ErrorResultTO();
            errors.MergeErrors(execErrors);

            var databaseServiceExecution = ServiceExecution as DatabaseServiceExecution;
            if(databaseServiceExecution != null)
            {
                databaseServiceExecution.InstanceInputDefinitions = inputs; // set the output mapping for the instance ;)
                databaseServiceExecution.InstanceOutputDefintions = outputs; // set the output mapping for the instance ;)
            }
            //ServiceExecution.DataObj = dataObject;
            var result = ServiceExecution.Execute(out execErrors, update);
            var fetchErrors = execErrors.FetchErrors();
            foreach(var error in fetchErrors)
            {
                dataObject.Environment.Errors.Add(error);
            }
            
            errors.MergeErrors(execErrors);

            // Adjust the remaining output mappings ;)
            return result;
        }
        private void GenerateRequestDictionaryFromDataObject(out ErrorResultTO errors)
        {
            var compiler = DataListFactory.CreateDataListCompiler();
            errors = new ErrorResultTO();

            ErrorResultTO invokeErrors;
            IBinaryDataList bdl = compiler.FetchBinaryDataList(DataObject.DataListID, out invokeErrors);
            errors.MergeErrors(invokeErrors);

            if(!invokeErrors.HasErrors())
            {
                foreach(IBinaryDataListEntry entry in bdl.FetchScalarEntries())
                {
                    IBinaryDataListItem itm = entry.FetchScalar();

                    if(!DataListUtil.IsSystemTag(itm.FieldName))
                    {
                        var stringBuilder = new StringBuilder("");
                        try
                        {
                            stringBuilder = new StringBuilder(itm.TheValue);
                        }
                        // ReSharper disable EmptyGeneralCatchClause
                        catch(Exception)
                        // ReSharper restore EmptyGeneralCatchClause
                        {
                        }
                        Request.AddArgument(itm.FieldName, stringBuilder);
                    }
                }
            }
        }
 public override Guid Execute(out ErrorResultTO errors, int update)
 {
     WebserviceExecution.InstanceInputDefinitions = InstanceInputDefinition;
     WebserviceExecution.InstanceOutputDefintions = InstanceOutputDefinition;
     var result = WebserviceExecution.Execute(out errors, update);
     return result;
 }
 public DataTable ConvertToDataTable(IBinaryDataList input, string recsetName, out ErrorResultTO errors, PopulateOptions populateOptions)
 {
     if(String.IsNullOrEmpty(recsetName))
     {
         throw new ArgumentNullException("recsetName");
     }
     if(input == null)
     {
         throw new ArgumentNullException("input");
     }
     var dbData = new DataTable();
     IBinaryDataListEntry entry;
     errors = null;
     string error;
     if(input.TryGetEntry(recsetName, out entry, out error))
     {
         if(entry.IsRecordset)
         {
             var cols = entry.Columns;
             var dataColumns = cols.ToList().ConvertAll(column => new DataColumn(column.ColumnName));
             dbData.Columns.AddRange(dataColumns.ToArray());
             var fetchRecordsetIndexes = entry.FetchRecordsetIndexes();
             while(fetchRecordsetIndexes.HasMore())
             {
                 var binaryDataListItems = entry.FetchRowAt(fetchRecordsetIndexes.FetchNextIndex(), out error);
                 if(populateOptions == PopulateOptions.IgnoreBlankRows && binaryDataListItems.All(item =>
                 {
                     string theValue;
                     try
                     {
                         theValue = item.TheValue;
                     }
                     catch(Exception)
                     {
                         theValue = null;
                     }
                     return String.IsNullOrEmpty(theValue);
                 }))
                 {
                     continue;
                 }
                 dbData.LoadDataRow(binaryDataListItems.Select(item =>
                 {
                     string theValue;
                     try
                     {
                         theValue = item.TheValue;
                     }
                     catch(Exception)
                     {
                         theValue = null;
                     }
                     return theValue as object;
                 }).ToArray(), LoadOption.OverwriteChanges);
             }
         }
     }
     return dbData;
 }
        public override Guid Execute(out ErrorResultTO errors)
        {
            _pluginServiceExecution.InstanceInputDefinitions = InstanceInputDefinition;
            _pluginServiceExecution.InstanceOutputDefintions = InstanceOutputDefinition;

            var result = _pluginServiceExecution.Execute(out errors);
            return result;
        }
        protected override IList<OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors, int update)
        {

            IList<OutputTO> outputs = new List<OutputTO>();

            allErrors = new ErrorResultTO();
            var colItr = new WarewolfListIterator();

            //get all the possible paths for all the string variables
            
            var outputItr = new WarewolfIterator(dataObject.Environment.Eval(OutputPath, update));
            colItr.AddVariableToIterateOn(outputItr);

            var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username, update));
            colItr.AddVariableToIterateOn(unameItr);

            var passItr = new WarewolfIterator(dataObject.Environment.Eval(DecryptedPassword,update));
            colItr.AddVariableToIterateOn(passItr);

            var privateKeyItr = new WarewolfIterator(dataObject.Environment.Eval(PrivateKeyFile, update));
            colItr.AddVariableToIterateOn(privateKeyItr);

            if(dataObject.IsDebugMode())
            {
                AddDebugInputItem(new DebugEvalResult(OutputPath, "File or Folder", dataObject.Environment, update));
                AddDebugInputItem(new DebugItemStaticDataParams(Overwrite.ToString(), "Overwrite"));
                AddDebugInputItemUserNamePassword(dataObject.Environment, update);
                if (!string.IsNullOrEmpty(PrivateKeyFile))
                {
                    AddDebugInputItem(PrivateKeyFile, "Destination Private Key File", dataObject.Environment, update);
                }
            }

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

                try
                {
                    IActivityIOPath dst = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(outputItr),
                                                                                colItr.FetchNextValue(unameItr),
                                                                                colItr.FetchNextValue(passItr),
                                                                                true, colItr.FetchNextValue(privateKeyItr));
                    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, "Failure"));
                    allErrors.AddError(e.Message);
                    break;
                }
            }

            return outputs;
        }
Example #10
0
        protected override IList<OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors, int update)
        {

            IList<OutputTO> outputs = new List<OutputTO>();

            allErrors = new ErrorResultTO();
            var colItr = new WarewolfListIterator();

            //get all the possible paths for all the string variables
            var inputItr = new WarewolfIterator(dataObject.Environment.Eval(InputPath, update));
            colItr.AddVariableToIterateOn(inputItr);

            var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username, update));
            colItr.AddVariableToIterateOn(unameItr);

            var passItr = new WarewolfIterator(dataObject.Environment.Eval(DecryptedPassword,update)); 
            colItr.AddVariableToIterateOn(passItr);

            var privateKeyItr = new WarewolfIterator(dataObject.Environment.Eval(PrivateKeyFile, update));
            colItr.AddVariableToIterateOn(privateKeyItr);

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

            if(dataObject.IsDebugMode())
            {
                AddDebugInputItem(InputPath, "Input Path", dataObject.Environment, update);
                AddDebugInputItemUserNamePassword(dataObject.Environment, update);
                if(!string.IsNullOrEmpty(PrivateKeyFile))
                {
                    AddDebugInputItem(PrivateKeyFile, "Private Key File", dataObject.Environment, update);
                }
            }

            while(colItr.HasMoreData())
            {
                IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker();
                IActivityIOPath ioPath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(inputItr),
                                                                                colItr.FetchNextValue(unameItr),
                                                                                colItr.FetchNextValue(passItr),
                                                                                true, colItr.FetchNextValue(privateKeyItr));
                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;
        }
        protected override IList<OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors)
        {

            IList<OutputTO> outputs = new List<OutputTO>();


            allErrors = new ErrorResultTO();

            var colItr = new WarewolfListIterator();

            //get all the possible paths for all the string variables

            var inputItr = new WarewolfIterator(dataObject.Environment.Eval(InputPath));
            colItr.AddVariableToIterateOn(inputItr);

            var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username));
            colItr.AddVariableToIterateOn(unameItr);

            var passItr = new WarewolfIterator(dataObject.Environment.Eval(Password));
            colItr.AddVariableToIterateOn(passItr);


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

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

            while(colItr.HasMoreData())
            {
                IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker();

                try
                {
                    IActivityIOPath dst = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(inputItr),
                                                                                colItr.FetchNextValue(unameItr),
                                                                                colItr.FetchNextValue(passItr),
                                                                                true);

                    IActivityIOOperationsEndPoint dstEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(dst);
                    string result = broker.Delete(dstEndPoint);
                    outputs[0].OutputStrings.Add(result);
                }
                catch(Exception e)
                {
                    outputs.Add(DataListFactory.CreateOutputTO(Result, "Failure"));
                    //outputs[0].OutputStrings.Add(null);
                    allErrors.AddError(e.Message);
                    break;
                }
            }

            return outputs;
        }
        public bool WriteDataList(Guid datalistID, IBinaryDataList datalist, ErrorResultTO errors) {
            bool result = false;

            if (datalistID != GlobalConstants.NullDataListID)
            {
                Repo[datalistID] = datalist;
                result = true;
            }

            return result;
        }
Example #13
0
 protected override Guid ExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out ErrorResultTO tmpErrors, int update)
 {
     _errorsTo = new ErrorResultTO();
     var pluginServiceExecution = GetNewPluginServiceExecution(dataObject);
     pluginServiceExecution.InstanceInputDefinitions = inputs;
     pluginServiceExecution.InstanceOutputDefintions = outputs;
     tmpErrors = new ErrorResultTO();
     tmpErrors.MergeErrors(_errorsTo);
     var result = ExecutePluginService(pluginServiceExecution, update);
     tmpErrors.MergeErrors(_errorsTo);
     return result;
 }
        public DataListTranslatedPayloadTO ConvertFrom(IBinaryDataList payload, out ErrorResultTO errors)
        {
            if(payload == null)
            {
                throw new ArgumentNullException("payload");
            }

            StringBuilder result = new StringBuilder("<" + RootTag + ">");
            errors = new ErrorResultTO();

            var entries = payload.FetchAllEntries();

            foreach(var entry in entries)
            {
                if(entry.IsRecordset)
                {
                    AddEntryToBuilder(result, entry);
                    result.Append(">");
                    foreach(var col in entry.Columns)
                    {
                        result.Append("<");
                        result.Append(col.ColumnName);
                        result.Append(" " + Description + "=\"");
                        result.Append(col.ColumnDescription);
                        result.Append("\" ");
                        result.Append(IsEditable + "=\"");
                        result.Append(col.IsEditable);
                        result.Append("\" ");
                        // Travis.Frisinger - Added Column direction
                        result.Append(GlobalConstants.DataListIoColDirection + "=\"");
                        result.Append(col.ColumnIODirection);
                        result.Append("\" ");
                        result.Append("/>");
                    }

                    result.Append("</");
                    result.Append(entry.Namespace);
                    result.Append(">");
                }
                else
                {
                    AddEntryToBuilder(result, entry);
                    result.Append("/>");
                }
            }

            result.Append("</" + RootTag + ">");

            DataListTranslatedPayloadTO tmp = new DataListTranslatedPayloadTO(result.ToString());

            return tmp;
        }
        internal static void DoRecordSetAppending(ErrorResultTO errors, IBinaryDataListEntry entry, StringBuilder result)
        {
            var cnt = entry.FetchLastRecordsetIndex();
            var cols = entry.Columns;
            if(!cols.Any(c => c.ColumnIODirection == enDev2ColumnArgumentDirection.Both || c.ColumnIODirection == enDev2ColumnArgumentDirection.Input))
            {
                return;
            }
            for(var i = 1; i <= cnt; i++)
            {
                string error;
                var rowData = entry.FetchRecordAt(i, out error);
                errors.AddError(error);

                result.Append("<");
                result.Append(entry.Namespace);
                result.Append(">");

                foreach(var col in rowData)
                {

                    var fName = col.FieldName;

                    if(cols.Any(c => c.ColumnName == fName &&
                        (c.ColumnIODirection == enDev2ColumnArgumentDirection.Both || c.ColumnIODirection == enDev2ColumnArgumentDirection.Input)))
                    {

                        result.Append("<");
                        result.Append(fName);
                        result.Append(">");
                        try
                        {
                            result.Append(col.TheValue);
                        }
                        // ReSharper disable EmptyGeneralCatchClause
                        catch (Exception)
                        {
                        }
                        result.Append("</");
                        result.Append(fName);
                        result.Append(">");
                    }
                }

                result.Append("</");
                result.Append(entry.Namespace);
                result.Append(">");
            }
        }
        // ReSharper disable InconsistentNaming
        public void DsfPluginActivity_DsfPluginActivityUnitTest_ExecutePluginService_ServiceExecuted()
        // ReSharper restore InconsistentNaming
        {
            //init
            var pluginActivity = new MockDsfPluginActivity();
            var errors = new ErrorResultTO();
            var mockContainer = new Mock<PluginServiceExecution>(new DsfDataObject(It.IsAny<string>(), It.IsAny<Guid>()), It.IsAny<bool>());
            mockContainer.Setup(c => c.Execute(out errors, 0)).Verifiable();

            //exe
            pluginActivity.MockExecutePluginService(mockContainer.Object);

            //assert
            Assert.IsFalse(errors.HasErrors(), "Errors where thrown while executing a plugin service");
            mockContainer.Verify(c => c.Execute(out errors, 0), Times.Once());
        }
        public override Guid Execute(out ErrorResultTO errors)
        {
            errors = new ErrorResultTO();
            _databaseServiceExecution.BeforeExecution(errors);

            var databaseServiceExecution = _databaseServiceExecution as DatabaseServiceExecution;
            if(databaseServiceExecution != null)
            {
                databaseServiceExecution.InstanceInputDefinitions = InstanceInputDefinition;
                databaseServiceExecution.InstanceOutputDefintions = InstanceOutputDefinition;
            }

            var result = _databaseServiceExecution.Execute(out errors);
            _databaseServiceExecution.AfterExecution(errors);
            return result;
        }
Example #18
0
        /// <summary>
        /// Executes the specified errors.
        /// </summary>
        /// <param name="errors">The errors.</param>
        /// <param name="update"></param>
        /// <returns></returns>
        public override Guid Execute(out ErrorResultTO errors, int update)
        {
            errors = new ErrorResultTO();
           // WorkflowApplicationFactory wfFactor = new WorkflowApplicationFactory();
            Guid result = GlobalConstants.NullDataListID;


            Dev2Logger.Log.Debug("Entered Wf Container");

            // Set Service Name
            DataObject.ServiceName = ServiceAction.ServiceName;
           
            // Set server ID, only if not set yet - original server;
            if(DataObject.ServerID == Guid.Empty)
                DataObject.ServerID = HostSecurityProvider.Instance.ServerID;

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

            // Travis : Now set Data List
            DataObject.DataList = ServiceAction.DataListSpecification;
            // Set original instance ID, only if not set yet - original resource;
            if(DataObject.OriginalInstanceID == Guid.Empty)
                DataObject.OriginalInstanceID = DataObject.DataListID;
            Dev2Logger.Log.Info(String.Format("Started Execution for Service Name:{0} Resource Id:{1} Mode:{2}",DataObject.ServiceName,DataObject.ResourceID,DataObject.IsDebug?"Debug":"Execute"));
            //Set execution origin
            if(!string.IsNullOrWhiteSpace(DataObject.ParentServiceName))
            {
                DataObject.ExecutionOrigin = ExecutionOrigin.Workflow;
                DataObject.ExecutionOriginDescription = DataObject.ParentServiceName;
            }
            else if(DataObject.IsDebug)
            {
                DataObject.ExecutionOrigin = ExecutionOrigin.Debug;
            }
            else
            {
                DataObject.ExecutionOrigin = ExecutionOrigin.External;
            }
            var userPrinciple = Thread.CurrentPrincipal;
            ErrorResultTO to = errors;
            Common.Utilities.PerformActionInsideImpersonatedContext(userPrinciple,()=>{result = ExecuteWf(to);});
            
            Dev2Logger.Log.Info(String.Format("Completed Execution for Service Name:{0} Resource Id: {1} Mode:{2}",DataObject.ServiceName,DataObject.ResourceID,DataObject.IsDebug?"Debug":"Execute"));
            return result;
        }
        /// <summary>
        /// Converts from a binary representation in the standard format to the specified <see cref="Format" />.
        /// </summary>
        /// <param name="input">The binary representation of the datalist.</param>
        /// <param name="errors">The errors.</param>
        /// <returns>
        /// An array of bytes that represent the datalist in the specified <see cref="Format" />
        /// </returns>
        /// <exception cref="System.ArgumentNullException">input</exception>
        public DataListTranslatedPayloadTO ConvertFrom(IBinaryDataList input, out ErrorResultTO errors)
        {
            errors = new ErrorResultTO();
            if(input == null) throw new ArgumentNullException("input");

            IList<string> itemKeys = input.FetchAllUserKeys();
            errors = new ErrorResultTO();

            StringBuilder result = new StringBuilder("{");
            int keyCnt = 0;

            foreach(string key in itemKeys)
            {
                IBinaryDataListEntry entry;

                // This check was never here - this means this method has no testing and was never sane ;)

                string error;
                if(input.TryGetEntry(key, out entry, out error))
                {
                    if(entry.IsRecordset)
                    {
                        result.Append(ProcessRecordSet(entry, out error));
                        errors.AddError(error);
                    }
                    else
                    {
                        result.Append(ProcessScalar(entry));
                    }
                }

                errors.AddError(error);

                // wack in , for field separator ;)
                keyCnt++;
                if(keyCnt < itemKeys.Count)
                {
                    result.Append(",");
                }
            }

            result.Append("}");

            DataListTranslatedPayloadTO tmp = new DataListTranslatedPayloadTO(result.ToString());

            return tmp;
        }
        /// <summary>
        /// Replaces a value in and entry with a new value.
        /// </summary>
        /// <param name="stringToSearch">The old string.</param>
        /// <param name="findString">The old string.</param>
        /// <param name="replacementString">The new string.</param>
        /// <param name="caseMatch">if set to <c>true</c> [case match].</param>
        /// <param name="errors">The errors.</param>
        /// <param name="replaceCount">The replace count.</param>
        /// <returns></returns>
        public string Replace(string stringToSearch, string findString, string replacementString, bool caseMatch, out ErrorResultTO errors, ref int replaceCount)
        {

            var oldString = stringToSearch;
            ErrorResultTO allErrors = new ErrorResultTO();
            errors = new ErrorResultTO();
            allErrors.MergeErrors(errors);

            var regexOptions = caseMatch ? NoneCompiled : IgnoreCaseCompiled;

            Regex regex = new Regex(Regex.Escape(findString), regexOptions);
            string tmpVal = oldString;
            replaceCount += regex.Matches(tmpVal).Count;
            var replaceValue = regex.Replace(tmpVal, replacementString);
            errors = allErrors;
            return replaceValue;
        }
        protected override Guid ExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out ErrorResultTO tmpErrors)
        {
            tmpErrors = new ErrorResultTO();
            var webserviceExecution = GetNewWebserviceExecution(dataObject);


            if(webserviceExecution != null && !tmpErrors.HasErrors())
            {
                webserviceExecution.InstanceOutputDefintions = outputs; // set the output mapping for the instance ;)
                webserviceExecution.InstanceInputDefinitions = inputs;
                ErrorResultTO invokeErrors;
                var result = webserviceExecution.Execute(out invokeErrors);
                dataObject.Environment.AddError(invokeErrors.MakeDataListReady());
                return result;
            }
            return Guid.NewGuid();
        }
        public DataListTranslatedPayloadTO ConvertFrom(IBinaryDataList payload, out ErrorResultTO errors)
        {
            if(payload == null)
            {
                throw new ArgumentNullException("payload");
            }

            StringBuilder result = new StringBuilder("<" + RootTag + ">");
            errors = new ErrorResultTO();

            var itemKeys = payload.FetchAllKeys();

            foreach(var key in itemKeys)
            {
                IBinaryDataListEntry entry;
                string error;
                if(payload.TryGetEntry(key, out entry, out error))
                {
                    if(entry.IsRecordset && (entry.ColumnIODirection == enDev2ColumnArgumentDirection.Input || entry.ColumnIODirection == enDev2ColumnArgumentDirection.Both))
                    {
                        DoRecordSetAppending(errors, entry, result);
                    }
                    else
                    {
                        var fName = entry.Namespace;
                        var val = entry.FetchScalar();
                        if(val != null && (entry.ColumnIODirection == enDev2ColumnArgumentDirection.Input || entry.ColumnIODirection == enDev2ColumnArgumentDirection.Both))
                        {
                            DoScalarAppending(result, fName, val);
                        }
                    }
                }

            }

            result.Append("</" + RootTag + ">");

            DataListTranslatedPayloadTO tmp = new DataListTranslatedPayloadTO(result.ToString());

            return tmp;
        }
        protected override Guid ExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out ErrorResultTO tmpErrors)
        {
            _errorsTo = new ErrorResultTO();
            var compiler = DataListFactory.CreateDataListCompiler();

            ErrorResultTO invokeErrors;
            esbChannel.CorrectDataList(dataObject, dataObject.WorkspaceID, out invokeErrors, compiler);

            dataObject.DataListID = compiler.Shape(dataObject.DataListID, enDev2ArgumentType.Input, inputs, out invokeErrors);
            _errorsTo.MergeErrors(invokeErrors);

            _errorsTo.MergeErrors(invokeErrors);
            var pluginServiceExecution = GetNewPluginServiceExecution(dataObject);
            pluginServiceExecution.InstanceInputDefinitions = inputs;
            pluginServiceExecution.InstanceOutputDefintions = outputs;
            tmpErrors = new ErrorResultTO();
            tmpErrors.MergeErrors(_errorsTo);
            var result = ExecutePluginService(pluginServiceExecution);
            tmpErrors.MergeErrors(_errorsTo);
            return result;
        }
        public override Guid Execute(out ErrorResultTO errors, int update)
        {
            errors = new ErrorResultTO();
            var invokeErrors = new ErrorResultTO();
            Guid result = GlobalConstants.NullDataListID;

            try
            {
                EsbManagementServiceLocator emsl = new EsbManagementServiceLocator();
                IEsbManagementEndpoint eme = emsl.LocateManagementService(ServiceAction.Name);

                if(eme != null)
                {
                    // Web request for internal service ;)
                    if(Request.Args == null)
                    {
                        GenerateRequestDictionaryFromDataObject(out invokeErrors);
                        errors.MergeErrors(invokeErrors);
                    }

                    var res = eme.Execute(Request.Args, TheWorkspace);
                    Request.ExecuteResult = res;
                    errors.MergeErrors(invokeErrors);
                    result = DataObject.DataListID;
                    Request.WasInternalService = true;
                }
                else
                {
                    errors.AddError("Could not locate management service [ " + ServiceAction.ServiceName + " ]");
                }
            }
            catch(Exception ex)
            {
                errors.AddError(ex.Message);
            }

            return result;
        }
        // ReSharper disable InconsistentNaming
        public void DsfDatabaseActivity_UnitTest_ExecutionImpl_InvokesDatabaseServiceExecution()
        // ReSharper restore InconsistentNaming
        {
            // ReSharper disable RedundantAssignment
            ErrorResultTO errors = new ErrorResultTO();
            // ReSharper restore RedundantAssignment

            var dataObj = new Mock<IDSFDataObject>();

            var dbServiceExecution = new Mock<IServiceExecution>();
            dbServiceExecution.Setup(s => s.DataObj).Returns(dataObj.Object);
            dbServiceExecution.Setup(s => s.Execute(out errors, 0)).Verifiable();

            var databaseActivity = new MockDsfDatabaseActivity(dbServiceExecution.Object);

            // ShapeForSubRequest
            var mockEsb = new Mock<IEsbChannel>();
            //mockEsb.Setup(s => s.ShapeForSubRequest(It.IsAny<IDSFDataObject>(), It.IsAny<string>(), It.IsAny<string>(), out errors)).Returns(null);
            databaseActivity.MockExecutionImpl(mockEsb.Object, dataObj.Object, string.Empty, string.Empty, out errors);

            //assert
            dbServiceExecution.Verify(s => s.Execute(out errors, 0));
        }
        public override Guid Execute(out ErrorResultTO errors, int update)
        {
            Dev2Logger.Log.Info(String.Format("Starting Remote Execution. Service Name:{0} Resource Id:{1} Mode:{2}", DataObject.ServiceName, DataObject.ResourceID, DataObject.IsDebug ? "Debug" : "Execute"));

            var serviceName = DataObject.ServiceName;

            errors = new ErrorResultTO();

            // get data in a format we can send ;)
            Dev2Logger.Log.Debug("Creating DataList fragment for remote execute");
            var dataListFragment = ExecutionEnvironmentUtils.GetXmlInputFromEnvironment(DataObject, DataObject.RemoteInvokeResultShape.ToString(), update);

            string result = string.Empty;

            var connection = GetConnection(DataObject.EnvironmentID);
            if (connection == null)
            {
                errors.AddError("Server source not found.");
                return DataObject.DataListID;
            }

            try
            {
                // Invoke Remote WF Here ;)
                result = ExecuteGetRequest(connection, serviceName, dataListFragment);
                IList<IDebugState> msg = DataObject.IsDebug? FetchRemoteDebugItems(connection):new List<IDebugState>();
                DataObject.RemoteDebugItems = msg; // set them so they can be acted upon
            }
            catch (Exception e)
            {
                var errorMessage = e.Message.Contains("Forbidden") ? "Executing a service requires Execute permissions" : e.Message;
                DataObject.Environment.Errors.Add(errorMessage);
                Dev2Logger.Log.Error(e);
            }

            // Create tmpDL
            ExecutionEnvironmentUtils.UpdateEnvironmentFromOutputPayload(DataObject,result.ToStringBuilder(),DataObject.RemoteInvokeResultShape.ToString(), update);
            Dev2Logger.Log.Info(String.Format("Completed Remote Execution. Service Name:{0} Resource Id:{1} Mode:{2}", DataObject.ServiceName, DataObject.ResourceID, DataObject.IsDebug ? "Debug" : "Execute"));

            return Guid.Empty;
        }
        /// <summary>
        /// Invokes the workflow.
        /// </summary>
        /// <param name="workflowActivity">The workflow activity.</param>
        /// <param name="dataTransferObject">The data transfer object.</param>
        /// <param name="executionExtensions">The execution extensions.</param>
        /// <param name="instanceId">The instance id.</param>
        /// <param name="workspace">The workspace.</param>
        /// <param name="bookmarkName">Name of the bookmark.</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        public IDSFDataObject InvokeWorkflow(Activity workflowActivity, IDSFDataObject dataTransferObject, IList<object> executionExtensions, Guid instanceId, IWorkspace workspace, string bookmarkName, out ErrorResultTO errors)
        {

            return InvokeWorkflowImpl(workflowActivity, dataTransferObject, executionExtensions, instanceId, workspace, bookmarkName, dataTransferObject.IsDebug, out errors);
        }
            public WorkflowApplicationRun(WorkflowApplicationFactory owner, ManualResetEventSlim waitHandle, IDSFDataObject dataTransferObject, WorkflowApplication instance, IWorkspace workspace, IList<object> executionExtensions, Guid parentWorkflowInstanceId, bool isDebug, ErrorResultTO errors, IExecutionToken executionToken)
            {
                _owner = owner;
                _waitHandle = waitHandle;
                _result = dataTransferObject;
                _instance = instance;
                _workspace = workspace;
                _executionExtensions = executionExtensions;
                _isDebug = isDebug;
                _parentWorkflowInstanceID = parentWorkflowInstanceId;
                _executionToken = executionToken;

                _instance.PersistableIdle = OnPersistableIdle;
                _instance.Unloaded = OnUnloaded;
                _instance.Completed = OnCompleted;
                _instance.Aborted = OnAborted;
                _instance.OnUnhandledException = OnUnhandledException;

                AllErrors = errors;
            }
        /// <summary>
        /// Invokes the workflow impl.
        /// </summary>
        /// <param name="workflowActivity">The workflow activity.</param>
        /// <param name="dataTransferObject">The data transfer object.</param>
        /// <param name="executionExtensions">The execution extensions.</param>
        /// <param name="instanceId">The instance id.</param>
        /// <param name="workspace">The workspace.</param>
        /// <param name="bookmarkName">Name of the bookmark.</param>
        /// <param name="isDebug">if set to <c>true</c> [is debug].</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        private IDSFDataObject InvokeWorkflowImpl(Activity workflowActivity, IDSFDataObject dataTransferObject, IList<object> executionExtensions, Guid instanceId, IWorkspace workspace, string bookmarkName, bool isDebug, out ErrorResultTO errors)
        {
            Tracker.TrackEvent(TrackerEventGroup.Workflows, TrackerEventName.Executed, string.Format("RES-{0}", dataTransferObject.ResourceID));

            if(AllErrors == null)
            {
                AllErrors = new ErrorResultTO();
            }
            IExecutionToken exeToken = new ExecutionToken { IsUserCanceled = false };

            ExecutionStatusCallbackDispatcher.Instance.Post(dataTransferObject.ExecutionCallbackID, ExecutionStatusCallbackMessageType.StartedCallback);
            WorkflowApplication wfApp = InitEntryPoint(workflowActivity, dataTransferObject, executionExtensions, instanceId, workspace, bookmarkName);
            errors = new ErrorResultTO();

            if(wfApp != null)
            {
                // add termination token
                wfApp.Extensions.Add(exeToken);

                using(ManualResetEventSlim waitHandle = new ManualResetEventSlim(false))
                {
                    WorkflowApplicationRun run = new WorkflowApplicationRun(this, waitHandle, dataTransferObject, wfApp, workspace, executionExtensions, FetchParentInstanceId(dataTransferObject), isDebug, errors, exeToken);


                    if(instanceId == Guid.Empty)
                    {
                        Interlocked.Increment(ref Balance);
                        run.Run();
                        _runTime = DateTime.Now;
                        waitHandle.Wait();
                    }
                    else
                    {
                        Interlocked.Increment(ref Balance);

                        try
                        {
                            if(!string.IsNullOrEmpty(bookmarkName))
                            {
                                dataTransferObject.CurrentBookmarkName = bookmarkName;
                                run.Resume(dataTransferObject);
                            }
                            else
                            {
                                run.Run();
                                _runTime = DateTime.Now;
                            }

                            waitHandle.Wait();
                        }
                        catch(InstanceNotReadyException e1)
                        {
                            Interlocked.Decrement(ref Balance);
                            ExecutionStatusCallbackDispatcher.Instance.Post(dataTransferObject.ExecutionCallbackID, ExecutionStatusCallbackMessageType.ErrorCallback);

                            errors.AddError(e1.Message);
                            AllErrors.AddError(e1.Message);
                            return null;
                        }
                        catch(InstancePersistenceException e2)
                        {
                            Interlocked.Decrement(ref Balance);
                            ExecutionStatusCallbackDispatcher.Instance.Post(dataTransferObject.ExecutionCallbackID, ExecutionStatusCallbackMessageType.ErrorCallback);

                            errors.AddError(e2.Message);
                            AllErrors.AddError(e2.Message);
                            return run.DataTransferObject.Clone();
                        }
                        catch(Exception ex)
                        {
                            Interlocked.Decrement(ref Balance);

                            errors.AddError(ex.Message);
                            AllErrors.AddError(ex.Message);

                            ExecutionStatusCallbackDispatcher.Instance.Post(dataTransferObject.ExecutionCallbackID, ExecutionStatusCallbackMessageType.ErrorCallback);

                            return run.DataTransferObject.Clone();
                        }
                    }

                    Interlocked.Decrement(ref Balance);
                    dataTransferObject = run.DataTransferObject.Clone();
                    var wfappUtils = new WfApplicationUtils();

                    ErrorResultTO invokeErrors;
                    if (dataTransferObject.IsDebugMode())
                    {
                        wfappUtils.DispatchDebugState(dataTransferObject, StateType.End, AllErrors.HasErrors(), AllErrors.MakeDisplayReady(), out invokeErrors, _runTime, false, true);
                    }
                    //AllErrors.MergeErrors(invokeErrors);
                    // avoid memory leak ;)
                    run.Dispose();
                }
            }
            else
            {
                errors.AddError("Internal System Error : Could not create workflow execution wrapper");
            }

            return dataTransferObject;
        }
 public abstract Guid Execute(out ErrorResultTO errors);