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; }
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; }
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; }
/// <summary> /// Pushes the system model to data list. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dlID">The dl ID.</param> /// <param name="model">The model.</param> /// <param name="errors">The errors.</param> /// <returns></returns> public Guid PushSystemModelToDataList <T>(Guid dlID, T model, out ErrorResultTO errors) { // Serialize the model first ;) var jsonModel = ConvertModelToJson(model); ErrorResultTO allErrors = new ErrorResultTO(); // Create a new DL if need be Guid pushID = dlID; if (pushID == GlobalConstants.NullDataListID) { IBinaryDataList bdl = Dev2BinaryDataListFactory.CreateDataList(); pushID = PushBinaryDataList(bdl.UID, bdl, out errors); allErrors.MergeErrors(errors); errors.ClearErrors(); } UpsertSystemTag(pushID, enSystemTag.SystemModel, jsonModel.ToString(), out errors); allErrors.MergeErrors(errors); errors = allErrors; return(pushID); }
/// <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; }
//MO - Changed : new ctor that accepts the new arguments public ForEachBootstrapTO(enForEachType forEachType, string from, string to, string csvNumbers, string numberOfExecutes, string recordsetName, IExecutionEnvironment compiler, out ErrorResultTO errors, int update) { errors = new ErrorResultTO(); ForEachType = forEachType; IIndexIterator localIndexIterator; switch(forEachType) { case enForEachType.InRecordset: var records = compiler.EvalRecordSetIndexes(recordsetName, update); if (!compiler.HasRecordSet(recordsetName) ) { errors.AddError("When selecting a recordset only valid recordsets can be used"); break; } localIndexIterator = new IndexListIndexIterator(records); IndexIterator = localIndexIterator; break; case enForEachType.InRange: if(string.IsNullOrWhiteSpace(@from)) { errors.AddError("The from field can not be left empty."); break; } if(string.IsNullOrWhiteSpace(to)) { errors.AddError("The to field can not be left empty."); break; } if(@from.Contains("(*)")) { errors.AddError("The Star notation is not accepted in the From field."); break; } var evalledFrom = ExecutionEnvironment.WarewolfEvalResultToString( compiler.Eval(@from, update)); int intFrom; if (!int.TryParse(evalledFrom, out intFrom) || intFrom < 1) { errors.AddError("From range must be a whole number from 1 onwards."); break; } if(to.Contains("(*)")) { errors.AddError("The Star notation is not accepted in the To field."); break; } var evalledTo= ExecutionEnvironment.WarewolfEvalResultToString( compiler.Eval(@to, update)); int intTo; if (!int.TryParse(evalledTo, out intTo) || intTo < 1) { errors.AddError("To range must be a whole number from 1 onwards."); break; } IndexList indexList; if(intFrom > intTo) { indexList = new IndexList(new HashSet<int>(), 0) { MinValue = intFrom, MaxValue = intTo }; ReverseIndexIterator revIdxItr = new ReverseIndexIterator(new HashSet<int>(), 0) { IndexList = indexList }; IndexIterator = revIdxItr; } else { indexList = new IndexList(new HashSet<int>(), 0) { MinValue = intFrom, MaxValue = intTo }; localIndexIterator = new IndexIterator(new HashSet<int>(), 0) { IndexList = indexList }; IndexIterator = localIndexIterator; } break; case enForEachType.InCSV: var csvIndexedsItr = ExecutionEnvironment.WarewolfEvalResultToString( compiler.Eval(csvNumbers, update)); ErrorResultTO allErrors; List<int> listOfIndexes = SplitOutCsvIndexes(csvIndexedsItr, out allErrors); if(allErrors.HasErrors()) { errors.MergeErrors(allErrors); break; } ListIndexIterator listLocalIndexIterator = new ListIndexIterator(listOfIndexes); ListOfIndex listOfIndex = new ListOfIndex(listOfIndexes); listLocalIndexIterator.IndexList = listOfIndex; IndexIterator = listLocalIndexIterator; break; default: if(numberOfExecutes != null && numberOfExecutes.Contains("(*)")) { errors.AddError("The Star notation is not accepted in the Numbers field."); break; } int intExNum; var numOfExItr = ExecutionEnvironment.WarewolfEvalResultToString( compiler.Eval(numberOfExecutes, update)); if (!int.TryParse(numOfExItr, out intExNum)) { errors.AddError("Number of executes must be a whole number from 1 onwards."); } IndexIterator = new IndexIterator(new HashSet<int>(), intExNum); break; } }
public void DispatchDebugState(IDSFDataObject dataObject, StateType stateType, bool hasErrors, string existingErrors, out ErrorResultTO errors, DateTime? workflowStartTime = null, bool interrogateInputs = false, bool interrogateOutputs = false) { errors = new ErrorResultTO(); if(dataObject != null) { Guid parentInstanceId; Guid.TryParse(dataObject.ParentInstanceID, out parentInstanceId); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); bool hasError = dataObject.Environment.HasErrors(); var errorMessage = String.Empty; if(hasError) { errorMessage = dataObject.Environment.FetchErrors(); } if(String.IsNullOrEmpty(existingErrors)) { existingErrors = errorMessage; } else { existingErrors += Environment.NewLine + errorMessage; } var debugState = new DebugState { ID = dataObject.OriginalInstanceID, ParentID = parentInstanceId, WorkspaceID = dataObject.WorkspaceID, StateType = stateType, StartTime = workflowStartTime ?? DateTime.Now, EndTime = DateTime.Now, ActivityType = ActivityType.Workflow, DisplayName = dataObject.ServiceName, IsSimulation = dataObject.IsOnDemandSimulation, ServerID = dataObject.ServerID, OriginatingResourceID = dataObject.ResourceID, OriginalInstanceID = dataObject.OriginalInstanceID, Server = string.Empty, Version = string.Empty, SessionID = dataObject.DebugSessionID, EnvironmentID = dataObject.EnvironmentID, ClientID = dataObject.ClientID, Name = stateType.ToString(), HasError = hasErrors || hasError, ErrorMessage = existingErrors }; if(interrogateInputs) { ErrorResultTO invokeErrors; var defs = compiler.GenerateDefsFromDataListForDebug(FindServiceShape(dataObject.WorkspaceID, dataObject.ResourceID), enDev2ColumnArgumentDirection.Input); var inputs = GetDebugValues(defs, dataObject, out invokeErrors); errors.MergeErrors(invokeErrors); debugState.Inputs.AddRange(inputs); } if(interrogateOutputs) { ErrorResultTO invokeErrors; var defs = compiler.GenerateDefsFromDataListForDebug(FindServiceShape(dataObject.WorkspaceID, dataObject.ResourceID), enDev2ColumnArgumentDirection.Output); var inputs = GetDebugValues(defs, dataObject, out invokeErrors); errors.MergeErrors(invokeErrors); debugState.Outputs.AddRange(inputs); } if(stateType == StateType.End) { debugState.NumberOfSteps = dataObject.NumberOfSteps; } if(stateType == StateType.Start) { debugState.ExecutionOrigin = dataObject.ExecutionOrigin; debugState.ExecutionOriginDescription = dataObject.ExecutionOriginDescription; } if(dataObject.IsDebugMode() || (dataObject.RunWorkflowAsync && !dataObject.IsFromWebServer)) { var debugDispatcher = GetDebugDispatcher(); if(debugState.StateType == StateType.End) { while(!debugDispatcher.IsQueueEmpty) { Thread.Sleep(100); } debugDispatcher.Write(debugState, dataObject.RemoteInvoke, dataObject.RemoteInvokerID, dataObject.ParentInstanceID, dataObject.RemoteDebugItems); } else { debugDispatcher.Write(debugState); } } } }
// NOTE : This will be tested by the related WebServices and Plugin Integration Test public Guid Populate(object input, Guid targetDl, string outputDefs, out ErrorResultTO errors) { // input is a string of output mappings ;) var compiler = DataListFactory.CreateDataListCompiler(); var outputDefinitions = (input as string); errors = new ErrorResultTO(); ErrorResultTO invokeErrors; // get sneeky and use the output shape operation for now, // as this should only every be called from external service containers all is good // if this is ever not the case be afraid, be very afraid! var targetDataList = compiler.FetchBinaryDataList(targetDl, out invokeErrors); errors.MergeErrors(invokeErrors); var parentDataList = compiler.FetchBinaryDataList(targetDataList.ParentUID, out invokeErrors); errors.MergeErrors(invokeErrors); var grandparentDl = compiler.FetchBinaryDataList(parentDataList.ParentUID, out invokeErrors); // as a result we need to re-set some alias operations that took place in the parent DataList where they happended ;) foreach(var entry in parentDataList.FetchRecordsetEntries()) { entry.AdjustAliasOperationForExternalServicePopulate(); } var parentId = parentDataList.UID; if(grandparentDl != null) { parentId = grandparentDl.UID; } compiler.SetParentID(targetDl, parentId); Guid result = compiler.Shape(targetDl, enDev2ArgumentType.Output, outputDefinitions, out invokeErrors); errors.MergeErrors(invokeErrors); return result; }
protected static IResponseWriter CreateForm(WebRequestTO webRequest, string serviceName, string workspaceId, NameValueCollection headers, IPrincipal user = null) { //lock(ExecutionObject) { string executePayload = ""; Guid workspaceGuid; if(workspaceId != null) { if(!Guid.TryParse(workspaceId, out workspaceGuid)) { workspaceGuid = WorkspaceRepository.Instance.ServerWorkspace.ID; } } else { workspaceGuid = WorkspaceRepository.Instance.ServerWorkspace.ID; } var allErrors = new ErrorResultTO(); var dataObject = new DsfDataObject(webRequest.RawRequestPayload, GlobalConstants.NullDataListID, webRequest.RawRequestPayload) { IsFromWebServer = true, ExecutingUser = user, ServiceName = serviceName, WorkspaceID = workspaceGuid }; // now bind any variables that are part of the path arguments ;) BindRequestVariablesToDataObject(webRequest, ref dataObject); // now process headers ;) if(headers != null) { Dev2Logger.Log.Debug("Remote Invoke"); var isRemote = headers.Get(HttpRequestHeader.Cookie.ToString()); var remoteId = headers.Get(HttpRequestHeader.From.ToString()); if(isRemote != null && remoteId != null) { if (isRemote.Equals(GlobalConstants.RemoteServerInvoke) ) { // we have a remote invoke ;) dataObject.RemoteInvoke = true; } if (isRemote.Equals(GlobalConstants.RemoteDebugServerInvoke)) { // we have a remote invoke ;) dataObject.RemoteNonDebugInvoke = true; } dataObject.RemoteInvokerID = remoteId; } } // now set the emition type ;) int loc; if(!String.IsNullOrEmpty(serviceName) && (loc = serviceName.LastIndexOf(".", StringComparison.Ordinal)) > 0) { // default it to xml dataObject.ReturnType = EmitionTypes.XML; if(loc > 0) { var typeOf = serviceName.Substring((loc + 1)).ToUpper(); EmitionTypes myType; if(Enum.TryParse(typeOf, out myType)) { dataObject.ReturnType = myType; } // adjust the service name to drop the type ;) // avoid .wiz amendments ;) if(!typeOf.ToLower().Equals(GlobalConstants.WizardExt)) { serviceName = serviceName.Substring(0, loc); dataObject.ServiceName = serviceName; } if(typeOf.Equals("api", StringComparison.OrdinalIgnoreCase)) { dataObject.ReturnType = EmitionTypes.SWAGGER; } } } else { // default it to xml dataObject.ReturnType = EmitionTypes.XML; } // ensure service gets set ;) if(dataObject.ServiceName == null) { dataObject.ServiceName = serviceName; } IResource resource = null; if(!String.IsNullOrEmpty(dataObject.ServiceName)) { resource = ResourceCatalog.Instance.GetResource(dataObject.WorkspaceID, dataObject.ServiceName); if(resource != null) { dataObject.ResourceID = resource.ResourceID; } } var esbEndpoint = new EsbServicesEndpoint(); dataObject.EsbChannel = esbEndpoint; var canExecute = true; if(ServerAuthorizationService.Instance != null) { var authorizationService = ServerAuthorizationService.Instance; var hasView = authorizationService.IsAuthorized(AuthorizationContext.View, dataObject.ResourceID.ToString()); var hasExecute = authorizationService.IsAuthorized(AuthorizationContext.Execute, dataObject.ResourceID.ToString()); canExecute = (hasExecute && hasView) || ((dataObject.RemoteInvoke || dataObject.RemoteNonDebugInvoke) && hasExecute) || (resource != null && resource.ResourceType == ResourceType.ReservedService); } // Build EsbExecutionRequest - Internal Services Require This ;) EsbExecuteRequest esbExecuteRequest = new EsbExecuteRequest { ServiceName = serviceName }; foreach(string key in webRequest.Variables) { esbExecuteRequest.AddArgument(key, new StringBuilder(webRequest.Variables[key])); } Dev2Logger.Log.Debug("About to execute web request [ " + serviceName + " ] DataObject Payload [ " + dataObject.RawPayload + " ]"); var executionDlid = GlobalConstants.NullDataListID; if (canExecute && dataObject.ReturnType != EmitionTypes.SWAGGER) { ErrorResultTO errors = null; // set correct principle ;) Thread.CurrentPrincipal = user; var userPrinciple = user; Common.Utilities.PerformActionInsideImpersonatedContext(userPrinciple, () => { executionDlid = esbEndpoint.ExecuteRequest(dataObject, esbExecuteRequest, workspaceGuid, out errors); }); allErrors.MergeErrors(errors); } else if(!canExecute) { allErrors.AddError("Executing a service externally requires View and Execute permissions"); } foreach(var error in dataObject.Environment.Errors) { allErrors.AddError(error,true); } // Fetch return type ;) var formatter = DataListFormat.CreateFormat("XML", EmitionTypes.XML, "text/xml"); // force it to XML if need be ;) // Fetch and convert DL ;) if(!dataObject.Environment.HasErrors()) { // a normal service request if(!esbExecuteRequest.WasInternalService) { dataObject.DataListID = executionDlid; dataObject.WorkspaceID = workspaceGuid; dataObject.ServiceName = serviceName; if(!dataObject.IsDebug || dataObject.RemoteInvoke || dataObject.RemoteNonDebugInvoke) { if (dataObject.ReturnType == EmitionTypes.JSON) { formatter = DataListFormat.CreateFormat("JSON", EmitionTypes.JSON, "application/json"); executePayload = ExecutionEnvironmentUtils.GetJsonOutputFromEnvironment(dataObject, resource.DataList.ToString(),0); } else if (dataObject.ReturnType == EmitionTypes.XML) { executePayload = ExecutionEnvironmentUtils.GetXmlOutputFromEnvironment(dataObject,Guid.Empty , resource.DataList.ToString(),0); }else if(dataObject.ReturnType == EmitionTypes.SWAGGER) { formatter = DataListFormat.CreateFormat("SWAGGER", EmitionTypes.SWAGGER, "application/json"); executePayload = ExecutionEnvironmentUtils.GetSwaggerOutputForService(resource, resource.DataList.ToString()); } } else { executePayload = string.Empty; } } else { // internal service request we need to return data for it from the request object ;) var serializer = new Dev2JsonSerializer(); executePayload = string.Empty; var msg = serializer.Deserialize<ExecuteMessage>(esbExecuteRequest.ExecuteResult); if(msg != null) { executePayload = msg.Message.ToString(); } // out fail safe to return different types of data from services ;) if(string.IsNullOrEmpty(executePayload)) { executePayload = esbExecuteRequest.ExecuteResult.ToString(); } } } else { if(dataObject.ReturnType == EmitionTypes.XML) { executePayload = "<FatalError> <Message> An internal error occurred while executing the service request </Message>"; executePayload += allErrors.MakeDataListReady(); executePayload += "</FatalError>"; } else { // convert output to JSON ;) executePayload = "{ \"FatalError\": \"An internal error occurred while executing the service request\","; executePayload += allErrors.MakeDataListReady(false); executePayload += "}"; } } Dev2Logger.Log.Debug("Execution Result [ " + executePayload + " ]"); // JSON Data ;) if(executePayload.IndexOf("</JSON>", StringComparison.Ordinal) >= 0) { int start = executePayload.IndexOf(GlobalConstants.OpenJSON, StringComparison.Ordinal); if(start >= 0) { int end = executePayload.IndexOf(GlobalConstants.CloseJSON, StringComparison.Ordinal); start += GlobalConstants.OpenJSON.Length; executePayload = CleanupHtml(executePayload.Substring(start, (end - start))); if(!String.IsNullOrEmpty(executePayload)) { return new StringResponseWriter(executePayload, ContentTypes.Json); } } } Dev2DataListDecisionHandler.Instance.RemoveEnvironment(dataObject.DataListID); dataObject.Environment = null; return new StringResponseWriter(executePayload, formatter.ContentType); } }
public string GenerateUserFriendlyModel(IExecutionEnvironment env, Dev2DecisionMode mode, out ErrorResultTO errors) { errors = new ErrorResultTO(); ErrorResultTO allErrors = new ErrorResultTO(); string fn = DecisionDisplayHelper.GetDisplayValue(EvaluationFn); if(PopulatedColumnCount == 0) { return "If " + fn + " "; } if(PopulatedColumnCount == 1) { if(DataListUtil.GetRecordsetIndexType(Col1) == enRecordsetIndexType.Star) { var allValues = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col1, env, out errors); allErrors.MergeErrors(errors); StringBuilder expandStarredIndex = new StringBuilder(); expandStarredIndex.Append(allValues[0] + " " + fn); allValues.RemoveAt(0); foreach(var value in allValues) { expandStarredIndex.Append(" " + mode + " " + value + " " + fn); } errors = allErrors; return "If " + expandStarredIndex; } errors = allErrors; return "If " + Col1 + " " + fn + " "; } if(PopulatedColumnCount == 2) { StringBuilder expandStarredIndices = new StringBuilder(); if(DataListUtil.GetRecordsetIndexType(Col1) != enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) == enRecordsetIndexType.Star) { var allCol2Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col2, env, out errors); allErrors.MergeErrors(errors); expandStarredIndices.Append(Col1 + " " + fn + " " + allCol2Values[0]); allCol2Values.RemoveAt(0); foreach(var value in allCol2Values) { expandStarredIndices.Append(" " + mode + " " + Col1 + " " + fn + " " + value); } errors = allErrors; return "If " + expandStarredIndices; } if(DataListUtil.GetRecordsetIndexType(Col1) == enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) != enRecordsetIndexType.Star) { var allCol1Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col1, env, out errors); allErrors.MergeErrors(errors); expandStarredIndices.Append(allCol1Values[0] + " " + fn + " " + Col2); allCol1Values.RemoveAt(0); foreach(var value in allCol1Values) { expandStarredIndices.Append(" " + mode + " " + value + " " + fn + " " + Col2); } errors = allErrors; return "If " + expandStarredIndices; } if((DataListUtil.GetRecordsetIndexType(Col1) == enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) == enRecordsetIndexType.Star) || (DataListUtil.GetRecordsetIndexType(Col1) != enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) != enRecordsetIndexType.Star)) { var allCol1Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col1, env, out errors); allErrors.MergeErrors(errors); var allCol2Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col2, env, out errors); allErrors.MergeErrors(errors); expandStarredIndices.Append(allCol1Values[0] + " " + fn + " " + allCol2Values[0]); allCol1Values.RemoveAt(0); allCol2Values.RemoveAt(0); for(var i = 0; i < Math.Max(allCol1Values.Count, allCol2Values.Count); i++) { if(i > allCol1Values.Count) { allCol1Values.Add(null); } if(i > allCol2Values.Count) { allCol2Values.Add(null); } try { expandStarredIndices.Append(" " + mode + " " + allCol1Values[i] + " " + fn + " " + allCol2Values[i]); } catch(IndexOutOfRangeException) { errors.AddError("You appear to have recordsets of differnt sizes"); allErrors.MergeErrors(errors); } } errors = allErrors; return "If " + expandStarredIndices; } errors = allErrors; return "If " + Col1 + " " + fn + " " + Col2 + " "; } if(PopulatedColumnCount == 3) { var expandStarredIndices = ResolveStarredIndices(env, mode.ToString(), out errors); allErrors.MergeErrors(errors); if(!string.IsNullOrEmpty(expandStarredIndices)) { errors = allErrors; return expandStarredIndices; } errors = allErrors; return "If " + Col1 + " " + fn + " " + Col2 + " and " + Col3; } errors = allErrors; return "<< Internal Error Generating Decision Model: Populated Column Count Cannot Exeed 3 >>"; }
public IBinaryDataList ConvertTo(object input, StringBuilder shape, out ErrorResultTO errors) { errors = new ErrorResultTO(); TranslatorUtils tu = new TranslatorUtils(); ErrorResultTO invokeErrors; var targetDL = tu.TranslateShapeToObject(shape, false, out invokeErrors); errors.MergeErrors(invokeErrors); DataTable dbData = (input as DataTable); var rs = targetDL.FetchAllKeys(); // ensure we only have a single recordset to map too ;) if(rs != null && rs.Count != 1) { throw new Exception("DataTable translator can only map to a single recordset!"); } if(rs != null) { var rsName = rs.FirstOrDefault(); if(dbData != null) { IBinaryDataListEntry entry; // build up the columns ;) string error; if(targetDL.TryGetEntry(rsName, out entry, out error)) { if(entry.IsRecordset) { var cols = entry.Columns; IDictionary<int, string> colMapping = BuildColumnNameToIndexMap(entry.Columns, dbData.Columns, null); // now convert to binary datalist ;) int rowIdx = 1; foreach(DataRow row in dbData.Rows) { IList<IBinaryDataListItem> items = new List<IBinaryDataListItem>(cols.Count); // build up the row int idx = 0; foreach(var item in row.ItemArray) { string colName; if(colMapping.TryGetValue(idx, out colName)) { items.Add(new BinaryDataListItem(item.ToString(), rsName, colName, rowIdx)); } idx++; } // add the row ;) entry.TryPutRecordRowAt(items, rowIdx, out error); errors.AddError(error); rowIdx++; } } else { // handle a scalar coming out ;) if(dbData.Rows != null && dbData.Rows.Count == 1) { var row = dbData.Rows[0].ItemArray; // Look up the correct index from the columns ;) int pos = 0; var cols = dbData.Columns; int idx = 0; while(pos < cols.Count && idx == -1) { if(cols[pos].ColumnName == entry.Namespace) { idx = pos; } pos++; } entry.TryPutScalar(new BinaryDataListItem(row[idx].ToString(), entry.Namespace), out error); errors.AddError(error); } } } else { errors.AddError(error); } } } return targetDL; }
//MO - Changed : new ctor that accepts the new arguments public ForEachBootstrapTOOld(enForEachType forEachType, string from, string to, string csvNumbers, string numberOfExecutes, string recordsetName, Guid dlID, IDataListCompiler compiler, out ErrorResultTO errors) { errors = new ErrorResultTO(); ForEachType = forEachType; IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IndexIterator localIndexIterator; IndexList indexList; switch(forEachType) { case enForEachType.InRecordset: IBinaryDataListEntry recordset = compiler.Evaluate(dlID, enActionType.User, recordsetName, false, out errors); if(recordset == null || !recordset.IsRecordset) { errors.AddError("When selecting a recordset only valid recordsets can be used"); break; } var isEmpty = recordset.IsEmpty(); if(isEmpty) { indexList = new IndexList(new HashSet<int> { 1 }, 0); localIndexIterator = new IndexIterator(new HashSet<int> { 1 }, 0); } else { indexList = new IndexList(new HashSet<int>(), 0) { MinValue = 1, MaxValue = recordset.FetchLastRecordsetIndex() }; localIndexIterator = new IndexIterator(new HashSet<int>(), 0); } localIndexIterator.IndexList = indexList; IndexIterator = localIndexIterator; break; case enForEachType.InRange: if(string.IsNullOrWhiteSpace(from)) { errors.AddError("The from field can not be left empty."); break; } if(string.IsNullOrWhiteSpace(to)) { errors.AddError("The to field can not be left empty."); break; } if(from.Contains("(*)")) { errors.AddError("The Star notation is not accepted in the From field."); break; } var fromItr = CreateDataListEvaluateIterator(from, dlID, compiler, colItr, errors); colItr.AddIterator(fromItr); int intFrom; if(!int.TryParse(colItr.FetchNextRow(fromItr).TheValue, out intFrom) || intFrom < 1) { errors.AddError("From range must be a whole number from 1 onwards."); break; } if(to.Contains("(*)")) { errors.AddError("The Star notation is not accepted in the To field."); break; } var toItr = CreateDataListEvaluateIterator(to, dlID, compiler, colItr, errors); colItr.AddIterator(toItr); int intTo; if(!int.TryParse(colItr.FetchNextRow(toItr).TheValue, out intTo) || intTo < 1) { errors.AddError("To range must be a whole number from 1 onwards."); break; } if(intFrom > intTo) { indexList = new IndexList(new HashSet<int>(), 0) { MinValue = intFrom, MaxValue = intTo }; ReverseIndexIterator revIdxItr = new ReverseIndexIterator(new HashSet<int>(), 0) { IndexList = indexList }; IndexIterator = revIdxItr; } else { indexList = new IndexList(new HashSet<int>(), 0) { MinValue = intFrom, MaxValue = intTo }; localIndexIterator = new IndexIterator(new HashSet<int>(), 0) { IndexList = indexList }; IndexIterator = localIndexIterator; } break; case enForEachType.InCSV: var csvIndexedsItr = CreateDataListEvaluateIterator(csvNumbers, dlID, compiler, colItr, errors); colItr.AddIterator(csvIndexedsItr); ErrorResultTO allErrors; List<int> listOfIndexes = SplitOutCsvIndexes(colItr.FetchNextRow(csvIndexedsItr).TheValue, out allErrors); if(allErrors.HasErrors()) { errors.MergeErrors(allErrors); break; } ListIndexIterator listLocalIndexIterator = new ListIndexIterator(listOfIndexes); ListOfIndex listOfIndex = new ListOfIndex(listOfIndexes); listLocalIndexIterator.IndexList = listOfIndex; IndexIterator = listLocalIndexIterator; break; default: if(numberOfExecutes != null && numberOfExecutes.Contains("(*)")) { errors.AddError("The Star notation is not accepted in the Numbers field."); break; } int intExNum; var numOfExItr = CreateDataListEvaluateIterator(numberOfExecutes, dlID, compiler, colItr, errors); colItr.AddIterator(numOfExItr); if(!int.TryParse(colItr.FetchNextRow(numOfExItr).TheValue, out intExNum)) { errors.AddError("Number of executes must be a whole number from 1 onwards."); } IndexIterator = new IndexIterator(new HashSet<int>(), intExNum); break; } }
public StringBuilder ConvertAndFilter(IBinaryDataList payload, StringBuilder filterShape, out ErrorResultTO errors) { if(payload == null) { throw new ArgumentNullException("payload"); } StringBuilder result = new StringBuilder("<" + RootTag + ">"); errors = new ErrorResultTO(); ErrorResultTO invokeErrors; TranslatorUtils tu = new TranslatorUtils(); IBinaryDataList targetDl = _tu.TranslateShapeToObject(filterShape, false, out invokeErrors); errors.MergeErrors(invokeErrors); IList<string> itemKeys = targetDl.FetchAllKeys(); foreach(string key in itemKeys) { IBinaryDataListEntry entry; IBinaryDataListEntry tmpEntry; string error; if(payload.TryGetEntry(key, out entry, out error) && targetDl.TryGetEntry(key, out tmpEntry, out error)) { if(entry.IsRecordset) { var idxItr = entry.FetchRecordsetIndexes(); while(idxItr.HasMore()) { var i = idxItr.FetchNextIndex(); IList<IBinaryDataListItem> rowData = entry.FetchRecordAt(i, out error); if(error != string.Empty) { errors.AddError(error); } result.Append("<"); result.Append(entry.Namespace); result.Append(" "); result.Append(GlobalConstants.RowAnnotation); result.Append("="); result.Append("\"" + i + "\""); result.Append(">"); foreach(IBinaryDataListItem col in rowData) { IBinaryDataListItem col1 = col; if(tmpEntry.Columns.Any((c => c.ColumnName == col1.FieldName))) { string fName = col.FieldName; result.Append("<"); result.Append(fName); result.Append(">"); try { result.Append(tu.FullCleanForEmit(col.TheValue)); } // ReSharper disable EmptyGeneralCatchClause catch(Exception) // ReSharper restore EmptyGeneralCatchClause { } result.Append("</"); result.Append(fName); result.Append(">"); } } result.Append("</"); result.Append(entry.Namespace); result.Append(">"); } } else { string fName = entry.Namespace; IBinaryDataListItem val = entry.FetchScalar(); if(val != null) { result.Append("<"); result.Append(fName); result.Append(">"); try { result.Append(entry.Namespace != GlobalConstants.ManagementServicePayload ? tu.FullCleanForEmit(val.TheValue) : val.TheValue); } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { } result.Append("</"); result.Append(fName); result.Append(">"); } } } } result.Append("</" + RootTag + ">"); return result; }
/// <summary> /// Invoke a management method which is a statically coded method in the service implementation for service engine administrators /// </summary> /// <param name="serviceAction">Action of type InvokeManagementDynamicService</param> /// <param name="xmlRequest">The XML request.</param> /// <returns> /// UnlimitedObject /// </returns> public Guid ManagementDynamicService(ServiceAction serviceAction, IDSFDataObject xmlRequest) { var errors = new ErrorResultTO(); var allErrors = new ErrorResultTO(); Guid result = GlobalConstants.NullDataListID; try { object[] parameterValues = null; //Instantiate a Endpoint object that contains all static management methods object o = this; //Activator.CreateInstance(typeof(Unlimited.Framework.DynamicServices.DynamicServicesEndpoint), new object[] {string.Empty}); //Get the management method MethodInfo m = o.GetType().GetMethod(serviceAction.SourceMethod); //Infer the parameters of the management method ParameterInfo[] parameters = m.GetParameters(); //If there are parameters then retrieve them from the service action input values if(parameters.Count() > 0) { IEnumerable<object> parameterData = from c in serviceAction.ServiceActionInputs select c.Value; parameterValues = parameterData.ToArray(); } //Invoke the management method and store the return value string val = m.Invoke(o, parameterValues).ToString(); result = ClientCompiler.UpsertSystemTag(xmlRequest.DataListID, enSystemTag.ManagmentServicePayload, val, out errors); //_clientCompiler.Upsert(xmlRequest.DataListID, DataListUtil.BuildSystemTagForDataList(enSystemTag.ManagmentServicePayload, true), val, out errors); allErrors.MergeErrors(errors); //returnval = new UnlimitedObject(GetXElement(val)); } catch(Exception ex) { allErrors.AddError(ex.Message); } finally { // handle any errors that might have occured if(allErrors.HasErrors()) { IBinaryDataListEntry be = Dev2BinaryDataListFactory.CreateEntry(enSystemTag.Error.ToString(), string.Empty); string error; be.TryPutScalar( Dev2BinaryDataListFactory.CreateBinaryItem(allErrors.MakeDataListReady(), enSystemTag.Error.ToString()), out error); if(error != string.Empty) { errors.AddError(error); } } // No cleanup to happen ;) } return result; }
/// <summary> /// Invokes the specified service as per the dataObject against theHost /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="errors">The errors.</param> /// <returns></returns> /// <exception cref="System.Exception">Can only execute workflows from web browser</exception> public Guid Invoke(IDSFDataObject dataObject, out ErrorResultTO errors) { var result = GlobalConstants.NullDataListID; var time = new Stopwatch(); time.Start(); errors = new ErrorResultTO(); int update = 0; // BUG 9706 - 2013.06.22 - TWR : added pre debug dispatch if(dataObject.Environment.HasErrors()) { errors.AddError(dataObject.Environment.FetchErrors()); DispatchDebugErrors(errors, dataObject, StateType.Before); } errors.ClearErrors(); try { var serviceId = dataObject.ResourceID; // we need to get better at getting this ;) var serviceName = dataObject.ServiceName; if(serviceId == Guid.Empty && string.IsNullOrEmpty(serviceName)) { errors.AddError(Resources.DynamicServiceError_ServiceNotSpecified); } else { try { var sl = new ServiceLocator(); Dev2Logger.Log.Debug("Finding service"); var theService = serviceId == Guid.Empty ? sl.FindService(serviceName, _workspace.ID) : sl.FindService(serviceId, _workspace.ID); if(theService == null) { errors.AddError("Service [ " + serviceName + " ] not found."); } else if(theService.Actions.Count <= 1) { #region Execute ESB container var theStart = theService.Actions.FirstOrDefault(); if(theStart != null && theStart.ActionType != Common.Interfaces.Core.DynamicServices.enActionType.InvokeManagementDynamicService && theStart.ActionType != Common.Interfaces.Core.DynamicServices.enActionType.Workflow && dataObject.IsFromWebServer) { throw new Exception("Can only execute workflows from web browser"); } Dev2Logger.Log.Debug("Mapping Action Dependencies"); MapServiceActionDependencies(theStart, sl); // Invoke based upon type ;) if(theStart != null) { theStart.DataListSpecification = theService.DataListSpecification; Dev2Logger.Log.Debug("Getting container"); var container = GenerateContainer(theStart, dataObject, _workspace); ErrorResultTO invokeErrors; result = container.Execute(out invokeErrors, update); errors.MergeErrors(invokeErrors); } #endregion } else { errors.AddError("Malformed Service [ " + serviceId + " ] it contains multiple actions"); } } catch(Exception e) { errors.AddError(e.Message); } finally { if (dataObject.Environment.HasErrors()) { var errorString = dataObject.Environment.FetchErrors(); var executionErrors = ErrorResultTO.MakeErrorResultFromDataListString(errorString); errors.MergeErrors(executionErrors); } dataObject.Environment.AddError(errors.MakeDataListReady()); if(errors.HasErrors()) { Dev2Logger.Log.Error(errors.MakeDisplayReady()); } } } } finally { time.Stop(); ServerStats.IncrementTotalRequests(); ServerStats.IncrementTotalTime(time.ElapsedMilliseconds); // BUG 9706 - 2013.06.22 - TWR : added DispatchDebugErrors(errors, dataObject, StateType.End); } return result; }
/// <summary> /// Invoke Stored Procedure on Sql Server /// </summary> /// <param name="serviceAction">Action of type Sql Server</param> /// <param name="req">The req.</param> /// <returns> /// UnlimitedObject /// </returns> //public dynamic SqlDatabaseCommand(ServiceAction serviceAction, IDSFDataObject req) //{ // Guid result = GlobalConstants.NullDataListID; // Guid tmpID = GlobalConstants.NullDataListID; // var errors = new ErrorResultTO(); // var allErrors = new ErrorResultTO(); // using(var cn = new SqlConnection(serviceAction.Source.ConnectionString)) // { // var dataset = new DataSet(); // try // { // //Create a SqlCommand to execute at the source // var cmd = new SqlCommand(); // cmd.CommandType = CommandType.StoredProcedure; // cmd.Connection = cn; // cmd.CommandText = serviceAction.SourceMethod; // cmd.CommandTimeout = serviceAction.CommandTimeout; // //Add the parameters to the SqlCommand // if(serviceAction.ServiceActionInputs.Count() > 0) // { // foreach(ServiceActionInput sai in serviceAction.ServiceActionInputs) // { // var injectVal = (string)sai.Value; // // 16.10.2012 : Travis.Frisinger - Convert empty to null // if(sai.EmptyToNull && injectVal == AppServerStrings.NullConstant) // { // cmd.Parameters.AddWithValue(sai.Source, DBNull.Value); // } // else // { // cmd.Parameters.AddWithValue(sai.Source, sai.Value); // } // } // } // cn.Open(); // var xmlDbResponse = new StringBuilder(); // var adapter = new SqlDataAdapter(cmd); // adapter.Fill(dataset); // string res = // DataSanitizerFactory.GenerateNewSanitizer(enSupportedDBTypes.MSSQL) // .SanitizePayload(dataset.GetXml()); // xmlDbResponse.Append(res); // cn.Close(); // //Alert the caller that request returned no data // if(string.IsNullOrEmpty(xmlDbResponse.ToString())) // { // // handle any errors that might have occured // IBinaryDataListEntry be = Dev2BinaryDataListFactory.CreateEntry(enSystemTag.Error.ToString(), // string.Empty); // string error; // be.TryPutScalar( // Dev2BinaryDataListFactory.CreateBinaryItem( // "The request yielded no response from the data store.", enSystemTag.Error.ToString()), // out error); // if(error != string.Empty) // { // errors.AddError(error); // } // SvrCompiler.Upsert(null, req.DataListID, // DataListUtil.BuildSystemTagForDataList(enSystemTag.Error, true), be, // out errors); // } // else // { // string tmpData = xmlDbResponse.ToString(); // string od = serviceAction.OutputDescription; // od = od.Replace("<Dev2XMLResult>", "").Replace("</Dev2XMLResult>", "").Replace("<JSON />", ""); // if(!string.IsNullOrWhiteSpace(od)) // { // IOutputDescriptionSerializationService outputDescriptionSerializationService = // OutputDescriptionSerializationServiceFactory.CreateOutputDescriptionSerializationService // (); // IOutputDescription outputDescriptionInstance = // outputDescriptionSerializationService.Deserialize(od); // if(outputDescriptionInstance != null) // { // IOutputFormatter outputFormatter = // OutputFormatterFactory.CreateOutputFormatter(outputDescriptionInstance); // string formatedPayload = outputFormatter.Format(tmpData).ToString(); // // TODO : Now create a new dataList and merge the result into the current dataList ;) // string dlShape = // ClientCompiler.ShapeDev2DefinitionsToDataList(serviceAction.ServiceActionOutputs, // enDev2ArgumentType.Output, false, // out errors); // allErrors.MergeErrors(errors); // tmpID = ClientCompiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), // formatedPayload, dlShape, out errors); // var parentID = ClientCompiler.FetchParentID(req.DataListID); // //ClientCompiler.SetParentID(tmpID, req.DataListID); // ClientCompiler.SetParentID(tmpID, parentID); // // set parent for merge op in finally... // allErrors.MergeErrors(errors); // } // } // } // cmd.Dispose(); // } // catch(Exception ex) // { // allErrors.AddError(ex.Message); // } // finally // { // // handle any errors that might have occured // IBinaryDataListEntry be = Dev2BinaryDataListFactory.CreateEntry(enSystemTag.Error.ToString(), // string.Empty); // string error; // be.TryPutScalar( // Dev2BinaryDataListFactory.CreateBinaryItem(allErrors.MakeDataListReady(), // enSystemTag.Error.ToString()), out error); // if(error != string.Empty) // { // errors.AddError(error); // } // SvrCompiler.Upsert(null, req.DataListID, // DataListUtil.BuildSystemTagForDataList(enSystemTag.Error, true), be, out errors); // // now merge and delete tmp // if(tmpID != GlobalConstants.NullDataListID) // { // ClientCompiler.Shape(tmpID, enDev2ArgumentType.Output, serviceAction.ServiceActionOutputs, // out errors); // ClientCompiler.DeleteDataListByID(tmpID); // result = req.DataListID; // } // //ExceptionHandling.WriteEventLogEntry("Application", string.Format("{0}.{1}", this.GetType().Name, "SqlDatabaseCommand"), string.Format("Exception:{0}\r\nInputData:{1}", xmlResponse.XmlString, xmlRequest.XmlString), EventLogEntryType.Error); // } // return result; // } //} public dynamic SqlDatabaseCommand(ServiceAction serviceAction, IDSFDataObject req) { Guid result = GlobalConstants.NullDataListID; Guid tmpID = GlobalConstants.NullDataListID; var errors = new ErrorResultTO(); var allErrors = new ErrorResultTO(); try { // Get XAML data from service action string xmlDbResponse = GetXmlDataFromSqlServiceAction(serviceAction); if (string.IsNullOrEmpty(xmlDbResponse)) { // If there was no data returned add error allErrors.AddError("The request yielded no response from the data store."); } else { // Get the output formatter from the service action IOutputFormatter outputFormatter = GetOutputFormatterFromServiceAction(serviceAction); if (outputFormatter == null) { // If there was an error getting the output formatter from the service action allErrors.AddError(string.Format("Output format in service action {0} is invalid.", serviceAction.Name)); } else { // Format the XML data string formatedPayload = outputFormatter.Format(xmlDbResponse).ToString(); // Create a shape from the service action outputs string dlShape = ClientCompiler.ShapeDev2DefinitionsToDataList(serviceAction.ServiceActionOutputs, enDev2ArgumentType.Output, false, out errors); allErrors.MergeErrors(errors); // Push formatted data into a datalist using the shape from the service action outputs tmpID = ClientCompiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), formatedPayload, dlShape, out errors); allErrors.MergeErrors(errors); // Attach a parent ID to the newly created datalist var parentID = ClientCompiler.FetchParentID(req.DataListID); ClientCompiler.SetParentID(tmpID, parentID); } } } catch (Exception ex) { allErrors.AddError(ex.Message); } finally { // If a datalist was ceated if (tmpID != GlobalConstants.NullDataListID) { // Merge into it's parent ClientCompiler.Shape(tmpID, enDev2ArgumentType.Output, serviceAction.ServiceActionOutputs, out errors); allErrors.MergeErrors(errors); // Delete data list ClientCompiler.DeleteDataListByID(tmpID); result = req.DataListID; } // Add any errors that occured to the datalist AddErrorsToDataList(allErrors, req.DataListID); } return result; }
public EvaluateRuleSet(EvaluateRuleSet prevIter) { Errors = new ErrorResultTO(); Errors.MergeErrors(prevIter.Errors); _result = prevIter._result; _ns = prevIter._ns; IsDebug = prevIter.IsDebug; EvaluateToRootOnly = prevIter.EvaluateToRootOnly; }
// internal to impl api methods private IBinaryDataList ConvertTo(byte[] input, StringBuilder targetShape, out ErrorResultTO errors, bool onlyMapInputs) { errors = new ErrorResultTO(); string payload = Encoding.UTF8.GetString(input); IBinaryDataList result = new BinaryDataList(); TranslatorUtils tu = new TranslatorUtils(); // build shape if(targetShape == null) { errors.AddError("Null payload or shape"); } else { ErrorResultTO invokeErrors; result = tu.TranslateShapeToObject(targetShape, true, out invokeErrors); errors.MergeErrors(invokeErrors); // populate the shape if(payload != string.Empty) { try { string toLoad = DataListUtil.StripCrap(payload); // clean up the rubish ;) XmlDocument xDoc = new XmlDocument(); // BUG 9626 - 2013.06.11 - TWR: ensure our DocumentElement toLoad = string.Format("<Tmp{0}>{1}</Tmp{0}>", Guid.NewGuid().ToString("N"), toLoad); xDoc.LoadXml(toLoad); if(xDoc.DocumentElement != null) { XmlNodeList children = xDoc.DocumentElement.ChildNodes; IDictionary<string, int> indexCache = new Dictionary<string, int>(); // BUG 9626 - 2013.06.11 - TWR: refactored for recursion TryConvert(children, result, indexCache, errors, onlyMapInputs); } // Transfer System Tags for(int i = 0; i < TranslationConstants.systemTags.Length; i++) { string key = TranslationConstants.systemTags.GetValue(i).ToString(); string query = String.Concat("//", key); XmlNode n = xDoc.SelectSingleNode(query); // try system namespace tags ;) if(n == null) { var values = "//" + DataListUtil.BuildSystemTagForDataList(key, false); query = values; n = xDoc.SelectSingleNode(query); } if(n != null && !string.IsNullOrEmpty(n.InnerXml)) { string bkey = DataListUtil.BuildSystemTagForDataList(key, false); string error; IBinaryDataListEntry sysEntry; if(result.TryGetEntry(bkey, out sysEntry, out error)) { sysEntry.TryPutScalar(Dev2BinaryDataListFactory.CreateBinaryItem(n.InnerXml, bkey), out error); } } } } catch(Exception e) { // if use passed in empty input they only wanted the shape ;) if(input.Length > 0) { errors.AddError(e.Message); } } } } return result; }
public IBinaryDataList ConvertTo(byte[] input, StringBuilder targetShape, out ErrorResultTO errors) { errors = new ErrorResultTO(); var payload = Encoding.UTF8.GetString(input); IBinaryDataList result = null; // build shape if(targetShape == null) { errors.AddError("Null payload or shape"); } else { ErrorResultTO invokeErrors; result = _tu.TranslateShapeToObject(targetShape, false, out invokeErrors); errors.MergeErrors(invokeErrors); // populate the shape if(payload != string.Empty) { try { string toLoad = DataListUtil.StripCrap(payload); // clean up the rubbish ;) XmlDocument xDoc = new XmlDocument(); try { xDoc.LoadXml(toLoad); } catch { // Append new root tags ;) toLoad = "<root>" + toLoad + "</root>"; xDoc.LoadXml(toLoad); } if(!string.IsNullOrEmpty(toLoad)) { if(xDoc.DocumentElement != null) { XmlNodeList children = xDoc.DocumentElement.ChildNodes; IDictionary<string, int> indexCache = new Dictionary<string, int>(); IBinaryDataListEntry entry; string error; if(children.Count > 0 && !DataListUtil.IsMsXmlBugNode(children[0].Name)) { #region Process children // spin through each element in the XML foreach(XmlNode c in children) { var hasCorrectIoDirection = true; if(c.Attributes != null) { var columnIoDirectionAttribute = c.Attributes["ColumnIODirection"]; if(columnIoDirectionAttribute != null) { var columnIoDirectionValue = columnIoDirectionAttribute.Value; var hasCorrectIoDirectionFromAttribute = columnIoDirectionValue == enDev2ColumnArgumentDirection.Output.ToString() || columnIoDirectionValue == enDev2ColumnArgumentDirection.Both.ToString(); hasCorrectIoDirection = hasCorrectIoDirectionFromAttribute; } } if(DataListUtil.IsSystemTag(c.Name) && !hasCorrectIoDirection) { continue; } // scalars and recordset fetch if(result.TryGetEntry(c.Name, out entry, out error)) { if(entry.IsRecordset) { // fetch recordset index int fetchIdx; int idx = indexCache.TryGetValue(c.Name, out fetchIdx) ? fetchIdx : 1; // process recordset XmlNodeList nl = c.ChildNodes; foreach(XmlNode subc in nl) { entry.TryPutRecordItemAtIndex(Dev2BinaryDataListFactory.CreateBinaryItem(subc.InnerXml, c.Name, subc.Name, (idx + "")), idx, out error); if(!string.IsNullOrEmpty(error)) { errors.AddError(error); } } // update this recordset index indexCache[c.Name] = ++idx; } else { entry.TryPutScalar(Dev2BinaryDataListFactory.CreateBinaryItem(c.InnerXml, c.Name), out error); if(!string.IsNullOrEmpty(error)) { errors.AddError(error); } } } else { errors.AddError(error); } } #endregion } else { var c = xDoc.DocumentElement; if(result.TryGetEntry(c.Name, out entry, out error)) { entry.TryPutScalar(Dev2BinaryDataListFactory.CreateBinaryItem(c.InnerXml, c.Name), out error); if(!string.IsNullOrEmpty(error)) { errors.AddError(error); } } } } } } catch(Exception e) { // if use passed in empty input they only wanted the shape ;) if(input.Length > 0) { errors.AddError(e.Message); } } } } 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); } } } }
/// <summary> /// Responsible for the processing of all inbound requests /// This method is reentrant and will call itself to /// for every invocation required in every generation /// of nesting. e.g services made up of services /// </summary> /// <param name="resourceDirectory">The singleton instance of the service library that contains all the logical services</param> /// <param name="xmlRequest">The actual client request message</param> /// <param name="dataListId">The id of the data list</param> /// <param name="errors">Errors resulting from this invoke</param> /// <returns></returns> public Guid Invoke(IDynamicServicesHost resourceDirectory, dynamic xmlRequest, Guid dataListId, out ErrorResultTO errors) { // Host = resourceDirectory #region Async processing of client request - queue the work item asynchronously //Get an UnlimitedObject from the xml string provided by the caller //TraceWriter.WriteTraceIf(_managementChannel != null && _loggingEnabled, "Inspecting inbound data request", Resources.TraceMessageType_Message); Guid result = GlobalConstants.NullDataListID; var allErrors = new ErrorResultTO(); errors = new ErrorResultTO(); if(xmlRequest.Async is string) { //TraceWriter.WriteTrace(_managementChannel, "Caller requested async execution"); bool isAsync; bool.TryParse(xmlRequest.Async, out isAsync); if(isAsync) { ThreadPool.QueueUserWorkItem(delegate { ErrorResultTO tmpErrors; //TraceWriter.WriteTrace(_managementChannel, "Queuing Asynchronous work", Resources.TraceMessageType_Message); xmlRequest.RemoveElementByTagName("Async"); IDynamicServicesInvoker invoker = new DynamicServicesInvoker(_dsfChannel, _managementChannel); result = invoker.Invoke(resourceDirectory, xmlRequest, dataListId, out tmpErrors); if(tmpErrors.HasErrors()) { allErrors.MergeErrors(tmpErrors); } //TraceWriter.WriteTrace(result.XmlString); if(result != GlobalConstants.NullDataListID) { // PBI : 5376 SvrCompiler.DeleteDataListByID(result, true); //TODO: Clean it up ;) } }); dynamic returnData = new UnlimitedObject(); returnData.Load(string.Format("<ServiceResponse>{0} Work Item Queued..</ServiceResponse>", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.fff"))); return returnData; } } #endregion #region Get a handle on the service that is being requested from the service directory string serviceName = string.Empty; //Set the service name as this is a complex message //with multiple services requests embedded in the inbound data //This will allow us to if(xmlRequest.Service is IEnumerable<UnlimitedObject>) { IEnumerable<UnlimitedObject> services = xmlRequest.Service; dynamic serviceData = services.First(); if(serviceData.Service is string) { serviceName = serviceData.Service; } } //If there is only a single service request then get the service name if(xmlRequest.Service is string) { serviceName = xmlRequest.Service; } //If the service name does not exist return an error to the caller if(string.IsNullOrEmpty(serviceName)) { xmlRequest.Error = Resources.DynamicServiceError_ServiceNotSpecified; } //Try to retrieve the service from the service directory IEnumerable<DynamicService> service; Host.LockServices(); try { service = from c in resourceDirectory.Services where serviceName != null && c.Name.Trim().Equals(serviceName.Trim(), StringComparison.CurrentCultureIgnoreCase) select c; } finally { Host.UnlockServices(); } service = service.ToList(); if(!service.Any()) { TraceWriter.WriteTrace(_managementChannel, string.Format("Service '{0}' Not Found", serviceName), Resources.TraceMessageType_Error); allErrors.AddError(string.Format("Service '{0}' Not Found", serviceName)); throw new InvalidOperationException(string.Format("Service '{0}' Not Found", serviceName)); //xmlRequest.Error = Resources.DynamicServiceError_ServiceNotFound; } #endregion //Instantiate a Dynamic Invocation type to invoke the service #region Transactionalized Service Invocation with support for MS-DTC dynamic dseException = null; //The transactionScope is used to create an ambient transaction that every action will be subject to //This transaction try { //TraceWriter.WriteTrace(_managementChannel, string.Format("Setting up transaction scope", serviceName), Resources.TraceMessageType_Message); using(var transactionScope = new TransactionScope()) { //TraceWriter.WriteTrace(_managementChannel, string.Format("Invoking Service '{0}'", serviceName), Resources.TraceMessageType_Message); #region Process several requests to different services as a single unit of work //Type 3 request (read above) //This is handled differently to type 1 and 2 requests //as it can execute in the context of either a single or //multiple services. //if (xmlRequest.IsMultipleRequests) { // TraceWriter.WriteTrace(_managementChannel, "Caller requested multiple service execution in single request", Resources.TraceMessageType_Message); // dynamic results = new UnlimitedObject(); // foreach (dynamic request in xmlRequest.Requests) { // dynamic result = new DynamicServicesInvoker(_dsfChannel, _managementChannel).Invoke(resourceDirectory, request); // if (result.HasError) { // return result; // } // results.AddResponse(result); // } // transactionScope.Complete(); // return results; //} #endregion DynamicService s = service.First(); result = Invoke(s, xmlRequest, dataListId, out errors); if(result == GlobalConstants.NullDataListID) { allErrors.AddError("Failed to invoke service"); } if(!ClientCompiler.HasErrors(result)) { transactionScope.Complete(); } //The service exists so invoke the service which runs all actions defined for the service //Return the response //return xmlResponses; } } //Occurs when an operation is attempted on a rolled back transaction catch(TransactionAbortedException abortEx) { dseException = abortEx; } //This exception is thrown when an action is attempted on a transaction that is in doubt. //A transaction is in doubt when the state of the transaction cannot be determined. //Specifically, the final outcome of the transaction, whether it commits or aborts, is never known for this transaction. catch(TransactionInDoubtException inDoubtEx) { dseException = inDoubtEx; } //Thrown when a resource manager cannot communicate with the transaction manager. catch(TransactionManagerCommunicationException transactionManagerEx) { dseException = transactionManagerEx; } //Thrown when a promotion fails catch(TransactionPromotionException promotionException) { dseException = promotionException; } catch(TransactionException transactionEx) { dseException = transactionEx; } if(dseException != null) { TraceWriter.WriteTrace(_managementChannel, string.Format("Service Execution Failed With Error\r\n{0}", new UnlimitedObject(dseException).XmlString), Resources.TraceMessageType_Error); } // set error variable errors = allErrors; if(errors.HasErrors()) { DispatchDebugState(xmlRequest, dataListId, allErrors); } return result; #endregion }
public Guid Populate(object input, Guid targetDl, string outputDefs, out ErrorResultTO errors) { errors = new ErrorResultTO(); var compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO invokeErrors; IBinaryDataList targetDL = compiler.FetchBinaryDataList(targetDl, out invokeErrors); errors.MergeErrors(invokeErrors); DataTable dbData = (input as DataTable); if(dbData != null && outputDefs != null) { var defs = DataListFactory.CreateOutputParser().Parse(outputDefs); HashSet<string> processedRecNames = new HashSet<string>(); foreach(var def in defs) { var expression = def.Value; var rsName = DataListUtil.ExtractRecordsetNameFromValue(expression); var rsType = DataListUtil.GetRecordsetIndexType(expression); var rowIndex = DataListUtil.ExtractIndexRegionFromRecordset(expression); var rsNameUse = def.RecordSetName; if(string.IsNullOrEmpty(rsName)) { rsName = rsNameUse; } if(string.IsNullOrEmpty(rsName)) { rsName = def.Name; } if(processedRecNames.Contains(rsName)) { continue; } processedRecNames.Add(rsName); // build up the columns ;) string error; IBinaryDataListEntry entry; if(targetDL.TryGetEntry(rsName, out entry, out error)) { if(entry.IsRecordset) { var cols = entry.Columns; IDictionary<int, string> colMapping = BuildColumnNameToIndexMap(entry.Columns, dbData.Columns, defs); // now convert to binary datalist ;) int rowIdx = entry.FetchAppendRecordsetIndex(); if(rsType == enRecordsetIndexType.Star) { rowIdx = 1; } if(rsType == enRecordsetIndexType.Numeric) { rowIdx = int.Parse(rowIndex); } if(dbData.Rows != null) { foreach(DataRow row in dbData.Rows) { IList<IBinaryDataListItem> items = new List<IBinaryDataListItem>(cols.Count); // build up the row int idx = 0; foreach(var item in row.ItemArray) { string colName; if(colMapping.TryGetValue(idx, out colName)) { items.Add(new BinaryDataListItem(item.ToString(), rsNameUse, colName, rowIdx)); } idx++; } // add the row ;) entry.TryPutRecordRowAt(items, rowIdx, out error); errors.AddError(error); rowIdx++; } } } else { // handle a scalar coming out ;) if(dbData.Rows != null && dbData.Rows.Count == 1) { var row = dbData.Rows[0].ItemArray; // Look up the correct index from the columns ;) int pos = 0; var cols = dbData.Columns; int idx = -1; while(pos < cols.Count && idx == -1) { if(cols[pos].ColumnName == entry.Namespace) { idx = pos; } pos++; } entry.TryPutScalar(new BinaryDataListItem(row[idx].ToString(), entry.Namespace), out error); errors.AddError(error); } } } else { errors.AddError(error); } } } compiler.PushBinaryDataList(targetDL.UID, targetDL, out invokeErrors); errors.MergeErrors(invokeErrors); return targetDL.UID; }
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; }
public Guid Invoke(DynamicService service, dynamic xmlRequest, Guid dataListId, out ErrorResultTO errors) { //dynamic result = new UnlimitedObject(); //dynamic forwardResult = new UnlimitedObject(); var allErrors = new ErrorResultTO(); errors = new ErrorResultTO(); if(service == null) { allErrors.AddError("Dynamic Service not found exception"); return GlobalConstants.NullDataListID; } string dataList = service.DataListSpecification; // PBI : 5376 Amendedment for DataList Server Guid result = GlobalConstants.NullDataListID; string data = xmlRequest.XmlString.Trim(); byte[] incomingData = Encoding.UTF8.GetBytes(data); Guid serviceDataId; var performDataListInMerge = false; if(dataList != string.Empty) { serviceDataId = SvrCompiler.ConvertTo(null, DataListFormat.CreateFormat(GlobalConstants._XML), incomingData, dataList, out errors); errors = new ErrorResultTO(); // re-set to avoid carring // PBI : 5376 // If dataListID == NullID, create a new list and set it as the current ID // Else, create a new list, union the old data into the new and continue on ;) if(dataListId != GlobalConstants.NullDataListID) { serviceDataId = SvrCompiler.Merge(null, serviceDataId, dataListId, enDataListMergeTypes.Union, enTranslationDepth.Data, false, out errors); } else { performDataListInMerge = true; } } else { serviceDataId = SvrCompiler.CloneDataList(dataListId, out errors); performDataListInMerge = true; } if (errors.HasErrors()) { allErrors.MergeErrors(errors); } IDSFDataObject dataObject = new DsfDataObject(xmlRequest.XmlString, serviceDataId); dataObject.DataList = dataList; if(performDataListInMerge) { SvrCompiler.ConditionalMerge(null, DataListMergeFrequency.Always, serviceDataId, dataObject.DatalistInMergeID, DataListMergeFrequency.Always, dataObject.DatalistInMergeType, dataObject.DatalistInMergeDepth); } // TODO : Reset the AmbientDataList to this ID? // Fetch data for Input binding... DataListTranslatedPayloadTO tmpData = null; dynamic inputBinding = null; // End PBI Amendments foreach(ServiceAction serviceAction in service.Actions) { //TraceWriter.WriteTrace(_managementChannel, string.Format("Validating the inputs of Service '{0}'", service.Name), Resources.TraceMessageType_Message); foreach(ServiceActionInput sai in serviceAction.ServiceActionInputs) { //Assigning the input the value from the callers request data //TraceWriter.WriteTrace(_managementChannel, string.Format("Discovered input '{0}'", sai.Name), Resources.TraceMessageType_Message); if(sai.CascadeSource) { TraceWriter.WriteTrace(_managementChannel, string.Format("Input '{0}' is cascaded", sai.Name), Resources.TraceMessageType_Message); //This is a cascaded input so retrieve the value from the //previous actions response //sai.Value = forwardResult.GetValue(sai.Name); } else { if(tmpData == null) { tmpData = SvrCompiler.ConvertFrom(null, serviceDataId, enTranslationDepth.Data, DataListFormat.CreateFormat(GlobalConstants._XML), out errors); if(!DataListUtil.isNullADL(tmpData.FetchAsString())) { inputBinding = new UnlimitedObject(tmpData.FetchAsString()); } else { // Empty data, try the incoming stream?! inputBinding = new UnlimitedObject(xmlRequest.XmlString); } } // 16.10.2012 : Travis.Frisinger - EmptyToNull amendments string tmpVal = inputBinding.GetValue(sai.Name); if(sai.EmptyToNull && tmpVal == string.Empty) { tmpVal = AppServerStrings.NullConstant; } sai.Value = tmpVal; } //TraceWriter.WriteTrace(string.Format("Assigning value {0} to input '{1}'", sai.Value.ToString(), sai.Name)); //Validating inputs if there is validation set up in the service definition if(sai.IsRequired && string.IsNullOrEmpty(sai.DefaultValue)) { if(!sai.Validate()) { allErrors.AddError(string.Format("Validation Failure. Argument '{0}' failed validation.", sai.Name)); //TraceWriter.WriteTrace(_managementChannel, string.Format("Argument '{0}' failed validation", sai.Name), Resources.TraceMessageType_Message); //xmlRequest.Error = string.Format("Validation Failure. Argument '{0}' failed validation.", sai.Name); //return xmlRequest; } } //This input does not have any value in the callers request //so we are setting the input value to the full request if(string.IsNullOrEmpty(sai.Value.ToString())) { sai.Value = !string.IsNullOrEmpty(sai.DefaultValue) ? sai.DefaultValue : string.Empty; } } //if (service.Mode == enDynamicServiceMode.ValidationOnly) //{ // xmlRequest.ValidationOnly.Result = true; // return xmlRequest; //} if(serviceAction.ActionType == enActionType.Switch) { if(!string.IsNullOrEmpty(serviceAction.Cases.DataElementName)) { ////Assigning the input the value from the callers request data //if (serviceAction.Cases.CascadeSource) //{ //This is a cascaded input so retrieve the value from the //previous actions response //sai.Value = actionResponse.GetValue(sai.Name); //serviceAction.Cases.DataElementValue = forwardResult.GetValue(serviceAction.Cases.DataElementName); //} //else //{ serviceAction.Cases.DataElementValue = xmlRequest.GetValue(serviceAction.Cases.DataElementName); //} } } // //Juries - This is a dirty hack, naughty naughty. //Hijacked current functionality to enable erros to be added to an item after its already been added to the tree // if(allErrors.HasErrors()) { DebugDispatcher.Instance.Write(new DebugState() { ParentID = dataObject.ParentInstanceID, WorkspaceID = dataObject.WorkspaceID, StartTime = DateTime.Now, EndTime = DateTime.Now, IsSimulation = false, ServerID = dataObject.ServerID, Server = string.Empty, Version = string.Empty, Name = GetType().Name, HasError = true, ErrorMessage = allErrors.MakeDisplayReady(), ActivityType = ActivityType.Workflow, StateType = StateType.Append }); } // TODO : properly build up DataList prior to this.... result = Invoke(serviceAction, dataObject, dataList); // Remember to clean up ;) if(dataListId != GlobalConstants.NullDataListID) { // Merge the execution DL into the mainDL ;) Guid mergeId = SvrCompiler.Merge(null, dataListId, serviceDataId, enDataListMergeTypes.Union, enTranslationDepth.Data, false, out errors); SvrCompiler.DeleteDataListByID(serviceDataId, true); // Now reset the DataListID on DataObject ;) if(result != serviceDataId) { throw new Exception("FATAL ERROR : DataList Execution Mis-Match!"); } dataObject.DataListID = mergeId; result = mergeId; } else { SvrCompiler.ConditionalMerge(null, DataListMergeFrequency.Always | DataListMergeFrequency.OnCompletion, dataObject.DatalistOutMergeID, dataObject.DataListID, dataObject.DatalistOutMergeFrequency, dataObject.DatalistOutMergeType, dataObject.DatalistOutMergeDepth); } // else we want to keep the DL around until we end execution #region Terminate the service if this Service Action is marked to terminate on fault //If this action should immediately terminate the execution of this service //then stop here and return the results thus far if(serviceAction.TerminateServiceOnFault && errors.HasErrors()) { result = GlobalConstants.NullDataListID; } #endregion } return result; }
protected static IResponseWriter CreateForm(WebRequestTO webRequest, string serviceName, string workspaceId, NameValueCollection headers, List<DataListFormat> publicFormats, IPrincipal user = null) { //lock(ExecutionObject) { string executePayload = ""; IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); Guid workspaceGuid; if(workspaceId != null) { if(!Guid.TryParse(workspaceId, out workspaceGuid)) { workspaceGuid = WorkspaceRepository.Instance.ServerWorkspace.ID; } } else { workspaceGuid = WorkspaceRepository.Instance.ServerWorkspace.ID; } var allErrors = new ErrorResultTO(); var dataObject = new DsfDataObject(webRequest.RawRequestPayload, GlobalConstants.NullDataListID, webRequest.RawRequestPayload) { IsFromWebServer = true, ExecutingUser = user, ServiceName = serviceName, WorkspaceID = workspaceGuid }; // now bind any variables that are part of the path arguments ;) BindRequestVariablesToDataObject(webRequest, ref dataObject); // now process headers ;) if(headers != null) { Dev2Logger.Log.Debug("Remote Invoke"); var isRemote = headers.Get(HttpRequestHeader.Cookie.ToString()); var remoteId = headers.Get(HttpRequestHeader.From.ToString()); if(isRemote != null && remoteId != null) { if(isRemote.Equals(GlobalConstants.RemoteServerInvoke)) { // we have a remote invoke ;) dataObject.RemoteInvoke = true; } dataObject.RemoteInvokerID = remoteId; } } // now set the emition type ;) int loc; if(!String.IsNullOrEmpty(serviceName) && (loc = serviceName.LastIndexOf(".", StringComparison.Ordinal)) > 0) { // default it to xml dataObject.ReturnType = EmitionTypes.XML; if(loc > 0) { var typeOf = serviceName.Substring((loc + 1)).ToUpper(); EmitionTypes myType; if(Enum.TryParse(typeOf, out myType)) { dataObject.ReturnType = myType; } // adjust the service name to drop the type ;) // avoid .wiz amendments ;) if(!typeOf.ToLower().Equals(GlobalConstants.WizardExt)) { serviceName = serviceName.Substring(0, loc); dataObject.ServiceName = serviceName; } } } else { // default it to xml dataObject.ReturnType = EmitionTypes.XML; } // ensure service gets set ;) if(dataObject.ServiceName == null) { dataObject.ServiceName = serviceName; } IResource resource = null; if(!String.IsNullOrEmpty(dataObject.ServiceName)) { resource = ResourceCatalog.Instance.GetResource(dataObject.WorkspaceID, dataObject.ServiceName); if(resource != null) { dataObject.ResourceID = resource.ResourceID; } } var esbEndpoint = new EsbServicesEndpoint(); dataObject.EsbChannel = esbEndpoint; var canExecute = true; if(ServerAuthorizationService.Instance != null) { var authorizationService = ServerAuthorizationService.Instance; var hasView = authorizationService.IsAuthorized(AuthorizationContext.View, dataObject.ResourceID.ToString()); var hasExecute = authorizationService.IsAuthorized(AuthorizationContext.Execute, dataObject.ResourceID.ToString()); canExecute = (hasExecute && hasView) || (dataObject.RemoteInvoke && hasExecute) || (resource != null && resource.ResourceType == ResourceType.ReservedService); } // Build EsbExecutionRequest - Internal Services Require This ;) EsbExecuteRequest esbExecuteRequest = new EsbExecuteRequest { ServiceName = serviceName }; Dev2Logger.Log.Debug("About to execute web request [ " + serviceName + " ] DataObject Payload [ " + dataObject.RawPayload + " ]"); var executionDlid = GlobalConstants.NullDataListID; if(canExecute) { ErrorResultTO errors; executionDlid = esbEndpoint.ExecuteRequest(dataObject, esbExecuteRequest, workspaceGuid, out errors); allErrors.MergeErrors(errors); } else { allErrors.AddError("Executing a service externally requires View and Execute permissions"); } foreach(var error in dataObject.Environment.Errors) { allErrors.AddError(error,true); } // Fetch return type ;) var formatter = publicFormats.FirstOrDefault(c => c.PublicFormatName == dataObject.ReturnType) ?? publicFormats.FirstOrDefault(c => c.PublicFormatName == EmitionTypes.XML); // force it to XML if need be ;) // Fetch and convert DL ;) if(executionDlid != GlobalConstants.NullDataListID && !dataObject.Environment.HasErrors()) { // a normal service request if(!esbExecuteRequest.WasInternalService) { dataObject.DataListID = executionDlid; dataObject.WorkspaceID = workspaceGuid; dataObject.ServiceName = serviceName; // some silly chicken thinks web request where a good idea for debug ;( if(!dataObject.IsDebug || dataObject.RemoteInvoke) { if (dataObject.ReturnType == EmitionTypes.JSON) { executePayload = ExecutionEnvironmentUtils.GetJsonOutputFromEnvironment(dataObject, workspaceGuid,resource.DataList.ToString()); } else if (dataObject.ReturnType == EmitionTypes.XML) { executePayload = ExecutionEnvironmentUtils.GetXmlOutputFromEnvironment(dataObject, workspaceGuid,resource.DataList.ToString()); } dataObject.Environment.AddError(allErrors.MakeDataListReady()); } else { executePayload = string.Empty; } } else { // internal service request we need to return data for it from the request object ;) var serializer = new Dev2JsonSerializer(); executePayload = string.Empty; var msg = serializer.Deserialize<ExecuteMessage>(esbExecuteRequest.ExecuteResult); if(msg != null) { executePayload = msg.Message.ToString(); } // out fail safe to return different types of data from services ;) if(string.IsNullOrEmpty(executePayload)) { executePayload = esbExecuteRequest.ExecuteResult.ToString(); } } } else { if(dataObject.ReturnType == EmitionTypes.XML) { executePayload = "<FatalError> <Message> An internal error occurred while executing the service request </Message>"; executePayload += allErrors.MakeDataListReady(); executePayload += "</FatalError>"; } else { // convert output to JSON ;) executePayload = "{ \"FatalError\": \"An internal error occurred while executing the service request\","; executePayload += allErrors.MakeDataListReady(false); executePayload += "}"; } } Dev2Logger.Log.Debug("Execution Result [ " + executePayload + " ]"); // Clean up the datalist from the server if(!dataObject.WorkflowResumeable && executionDlid != GlobalConstants.NullDataListID) { compiler.ForceDeleteDataListByID(executionDlid); if(dataObject.IsDebug && !dataObject.IsRemoteInvoke && !dataObject.RunWorkflowAsync) { DataListRegistar.ClearDataList(); } else { foreach(var thread in dataObject.ThreadsToDispose) { DataListRegistar.DisposeScope(thread.Key, executionDlid); } DataListRegistar.DisposeScope(Thread.CurrentThread.ManagedThreadId, executionDlid); } } // old HTML throw back ;) if(dataObject.ReturnType == EmitionTypes.WIZ) { int start = (executePayload.IndexOf("<Dev2System.FormView>", StringComparison.Ordinal) + 21); int end = (executePayload.IndexOf("</Dev2System.FormView>", StringComparison.Ordinal)); int len = (end - start); if(len > 0) { if(dataObject.ReturnType == EmitionTypes.WIZ) { string tmp = executePayload.Substring(start, (end - start)); string result = CleanupHtml(tmp); const string DocType = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">"; return new StringResponseWriter(String.Format("{0}\r\n{1}", DocType, result), ContentTypes.Html); } } } // JSON Data ;) if(executePayload.IndexOf("</JSON>", StringComparison.Ordinal) >= 0) { int start = executePayload.IndexOf(GlobalConstants.OpenJSON, StringComparison.Ordinal); if(start >= 0) { int end = executePayload.IndexOf(GlobalConstants.CloseJSON, StringComparison.Ordinal); start += GlobalConstants.OpenJSON.Length; executePayload = CleanupHtml(executePayload.Substring(start, (end - start))); if(!String.IsNullOrEmpty(executePayload)) { return new StringResponseWriter(executePayload, ContentTypes.Json); } } } Dev2DataListDecisionHandler.Instance.RemoveEnvironment(dataObject.DataListID); dataObject.Environment = null; // else handle the format requested ;) return new StringResponseWriter(executePayload, formatter.ContentType); } }
/// <summary> /// Invokes a plugin assembly /// </summary> /// <param name="plugin">The action of type Plugin</param> /// <param name="req">The req.</param> /// <param name="formatOutput">Indicates if the output of the plugin should be run through the formatter</param> /// <returns> /// Unlimited object /// </returns> public Guid Plugin(ServiceAction plugin, IDSFDataObject req, bool formatOutput) { Guid result = GlobalConstants.NullDataListID; Guid tmpID = GlobalConstants.NullDataListID; var errors = new ErrorResultTO(); var allErrors = new ErrorResultTO(); try { AppDomain tmpDomain = plugin.PluginDomain; //Instantiate the Remote Oject handler which will allow cross application domain access var remoteHandler = (RemoteObjectHandler) tmpDomain.CreateInstanceFromAndUnwrap(typeof(IFrameworkDataChannel).Module.Name, typeof(RemoteObjectHandler).ToString()); var dataBuilder = new StringBuilder("<Args><Args>"); foreach(ServiceActionInput sai in plugin.ServiceActionInputs) { dataBuilder.Append("<Arg>"); dataBuilder.Append("<TypeOf>"); dataBuilder.Append(sai.NativeType); dataBuilder.Append("</TypeOf>"); dataBuilder.Append("<Value>"); dataBuilder.Append(sai.Value); // Fetch value and assign dataBuilder.Append("</Value>"); dataBuilder.Append("</Arg>"); } dataBuilder.Append("</Args></Args>"); //xele.Value = (remoteHandler.RunPlugin(plugin.Source.AssemblyLocation, plugin.Source.AssemblyName, plugin.SourceMethod, data)); string exeValue = (remoteHandler.RunPlugin(plugin.Source.AssemblyLocation, plugin.Source.AssemblyName, plugin.SourceMethod, dataBuilder.ToString(), plugin.OutputDescription, formatOutput)); // TODO : Now create a new dataList and merge the result into the current dataList ;) string dlShape = ClientCompiler.ShapeDev2DefinitionsToDataList(plugin.ServiceActionOutputs, enDev2ArgumentType.Output, false, out errors); allErrors.MergeErrors(errors); tmpID = ClientCompiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), exeValue, dlShape, out errors); ClientCompiler.SetParentID(tmpID, req.DataListID); // set parent for merge op in finally... allErrors.MergeErrors(errors); //Unload the temporary application domain //AppDomain.Unload(tmpDomain); -- throws exception when attempting to access after first unload?! -- A strange world C# / Winblows dev is } catch(Exception ex) { allErrors.AddError(ex.Message); } finally { // handle any errors that might have occured IBinaryDataListEntry be = Dev2BinaryDataListFactory.CreateEntry(enSystemTag.Error.ToString(), string.Empty); string error; be.TryPutScalar( Dev2BinaryDataListFactory.CreateBinaryItem(allErrors.MakeDataListReady(), enSystemTag.Error.ToString()), out error); errors.AddError(error); SvrCompiler.Upsert(null, req.DataListID, DataListUtil.BuildSystemTagForDataList(enSystemTag.Error, true), be, out errors); // now merge and delete tmp if(tmpID != GlobalConstants.NullDataListID) { // Travis.Frisinger - 29.01.2013 - Bug 8352 // We merge here since we never have the shape generated here in the request DL ;) Guid mergeID = ClientCompiler.Merge(req.DataListID, tmpID, enDataListMergeTypes.Union, enTranslationDepth.Data_With_Blank_OverWrite, false, out errors); if(mergeID == GlobalConstants.NullDataListID) { allErrors.AddError("Failed to merge data from Plugin Invoke"); allErrors.MergeErrors(errors); } //ClientCompiler.Shape(tmpID, enDev2ArgumentType.Output, plugin.ServiceActionOutputs, out errors); ClientCompiler.DeleteDataListByID(tmpID); result = req.DataListID; } } return result; }
/// <summary> /// Creates a binary data list from XML data. /// </summary> /// <param name="xmlDataList">The XML data list.</param> /// <param name="errors">The errors.</param> /// <returns></returns> private IBinaryDataList CreateBinaryDataListFromXmlData(string xmlDataList, out ErrorResultTO errors) { IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); IBinaryDataList result = null; var allErrors = new ErrorResultTO(); Guid dlGuid = compiler.ConvertTo( DataListFormat.CreateFormat(GlobalConstants._Studio_XML), xmlDataList.ToStringBuilder(), xmlDataList.ToStringBuilder(), out errors); if(!errors.HasErrors()) { result = compiler.FetchBinaryDataList(dlGuid, out errors); if(errors.HasErrors()) { allErrors.MergeErrors(errors); } } compiler.ForceDeleteDataListByID(dlGuid); return result; }
/// <summary> /// Converts the and filter. /// </summary> /// <param name="payload">The payload.</param> /// <param name="filterShape">The filter shape.</param> /// <param name="errors">The errors.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">payload</exception> public StringBuilder ConvertAndFilter(IBinaryDataList payload, StringBuilder filterShape, out ErrorResultTO errors) { if(payload == null) { throw new ArgumentNullException("payload"); } int keyCnt = 0; errors = new ErrorResultTO(); TranslatorUtils tu = new TranslatorUtils(); ErrorResultTO invokeErrors; IBinaryDataList targetDl = tu.TranslateShapeToObject(filterShape, false, out invokeErrors); errors.MergeErrors(invokeErrors); IList<string> itemKeys = targetDl.FetchAllUserKeys(); StringBuilder result = new StringBuilder("{"); foreach(string key in itemKeys) { IBinaryDataListEntry entry; IBinaryDataListEntry tmpEntry; string error; if(payload.TryGetEntry(key, out entry, out error) && targetDl.TryGetEntry(key, out tmpEntry, out error)) { if(entry.IsRecordset) { result.Append(ProcessRecordSet(entry, out error)); errors.AddError(error); } else { result.Append(ProcessScalar(entry)); } // wack in , for field separator ;) keyCnt++; if(keyCnt < itemKeys.Count) { result.Append(","); } } errors.AddError(error); } result.Append("}"); return result; }