/// <summary>
        /// Executes the request.
        /// </summary>
        /// <param name="dataObject">The data object.</param>
        /// <param name="request"></param>
        /// <param name="workspaceId">The workspace ID.</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        public Guid ExecuteRequest(IDSFDataObject dataObject, EsbExecuteRequest request, Guid workspaceId, out ErrorResultTO errors)
        {
            var resultID = GlobalConstants.NullDataListID;

            errors = new ErrorResultTO();
            IWorkspace theWorkspace = null;

            Common.Utilities.PerformActionInsideImpersonatedContext(Common.Utilities.ServerUser, () =>
            {
                theWorkspace = wRepository.Get(workspaceId);
            });
            // If no DLID, we need to make it based upon the request ;)
            if (dataObject.DataListID == GlobalConstants.NullDataListID)
            {
                IResource resource;
                try
                {
                    resource = dataObject.ResourceID == Guid.Empty ? GetResource(workspaceId, dataObject.ServiceName) : GetResource(workspaceId, dataObject.ResourceID);
                }
                catch (Exception ex)
                {
                    Dev2Logger.Error(ex);
                    errors.AddError(string.Format(ErrorResource.ServiceNotFound, dataObject.ServiceName));
                    return(resultID);
                }

                if (resource?.DataList != null)
                {
                    Dev2Logger.Debug("Mapping Inputs from Environment");
                    ExecutionEnvironmentUtils.UpdateEnvironmentFromInputPayload(dataObject, dataObject.RawPayload, resource.DataList.ToString());
                }
                dataObject.RawPayload = new StringBuilder();

                // We need to create the parentID around the system ;)
                dataObject.ParentThreadID = Thread.CurrentThread.ManagedThreadId;
            }

            try
            {
                // Setup the invoker endpoint ;)
                Dev2Logger.Debug("Creating Invoker");
                using (var invoker = new EsbServiceInvoker(this, theWorkspace, request))
                {
                    // Should return the top level DLID
                    ErrorResultTO invokeErrors;
                    resultID = invoker.Invoke(dataObject, out invokeErrors);
                    errors.MergeErrors(invokeErrors);
                }
            }
            catch (Exception ex)
            {
                errors.AddError(ex.Message);
            }
            return(resultID);
        }
        public void ExecutionEnvironmentUtils_UpdateEnvironmentFromInputPayload_WithXmlChar_ShouldStillMapWhenInputAsJson()
        {
            var          dataObj  = new DsfDataObject(string.Empty, Guid.NewGuid());
            const string dataList = "<DataList>" +
                                    "<input Description=\"\" IsEditable=\"True\" ColumnIODirection=\"Input\"/>" +
                                    "</DataList>";
            var inputPayload = new StringBuilder("{\"input\":\"123<1234\"}");

            ExecutionEnvironmentUtils.UpdateEnvironmentFromInputPayload(dataObj, inputPayload, dataList);
            Assert.IsNotNull(dataObj.Environment);
            var values = dataObj.Environment.EvalAsListOfStrings("[[input]]", 0);

            Assert.IsNotNull(values);
            Assert.AreEqual(1, values.Count);
            Assert.AreEqual("123<1234", values[0]);
        }
