Click here to Skip to main content
14,236,142 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am passing a custom variable type from one action to another action in a workflow. Here is the definition of the custom object

public class ConfigDatabase
{
public string Name;
public string Host;
public string Port;
public string Instance;
public string User;
public string Password;
}

public class ConfigDatabases
{
public string DatabaseToUse;
public List<configdatabase> DatabaseList;

public ConfigDatabases()
{
DatabaseList = new List<configdatabase>();
}
}

public class ConfigEnvironment
{
public ConfigDatabases EnvironmentConfigDatabase;

public ConfigEnvironment()
{
EnvironmentConfigDatabase = new ConfigDatabases();
}

public ConfigDatabase ReturnDatabaseInfo()
{
ConfigDatabase ConfigDatabaseInfo = new ConfigDatabase();
for (int Count1 = 0; Count1 < EnvironmentConfigDatabase.DatabaseList.Count; Count1++)
{
if (EnvironmentConfigDatabase.DatabaseList[Count1].Name == EnvironmentConfigDatabase.DatabaseToUse)
{
ConfigDatabaseInfo = EnvironmentConfigDatabase.DatabaseList[Count1];
return ConfigDatabaseInfo;
}
}
return ConfigDatabaseInfo;
}

public string GetDatabaseConnectionString()
{
ConfigDatabase DatabaseInfo = ReturnDatabaseInfo();
string ConnectionString = "Data Source=(description=(address=(protocol=tcp)(host=" + DatabaseInfo.Host + ")(port=" + DatabaseInfo.Port + "))(connect_data=(sid=" + DatabaseInfo.Instance + ")));User ID=" + DatabaseInfo.User + ";Password=" + DatabaseInfo.Password + ";";
return ConnectionString;
}
}

During the first step of the action, it will run the following code to load the config data from a file and store in an object (ConfigEnvironment) that is returned in function Execute

public sealed class InitializeEnvironment : CodeActivity<configenvironment>
{
// Define an activity input argument of type string
public InArgument<string> EnvironmentFileLocation { get; set; }

// If your activity returns a value, derive from CodeActivity<tresult> // and return the value from the Execute method.
protected override ConfigEnvironment Execute(CodeActivityContext context)
{
// Obtain the runtime value of the Text input argument
string EnvironmentFile = context.GetValue(this.EnvironmentFileLocation);
EnvironmentConfigInitialization EnvironmentInitialize = new EnvironmentConfigInitialization(EnvironmentFile);
ConfigEnvironment EnvironmentDetail = EnvironmentInitialize.LoadData();
return EnvironmentDetail;
}
}

In the subsequent activity in the workflow, I would like to obtain the data stored in this object. However, the following code will have a compile error as EnvironmentDetail object could not find the function GetDatabaseConnectionString.

public sealed class ExecuteSQL : CodeActivity<datarowcollection>
{
// Define an activity input argument of type string
public InArgument<string> SQLScript { get; set; }
public InArgument<configenvironment> EnvironmentDetail { get; set; }

// If your activity returns a value, derive from CodeActivity<tresult> // and return the value from the Execute method.
protected override DataRowCollection Execute(CodeActivityContext context)
{

string connectionString4 = EnvironmentDetail.GetDatabaseConnectionString(); //This create a compile error

}
}

The compile warning is the following
'System.Activities.InArgument<configenvironment>' does not contain a definition for 'GetDatabaseConnectionString' and no extension method 'GetDatabaseConnectionString' accepting a first argument of type 'System.Activities.InArgument<configenvironment>' could be found (are you missing a using directive or an assembly reference?)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100