/// <summary> /// Checks if parameter's getter if async /// and gets it's value /// </summary> /// <param name="parameterName">Name of parameter to get</param> /// <param name="processInstance">Instance of the process</param> /// <returns>Value of given parameter</returns> public async Task <object> GetExternalParameterAsync(string parameterName, ProcessInstance processInstance) { if (parameterName == "Data") { var entity = await processInstance.GetEntityAsync(); if (entity == null) { throw new Exception("Can not find entity within current process instance."); } return(entity); } return(null); }
/// <summary> /// Calls parameter's setter if it's setter is asynchronous /// </summary> /// <param name="parameterName">Name of parameter to set value</param> /// <param name="parameterValue">Value of parameter to set</param> /// <param name="processInstance">Instance of the process</param> public async Task SetExternalParameterAsync(string parameterName, object parameterValue, ProcessInstance processInstance) { if (parameterName == "Data") { var model = await processInstance.GetEntityModelAsync(); if (parameterValue is DynamicEntity) { var data = (DynamicEntity)parameterValue; //TODO: Evgeny Betin. Hot fix data types of collections WFE and DWKit integration foreach (var element in model.Attributes) { var value = data[element.Name]; try { if (value != null && element.Type.CLRType != value.GetType()) { data[element.Name] = element.Type.ParseToCLRType(value); } } catch (Exception ex) { throw new Exception($"Can not convert type {value.GetType()} of attribute {element.Name} to type {element.Type.CLRType}: {ex.Message}."); } } //TODO: Evgeny Betin. Hot fix names of attributes entities in DWKit and WFE parameters var entity = await processInstance.GetEntityAsync(); foreach (var collection in model.Collections) { data[collection.Name] = entity[collection.Name]; } await model.UpdateSingleAsync(data); } else { throw new Exception("WorkflowParameters.SetExternalParameters expect DynamicEntity type in parameterValue."); } } }