Exemplo n.º 1
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(InternalCreateOrchestrationInstanceWithRaisedEventAsync(
                NameVersionHelper.GetDefaultName(orchestrationType),
                NameVersionHelper.GetDefaultVersion(orchestrationType),
                instanceId,
                orchestrationInput,
                null,
                dedupeStatuses,
                eventName,
                eventData));
 }
Exemplo n.º 2
0
        public ScheduleProxy(OrchestrationContext context, Type @interface, bool useFullyQualifiedMethodNames)
        {
            this.context = context;
            interfaze    = @interface;
            this.useFullyQualifiedMethodNames = useFullyQualifiedMethodNames;

            //If type can be determined by name
            returnTypes = 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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
 }
Exemplo n.º 7
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));
 }
Exemplo n.º 8
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));
 }
Exemplo n.º 9
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));
 }