Example #1
0
 /// <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));
 }
Example #2
0
 /// <summary>
 ///     Create a new orchestration of the specified type with an automatically generated instance id
 /// </summary>
 /// <param name="orchestrationType">Type that derives from TaskOrchestration</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, object input)
 {
     return(InternalCreateOrchestrationInstanceWithRaisedEventAsync(
                NameVersionHelper.GetDefaultName(orchestrationType),
                NameVersionHelper.GetDefaultVersion(orchestrationType),
                null,
                input,
                null,
                null,
                null));
 }
Example #3
0
 /// <summary>
 ///     Create a new orchestration of the specified type with an automatically generated instance id
 /// </summary>
 /// <param name="orchestrationType">Type that derives from TaskOrchestration</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, object input)
 {
     return(this.InternalCreateOrchestrationInstanceWithRaisedEventAsync(
                NameVersionHelper.GetDefaultName(orchestrationType),
                NameVersionHelper.GetDefaultVersion(orchestrationType),
                orchestrationInstanceId: null,
                orchestrationInput: input,
                orchestrationTags: null,
                dedupeStatuses: null,
                eventName: null,
                eventData: null));
 }
Example #4
0
 /// <summary>
 ///     Creates an orchestration instance, and raises an event for it, which eventually causes the OnEvent() method in the
 ///     orchestration to fire.
 /// </summary>
 /// <param name="orchestrationType">Type that derives from TaskOrchestration</param>
 /// <param name="orchestrationInput">Input parameter to the specified TaskOrchestration</param>
 /// <param name="eventName">Name of the event</param>
 /// <param name="eventData">Data for the event</param>
 /// <returns>OrchestrationInstance that represents the orchestration that was created</returns>
 public Task <OrchestrationInstance> CreateOrchestrationInstanceWithRaisedEventAsync(
     Type orchestrationType,
     object orchestrationInput,
     string eventName,
     object eventData)
 {
     return(InternalCreateOrchestrationInstanceWithRaisedEventAsync(
                NameVersionHelper.GetDefaultName(orchestrationType),
                NameVersionHelper.GetDefaultVersion(orchestrationType),
                null,
                orchestrationInput,
                null,
                eventName,
                eventData));
 }
Example #5
0
 /// <summary>
 ///     Create a new orchestration of the specified type with the specified instance id, scheduled to start at an specific time
 /// </summary>
 /// <param name="orchestrationType">Type that derives from TaskOrchestration</param>
 /// <param name="input">Input parameter to the specified TaskOrchestration</param>
 /// <param name="startAt">Orchestration start time</param>
 /// <returns>OrchestrationInstance that represents the orchestration that was created</returns>
 public Task <OrchestrationInstance> CreateScheduledOrchestrationInstanceAsync(
     Type orchestrationType,
     object input,
     DateTime startAt)
 {
     return(this.InternalCreateOrchestrationInstanceWithRaisedEventAsync(
                NameVersionHelper.GetDefaultName(orchestrationType),
                NameVersionHelper.GetDefaultVersion(orchestrationType),
                null,
                input,
                null,
                null,
                null,
                null,
                startAt: startAt));
 }
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            if (!this.returnTypes.TryGetValue(binder.Name, out Type returnType))
            {
                throw new Exception("Method name '" + binder.Name + "' not known.");
            }

            string normalizedMethodName = this.useFullyQualifiedMethodNames
                ? NameVersionHelper.GetFullyQualifiedMethodName(this.interfaze.Name, NameVersionHelper.GetDefaultName(binder))
                : NameVersionHelper.GetDefaultName(binder);

            if (returnType == typeof(Task))
            {
                result = this.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[]) });
                if (scheduleMethod == null)
                {
                    throw new Exception($"Method 'ScheduleTask' not found. Type Name: {nameof(OrchestrationContext)}");
                }

                MethodInfo genericScheduleMethod = scheduleMethod.MakeGenericMethod(genericArguments[0]);

                result = genericScheduleMethod.Invoke(this.context, new object[]
                {
                    normalizedMethodName,
                    NameVersionHelper.GetDefaultVersion(binder), args
                });
            }

            return(true);
        }
 /// <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>
 /// <param name="dedupeStatuses">States of previous orchestration executions to be considered while de-duping new orchestrations on the client</param>
 /// <returns>OrchestrationInstance that represents the orchestration that was created</returns>
 public Task <OrchestrationInstance> CreateOrchestrationInstanceAsync(
     Type orchestrationType,
     string instanceId,
     object input,
     OrchestrationStatus[] dedupeStatuses
     )
 {
     return(InternalCreateOrchestrationInstanceWithRaisedEventAsync(
                NameVersionHelper.GetDefaultName(orchestrationType),
                NameVersionHelper.GetDefaultVersion(orchestrationType),
                instanceId,
                input,
                null,
                dedupeStatuses,
                null,
                null));
 }
        public ScheduleProxy(OrchestrationContext context, Type @interface, bool useFullyQualifiedMethodNames)
        {
            this.context   = context;
            this.interfaze = @interface;
            this.useFullyQualifiedMethodNames = useFullyQualifiedMethodNames;

            //If type can be determined by name
            this.returnTypes = this.interfaze.GetMethods()
                               .Where(method => !method.IsSpecialName)
                               .GroupBy(method => NameVersionHelper.GetDefaultName(method))
                               .Where(group => group.Select(method => method.ReturnType).Distinct().Count() == 1)
                               .Select(group => new
            {
                Name       = group.Key,
                ReturnType = group.Select(method => method.ReturnType).Distinct().Single()
            })
                               .ToDictionary(info => info.Name, info => info.ReturnType);
        }
