public AddError ( string msg, bool checkForDuplicates = false ) : void | ||
msg | string | The MSG. |
checkForDuplicates | bool | |
return | void |
public System.Guid MockExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out DataList.Contract.ErrorResultTO tmpErrors) { tmpErrors = new ErrorResultTO(); tmpErrors.AddError("Something bad happened"); return Guid.Empty; }
protected override IList<OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors) { IList<OutputTO> outputs = new List<OutputTO>(); allErrors = new ErrorResultTO(); var colItr = new WarewolfListIterator(); //get all the possible paths for all the string variables var inputItr = new WarewolfIterator(dataObject.Environment.Eval(InputPath)); colItr.AddVariableToIterateOn(inputItr); var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username)); colItr.AddVariableToIterateOn(unameItr); var passItr = new WarewolfIterator(dataObject.Environment.Eval(Password)); colItr.AddVariableToIterateOn(passItr); outputs.Add(DataListFactory.CreateOutputTO(Result)); if(dataObject.IsDebugMode()) { AddDebugInputItem(InputPath, "Input Path", dataObject.Environment); AddDebugInputItemUserNamePassword(dataObject.Environment); } while(colItr.HasMoreData()) { IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker(); IActivityIOPath ioPath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(inputItr), colItr.FetchNextValue(unameItr), colItr.FetchNextValue(passItr), true); IActivityIOOperationsEndPoint endpoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(ioPath); try { string result = broker.Get(endpoint); outputs[0].OutputStrings.Add(result); } catch(Exception e) { outputs[0].OutputStrings.Add(null); allErrors.AddError(e.Message); break; } } return outputs; }
public override Guid Execute(out ErrorResultTO errors) { 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; }
internal static void DoRecordSetAppending(ErrorResultTO errors, IBinaryDataListEntry entry, StringBuilder result) { var cnt = entry.FetchLastRecordsetIndex(); var cols = entry.Columns; if(!cols.Any(c => c.ColumnIODirection == enDev2ColumnArgumentDirection.Both || c.ColumnIODirection == enDev2ColumnArgumentDirection.Input)) { return; } for(var i = 1; i <= cnt; i++) { string error; var rowData = entry.FetchRecordAt(i, out error); errors.AddError(error); result.Append("<"); result.Append(entry.Namespace); result.Append(">"); foreach(var col in rowData) { var fName = col.FieldName; if(cols.Any(c => c.ColumnName == fName && (c.ColumnIODirection == enDev2ColumnArgumentDirection.Both || c.ColumnIODirection == enDev2ColumnArgumentDirection.Input))) { result.Append("<"); result.Append(fName); result.Append(">"); try { result.Append(col.TheValue); } // ReSharper disable EmptyGeneralCatchClause catch (Exception) { } result.Append("</"); result.Append(fName); result.Append(">"); } } result.Append("</"); result.Append(entry.Namespace); result.Append(">"); } }
protected override IList<OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors, int update) { IList<OutputTO> outputs = new List<OutputTO>(); allErrors = new ErrorResultTO(); var colItr = new WarewolfListIterator(); //get all the possible paths for all the string variables var outputItr = new WarewolfIterator(dataObject.Environment.Eval(OutputPath, update)); colItr.AddVariableToIterateOn(outputItr); var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username, update)); colItr.AddVariableToIterateOn(unameItr); var passItr = new WarewolfIterator(dataObject.Environment.Eval(DecryptedPassword,update)); colItr.AddVariableToIterateOn(passItr); if(dataObject.IsDebugMode()) { AddDebugInputItem(new DebugEvalResult(OutputPath, "File or Folder", dataObject.Environment, update)); AddDebugInputItem(new DebugItemStaticDataParams(Overwrite.ToString(), "Overwrite")); AddDebugInputItemUserNamePassword(dataObject.Environment, update); } while(colItr.HasMoreData()) { IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker(); Dev2CRUDOperationTO opTo = new Dev2CRUDOperationTO(Overwrite); try { IActivityIOPath dst = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(outputItr), colItr.FetchNextValue(unameItr), colItr.FetchNextValue(passItr), true); IActivityIOOperationsEndPoint dstEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(dst); string result = broker.Create(dstEndPoint, opTo, true); outputs.Add(DataListFactory.CreateOutputTO(Result, result)); } catch(Exception e) { outputs.Add(DataListFactory.CreateOutputTO(Result, "Failure")); allErrors.AddError(e.Message); break; } } return outputs; }
//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; } }
protected override IList<OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors, int update) { IList<OutputTO> outputs = new List<OutputTO>(); allErrors = new ErrorResultTO(); var colItr = new WarewolfListIterator(); //get all the possible paths for all the string variables var inputItr = new WarewolfIterator(dataObject.Environment.Eval(InputPath, update)); colItr.AddVariableToIterateOn(inputItr); var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username, update)); colItr.AddVariableToIterateOn(unameItr); var passItr = new WarewolfIterator(dataObject.Environment.Eval(DecryptedPassword,update)); colItr.AddVariableToIterateOn(passItr); var privateKeyItr = new WarewolfIterator(dataObject.Environment.Eval(PrivateKeyFile, update)); colItr.AddVariableToIterateOn(privateKeyItr); outputs.Add(DataListFactory.CreateOutputTO(Result)); if(dataObject.IsDebugMode()) { AddDebugInputItem(InputPath, "Input Path", dataObject.Environment, update); AddDebugInputItemUserNamePassword(dataObject.Environment, update); if (!string.IsNullOrEmpty(PrivateKeyFile)) { AddDebugInputItem(PrivateKeyFile, "Private Key File", dataObject.Environment, update); } } while(colItr.HasMoreData()) { IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker(); try { IActivityIOPath dst = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(inputItr), colItr.FetchNextValue(unameItr), colItr.FetchNextValue(passItr), true, colItr.FetchNextValue(privateKeyItr)); IActivityIOOperationsEndPoint dstEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(dst); string result = broker.Delete(dstEndPoint); outputs[0].OutputStrings.Add(result); } catch(Exception e) { outputs.Add(DataListFactory.CreateOutputTO(Result, "Failure")); //outputs[0].OutputStrings.Add(null); allErrors.AddError(e.Message); break; } } return outputs; }
/// <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; }
public override Guid Execute(out ErrorResultTO errors, int update) { errors = new ErrorResultTO(); errors.AddError(" [[CityName]] does not exist in your Data List"); errors.AddError("Error"); errors.AddError("Error 2"); errors.AddError("Error 3"); errors.AddError("Faulty Things Happened"); return DataObject.DataListID; }
protected override IList<OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors, int update) { IList<OutputTO> outputs = new List<OutputTO>(); allErrors = new ErrorResultTO(); ColItr = new WarewolfListIterator(); //get all the possible paths for all the string variables var inputItr = new WarewolfIterator(dataObject.Environment.Eval(InputPath, update)); ColItr.AddVariableToIterateOn(inputItr); var outputItr = new WarewolfIterator(dataObject.Environment.Eval(OutputPath, update)); ColItr.AddVariableToIterateOn(outputItr); var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username, update)); ColItr.AddVariableToIterateOn(unameItr); var passItr = new WarewolfIterator(dataObject.Environment.Eval(DecryptedPassword,update)); ColItr.AddVariableToIterateOn(passItr); var desunameItr = new WarewolfIterator(dataObject.Environment.Eval(DestinationUsername, update)); ColItr.AddVariableToIterateOn(desunameItr); var despassItr = new WarewolfIterator(dataObject.Environment.Eval(DecryptedDestinationPassword,update)); ColItr.AddVariableToIterateOn(despassItr); AddItemsToIterator(dataObject.Environment, update); outputs.Add(DataListFactory.CreateOutputTO(Result)); if(dataObject.IsDebugMode()) { AddDebugInputItem(new DebugEvalResult(InputPath, "Source Path", dataObject.Environment, update)); AddDebugInputItemUserNamePassword(dataObject.Environment, update); AddDebugInputItem(new DebugEvalResult(OutputPath, "Destination Path", dataObject.Environment, update)); AddDebugInputItemDestinationUsernamePassword(dataObject.Environment, DestinationPassword, DestinationUsername, update); AddDebugInputItem(new DebugItemStaticDataParams(Overwrite.ToString(), "Overwrite")); AddDebugInputItems(dataObject.Environment, update); } while(ColItr.HasMoreData()) { var hasError = false; IActivityIOPath src = null; IActivityIOPath dst = null; try { src = ActivityIOFactory.CreatePathFromString(ColItr.FetchNextValue(inputItr), ColItr.FetchNextValue(unameItr), ColItr.FetchNextValue(passItr), true); } catch(IOException ioException) { allErrors.AddError("Source: " + ioException.Message); hasError = true; } try { dst = ActivityIOFactory.CreatePathFromString(ColItr.FetchNextValue(outputItr), ColItr.FetchNextValue(desunameItr), ColItr.FetchNextValue(despassItr), true); } catch(IOException ioException) { allErrors.AddError("Destination:" + ioException.Message); hasError = true; } if(hasError) { outputs[0].OutputStrings.Add(null); MoveRemainingIterators(); continue; } IActivityIOOperationsEndPoint scrEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(src); IActivityIOOperationsEndPoint dstEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(dst); try { IActivityOperationsBroker broker = GetOperationBroker(); var result = ExecuteBroker(broker, scrEndPoint, dstEndPoint); outputs[0].OutputStrings.Add(result); } catch(Exception e) { allErrors.AddError(e.Message); outputs[0].OutputStrings.Add(null); } } return outputs; }
/// <summary> /// Makes ErrorResultTO from a error string from the data list. /// </summary> /// <param name="errorsString">Error string to convert</param> /// <returns>ErrorResultsTO</returns> public static ErrorResultTO MakeErrorResultFromDataListString(string errorsString) { ErrorResultTO result = new ErrorResultTO(); try { if(!string.IsNullOrEmpty(errorsString)) { errorsString = string.Concat("<Error>", errorsString, "</Error>"); XElement errorNode = XElement.Parse(errorsString); foreach(XElement element in errorNode.Elements("InnerError")) { result.AddError(element.Value); } } } catch(Exception) { result.AddError(errorsString); } return result; }
protected override Guid ExecutionImpl(IEsbChannel esbChannel, IDSFDataObject dataObject, string inputs, string outputs, out ErrorResultTO tmpErrors, int undate) { tmpErrors = new ErrorResultTO(); tmpErrors.AddError("This is an error"); return Guid.NewGuid(); }
/// <summary> /// Creates the list of data list item view model to bind to. /// </summary> /// <param name="errorString">The error string.</param> /// <returns></returns> public void CreateListsOfIDataListItemModelToBindTo(out string errorString) { errorString = string.Empty; IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); if(!string.IsNullOrEmpty(Resource.DataList)) { ErrorResultTO errors = new ErrorResultTO(); try { IBinaryDataList binarnyDl = CreateBinaryDataListFromXmlData(Resource.DataList, out errors); if (!errors.HasErrors()) { ConvertBinaryDataListToListOfIDataListItemModels(binarnyDl, out errorString); } else { string errorMessage = errors.FetchErrors().Aggregate(string.Empty, (current, error) => current + error); throw new Exception(errorMessage); } if (binarnyDl != null) compiler.ForceDeleteDataListByID(binarnyDl.UID); } catch(Exception) { errors.AddError("Invalid variable list. Please insure that your variable list has valid entries"); } } else { RecsetCollection.Clear(); AddRecordSet(); ScalarCollection.Clear(); } BaseCollection = new OptomizedObservableCollection<DataListHeaderItemModel>(); DataListHeaderItemModel varNode = DataListItemModelFactory.CreateDataListHeaderItem("Variable"); if(ScalarCollection.Count == 0) { var dataListItemModel = DataListItemModelFactory.CreateDataListModel(string.Empty); ScalarCollection.Add(dataListItemModel); } varNode.Children = ScalarCollection; BaseCollection.Add(varNode); //AddRecordsetNamesIfMissing(); DataListHeaderItemModel recordsetsNode = DataListItemModelFactory.CreateDataListHeaderItem("Recordset"); if(RecsetCollection.Count == 0) { AddRecordSet(); } recordsetsNode.Children = RecsetCollection; BaseCollection.Add(recordsetsNode); }
/// <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; }
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; }
/// <summary> /// Executes the specified errors. /// </summary> /// <param name="errors">The errors.</param> /// <returns></returns> public override Guid Execute(out ErrorResultTO errors) { errors = new ErrorResultTO(); // WorkflowApplicationFactory wfFactor = new WorkflowApplicationFactory(); Guid result = GlobalConstants.NullDataListID; // Set Service Name DataObject.ServiceName = ServiceAction.ServiceName; // Set server ID, only if not set yet - original server; if(DataObject.ServerID == Guid.Empty) DataObject.ServerID = HostSecurityProvider.Instance.ServerID; // Set resource ID, only if not set yet - original resource; if(DataObject.ResourceID == Guid.Empty && ServiceAction != null && ServiceAction.Service != null) DataObject.ResourceID = ServiceAction.Service.ID; // Travis : Now set Data List DataObject.DataList = ServiceAction.DataListSpecification; // Set original instance ID, only if not set yet - original resource; if(DataObject.OriginalInstanceID == Guid.Empty) DataObject.OriginalInstanceID = DataObject.DataListID; Dev2Logger.Log.Info(String.Format("Started Execution for Service Name:{0} Resource Id:{1} Mode:{2}",DataObject.ServiceName,DataObject.ResourceID,DataObject.IsDebug?"Debug":"Execute")); //Set execution origin if(!string.IsNullOrWhiteSpace(DataObject.ParentServiceName)) { DataObject.ExecutionOrigin = ExecutionOrigin.Workflow; DataObject.ExecutionOriginDescription = DataObject.ParentServiceName; } else if(DataObject.IsDebug) { DataObject.ExecutionOrigin = ExecutionOrigin.Debug; } else { DataObject.ExecutionOrigin = ExecutionOrigin.External; } try { // BUG 9304 - 2013.05.08 - TWR - Added CompileExpressions //_workflowHelper.CompileExpressions(theActivity,DataObject.ResourceID); //IDSFDataObject exeResult = wfFactor.InvokeWorkflow(activity.Value, DataObject, // new List<object> { EsbChannel, }, instanceId, // TheWorkspace, bookmark, out errors); var wfappUtils = new WfApplicationUtils(); IExecutionToken exeToken = new ExecutionToken { IsUserCanceled = false }; DataObject.ExecutionToken = exeToken; ErrorResultTO invokeErrors; if (DataObject.IsDebugMode()) { wfappUtils.DispatchDebugState(DataObject, StateType.Start, DataObject.Environment.HasErrors(), DataObject.Environment.FetchErrors(), out invokeErrors, null, true); } Eval(DataObject.ResourceID, DataObject); if (DataObject.IsDebugMode()) { wfappUtils.DispatchDebugState(DataObject, StateType.End, DataObject.Environment.HasErrors(), DataObject.Environment.FetchErrors(), out invokeErrors, DateTime.Now, false, true); } result = DataObject.DataListID; } catch(InvalidWorkflowException iwe) { Dev2Logger.Log.Error(iwe); var msg = iwe.Message; int start = msg.IndexOf("Flowchart ", StringComparison.Ordinal); // trap the no start node error so we can replace it with something nicer ;) errors.AddError(start > 0 ? GlobalConstants.NoStartNodeError : iwe.Message); } catch(Exception ex) { Dev2Logger.Log.Error(ex); errors.AddError(ex.Message); } finally { //ServiceAction.PushActivity(activity); } Dev2Logger.Log.Info(String.Format("Completed Execution for Service Name:{0} Resource Id: {1} Mode:{2}",DataObject.ServiceName,DataObject.ResourceID,DataObject.IsDebug?"Debug":"Execute")); return result; }
/// <summary> /// Creates the list of data list item view model to bind to. /// </summary> /// <param name="errorString">The error string.</param> /// <returns></returns> public void CreateListsOfIDataListItemModelToBindTo(out string errorString) { errorString = string.Empty; if(!string.IsNullOrEmpty(Resource.DataList)) { ErrorResultTO errors = new ErrorResultTO(); try { ConvertDataListStringToCollections(Resource.DataList); } catch(Exception) { errors.AddError("Invalid variable list. Please insure that your variable list has valid entries"); } } else { RecsetCollection.Clear(); AddRecordSet(); ScalarCollection.Clear(); } BaseCollection = new OptomizedObservableCollection<DataListHeaderItemModel>(); DataListHeaderItemModel varNode = DataListItemModelFactory.CreateDataListHeaderItem("Variable"); if(ScalarCollection.Count == 0) { var dataListItemModel = DataListItemModelFactory.CreateDataListModel(string.Empty); ScalarCollection.Add(dataListItemModel); } varNode.Children = ScalarCollection; BaseCollection.Add(varNode); DataListHeaderItemModel recordsetsNode = DataListItemModelFactory.CreateDataListHeaderItem("Recordset"); if(RecsetCollection.Count == 0) { AddRecordSet(); } recordsetsNode.Children = RecsetCollection; BaseCollection.Add(recordsetsNode); }
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(byte[] input, StringBuilder targetShape, out ErrorResultTO errors) { errors = new ErrorResultTO(); var payload = Encoding.UTF8.GetString(input); IBinaryDataList result = null; // build shape if(String.IsNullOrEmpty(targetShape.ToString())) { errors.AddError("Null payload shape"); } else { string error; result = BuildTargetShape(targetShape, out error); if(!string.IsNullOrEmpty(error)) { errors.AddError(error); } // populate the shape if(payload != string.Empty) { try { XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(payload); if(xDoc.DocumentElement != null) { var children = xDoc.DocumentElement.ChildNodes; IDictionary<string, int> indexCache = new Dictionary<string, int>(); { // spin through each element in the XML foreach(XmlNode c in children) { if(!DataListUtil.IsSystemTag(c.Name)) { // scalars and recordset fetch IBinaryDataListEntry entry; if(result.TryGetEntry(c.Name, out entry, out error)) { if(entry.IsRecordset) { // fetch recordset index int fetchIdx; int idx; // recset index if(indexCache.TryGetValue(c.Name, out fetchIdx)) { idx = fetchIdx; } else { // 28-02-2013 - Sashen.Naidoo // BUG 9144 // A cache miss does not necessary mean there is nothing in the record set, // it just means the value isn't in the record set. idx = indexCache.Count == 0 ? 1 : indexCache.Count; } // process recordset var 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 { // process scalar entry.TryPutScalar(Dev2BinaryDataListFactory.CreateBinaryItem(c.InnerXml, c.Name), out error); if(!string.IsNullOrEmpty(error)) { errors.AddError(error); } } } else { errors.AddError(error); } } } } } // Transfer System Tags for(var i = 0; i < TranslationConstants.systemTags.Length; i++) { var key = TranslationConstants.systemTags.GetValue(i).ToString(); var query = String.Concat("//", key); var n = xDoc.SelectSingleNode(query); if(n != null && !string.IsNullOrEmpty(n.InnerXml)) { var bkey = GlobalConstants.SystemTagNamespace + "." + key; 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; }
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); } }
protected override IList<OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors, int update) { IList<OutputTO> outputs = new List<OutputTO>(); allErrors = new ErrorResultTO(); var colItr = new WarewolfListIterator(); //get all the possible paths for all the string variables var inputItr = new WarewolfIterator(dataObject.Environment.Eval(OutputPath, update)); colItr.AddVariableToIterateOn(inputItr); var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username, update)); colItr.AddVariableToIterateOn(unameItr); var passItr = new WarewolfIterator(dataObject.Environment.Eval(DecryptedPassword,update)); colItr.AddVariableToIterateOn(passItr); var privateKeyItr = new WarewolfIterator(dataObject.Environment.Eval(PrivateKeyFile, update)); colItr.AddVariableToIterateOn(privateKeyItr); var contentItr =new WarewolfIterator(dataObject.Environment.Eval(FileContents, update)); colItr.AddVariableToIterateOn(contentItr); outputs.Add(DataListFactory.CreateOutputTO(Result)); if(dataObject.IsDebugMode()) { AddDebugInputItem(OutputPath, "Output Path", dataObject.Environment, update); AddDebugInputItem(new DebugItemStaticDataParams(GetMethod(), "Method")); AddDebugInputItemUserNamePassword(dataObject.Environment, update); if (!string.IsNullOrEmpty(PrivateKeyFile)) { AddDebugInputItem(PrivateKeyFile, "Private Key File", dataObject.Environment, update); } AddDebugInputItem(FileContents, "File Contents", dataObject.Environment, update); } while(colItr.HasMoreData()) { IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker(); var writeType = GetCorrectWriteType(); Dev2PutRawOperationTO putTo = ActivityIOFactory.CreatePutRawOperationTO(writeType, TextUtils.ReplaceWorkflowNewLinesWithEnvironmentNewLines(colItr.FetchNextValue(contentItr))); IActivityIOPath opath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(inputItr), colItr.FetchNextValue(unameItr), colItr.FetchNextValue(passItr), true, colItr.FetchNextValue(privateKeyItr)); IActivityIOOperationsEndPoint endPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(opath); try { if(allErrors.HasErrors()) { outputs[0].OutputStrings.Add(null); } else { string result = broker.PutRaw(endPoint, putTo); outputs[0].OutputStrings.Add(result); } } catch(Exception e) { outputs[0].OutputStrings.Add(null); allErrors.AddError(e.Message); break; } } return outputs; }
public void CanConvertErrorResultTojson() { ErrorResultTO errors = new ErrorResultTO(); errors.AddError("Error 1"); errors.AddError("Error 2"); var result = errors.MakeDataListReady(false); const string expected = "\"errors\": [ \"Error 1\",\"Error 2\"]"; Assert.AreEqual(expected, result, "Expected [ " + expected + " but got [ " + result + " ]"); }
List<int> SplitOutCsvIndexes(string csvNumbers, out ErrorResultTO errors) { errors = new ErrorResultTO(); List<int> result = new List<int>(); var splitStrings = csvNumbers.Split(','); foreach(var splitString in splitStrings) { if(!string.IsNullOrEmpty(splitString)) { int index; if(int.TryParse(splitString, out index)) { result.Add(index); } else { errors.AddError("Invalid characters have been entered in the CSV Numbers"); return result; } } } return result; }
public void ErrorResultTO_MakeDatalistReady_CannotSetUnknownMemberError_MessageConvertedToOutdatedServerError() { var errorResultTO = new ErrorResultTO(); errorResultTO.AddError("Cannot set unknown member"); //------------Execute Test--------------------------- var result = errorResultTO.MakeDataListReady(false); const string expected = "\"errors\": [ \"Resource has unrecognized formatting, this Warewolf Server may be to outdated to read this resource.\"]"; // Assert Message Converted To Outdated Server Error Assert.AreEqual(expected, result, "Error message not relevent"); }
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); } }
protected override IList<OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors, int update) { IsNotCertVerifiable = true; allErrors = new ErrorResultTO(); IList<OutputTO> outputs = new List<OutputTO>(); var colItr = new WarewolfListIterator(); //get all the possible paths for all the string variables var inputItr = new WarewolfIterator(dataObject.Environment.Eval(InputPath, update)); colItr.AddVariableToIterateOn(inputItr); var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username, update)); colItr.AddVariableToIterateOn(unameItr); var passItr = new WarewolfIterator(dataObject.Environment.Eval(DecryptedPassword,update)); colItr.AddVariableToIterateOn(passItr); var privateKeyItr = new WarewolfIterator(dataObject.Environment.Eval(PrivateKeyFile, update)); colItr.AddVariableToIterateOn(privateKeyItr); if(dataObject.IsDebugMode()) { AddDebugInputItem(InputPath, "Input Path", dataObject.Environment, update); AddDebugInputItem(new DebugItemStaticDataParams(GetReadType().GetDescription(), "Read")); AddDebugInputItemUserNamePassword(dataObject.Environment, update); if (!string.IsNullOrEmpty(PrivateKeyFile)) { AddDebugInputItem(PrivateKeyFile, "Private Key File", dataObject.Environment, update); } } while(colItr.HasMoreData()) { IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker(); IActivityIOPath ioPath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(inputItr), colItr.FetchNextValue(unameItr), colItr.FetchNextValue(passItr), true, colItr.FetchNextValue(privateKeyItr)); IActivityIOOperationsEndPoint endPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(ioPath); try { IList<IActivityIOPath> listOfDir = broker.ListDirectory(endPoint, GetReadType()); if(DataListUtil.IsValueRecordset(Result) && DataListUtil.GetRecordsetIndexType(Result) != enRecordsetIndexType.Numeric) { if(DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Star) { string recsetName = DataListUtil.ExtractRecordsetNameFromValue(Result); string fieldName = DataListUtil.ExtractFieldNameFromValue(Result); int indexToUpsertTo = 1; if(listOfDir != null) { foreach(IActivityIOPath pa in listOfDir) { string fullRecsetName = DataListUtil.CreateRecordsetDisplayValue(recsetName, fieldName, indexToUpsertTo.ToString(CultureInfo.InvariantCulture)); outputs.Add(DataListFactory.CreateOutputTO(DataListUtil.AddBracketsToValueIfNotExist(fullRecsetName), pa.Path)); indexToUpsertTo++; } } } else if(DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Blank) { if(listOfDir != null) { foreach(IActivityIOPath pa in listOfDir) { outputs.Add(DataListFactory.CreateOutputTO(Result, pa.Path)); } } } } else { if(listOfDir != null) { string xmlList = string.Join(",", listOfDir.Select(c => c.Path)); outputs.Add(DataListFactory.CreateOutputTO(Result)); outputs.Last().OutputStrings.Add(xmlList); } } } catch(Exception e) { outputs.Add(DataListFactory.CreateOutputTO(null)); allErrors.AddError(e.Message); break; } } return outputs; }
/// <summary> /// Invokes the workflow impl. /// </summary> /// <param name="workflowActivity">The workflow activity.</param> /// <param name="dataTransferObject">The data transfer object.</param> /// <param name="executionExtensions">The execution extensions.</param> /// <param name="instanceId">The instance id.</param> /// <param name="workspace">The workspace.</param> /// <param name="bookmarkName">Name of the bookmark.</param> /// <param name="isDebug">if set to <c>true</c> [is debug].</param> /// <param name="errors">The errors.</param> /// <returns></returns> private IDSFDataObject InvokeWorkflowImpl(Activity workflowActivity, IDSFDataObject dataTransferObject, IList<object> executionExtensions, Guid instanceId, IWorkspace workspace, string bookmarkName, bool isDebug, out ErrorResultTO errors) { Tracker.TrackEvent(TrackerEventGroup.Workflows, TrackerEventName.Executed, string.Format("RES-{0}", dataTransferObject.ResourceID)); if(AllErrors == null) { AllErrors = new ErrorResultTO(); } IExecutionToken exeToken = new ExecutionToken { IsUserCanceled = false }; ExecutionStatusCallbackDispatcher.Instance.Post(dataTransferObject.ExecutionCallbackID, ExecutionStatusCallbackMessageType.StartedCallback); WorkflowApplication wfApp = InitEntryPoint(workflowActivity, dataTransferObject, executionExtensions, instanceId, workspace, bookmarkName); errors = new ErrorResultTO(); if(wfApp != null) { // add termination token wfApp.Extensions.Add(exeToken); using(ManualResetEventSlim waitHandle = new ManualResetEventSlim(false)) { WorkflowApplicationRun run = new WorkflowApplicationRun(this, waitHandle, dataTransferObject, wfApp, workspace, executionExtensions, FetchParentInstanceId(dataTransferObject), isDebug, errors, exeToken); if(instanceId == Guid.Empty) { Interlocked.Increment(ref Balance); run.Run(); _runTime = DateTime.Now; waitHandle.Wait(); } else { Interlocked.Increment(ref Balance); try { if(!string.IsNullOrEmpty(bookmarkName)) { dataTransferObject.CurrentBookmarkName = bookmarkName; run.Resume(dataTransferObject); } else { run.Run(); _runTime = DateTime.Now; } waitHandle.Wait(); } catch(InstanceNotReadyException e1) { Interlocked.Decrement(ref Balance); ExecutionStatusCallbackDispatcher.Instance.Post(dataTransferObject.ExecutionCallbackID, ExecutionStatusCallbackMessageType.ErrorCallback); errors.AddError(e1.Message); AllErrors.AddError(e1.Message); return null; } catch(InstancePersistenceException e2) { Interlocked.Decrement(ref Balance); ExecutionStatusCallbackDispatcher.Instance.Post(dataTransferObject.ExecutionCallbackID, ExecutionStatusCallbackMessageType.ErrorCallback); errors.AddError(e2.Message); AllErrors.AddError(e2.Message); return run.DataTransferObject.Clone(); } catch(Exception ex) { Interlocked.Decrement(ref Balance); errors.AddError(ex.Message); AllErrors.AddError(ex.Message); ExecutionStatusCallbackDispatcher.Instance.Post(dataTransferObject.ExecutionCallbackID, ExecutionStatusCallbackMessageType.ErrorCallback); return run.DataTransferObject.Clone(); } } Interlocked.Decrement(ref Balance); dataTransferObject = run.DataTransferObject.Clone(); var wfappUtils = new WfApplicationUtils(); ErrorResultTO invokeErrors; if (dataTransferObject.IsDebugMode()) { wfappUtils.DispatchDebugState(dataTransferObject, StateType.End, AllErrors.HasErrors(), AllErrors.MakeDisplayReady(), out invokeErrors, _runTime, false, true); } //AllErrors.MergeErrors(invokeErrors); // avoid memory leak ;) run.Dispose(); } } else { errors.AddError("Internal System Error : Could not create workflow execution wrapper"); } return dataTransferObject; }
/// <summary> /// Translates the shape automatic object. /// </summary> /// <param name="shape">The shape.</param> /// <param name="includeSysTags">Includes the system tags when building the DataList</param> /// <param name="errors">The errors.</param> /// <returns></returns> public IBinaryDataList TranslateShapeToObject(StringBuilder shape, bool includeSysTags, out ErrorResultTO errors) { IBinaryDataList result = null; errors = new ErrorResultTO(); try { XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(shape.ToString()); string error; if(xDoc.DocumentElement != null) { XmlNodeList children = xDoc.DocumentElement.ChildNodes; HashSet<string> procssesNamespaces = new HashSet<string>(); result = Dev2BinaryDataListFactory.CreateDataList(); foreach(XmlNode c in children) { XmlAttribute descAttribute = null; XmlAttribute ioDirection = null; if(!DataListUtil.IsSystemTag(c.Name)) { if(c.HasChildNodes) { IList<Dev2Column> cols = new List<Dev2Column>(); //recordset // build template if(!procssesNamespaces.Contains(c.Name)) { procssesNamespaces.Add(c.Name); // build columns foreach(XmlNode subc in c.ChildNodes) { if(subc.Attributes != null) { descAttribute = subc.Attributes["Description"]; ioDirection = subc.Attributes["ColumnIODirection"]; } // set column io direction enDev2ColumnArgumentDirection dirCol = enDev2ColumnArgumentDirection.None; if(ioDirection != null) { Enum.TryParse(ioDirection.Value, out dirCol); } if(descAttribute != null) { cols.Add(DataListFactory.CreateDev2Column(subc.Name, descAttribute.Value, true, dirCol)); } else { cols.Add(DataListFactory.CreateDev2Column(subc.Name, String.Empty, true, dirCol)); } } string myError; if(c.Attributes != null) { descAttribute = c.Attributes["Description"]; ioDirection = c.Attributes["ColumnIODirection"]; } // set column io direction enDev2ColumnArgumentDirection dir = enDev2ColumnArgumentDirection.None; if(ioDirection != null) { Enum.TryParse(ioDirection.Value, out dir); } if(descAttribute != null) { if(!result.TryCreateRecordsetTemplate(c.Name, descAttribute.Value, cols, true, true, dir, out myError)) { errors.AddError(myError); } } else { if(!result.TryCreateRecordsetTemplate(c.Name, String.Empty, cols, true, true, dir, out myError)) { errors.AddError(myError); } } } else { // it is a duplicate we need to handle this correctly ;) // build columns IBinaryDataListEntry amendEntry; result.TryGetEntry(c.Name, out amendEntry, out error); errors.AddError(error); if(amendEntry != null) { cols = amendEntry.Columns; foreach(XmlNode subc in c.ChildNodes) { if(subc.Attributes != null) { descAttribute = subc.Attributes["Description"]; ioDirection = subc.Attributes["ColumnIODirection"]; } // set column io direction enDev2ColumnArgumentDirection dir = enDev2ColumnArgumentDirection.None; if(ioDirection != null) { Enum.TryParse(ioDirection.Value, out dir); } if(descAttribute != null) { cols.Add(DataListFactory.CreateDev2Column(subc.Name, descAttribute.Value, true, dir)); } else { cols.Add(DataListFactory.CreateDev2Column(subc.Name, String.Empty, true, dir)); } } // now re-insert the entry ;) if(!result.TryCreateRecordsetTemplate(c.Name, String.Empty, cols, true, out error)) { errors.AddError(error); } } } } else { //scalar if(c.Attributes != null) { descAttribute = c.Attributes["Description"]; ioDirection = c.Attributes["ColumnIODirection"]; } // get column direction enDev2ColumnArgumentDirection dir = enDev2ColumnArgumentDirection.None; if(ioDirection != null) { Enum.TryParse(ioDirection.Value, out dir); } if(descAttribute != null) { result.TryCreateScalarTemplate(String.Empty, c.Name, descAttribute.Value, true, true, dir, out error); } else { result.TryCreateScalarTemplate(String.Empty, c.Name, String.Empty, true, true, dir, out error); } } } } } if(includeSysTags) { // Build System Tag Shape ;) for(int i = 0; i < TranslationConstants.systemTags.Length; i++) { if(result != null) { result.TryCreateScalarTemplate(GlobalConstants.SystemTagNamespace, TranslationConstants.systemTags.GetValue(i).ToString(), String.Empty, true, out error); } } } } catch(Exception e) { errors.AddError(e.Message); } return result; }
public override Guid Execute(out ErrorResultTO errors, int update) { Dev2Logger.Log.Info(String.Format("Starting Remote Execution. Service Name:{0} Resource Id:{1} Mode:{2}", DataObject.ServiceName, DataObject.ResourceID, DataObject.IsDebug ? "Debug" : "Execute")); var serviceName = DataObject.ServiceName; errors = new ErrorResultTO(); // get data in a format we can send ;) Dev2Logger.Log.Debug("Creating DataList fragment for remote execute"); var dataListFragment = ExecutionEnvironmentUtils.GetXmlInputFromEnvironment(DataObject, DataObject.RemoteInvokeResultShape.ToString(), update); string result = string.Empty; var connection = GetConnection(DataObject.EnvironmentID); if (connection == null) { errors.AddError("Server source not found."); return DataObject.DataListID; } try { // Invoke Remote WF Here ;) result = ExecuteGetRequest(connection, serviceName, dataListFragment); IList<IDebugState> msg = DataObject.IsDebug? FetchRemoteDebugItems(connection):new List<IDebugState>(); DataObject.RemoteDebugItems = msg; // set them so they can be acted upon } catch (Exception e) { var errorMessage = e.Message.Contains("Forbidden") ? "Executing a service requires Execute permissions" : e.Message; DataObject.Environment.Errors.Add(errorMessage); Dev2Logger.Log.Error(e); } // Create tmpDL ExecutionEnvironmentUtils.UpdateEnvironmentFromOutputPayload(DataObject,result.ToStringBuilder(),DataObject.RemoteInvokeResultShape.ToString(), update); Dev2Logger.Log.Info(String.Format("Completed Remote Execution. Service Name:{0} Resource Id:{1} Mode:{2}", DataObject.ServiceName, DataObject.ResourceID, DataObject.IsDebug ? "Debug" : "Execute")); return Guid.Empty; }
//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; } }