Specifies the .NET configuration file to load into the host application domain during task execution. If you wish to use the current configuration file, pass in ConfigurationFile.
Namespace: AGI.Parallel.Infrastructure
Assembly: AGI.Parallel.Infrastructure (in AGI.Parallel.Infrastructure.dll) Version: 1.2.0.275 (1.2.0.275)

Syntax

C#
public void SetConfigurationFile(
        string configurationPath
)
Visual Basic
Public Sub SetConfigurationFile ( _
        configurationPath As String _
)

Parameters

configurationPath
Type: System..::..String
The path to the configuration file.

Examples

  Copy imageCopy
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));
            }
        }
    }
}

Exceptions

Exception Condition
System..::..ArgumentNullException If configurationPath is null.
System.IO..::..FileNotFoundException If specified configuration file doesn't exist.

See Also