/// <summary> /// Schedule a TaskActivity by type. Also retry on failure as per supplied policy. /// </summary> /// <typeparam name="T">Return Type of the TaskActivity.Exeute method</typeparam> /// <param name="taskActivityType">Type that dervices from TaskActivity class</param> /// <param name="retryOptions">Retry policy</param> /// <param name="parameters">Parameters for the TaskActivity.Execute method</param> /// <returns>Task that represents the execution of the specified TaskActivity</returns> public virtual Task <T> ScheduleWithRetry <T>(Type taskActivityType, RetryOptions retryOptions, params object[] parameters) { return(ScheduleWithRetry <T>(NameVersionHelper.GetDefaultName(taskActivityType), NameVersionHelper.GetDefaultVersion(taskActivityType), retryOptions, parameters)); }
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { Type returnType = null; if (!returnTypes.TryGetValue(binder.Name, out returnType)) { throw new Exception("Method name '" + binder.Name + "' not known."); } string normalizedMethodName = useFullyQualifiedMethodNames ? NameVersionHelper.GetFullyQualifiedMethodName(interfaze.Name, NameVersionHelper.GetDefaultName(binder)) : NameVersionHelper.GetDefaultName(binder); if (returnType.Equals(typeof(Task))) { result = context.ScheduleTask <object>(normalizedMethodName, NameVersionHelper.GetDefaultVersion(binder), args); } else { if (!returnType.IsGenericType) { throw new Exception("Return type is not a generic type. Type Name: " + returnType.FullName); } Type[] genericArguments = returnType.GetGenericArguments(); if (genericArguments.Length != 1) { throw new Exception("Generic Parameters are not equal to 1. Type Name: " + returnType.FullName); } MethodInfo scheduleMethod = typeof(OrchestrationContext).GetMethod("ScheduleTask", new[] { typeof(string), typeof(string), typeof(object[]) }); MethodInfo genericScheduleMethod = scheduleMethod.MakeGenericMethod(genericArguments[0]); result = genericScheduleMethod.Invoke(context, new object[] { normalizedMethodName, NameVersionHelper.GetDefaultVersion(binder), args }); } return(true); }
/// <summary> /// Infers and adds every method in the specified interface T on the /// passed in object as a different TaskActivity with Name set to the method name /// and version set to an empty string. Methods can then be invoked from task orchestrations /// by calling ScheduleTask(name, version) with name as the method name and string.Empty as the version. /// </summary> /// <typeparam name="T">Interface</typeparam> /// <param name="activities">Object that implements this interface</param> /// <param name="useFullyQualifiedMethodNames"> /// If true, the method name translation from the interface contains /// the interface name, if false then only the method name is used /// </param> /// <returns></returns> public TaskHubWorker AddTaskActivitiesFromInterface <T>(T activities, bool useFullyQualifiedMethodNames) { Type @interface = typeof(T); if ([email protected]) { throw new Exception("Contract can only be an interface."); } foreach (MethodInfo methodInfo in @interface.GetMethods()) { TaskActivity taskActivity = new ReflectionBasedTaskActivity(activities, methodInfo); ObjectCreator <TaskActivity> creator = new NameValueObjectCreator <TaskActivity>( NameVersionHelper.GetDefaultName(methodInfo, useFullyQualifiedMethodNames), NameVersionHelper.GetDefaultVersion(methodInfo), taskActivity); activityManager.Add(creator); } return(this); }
/// <summary> /// Create a new orchestration of the specified type with the specified instance id /// </summary> /// <param name="orchestrationType">Type that derives from TaskOrchestration</param> /// <param name="instanceId">Instance id for the orchestration to be created, must be unique across the Task Hub</param> /// <param name="input">Input parameter to the specified TaskOrchestration</param> /// <returns>OrchestrationInstance that represents the orchestration that was created</returns> public Task <OrchestrationInstance> CreateOrchestrationInstanceAsync(Type orchestrationType, string instanceId, object input) { return(CreateOrchestrationInstanceAsync(NameVersionHelper.GetDefaultName(orchestrationType), NameVersionHelper.GetDefaultVersion(orchestrationType), instanceId, input)); }
void Initialize(object obj) { Name = NameVersionHelper.GetDefaultName(obj); Version = NameVersionHelper.GetDefaultVersion(obj); }
/// <summary> /// Create a suborchestration of the specified type with the specified instance id /// </summary> /// <typeparam name="T">Return Type of the TaskOrchestration.RunTask method</typeparam> /// <param name="orchestrationType">Type of the TaskOrchestration derived class to instantiate</param> /// <param name="instanceId">InstanceId of the suborchestration to create</param> /// <param name="input">Input for the TaskOrchestration.RunTask method</param> /// <returns>Task that represents the execution of the specified suborchestration</returns> public virtual Task <T> CreateSubOrchestrationInstance <T>(Type orchestrationType, string instanceId, object input) { return(CreateSubOrchestrationInstance <T>(NameVersionHelper.GetDefaultName(orchestrationType), NameVersionHelper.GetDefaultVersion(orchestrationType), instanceId, input)); }
/// <summary> /// Schedule a TaskActivity by type. /// </summary> /// <typeparam name="T">Return Type of the TaskActivity.Exeute method</typeparam> /// <param name="taskActivityType">Type that dervices from TaskActivity class</param> /// <param name="parameters">Parameters for the TaskActivity.Execute method</param> /// <returns>Task that represents the execution of the specified TaskActivity</returns> public virtual Task <TResult> ScheduleTask <TResult>(Type activityType, params object[] parameters) { return(ScheduleTask <TResult>(NameVersionHelper.GetDefaultName(activityType), NameVersionHelper.GetDefaultVersion(activityType), parameters)); }
/// <summary> /// Create a suborchestration of the specified type. Also retry on failure as per supplied policy. /// </summary> /// <typeparam name="T">Return Type of the TaskOrchestration.RunTask method</typeparam> /// <param name="orchestrationType">Type of the TaskOrchestration derived class to instantiate</param> /// <param name="retryOptions">Retry policy</param> /// <param name="input">Input for the TaskOrchestration.RunTask method</param> /// <returns>Task that represents the execution of the specified suborchestration</returns> public virtual Task <T> CreateSubOrchestrationInstanceWithRetry <T>(Type orchestrationType, RetryOptions retryOptions, object input) { return(CreateSubOrchestrationInstanceWithRetry <T>(NameVersionHelper.GetDefaultName(orchestrationType), NameVersionHelper.GetDefaultVersion(orchestrationType), retryOptions, input)); }