/// <summary> /// Returns the Cadence activity type name to be used for a activity interface or /// implementation class. /// </summary> /// <param name="activityType">The activity interface or implementation type.</param> /// <param name="activityAttribute">Specifies the <see cref="ActivityAttribute"/>.</param> /// <returns>The type name.</returns> /// <remarks> /// <para> /// If <paramref name="activityAttribute"/> is passed and <see cref="ActivityAttribute.Name"/> /// is not <c>null</c> or empty, then the name specified in the attribute is returned. /// </para> /// <para> /// Otherwise, we'll return the fully qualified name of the activity interface /// with the leadting "I" removed. /// </para> /// </remarks> internal static string GetActivityTypeName(Type activityType, ActivityAttribute activityAttribute) { Covenant.Requires <ArgumentNullException>(activityType != null, nameof(activityType)); if (activityAttribute != null && !string.IsNullOrEmpty(activityAttribute.Name)) { return(activityAttribute.Name); } if (activityType.IsClass) { CadenceHelper.ValidateActivityImplementation(activityType); activityType = CadenceHelper.GetActivityInterface(activityType); } else { CadenceHelper.ValidateActivityInterface(activityType); } var fullName = activityType.FullName; var name = activityType.Name; if (name.StartsWith("I") && name != "I") { // We're going to strip the leading "I" from the unqualified // type name (unless that's the only character). fullName = fullName.Substring(0, fullName.Length - name.Length); fullName += name.Substring(1); } // We need to replace the "+" characters .NET uses for nested types into // "." so the result will be a valid C# type identifier. return(fullName.Replace('+', '.')); }
/// <summary> /// Creates a local activity stub instance suitable for executing a non-local activity. /// </summary> /// <param name="client">The associated <see cref="CadenceClient"/>.</param> /// <param name="workflow">The parent workflow.</param> /// <param name="activityType">The activity implementation type.</param> /// <param name="options">Specifies the <see cref="LocalActivityOptions"/>.</param> /// <returns>The activity stub as an <see cref="object"/>.</returns> public object CreateLocal(CadenceClient client, Workflow workflow, Type activityType, LocalActivityOptions options) { return(localConstructor.Invoke(new object[] { client, client.DataConverter, workflow, activityType, options, CadenceHelper.GetActivityInterface(activityType) })); }
/// <summary> /// Creates a local activity stub instance suitable for executing a local activity. /// </summary> /// <param name="client">The associated <see cref="CadenceClient"/>.</param> /// <param name="workflow">The parent workflow.</param> /// <param name="activityType">The activity implementation type.</param> /// <param name="options">Specifies the <see cref="LocalActivityOptions"/> or <c>null</c>.</param> /// <returns>The activity stub as an <see cref="object"/>.</returns> public object CreateLocal(CadenceClient client, Workflow workflow, Type activityType, LocalActivityOptions options) { Covenant.Requires <ArgumentNullException>(client != null, nameof(client)); Covenant.Requires <ArgumentNullException>(workflow != null, nameof(workflow)); Covenant.Requires <ArgumentNullException>(activityType != null, nameof(activityType)); options = options ?? new LocalActivityOptions(); return(localConstructor.Invoke(new object[] { client, client.DataConverter, workflow, activityType, options, CadenceHelper.GetActivityInterface(activityType) })); }