public IRunningTask Build(TaskInfo taskInfo)
        {
            string instanceTypeJson = jsonConverter.ConvertFromJson <string>(taskInfo.InstanceType);
            Type   instanceType     = Type.GetType(instanceTypeJson, throwOnError: true, ignoreCase: true);

            Type[]     argumentTypes = jsonConverter.ConvertFromJson <Type[]>(taskInfo.ParametersTypes);
            MethodInfo method        = expressionConverter.GetNonOpenMatchingMethod(instanceType, taskInfo.Method, argumentTypes);

            string[] serializedArguments = jsonConverter.ConvertFromJson <string[]>(taskInfo.Arguments);

            object[] arguments = expressionConverter.DeserializeArguments(method, serializedArguments);


            //TODO: Activate and run task (Smart logic)
            var instance = Activator.CreateInstance(instanceType);

            return(new RunningTask(taskInfo, instance, method, argumentTypes, arguments));
        }
Пример #2
0
        /// <summary>
        /// Convert task entity into the task model.
        /// </summary>
        /// <param name="taskEntity">The <see cref="TaskEntity"/> instance.</param>
        /// <returns>The <see cref="TaskModel"/> instance.</returns>
        public TaskModel Convert(TaskEntity taskEntity)
        {
            string instanceTypeJson = jsonConverter.ConvertFromJson <string>(taskEntity.InstanceType);
            Type   instanceType     = Type.GetType(instanceTypeJson, throwOnError: true, ignoreCase: true);

            Type[]     argumentTypes = jsonConverter.ConvertFromJson <Type[]>(taskEntity.ParametersTypes);
            MethodInfo method        = expressionConverter.GetNonOpenMatchingMethod(instanceType, taskEntity.Method, argumentTypes);

            string[] serializedArguments = jsonConverter.ConvertFromJson <string[]>(taskEntity.Arguments);

            object[] arguments = expressionConverter.DeserializeArguments(method, serializedArguments);

            ActivationData activationData = new ActivationData(instanceType, method, arguments, argumentTypes);

            ScheduleInformation scheduleInformation = new ScheduleInformation(taskEntity.RepeatCrashCount);

            TaskModel taskModel = new TaskModel(taskEntity.Id, taskEntity.QueueId, taskEntity.ServerId, activationData, taskEntity.TaskState, scheduleInformation);

            return(taskModel);
        }