public virtual IVariableTypes AddType(IVariableType type, int index) { typesList.Insert(index, type); typesMap[type.TypeName] = type; return(this); }
public static IGenericVariableType EnumerableOf(IVariableType _type) { return(new TemplateGenericVariableType("IEnumerable", new List <IVariableType>() { _type })); }
protected internal virtual void UpdateVariableInstance(IVariableInstanceEntity variableInstance, object value, IExecutionEntity sourceActivityExecution) { // Always check if the type should be altered. It's possible that the // previous type is lower in the type // checking chain (e.g. serializable) and will return true on // isAbleToStore(), even though another type // higher in the chain is eligible for storage. IVariableTypes variableTypes = Context.ProcessEngineConfiguration.VariableTypes; IVariableType newType = variableTypes.FindVariableType(value); if (newType != null && !newType.Equals(variableInstance.Type)) { variableInstance.Value = null; variableInstance.Type = newType; variableInstance.ForceUpdate(); variableInstance.Value = value; } else { variableInstance.Value = value; } Context.CommandContext.HistoryManager.RecordHistoricDetailVariableCreate(variableInstance, sourceActivityExecution, ActivityIdUsedForDetails); Context.CommandContext.HistoryManager.RecordVariableUpdate(variableInstance); }
protected virtual void InitializeProcessContext(ProcessInstance processInstance, IList <ValuedDataObject> dataObjects) { var dataObjectsMap = dataObjects.ToDictionary(x => x.Id); IVariableType type = null; foreach (var dataObject in dataObjects) { var value = dataObject.Value; type = Variables.VariableType.Resolve(value); var variable = new Variable(); variable.Name = dataObject.Id; variable.Type = type.Name; type.SetValue(variable, value); processInstance.Variables.Add(variable); } if (variables != null && variables.Count > 0) { var em = variables.GetEnumerator(); while (em.MoveNext()) { processInstance.SetVariable(em.Current.Key, em.Current.Value); } } }
public static IGenericVariableType ListOf(IVariableType _type) { return(new TemplateGenericVariableType("List", new List <IVariableType>() { _type })); }
protected virtual Variable AddVariable(string name, object value, IVariableType type = null) { if (value == null) { return(null); } if (type == null) { type = VariableType.Resolve(value); } var variable = new Variable(); variable.Name = name; variable.Type = type.Name; type.SetValue(variable, value); this.Variables.Add(variable); this.variableByName.Add(name, variable); return(variable); }
/// <summary> /// Verifies that the variable type attributes are consistent with each other. /// </summary> private bool VerifyVariableTypeConsistency(IVariableType node) { // check for error during read. StatusCode?status = node.Value as StatusCode?; if (status == null) { TypeInfo typeInfo = TypeInfo.IsInstanceOfDataType( node.Value, node.DataType, node.ValueRank, Session.NamespaceUris, Session.TypeTree); if (typeInfo == null) { Log( "Value has incorrect data type for Node '{0}'. NodeId = {1}, Attribute = {2}, ValueRank = {3}, Value = {4}", node, node.NodeId, node.DataType, node.ValueRank, new Variant(node.Value)); return(false); } } return(true); }
protected virtual void EnsureInitialized() { if (this.typeHandler != null) { return; } this.typeHandler = VariableType.Get(this.Type); }
public virtual IVariableInstanceEntity Create(string name, IVariableType type, object value) { IVariableInstanceEntity variableInstance = Create(); variableInstance.Name = name; variableInstance.Type = type; variableInstance.TypeName = type.TypeName; variableInstance.Value = value; return(variableInstance); }
public TemplateFunction(Privacy privacy, Overridability overridability, IVariableType returnType, string name, IList <IVariable> parameters) { this.overridability = overridability; this.name = name; this.parameters = parameters; this.privacy = privacy; this.returnType = returnType; this.codeBlock = new TemplateCodeBlock(); this.indent = "\t"; this.tags = new List <ITag>(); }
public virtual int GetTypeIndex(string typeName) { IVariableType type = typesMap[typeName]; if (type != null) { return(GetTypeIndex(type)); } else { return(-1); } }
private TemplateProperty(string comment, IVariableType variableType, string name, IVariable variable, bool canGet, string getter, bool canSet, string setter) { this.canGet = canGet; this.canSet = canSet; this.comment = comment; this.getter = getter; this.name = name; this.setter = setter; this.variable = variable; this.variableType = variableType; if (this.variable != null) { this.isStatic = this.variable.IsStatic; } }
/// <summary> /// Find the specified variable type. /// </summary> public static IVariableType Get(string name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } IVariableType type = null; if (typeMapping.TryGetValue(name, out type)) { return(type); } throw new NotSupportedException($"The variable type '{name}' was not supported."); }
public TemplateVariable(bool isStatic, IVariableType _type, string instanceName) { if (!string.IsNullOrWhiteSpace(instanceName)) { string prefix = instanceName.Substring(0, 1).ToLower(); string suffix = instanceName.Substring(1, instanceName.Length - 1); this.instanceName = prefix + suffix; } else { this.instanceName = null; } this.isStatic = isStatic; this._type = _type; }
public void Where(IVariableType genericType, IInterface isOfInterface) { if (genericType == null) { throw new ArgumentNullException("Generic Type"); } if (isOfInterface == null) { throw new ArgumentNullException("Is Of Interface"); } if (this.whereClause.ContainsKey(genericType)) { throw new ArgumentException("Generic Type (" + genericType.Name + ") Where already set."); } this.whereClause[genericType] = isOfInterface; }
static VariableType() { var defaultTypes = new IVariableType[] { new StringType(), new IntegerType(), new LongType(), new DoubleType(), new BooleanType(), new DateType(), new ByteArrayType(), new ListType(), new SerializableType() }; types.AddRange(defaultTypes); typeMapping = types.ToDictionary(x => x.Name); //add NullType. typeMapping.Add("null", NullType); }
/// <summary cref="NodeSource.UpdateAttributes" /> protected override void UpdateAttributes(ILocalNode source) { base.UpdateAttributes(source); IVariableType type = source as IVariableType; if (type != null) { if (typeof(T).IsInstanceOfType(type.Value)) { Value = (T)type.Value; } DataType = type.DataType; ValueRank = type.ValueRank; ArrayDimensions = null; IsAbstract = type.IsAbstract; if (type.ArrayDimensions != null && type.ArrayDimensions.Count > 0) { ArrayDimensions = (IList <uint>)Utils.Clone(type.ArrayDimensions); } } }
public virtual void Initialize(IVariableTypes types) { if (variableInstanceEntity == null) { IVariableType type = types.FindVariableType(value); if (type is ByteArrayType) { throw new ActivitiIllegalArgumentException("Variables of type ByteArray cannot be used to query"); } else if (type is IEntityVariableType && @operator != QueryOperator.EQUALS) { throw new ActivitiIllegalArgumentException("JPA entity variables can only be used in 'variableValueEquals'"); } else if (type is IEntityListVariableType) { throw new ActivitiIllegalArgumentException("Variables containing a list of JPA entities cannot be used to query"); } else { // Type implementation determines which fields are set on the entity variableInstanceEntity = Context.CommandContext.VariableInstanceEntityManager.Create(name, type, value); } } }
protected internal virtual IVariableInstanceEntity CreateVariableInstance(string variableName, object value, IExecutionEntity sourceActivityExecution) { IVariableTypes variableTypes = Context.ProcessEngineConfiguration.VariableTypes; IVariableType type = variableTypes.FindVariableType(value); IVariableInstanceEntity variableInstance = Context.CommandContext.VariableInstanceEntityManager.Create(variableName, type, value); InitializeVariableInstanceBackPointer(variableInstance); Context.CommandContext.VariableInstanceEntityManager.Insert(variableInstance); if (variableInstances != null) { variableInstances[variableName] = variableInstance; } // Record historic variable Context.CommandContext.HistoryManager.RecordVariableCreate(variableInstance); // Record historic detail Context.CommandContext.HistoryManager.RecordHistoricDetailVariableCreate(variableInstance, sourceActivityExecution, ActivityIdUsedForDetails); return(variableInstance); }
public static IActivitiVariableEvent CreateVariableEvent(ActivitiEventType type, string variableName, object variableValue, IVariableType variableType, string taskId, string executionId, string processInstanceId, string processDefinitionId) { ActivitiVariableEventImpl newEvent = new ActivitiVariableEventImpl(type) { VariableName = variableName, VariableValue = variableValue, VariableType = variableType, TaskId = taskId, ExecutionId = executionId, ProcessDefinitionId = processDefinitionId, ProcessInstanceId = processInstanceId }; return(newEvent); }
public TemplateProperty(string comment, IVariableType variableType, string name, bool canGet, bool canSet) : this(comment, variableType, name, null, canGet, null, canSet, null) { }
public TemplateProperty(IVariableType variableType, string name, string getter, string setter) : this(null, variableType, name, getter, setter) { }
public static string MockOf(IVariableType _type) { return("Mock<" + _type.Name + ">"); }
public TemplateProperty(string comment, IVariableType variableType, string name, string getter, string setter) : this(comment, variableType, name, null, !string.IsNullOrWhiteSpace(getter), getter, !string.IsNullOrWhiteSpace(setter), setter) { }
public static string NewMockOf(IVariableType _type) { return("new " + MockOf(_type) + "()"); }
/// <summary> /// Verifies that the node attributes are consistent with each other. /// </summary> protected bool VerifyAttributeConsistency(Node node) { if (((~node.WriteMask) & node.UserWriteMask) != 0) { Log( "UserWriteMask allows more access that WriteMask for Node '{0}'. NodeId = {1}, WriteMask = {2}, UserWriteMask = {3}", node, node.NodeId, node.WriteMask, node.UserWriteMask); return(false); } IMethod method = node as IMethod; if (method != null) { if (method.UserExecutable && !method.Executable) { Log( "UserExecutable allows more access that Executable for Node '{0}'. NodeId = {1}, Executable = {2}, UserExecutable = {3}", node, node.NodeId, method.Executable, method.UserExecutable); return(false); } } IVariableBase variableBase = node as IVariableBase; if (variableBase != null) { if (!VerifyVariableBaseConsistency(variableBase)) { return(false); } } IVariable variable = node as IVariable; if (variable != null) { if (!VerifyVariableConsistency(variable)) { return(false); } } IVariableType variableType = node as IVariableType; if (variableType != null) { if (!VerifyVariableTypeConsistency(variableType)) { return(false); } } return(true); }
public virtual IVariableTypes RemoveType(IVariableType type) { typesList.Remove(type); typesMap.Remove(type.TypeName); return(this); }
public virtual IVariableTypes AddType(IVariableType type) { return(AddType(type, typesList.Count)); }
public virtual int GetTypeIndex(IVariableType type) { return(typesList.IndexOf(type)); }
/// <summary> /// Verifies that the variable type attributes are consistent with each other. /// </summary> private bool VerifyVariableTypeConsistency(IVariableType node) { // check for error during read. StatusCode? status = node.Value as StatusCode?; if (status == null) { TypeInfo typeInfo = TypeInfo.IsInstanceOfDataType( node.Value, node.DataType, node.ValueRank, Session.NamespaceUris, Session.TypeTree); if (typeInfo == null) { Log( "Value has incorrect data type for Node '{0}'. NodeId = {1}, Attribute = {2}, ValueRank = {3}, Value = {4}", node, node.NodeId, node.DataType, node.ValueRank, new Variant(node.Value)); return false; } } return true; }
protected internal virtual IDictionary <string, object> createData(IActivitiVariableEvent variableEvent) { IDictionary <string, object> data = new Dictionary <string, object>(); PutInMapIfNotNull(data, FieldsFields.NAME, variableEvent.VariableName); PutInMapIfNotNull(data, FieldsFields.PROCESS_DEFINITION_ID, variableEvent.ProcessDefinitionId); PutInMapIfNotNull(data, FieldsFields.PROCESS_INSTANCE_ID, variableEvent.ProcessInstanceId); PutInMapIfNotNull(data, FieldsFields.EXECUTION_ID, variableEvent.ExecutionId); PutInMapIfNotNull(data, FieldsFields.VALUE, variableEvent.VariableValue); IVariableType variableType = variableEvent.VariableType; if (variableType is BooleanType) { PutInMapIfNotNull(data, FieldsFields.VALUE_BOOLEAN, (bool?)variableEvent.VariableValue); PutInMapIfNotNull(data, FieldsFields.VALUE, variableEvent.VariableValue); PutInMapIfNotNull(data, FieldsFields.VARIABLE_TYPE, TYPE_BOOLEAN); } else if (variableType is StringType || variableType is LongStringType) { PutInMapIfNotNull(data, FieldsFields.VALUE_STRING, (string)variableEvent.VariableValue); PutInMapIfNotNull(data, FieldsFields.VARIABLE_TYPE, TYPE_STRING); } else if (variableType is ShortType) { short?value = (short?)variableEvent.VariableValue; PutInMapIfNotNull(data, FieldsFields.VALUE_SHORT, value); PutInMapIfNotNull(data, FieldsFields.VARIABLE_TYPE, TYPE_SHORT); if (value != null) { PutInMapIfNotNull(data, FieldsFields.VALUE_INTEGER, value.Value); PutInMapIfNotNull(data, FieldsFields.VALUE_LONG, value.Value); PutInMapIfNotNull(data, FieldsFields.VALUE_DOUBLE, value.Value); } } else if (variableType is IntegerType) { int?value = (int?)variableEvent.VariableValue; PutInMapIfNotNull(data, FieldsFields.VALUE_INTEGER, value); PutInMapIfNotNull(data, FieldsFields.VARIABLE_TYPE, TYPE_INTEGER); if (value != null) { PutInMapIfNotNull(data, FieldsFields.VALUE_LONG, value.Value); PutInMapIfNotNull(data, FieldsFields.VALUE_DOUBLE, value.Value); } } else if (variableType is LongType) { long?value = (long?)variableEvent.VariableValue; PutInMapIfNotNull(data, FieldsFields.VALUE_LONG, value); PutInMapIfNotNull(data, FieldsFields.VARIABLE_TYPE, TYPE_LONG); if (value != null) { PutInMapIfNotNull(data, FieldsFields.VALUE_DOUBLE, value.Value); } } else if (variableType is DoubleType) { double?value = (double?)variableEvent.VariableValue; PutInMapIfNotNull(data, FieldsFields.VALUE_DOUBLE, value); PutInMapIfNotNull(data, FieldsFields.VARIABLE_TYPE, TYPE_DOUBLE); if (value != null) { PutInMapIfNotNull(data, FieldsFields.VALUE_INTEGER, value.Value); PutInMapIfNotNull(data, FieldsFields.VALUE_LONG, value.Value); } } else if (variableType is DateType) { DateTime value = (DateTime)variableEvent.VariableValue; PutInMapIfNotNull(data, FieldsFields.VALUE_DATE, value != null ? (long?)value.Ticks : null); PutInMapIfNotNull(data, FieldsFields.VARIABLE_TYPE, TYPE_DATE); } else if (variableType is UUIDType) { string value = null; if (variableEvent.VariableValue is System.Guid) { value = ((System.Guid)variableEvent.VariableValue).ToString(); } else { value = (string)variableEvent.VariableValue; } PutInMapIfNotNull(data, FieldsFields.VALUE_UUID, value); PutInMapIfNotNull(data, FieldsFields.VALUE_STRING, value); PutInMapIfNotNull(data, FieldsFields.VARIABLE_TYPE, TYPE_UUID); } else if (variableType is SerializableType || (variableEvent.VariableValue != null && (variableEvent.VariableValue is object))) { // Last try: serialize it to json ObjectMapper objectMapper = new ObjectMapper(); try { string value = objectMapper.WriteValueAsString(variableEvent.VariableValue); PutInMapIfNotNull(data, FieldsFields.VALUE_JSON, value); PutInMapIfNotNull(data, FieldsFields.VARIABLE_TYPE, TYPE_JSON); PutInMapIfNotNull(data, FieldsFields.VALUE, value); } catch (Exception) { // Nothing to do about it log.LogDebug("Could not serialize variable value " + variableEvent.VariableValue); } } return(data); }