Skip to content

Add a generated class for loading all relevant schemas in a single operator. #7

Description

@RoboDoig

For any given ucl-open template, we can easily define an operator that loads all input schemas in a single operator, e.g.:

public class LoadSchemas : Source<Tuple<UclOpenSession, UclOpenHfVisualRig, UclOpenHfVisualTaskLogic>>
{
    [Description("The relative or absolute path of the session file to open for reading.")]
    [Editor("Bonsai.Design.OpenFileNameEditor, Bonsai.Design", DesignTypes.UITypeEditor)]
    public string SessionSettingsPath {get; set;}

    [Description("The relative or absolute path of the rig file to open for reading.")]
    [Editor("Bonsai.Design.OpenFileNameEditor, Bonsai.Design", DesignTypes.UITypeEditor)]
    public string RigSettingsPath {get; set;}

    [Description("The relative or absolute path of the task file to open for reading.")]
    [Editor("Bonsai.Design.OpenFileNameEditor, Bonsai.Design", DesignTypes.UITypeEditor)]
    public string TaskLogicSettingsPath {get; set;}

    public override IObservable<Tuple<UclOpenSession, UclOpenHfVisualRig, UclOpenHfVisualTaskLogic>> Generate()
    {
        string sessionSettingsRaw = File.ReadAllText(SessionSettingsPath);
        string rigSettingsRaw = File.ReadAllText(RigSettingsPath);
        string taskLogicSettingsRaw = File.ReadAllText(TaskLogicSettingsPath);

        var sessionSource = Observable.Return(Newtonsoft.Json.JsonConvert.DeserializeObject<UclOpenSession>(sessionSettingsRaw));
        var rigSource = Observable.Return(Newtonsoft.Json.JsonConvert.DeserializeObject<UclOpenHfVisualRig>(rigSettingsRaw));
        var taskLogicSource = Observable.Return(Newtonsoft.Json.JsonConvert.DeserializeObject<UclOpenHfVisualTaskLogic>(taskLogicSettingsRaw));

        return sessionSource.Zip(rigSource, taskLogicSource, (s1, s2, s3) =>
        {
            return Tuple.Create(s1, s2, s3);
        });
    }
}

Ideally this should be auto-generated for each project as all that is really being changed in each template copy is naming of the prefix and project, e.g. 'UclOpenHfVisual' should be generic as .

Simplest way to do this is probably just to add a T4 template in the template extensions with a T4Preprocess step in the .csproj.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions