using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SimioAPI;
using SimioAPI.Extensions;
namespace CallMatlab
{
class UserStepDefinition : IStepDefinition
{
#region IStepDefinition Members
///
/// Property returning the full name for this type of step. The name should contain no spaces.
///
public string Name
{
get { return "CallMatlab"; }
}
///
/// Property returning a short description of what the step does.
///
public string Description
{
get { return "Call Matlab Function"; }
}
///
/// Property returning an icon to display for the step in the UI.
///
public System.Drawing.Image Icon
{
get { return null; }
}
///
/// Property returning a unique static GUID for the step.
///
public Guid UniqueID
{
get { return MY_ID; }
}
static readonly Guid MY_ID = new Guid("{6ad13417-6808-4c41-9a26-cfaf18a8d472}");
///
/// Property returning the number of exits out of the step. Can return either 1 or 2.
///
public int NumberOfExits
{
get { return 1; }
}
///
/// Method called that defines the property schema for the step.
///
public void DefineSchema(IPropertyDefinitions schema)
{
IPropertyDefinition pd1;
IPropertyDefinition pd2;
pd1 = schema.AddStringProperty("FunName", string.Empty);
pd1.DisplayName = "Func Name";
pd1.Description = "Matlab Function Name";
pd1.Required = true;
pd2 = schema.AddStringProperty("FunAddress", string.Empty);
pd2.DisplayName = "Func Address";
pd2.Description = "Matlab Function Address";
pd2.Required = true;
}
///
/// Method called to create a new instance of this step type to place in a process.
/// Returns an instance of the class implementing the IStep interface.
///
public IStep CreateStep(IPropertyReaders properties)
{
return new UserStep(properties);
}
#endregion
}
class UserStep : IStep
{
IPropertyReaders _props;
IPropertyReader _FunctionNameProp;
IPropertyReader _FolderAddressProp;
public UserStep(IPropertyReaders properties)
{
_props = properties;
_FunctionNameProp = _props.GetProperty("FunName");
_FolderAddressProp = _props.GetProperty("FunAddress");
}
#region IStep Members
///
/// Method called when a process token executes the step.
///
public ExitType Execute(IStepExecutionContext context)
{
String FunctionNameStr = _FunctionNameProp.GetStringValue(context);
String FolderAddressStr = _FolderAddressProp.GetStringValue(context);
context.ExecutionInformation.TraceInformation(String.Format("The MATLAB Function ‘{0}’ located at ‘{1}’ is triggered.", FunctionNameStr, FolderAddressStr));
FolderAddressStr = "cd " + "'" + FolderAddressStr + "'";
MLApp.MLApp matlab = new MLApp.MLApp();
matlab.Execute(FolderAddressStr);
matlab.Execute(FunctionNameStr);
return ExitType.FirstExit;
}
#endregion
}
}