public AssemblyInvoker(SlaveContext context, IAssemblyInfoCollection assemblyInfo, ITypeDataCollection typeDatas) { this._assembliesMapping = new Dictionary <string, Assembly>(assemblyInfo.Count); this._typeDataMapping = new Dictionary <string, Type>(typeDatas.Count); this._assemblyInfos = assemblyInfo; this._typeDatas = typeDatas; this._context = context; this._dotNetLibDir = context.GetProperty <string>("DotNetLibDir"); this._platformLibDir = context.GetProperty <string>("PlatformLibDir"); this._instanceLibDir = context.GetProperty <string>("InstanceLibDir").Split(';'); _valueTypeConvertors = new Dictionary <string, Func <string, object> >(20) { { typeof(double).Name, valueStr => double.Parse(valueStr) }, { typeof(float).Name, valueStr => float.Parse(valueStr) }, { typeof(long).Name, valueStr => long.Parse(valueStr) }, { typeof(ulong).Name, valueStr => ulong.Parse(valueStr) }, { typeof(int).Name, valueStr => int.Parse(valueStr) }, { typeof(uint).Name, valueStr => uint.Parse(valueStr) }, { typeof(short).Name, valueStr => short.Parse(valueStr) }, { typeof(ushort).Name, valueStr => ushort.Parse(valueStr) }, { typeof(char).Name, valueStr => char.Parse(valueStr) }, { typeof(byte).Name, valueStr => byte.Parse(valueStr) }, { typeof(bool).Name, valueStr => bool.Parse(valueStr) }, { typeof(decimal).Name, valueStr => decimal.Parse(valueStr) }, { typeof(sbyte).Name, valueStr => sbyte.Parse(valueStr) }, { typeof(DateTime).Name, valueStr => DateTime.Parse(valueStr) }, }; }
private static void ValidateTypeDatas(ISequenceStep sequenceStep, ITypeDataCollection typeDatas) { if (sequenceStep.HasSubSteps) { foreach (ISequenceStep subStep in sequenceStep.SubSteps) { ValidateTypeDatas(subStep, typeDatas); } } else { FunctionData functionData = sequenceStep.Function as FunctionData; if (null == functionData) { return; } if (Constants.UnverifiedTypeIndex != functionData.ClassTypeIndex) { functionData.ClassType = typeDatas[functionData.ClassTypeIndex]; } Argument returnType = functionData.ReturnType as Argument; if (null != returnType && Constants.UnverifiedTypeIndex != returnType.TypeIndex) { returnType.Type = typeDatas[returnType.TypeIndex]; } foreach (IArgument rawArgument in functionData.ParameterType) { Argument argument = rawArgument as Argument; if (Constants.UnverifiedTypeIndex != argument.TypeIndex) { argument.Type = typeDatas[argument.TypeIndex]; } } } }
private static void VerifyTypeIndexes(ITypeDataCollection typeDatas, FunctionData functionData) { if (functionData?.ClassType == null) { if (null != functionData) { functionData.ClassTypeIndex = Constants.UnverifiedTypeIndex; } return; } int index = typeDatas.IndexOf(functionData.ClassType); if (-1 == index) { index = typeDatas.Count; typeDatas.Add(functionData.ClassType); } functionData.ClassTypeIndex = index; foreach (IArgument argument in functionData.ParameterType) { VerifyTypeIndexes(typeDatas, argument as Argument); } VerifyTypeIndexes(typeDatas, functionData.ReturnType as Argument); }
private static void ValidateTypeDatas(ISequence sequence, ITypeDataCollection typeDatas) { ValidateTypeDatas(sequence.Variables, typeDatas); foreach (ISequenceStep sequenceStep in sequence.Steps) { ValidateTypeDatas(sequenceStep, typeDatas); } }
private static void ValidateTypeDatas(IVariableCollection variables, ITypeDataCollection typeDatas) { foreach (IVariable rawVariable in variables) { Variable variable = rawVariable as Variable; if (Constants.UnverifiedTypeIndex != variable.TypeIndex) { variable.Type = typeDatas[variable.TypeIndex]; } } }
private static void ValidateTypeDatas(IArgumentCollection variables, ITypeDataCollection typeDatas) { foreach (IArgument rawArguments in variables) { Argument argument = rawArguments as Argument; if (Constants.UnverifiedTypeIndex != argument.TypeIndex) { argument.Type = typeDatas[argument.TypeIndex]; } } }
private static void VerifySequenceData(ITypeDataCollection parentTypeDatas, ISequence sequence) { foreach (IVariable variable in sequence.Variables) { VerifyTypeIndexes(parentTypeDatas, variable as Variable); } foreach (ISequenceStep sequenceStep in sequence.Steps) { VerifyTypeIndexes(parentTypeDatas, sequenceStep); } }
private static void RefreshTypeIndex(ISequence sequence, ITypeDataCollection typeDataCollection) { foreach (IVariable variable in sequence.Variables) { Variable variableObj = (variable as Variable); variableObj.TypeIndex = typeDataCollection.IndexOf(variableObj.Type); } foreach (ISequenceStep sequenceStep in sequence.Steps) { RefreshTypeIndex(sequenceStep, typeDataCollection); } }
private static void VerifyTypeIndexes(ITypeDataCollection typeDatas, ISequenceStep step) { if (step.HasSubSteps) { foreach (ISequenceStep subStep in step.SubSteps) { VerifyTypeIndexes(typeDatas, subStep); } } else { VerifyTypeIndexes(typeDatas, step.Function as FunctionData); } }
private void RefreshUsedTypeDatas(ITypeDataCollection typeDatas, HashSet <ITypeData> usedTypeDatas) { for (int i = typeDatas.Count - 1; i >= 0; i--) { if (usedTypeDatas.Contains(typeDatas[i])) { continue; } typeDatas.RemoveAt(i); } foreach (ITypeData usedTypeData in usedTypeDatas) { // 如果已存在add方法内部会进行判断 typeDatas.Add(usedTypeData); } }
private static void VerifyTypeIndexes(ITypeDataCollection typeDatas, Argument argument) { if (null == argument.Type || VariableType.Undefined == argument.VariableType) { argument.TypeIndex = Constants.UnverifiedTypeIndex; return; } int index = typeDatas.IndexOf(argument.Type); if (-1 == index) { index = typeDatas.Count; typeDatas.Add(argument.Type); } argument.TypeIndex = index; }
private static void VerifyTypeIndexes(ITypeDataCollection typeDatas, Variable variable) { if (null == variable.Type || VariableType.Undefined == variable.VariableType) { variable.TypeIndex = Constants.UnverifiedTypeIndex; return; } int index = typeDatas.IndexOf(variable.Type); if (-1 == index) { index = typeDatas.Count; typeDatas.Add(variable.Type); } variable.TypeIndex = index; }
private static void RefreshTypeIndex(ISequenceStep sequenceStep, ITypeDataCollection typeDataCollection) { if (sequenceStep.HasSubSteps) { foreach (ISequenceStep subStep in sequenceStep.SubSteps) { RefreshTypeIndex(subStep, typeDataCollection); } } else { FunctionData functionData = sequenceStep.Function as FunctionData; functionData.ClassTypeIndex = typeDataCollection.IndexOf(functionData.ClassType); foreach (IArgument argument in functionData.ParameterType) { RefreshTypeIndex(argument, typeDataCollection); } RefreshTypeIndex(functionData.ReturnType, typeDataCollection); } }
private static void RefreshTypeIndex(IArgument argument, ITypeDataCollection typeDataCollection) { Argument argumentObj = argument as Argument; argumentObj.TypeIndex = typeDataCollection.IndexOf(argumentObj.Type); }