//--------------------------------------------------------------------- // Static members /// <summary> /// Normalizes the options passed by creating or cloning a new instance as /// required and filling unset properties using default client settings. /// </summary> /// <param name="client">The associated Cadence client.</param> /// <param name="options">The input options or <c>null</c>.</param> /// <param name="activityInterface">Optionally specifies the activity interface definition.</param> /// <param name="method">Optionally specifies the target workflow method.</param> /// <returns>The normalized options.</returns> /// <exception cref="ArgumentNullException">Thrown if a valid task list is not specified.</exception> internal static ActivityOptions Normalize(CadenceClient client, ActivityOptions options, Type activityInterface = null, MethodInfo method = null) { Covenant.Requires <ArgumentNullException>(client != null, nameof(client)); ActivityInterfaceAttribute interfaceAttribute = null; ActivityMethodAttribute methodAttribute = null; if (options == null) { options = new ActivityOptions(); } else { options = options.Clone(); } if (activityInterface != null) { CadenceHelper.ValidateActivityInterface(activityInterface); interfaceAttribute = activityInterface.GetCustomAttribute <ActivityInterfaceAttribute>(); } if (method != null) { methodAttribute = method.GetCustomAttribute <ActivityMethodAttribute>(); } if (string.IsNullOrEmpty(options.Domain)) { if (!string.IsNullOrEmpty(methodAttribute?.Domain)) { options.Domain = methodAttribute.Domain; } if (string.IsNullOrEmpty(options.Domain) && !string.IsNullOrEmpty(interfaceAttribute?.Domain)) { options.Domain = interfaceAttribute.Domain; } } if (string.IsNullOrEmpty(options.TaskList)) { if (!string.IsNullOrEmpty(methodAttribute?.TaskList)) { options.TaskList = methodAttribute.TaskList; } if (string.IsNullOrEmpty(options.TaskList) && !string.IsNullOrEmpty(interfaceAttribute?.TaskList)) { options.TaskList = interfaceAttribute.TaskList; } } if (options.ScheduleToCloseTimeout <= TimeSpan.Zero) { if (methodAttribute != null && methodAttribute.ScheduleToCloseTimeoutSeconds > 0) { options.ScheduleToCloseTimeout = TimeSpan.FromSeconds(methodAttribute.ScheduleToCloseTimeoutSeconds); } if (options.ScheduleToCloseTimeout <= TimeSpan.Zero) { options.ScheduleToCloseTimeout = client.Settings.ActivityScheduleToCloseTimeout; } } if (options.ScheduleToStartTimeout <= TimeSpan.Zero) { if (methodAttribute != null && methodAttribute.ScheduleToStartTimeoutSeconds > 0) { options.ScheduleToStartTimeout = TimeSpan.FromSeconds(methodAttribute.ScheduleToStartTimeoutSeconds); } if (options.ScheduleToStartTimeout <= TimeSpan.Zero) { options.ScheduleToStartTimeout = client.Settings.ActivityScheduleToStartTimeout; } } if (options.StartToCloseTimeout <= TimeSpan.Zero) { if (methodAttribute != null && methodAttribute.StartToCloseTimeoutSeconds > 0) { options.StartToCloseTimeout = TimeSpan.FromSeconds(methodAttribute.StartToCloseTimeoutSeconds); } if (options.StartToCloseTimeout <= TimeSpan.Zero) { options.StartToCloseTimeout = client.Settings.ActivityStartToCloseTimeout; } } return(options); }
/// <summary> /// Prepends the Cadence client ID to the activity type name and optional /// activity method attribute name to generate the key used to dereference the /// <see cref="nameToRegistration"/> dictionary. /// </summary> /// <param name="client">The Cadence client.</param> /// <param name="activityTypeName">The activity type name.</param> /// <param name="activityMethodAttribute">Optionally specifies the activity method attribute. </param> /// <returns>The prepended activity registration key.</returns> private static string GetActivityTypeKey(CadenceClient client, string activityTypeName, ActivityMethodAttribute activityMethodAttribute = null) { Covenant.Requires <ArgumentNullException>(client != null, nameof(client)); Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(activityTypeName), nameof(activityTypeName)); if (string.IsNullOrEmpty(activityMethodAttribute?.Name)) { return($"{client.ClientId}::{activityTypeName}"); } else { return($"{client.ClientId}::{activityTypeName}::{activityMethodAttribute.Name}"); } }