Example #9
0
 /// <summary>
 ///     Creates an orchestration instance, and raises an event for it, which eventually causes the OnEvent() method in the
 ///     orchestration to fire.
 /// </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="orchestrationInput">Input parameter to the specified TaskOrchestration</param>
 /// <param name="dedupeStatuses">States of previous orchestration executions to be considered while de-duping new orchestrations on the client</param>
 /// <param name="eventName">Name of the event</param>
 /// <param name="eventData">Data for the event</param>
 /// <returns>OrchestrationInstance that represents the orchestration that was created</returns>
 public Task <OrchestrationInstance> CreateOrchestrationInstanceWithRaisedEventAsync(
     Type orchestrationType,
     string instanceId,
     object orchestrationInput,
     OrchestrationStatus[] dedupeStatuses,
     string eventName,
     object eventData)
 {
     return(this.InternalCreateOrchestrationInstanceWithRaisedEventAsync(
                NameVersionHelper.GetDefaultName(orchestrationType),
                NameVersionHelper.GetDefaultVersion(orchestrationType),
                instanceId,
                orchestrationInput,
                orchestrationTags: null,
                dedupeStatuses,
                eventName,
                eventData));
 }
Example #10
0
        /// <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>
        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);
        }
Example #11
0
        /// <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>
        /// <param name="interface">Interface type.</param>
        /// <param name="activities">Object that implements the <paramref name="interface"/> 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>
        public TaskHubWorker AddTaskActivitiesFromInterface(Type @interface, object activities, bool useFullyQualifiedMethodNames = false)
        {
            if ([email protected])
            {
                throw new Exception("Contract can only be an interface.");
            }

            if ([email protected](activities.GetType()))
            {
                throw new ArgumentException($"{activities.GetType().FullName} does not implement {@interface.FullName}", nameof(activities));
            }

            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);
                this.activityManager.Add(creator);
            }

            return(this);
        }
 void Initialize(object obj)
 {
     this.Name    = NameVersionHelper.GetDefaultName(obj);
     this.Version = NameVersionHelper.GetDefaultVersion(obj);
 }
Example #13
0
 /// <summary>
 ///     Create a sub-orchestration 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 sub-orchestration to create</param>
 /// <param name="input">Input for the TaskOrchestration.RunTask method</param>
 /// <returns>Task that represents the execution of the specified sub-orchestration</returns>
 public virtual Task <T> CreateSubOrchestrationInstance <T>(Type orchestrationType, string instanceId, object input)
 {
     return(CreateSubOrchestrationInstance <T>(NameVersionHelper.GetDefaultName(orchestrationType),
                                               NameVersionHelper.GetDefaultVersion(orchestrationType), instanceId, input));
 }
Example #14
0
 /// <summary>
 ///     Schedule a TaskActivity by type.
 /// </summary>
 /// <typeparam name="TResult">Return Type of the TaskActivity.Execute method</typeparam>
 /// <param name="activityType">Type that devices 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));
 }
Example #15
0
 /// <summary>
 ///     Create a sub-orchestration 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 sub-orchestration</returns>
 public virtual Task <T> CreateSubOrchestrationInstanceWithRetry <T>(Type orchestrationType,
                                                                     RetryOptions retryOptions, object input)
 {
     return(CreateSubOrchestrationInstanceWithRetry <T>(NameVersionHelper.GetDefaultName(orchestrationType),
                                                        NameVersionHelper.GetDefaultVersion(orchestrationType), retryOptions, input));
 }