//======================================================
        //      Public methods
        //======================================================
        /// <summary>
        /// Instanciates a new process step from a deserialized description.
        /// </summary>
        /// <param name="data">The data describing the process step.</param>
        /// <returns>The instanciated process step, or null if an error occured.</returns>
        public static ProcessStep Instanciate(ProcessStepInstanceData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            // Check the runtime type for validity
            var definition  = data?.Definition;
            var runtimeType = definition?.RuntimeType;

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

            // Try instanciating an instance of the runtime state
            ProcessStep step = null;

            try
            {
                step = Activator.CreateInstance(runtimeType) as ProcessStep;
            }
            catch
            {
                return(null);
            }

            // Set the parameters
            step.Id         = data.Id;
            step.Definition = definition;
            foreach (var parameterKvp in data.ParameterValues)
            {
                try
                {
                    Util.SetMemberValue(step, parameterKvp.Key, parameterKvp.Value);
                }
                catch { }
            }

            return(step);
        }
예제 #2
0
        private static ProcessInstanceData LoadProcessDescriptionFromDatabase()
        {
            // Configure the transport process
            // This configuration should be done in the UI and only loaded from the database/file at this point.
            // No logic is contained in these classes, pure data level.
            // The setup is only meant to show the usage of the classes.
            var data = new ProcessInstanceData();

            data.Name = "My transport process";
            ProcessStepInstanceData dataA, dataB;

            data.Steps.Add(dataA = new ProcessStepInstanceData()
            {
                Id = 1, DefinitionName = "WaitStep"
            });
            dataA.ParameterValues["Duration"] = 12.0;
            data.Steps.Add(dataB = new ProcessStepInstanceData()
            {
                Id = 2, DefinitionName = "DeliverStepDummy"
            });
            data.InitialStateId = dataA.Id;
            data.Edges.Add(new EdgeData()
            {
                SourceId = dataA.Id, DestinationId = dataB.Id, SourceExit = ExitPointDefinition.Default.Name
            });
            data.Edges.Add(new EdgeData()
            {
                SourceId = dataB.Id, DestinationId = dataA.Id, SourceExit = "Done"
            });
            data.Edges.Add(new EdgeData()
            {
                SourceId = dataB.Id, DestinationId = dataB.Id, SourceExit = "Failed"
            });

            return(data);
        }