Beispiel #3
0
        private static bool EnsureDataListIdIsSet(IDSFDataObject dataObject, Guid workspaceId, ErrorResultTO errors)
        {
            if (dataObject.DataListID == GlobalConstants.NullDataListID)
            {
                var resource = GetResource(dataObject, workspaceId, errors);
                if (resource?.HasDataList ?? false)
                {
                    Dev2Logger.Debug("Remote Invoke", dataObject.ExecutionID.ToString());
                    Dev2Logger.Debug("Mapping Inputs from Environment", dataObject.ExecutionID.ToString());
                    ExecutionEnvironmentUtils.UpdateEnvironmentFromInputPayload(dataObject, dataObject.RawPayload, resource.DataList.ToString());
                }
                dataObject.RawPayload = new StringBuilder();

                // We need to create the parentID around the system
                dataObject.ParentThreadID = Thread.CurrentThread.ManagedThreadId;
            }
            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Executes the request.
        /// </summary>
        /// <param name="dataObject">The data object.</param>
        /// <param name="request"></param>
        /// <param name="workspaceId">The workspace ID.</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        public Guid ExecuteRequest(IDSFDataObject dataObject, EsbExecuteRequest request, Guid workspaceId, out ErrorResultTO errors)
        {
            var resultID = GlobalConstants.NullDataListID;

            errors = new ErrorResultTO();
            var theWorkspace = WorkspaceRepository.Instance.Get(workspaceId);

            var principle = Thread.CurrentPrincipal;
            var name      = principle.Identity.Name;


            // If no DLID, we need to make it based upon the request ;)
            if (dataObject.DataListID == GlobalConstants.NullDataListID)
            {
                IResource resource;
                try
                {
                    resource = dataObject.ResourceID == Guid.Empty ? GetResource(workspaceId, dataObject.ServiceName) : GetResource(workspaceId, dataObject.ResourceID);
                }
                catch (Exception ex)
                {
                    Dev2Logger.Log.Error(ex);
                    errors.AddError(string.Format("Service [ {0} ] not found.", dataObject.ServiceName));
                    return(resultID);
                }

                // TODO : Amend here to respect Inputs only when creating shape ;)
                if (resource != null)
                {
                    if (resource.DataList != null)
                    {
                        Dev2Logger.Log.Debug("Mapping Inputs from Environment");
                        ExecutionEnvironmentUtils.UpdateEnvironmentFromInputPayload(dataObject, dataObject.RawPayload, resource.DataList.ToString(), 0);
                    }
                }
                dataObject.RawPayload = new StringBuilder();

                // We need to create the parentID around the system ;)
                dataObject.ParentThreadID = Thread.CurrentThread.ManagedThreadId;
            }

            try
            {
                // Setup the invoker endpoint ;)
                Dev2Logger.Log.Debug("Creating Invoker");
                using (var invoker = new EsbServiceInvoker(this, this, theWorkspace, request))
                {
                    // Should return the top level DLID
                    ErrorResultTO invokeErrors;
                    resultID = invoker.Invoke(dataObject, out invokeErrors);
                    errors.MergeErrors(invokeErrors);
                }
            }
            catch (Exception ex)
            {
                errors.AddError(ex.Message);
            }



            return(resultID);
        }
        /// <summary>
        /// Executes the request.
        /// </summary>
        /// <param name="dataObject">The data object.</param>
        /// <param name="request"></param>
        /// <param name="workspaceId">The workspace ID.</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        public Guid ExecuteRequest(IDSFDataObject dataObject, EsbExecuteRequest request, Guid workspaceId, out ErrorResultTO errors)
        {
            var resultID = GlobalConstants.NullDataListID;

            errors = new ErrorResultTO();
            var theWorkspace = WorkspaceRepository.Instance.Get(workspaceId);
            var compiler     = DataListFactory.CreateDataListCompiler();

            var principle = Thread.CurrentPrincipal;
            var name      = principle.Identity.Name;

            Dev2Logger.Log.Info("EXECUTION USER CONTEXT IS [ " + name + " ] FOR SERVICE [ " + dataObject.ServiceName + " ]");

            // If no DLID, we need to make it based upon the request ;)
            if (dataObject.DataListID == GlobalConstants.NullDataListID)
            {
                StringBuilder theShape;
                IResource     resource;
                try
                {
                    theShape = dataObject.ResourceID == Guid.Empty ? FindServiceShape(workspaceId, dataObject.ServiceName) : FindServiceShape(workspaceId, dataObject.ResourceID);
                    resource = dataObject.ResourceID == Guid.Empty ? GetResource(workspaceId, dataObject.ServiceName) : GetResource(workspaceId, dataObject.ResourceID);
                }
                catch (Exception ex)
                {
                    Dev2Logger.Log.Error(ex);
                    errors.AddError(string.Format("Service [ {0} ] not found.", dataObject.ServiceName));
                    return(resultID);
                }

                // TODO : Amend here to respect Inputs only when creating shape ;)
                ErrorResultTO invokeErrors;
                if (resource != null)
                {
                    if (resource.DataList != null)
                    {
                        ExecutionEnvironmentUtils.UpdateEnvironmentFromInputPayload(dataObject, dataObject.RawPayload, resource.DataList.ToString());
                    }
                }
                dataObject.DataListID = compiler.ConvertAndOnlyMapInputs(DataListFormat.CreateFormat(GlobalConstants._XML), dataObject.RawPayload, theShape, out invokeErrors);
                // The act of doing this moves the index data correctly ;)
                // We need to remove this in the future.
#pragma warning disable 168
                // ReSharper disable UnusedVariable
                var convertFrom = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), enTranslationDepth.Data, out errors);
                // ReSharper restore UnusedVariable
#pragma warning restore 168
                errors.MergeErrors(invokeErrors);
                dataObject.RawPayload = new StringBuilder();

                // We need to create the parentID around the system ;)
                dataObject.ParentThreadID = Thread.CurrentThread.ManagedThreadId;
            }

            try
            {
                // Setup the invoker endpoint ;)
                using (var invoker = new EsbServiceInvoker(this, this, theWorkspace, request))
                {
                    // Should return the top level DLID
                    ErrorResultTO invokeErrors;
                    resultID = invoker.Invoke(dataObject, out invokeErrors);
                    errors.MergeErrors(invokeErrors);
                }
            }
            catch (Exception ex)
            {
                errors.AddError(ex.Message);
            }
            finally
            {
                // clean up after the request has executed ;)
                if (dataObject.IsDebug && !_doNotWipeDataList && !dataObject.IsRemoteInvoke)
                {
                    DataListRegistar.ClearDataList();
                }
                else
                {
                    foreach (var thread in dataObject.ThreadsToDispose)
                    {
                        DataListRegistar.DisposeScope(thread.Key, resultID);
                    }

                    DataListRegistar.DisposeScope(Thread.CurrentThread.ManagedThreadId, resultID);
                }
            }

            return(resultID);
        }