Click or drag to resize

TaskEnvironmentSetConfigurationString Method

Specifies the .NET configuration as a string to load into the host application domain during task execution.

Namespace:  AGI.Parallel.Infrastructure
Assembly:  AGI.Parallel.Infrastructure (in AGI.Parallel.Infrastructure.dll) Version: 2.9.0.1601 (2.9.0.1601)
Syntax
public void SetConfigurationString(
	string configurationString
)

Parameters

configurationString
Type: SystemString
The configuration string.
Examples
using System;
using System.Configuration;
using System.IO;
using AGI.Parallel.Client;
using AGI.Parallel.Infrastructure;

namespace CodeSamples
{
    class Program
    {
        static void Main(string[] args)
        {
            // For this example, let's just create the example config file.  In production,
            // you may know beforehand your configuration file or if you want the host
            // process to use the same configuration file the current application is running
            // as you can pass: AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
            string configurationPath = Path.GetTempFileName();
            File.WriteAllText(configurationPath, @"<configuration>
  <appSettings>
    <add key=""YourKey"" value=""KeyValue"" />
  </appSettings>
</configuration>");

            using (IJobScheduler scheduler = new ClusterJobScheduler("localhost"))
            {
                scheduler.Connect();
                Job job = scheduler.CreateJob();

                // Pass in the configuration file path to SetConfigurationFile
                // You can also pass the configuration content as a string to SetConfigurationString
                job.TaskEnvironment.SetConfigurationFile(configurationPath);

                job.AddTask(new ReportsConfigurationFile());
                job.Submit();
                job.WaitUntilDone();

                Console.WriteLine("YourKey: " + job.Tasks[0].Result);
                Console.WriteLine("ConfigurationContent:\n" + job.Tasks[0].StandardOutput);
            }

            /*
             * The output of the application should resemble:
             * YourKey: KeyValue
             * ConfigurationContent:
             * <configuration>
             *   <appSettings>
             *     <add key="YourKey" value="KeyValue" />
             *   </appSettings>
             * </configuration>
             */
        }

        [Serializable]
        class ReportsConfigurationFile : Task
        {
            public override void Execute()
            {
                // Demonstrates how you could use the example configuration content we sent.

                // If you receive "error CS0103: The name 'ConfigurationManager' does not exist in the current context"
                // at this line, add a reference to the System.Configuration assembly to the project.
                this.Result = ConfigurationManager.AppSettings["YourKey"].ToString();

                // Let's just print out the file so that we see that it is actually loaded on the host side.
                Console.WriteLine(File.ReadAllText(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile));
            }
        }
    }
}
See Also

STK Parallel Computing Server 2.9 API for .NET