コード例 #1
0
ファイル: WorkflowActivity.cs プロジェクト: ogazitt/zaplify
        /// <summary>
        /// Factory method to construct a typed activity based on its typename
        /// </summary>
        /// <param name="typeName">Type name to instantiate</param>
        /// <returns>typed activity</returns>
        public static WorkflowActivity CreateActivity(string typeName)
        {
            if (typeName == null)
            {
                return(null);
            }

            // ensure that the activity is in the fully-qualified form
            // this assumes the WorkflowActivity class is in the same namespace as the one we are about to load
            string fullName = typeof(WorkflowActivity).FullName;

            if (typeName.StartsWith(fullName) == false)
            {
                fullName = fullName.Replace(typeof(WorkflowActivity).Name, "");
                typeName = fullName + typeName;
            }

            Type activityType = Type.GetType(typeName);

            if (activityType == null)
            {
                TraceLog.TraceError("Could not find type name " + typeName);
                return(null);
            }

            WorkflowActivity activity = Activator.CreateInstance(activityType) as WorkflowActivity;

            return(activity);
        }
コード例 #2
0
ファイル: WorkflowActivity.cs プロジェクト: ogazitt/zaplify
        /// <summary>
        /// Factory method to construct a typed activity based on its definition
        /// </summary>
        /// <param name="definition">Json value corresponding to activity definition</param>
        /// <param name="instance">Workflow instance</param>
        /// <returns>typed activity</returns>
        public static WorkflowActivity CreateActivity(JObject definition, WorkflowInstance instance)
        {
            string           typeName = (string)definition["Name"];
            WorkflowActivity activity = CreateActivity(typeName);

            if (activity == null)
            {
                return(null);
            }

            foreach (var prop in definition)
            {
                switch (prop.Value.Type)
                {
                case JTokenType.Object:     // a sub-object (typically a nested activity) - store as a string
                    activity.InputParameters[prop.Key] = prop.Value.ToString();
                    break;

                case JTokenType.Array:     // treat as a string template and format appropriately
                    activity.InputParameters[prop.Key] = FormatStringTemplate(instance, prop.Value.ToString());
                    break;

                default:     // treat as a string and expand any variables
                    activity.InputParameters[prop.Key] = ExpandVariables(instance, (string)prop.Value.ToString());
                    break;
                }
            }
            return(activity);
        }