static void Main(string[] args)
        {
            // Create a variable for the workflow path.
            string workflowFileName = "SampleWorkflow.xaml";

            // Read the XAML into the variable.
            string xaml = File.ReadAllText(workflowFileName);

            // Create a runtime to host the workflow, passing the custom configuration provider.
            PSWorkflowRuntime runtime = new PSWorkflowRuntime(new SampleConfigurationProvider());

            // Parameters to the workflow can be provided in this dictionary.
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            // Pass the ID of the current process, which the sample workflow expects as an input parameter.
            parameters.Add("ProcessId", (new List <int>()
            {
                Process.GetCurrentProcess().Id
            }).ToArray());

            // Create the job, providing the XAML definition.
            PSWorkflowJob job = runtime.JobManager.CreateJob(Guid.NewGuid(), xaml, "Get-CurrentProcess", "SampleWorkflow", parameters);

            // Subscribe to the state change event before starting the job.
            AutoResetEvent wfEvent = new AutoResetEvent(false);

            job.StateChanged += delegate(object sender, JobStateEventArgs e)
            {
                switch (e.JobStateInfo.State)
                {
                case JobState.Failed:
                case JobState.Completed:
                {
                    wfEvent.Set();
                }
                break;
                }
            };

            // Start the job.
            job.StartJob();

            // Wait for the state changes event.
            wfEvent.WaitOne();

            if (job.JobStateInfo.State == JobState.Completed)
            {
                Console.WriteLine("The job has completed successfully.");
                Console.WriteLine("Total processes found: " + job.PSWorkflowInstance.Streams.OutputStream.Count);
            }
            else
            {
                Console.WriteLine("The job has Failed.");
            }

            Console.WriteLine("Press <Enter> to continue...");
            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            // Set the path to the XAML workflow.
            string workflowFileName = "SampleWorkflow.xaml";

            // Read the XAML from the workflow into the variable
            string xaml = File.ReadAllText(workflowFileName);

            // Create a runtime to host the workflow, passing the custom configuration provider to the constructor.
            PSWorkflowRuntime runtime = new PSWorkflowRuntime(new SampleConfigurationProvider());

            // Parameters for the workflow can be provided in this dictionary
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            // Create the job. Because we are using the default file-based store, we need to provide the XAML worklfow definition.
            PSWorkflowJob job = runtime.JobManager.CreateJob(Guid.NewGuid(), xaml, "Get-CurrentProcess", "SampleWorkflow", parameters);

            // Subscribe to the state change event before starting the job.
            AutoResetEvent wfEvent = new AutoResetEvent(false);

            job.StateChanged += delegate(object sender, JobStateEventArgs e)
            {
                switch (e.JobStateInfo.State)
                {
                case JobState.Failed:
                case JobState.Completed:
                {
                    wfEvent.Set();
                }
                break;
                }
            };

            // Start the job
            job.StartJob();

            // Wait for the state change event.
            wfEvent.WaitOne();

            if (job.JobStateInfo.State == JobState.Completed)
            {
                Console.WriteLine("The job has completed successfully.");
                Console.WriteLine("Total Commands found: " + job.PSWorkflowInstance.Streams.OutputStream.Count);
            }
            else
            {
                Console.WriteLine("The job has Failed.");
            }

            Console.WriteLine("Press <Enter> to continue...");
            Console.ReadLine();
        }
 // Pass the  PSWorkflowRuntime as the parameter.
 // This resumes execution of the job.
 public SampleActivityController(PSWorkflowRuntime runtime)
     : base(runtime)
 {
     _runtime = runtime;
 }
        static void Main(string[] args)
        {
            // Creat a variable for the workflow path.
            string workflowFileName = "SampleWorkflow.xaml";
            // Specify the database server name and instace before executing this command.
            string dbServer = "ServerName\\InstanceName";
            string database = "M3PExtendedStore";

            // Read the XAML into the variable
            string xaml = File.ReadAllText(workflowFileName);

            string conString = GetConnectionString(dbServer, database);

            // Create a runtime to host the application, passing the custom configuration provider.
            PSWorkflowRuntime runtime = new PSWorkflowRuntime(new SampleConfigurationProvider(conString));

            // Parameters to the workflow can be provided in this dictionary
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            // Create the job, providing the XAML definition.
            PSWorkflowJob job = runtime.JobManager.CreateJob(Guid.NewGuid(), xaml, "Get-CurrentProcess", "SampleWorkflow", parameters);

            // Subscribe to the state change event before starting the job.
            AutoResetEvent wfEvent = new AutoResetEvent(false);

            job.StateChanged += delegate(object sender, JobStateEventArgs e)
            {
                switch (e.JobStateInfo.State)
                {
                case JobState.Failed:
                case JobState.Completed:
                case JobState.Suspended:
                {
                    wfEvent.Set();
                }
                break;
                }
            };

            // Start the job
            job.StartJob();

            // Wait for the state changes event
            wfEvent.WaitOne();

            // Check whether the workflow is in the suspended state.
            if (job.JobStateInfo.State == JobState.Suspended)
            {
                Console.WriteLine("The job has suspended successfully.");
            }
            else
            {
                // If not, inform the user that the job was not suspended.
                Console.WriteLine("The job has not reached a desired state.");
                Console.ReadLine();
                return;
            }


            Console.WriteLine("Resuming the job.");
            // Resume
            job.ResumeJob();

            // Wait for the state changes event
            wfEvent.WaitOne();

            // The workfow should be completed
            if (job.JobStateInfo.State == JobState.Completed)
            {
                Console.WriteLine("The job has completed successfully.");
                Console.WriteLine("Total Process found: " + job.PSWorkflowInstance.Streams.OutputStream.Count);
            }
            else
            {
                Console.WriteLine("The job has Failed.");
            }

            Console.WriteLine("Press <Enter> to continue...");
            Console.ReadLine();
        }
示例#5
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 /// <param name="runtime"></param>
 protected PSResumableActivityHostController(PSWorkflowRuntime runtime)
     : base(runtime)
 {
 }
示例#6
0
 /// <summary>
 /// Runtime should be provided for accessing the runtime activity mode
 /// </summary>
 protected PSActivityHostController(PSWorkflowRuntime runtime)
 {
     _runtime = runtime;
 }
示例#7
0
 protected PSActivityHostController(PSWorkflowRuntime runtime)
 {
     this._inProcActivityLookup = new ConcurrentDictionary <string, bool>();
     this._runtime = runtime;
 }