Skip to content

BHoM_Adapter: Adding Before and After methods for each action #384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions BHoM_Adapter/AdapterActions/Execute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ public virtual bool SetupExecuteConfig(ActionConfig actionConfig, out ActionConf
return true;
}

/******************************************************/

[Description("Performs an action prior to any execute actions. For example can be used to open up a file for repeated execute actions.")]
public virtual bool BeforeExecute(IExecuteCommand command, ActionConfig actionConfig = null)
{
m_HasRunPreExecuteAction = true;
return true;
}

/******************************************************/

[Description("Performs an action after any execute actions. For example can be used to close a file for repeated execute actions.")]
public virtual bool AfterExecute(IExecuteCommand command, ActionConfig actionConfig = null)
{
m_HasRunPreExecuteAction = false; //Reset for next execute action
return true;
}

/******************************************************/

[Description("To be implemented to send specific commands to the external software, through its API or other means." +
"To be implemented (overridden) in Toolkits.")]
[Output("Output<object, bool>", "Output is a tuple-like class with: " +
Expand Down
20 changes: 20 additions & 0 deletions BHoM_Adapter/AdapterActions/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ public virtual bool Move(IBHoMAdapter to, IRequest request,

return to.Push(objects.Cast<IObject>(), tag, pushType, pushConfig).Count() == count;
}

/******************************************************/

[Description("Performs an action prior to any move actions. For example can be used to open up a file for repeated move actions.")]
public virtual bool BeforeMove(IBHoMAdapter to, IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig pullConfig = null, PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null)
{
m_HasRunPreMoveAction = true;
return true;
}

/******************************************************/

[Description("Performs an action after any move actions. For example can be used to close a file for repeated move actions.")]
public virtual bool AfterMove(IBHoMAdapter to, IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig pullConfig = null, PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null)
{
m_HasRunPreMoveAction = false; //Reset for next move action
return true;
}

/******************************************************/
}
}

Expand Down
28 changes: 23 additions & 5 deletions BHoM_Adapter/AdapterActions/Pull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public virtual bool SetupPullRequest(object request, out IRequest actualRequest)
return true;
}

/******************************************************/

[Description("Performs a set up for the ActionConfig of the Pull Action.")]
public virtual bool SetupPullConfig(ActionConfig actionConfig, out ActionConfig pullConfig)
{
Expand All @@ -69,6 +71,26 @@ public virtual bool SetupPullConfig(ActionConfig actionConfig, out ActionConfig
return true;
}

/******************************************************/

[Description("Performs an action prior to any pull actions. For example can be used to open up a file for repeated pull actions.")]
public virtual bool BeforePull(IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig actionConfig = null)
{
m_HasRunPrePullAction = true;
return true;
}

/******************************************************/

[Description("Performs an action after any pull actions. For example can be used to close a file that was opened for repeated pull actions.")]
public virtual bool AfterPull(IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig actionConfig = null)
{
m_HasRunPrePullAction = false; //Reset to false for the next pull
return true;
}

/******************************************************/

[Description("Pulls objects from an external software using the basic CRUD/Read method as appropriate.")]
public virtual IEnumerable<object> Pull(IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig actionConfig = null)
{
Expand All @@ -86,8 +108,4 @@ public virtual IEnumerable<object> Pull(IRequest request, PullType pullType = Pu
return read;
}
}
}




}
20 changes: 20 additions & 0 deletions BHoM_Adapter/AdapterActions/Push.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ public virtual List<object> Push(IEnumerable<object> objects, string tag = "", P
this.ClearCache();
return success ? objectsToPush.Cast<object>().ToList() : new List<object>();
}

/******************************************************/

[Description("Performs an action prior to any push actions. For example can be used to open up a file for repeated push actions.")]
public virtual bool BeforePush(IEnumerable<object> objects, string tag = "", PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null)
{
m_HasRunPrePushAction = true;
return true;
}

/******************************************************/

[Description("Performs an action after any push actions. For example can be used to close a file for repeated push actions.")]
public virtual bool AfterPush(IEnumerable<object> objects, string tag = "", PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null)
{
m_HasRunPrePushAction = false; //Reset for next push action
return true;
}

/******************************************************/
}
}

Expand Down
20 changes: 20 additions & 0 deletions BHoM_Adapter/AdapterActions/Remove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ public virtual int Remove(IRequest request, ActionConfig actionConfig = null)
this.ClearCache();
return Delete(request as dynamic, actionConfig);
}

/******************************************************/

[Description("Performs an action prior to any remove actions. For example can be used to open up a file for repeated remove actions.")]
public virtual bool BeforeRemove(IRequest request, ActionConfig actionConfig = null)
{
m_HasRunPreRemoveAction = true;
return true;
}

/******************************************************/

[Description("Performs an action after any remove actions. For example can be used to close a file for repeated remove actions.")]
public virtual bool AfterRemove(IRequest request, ActionConfig actionConfig = null)
{
m_HasRunPreRemoveAction = false; //Reset for next remove action
return true;
}

/******************************************************/
}
}

Expand Down
6 changes: 6 additions & 0 deletions BHoM_Adapter/BHoMAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public abstract partial class BHoMAdapter : IBHoMAdapter
// e.g. AdapterSettings.WrapNonBHoMObjects = true;
protected AdapterSettings m_AdapterSettings { get; set; } = new AdapterSettings();

protected bool m_HasRunPrePullAction { get; set; } = false; //Flag to determine whether the adapter has run pre-pull actions
protected bool m_HasRunPrePushAction { get; set; } = false; //Flag to determine whether the adapter has run pre-push actions
protected bool m_HasRunPreExecuteAction { get; set; } = false; //Flag to determine whether the adapter has run pre-execute actions
protected bool m_HasRunPreMoveAction { get; set; } = false; //Flag to determine whether the adapter has run pre-move actions
protected bool m_HasRunPreRemoveAction { get; set; } = false; //Flag to determine whether the adapter has run pre-remove actions

/***************************************************/
/**** Public Events ****/
/***************************************************/
Expand Down