-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved all Adapter Actions in their folder.
- Loading branch information
Showing
7 changed files
with
311 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* This file is part of the Buildings and Habitats object Model (BHoM) | ||
* Copyright (c) 2015 - 2018, the respective contributors. All rights reserved. | ||
* | ||
* Each contributor holds copyright over their respective contributions. | ||
* The project versioning (Git) records all such contribution source information. | ||
* | ||
* | ||
* The BHoM is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3.0 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The BHoM is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||
*/ | ||
|
||
using BH.oM.Base; | ||
using BH.Engine.Base; | ||
using BH.oM.Data.Requests; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace BH.Adapter | ||
{ | ||
public abstract partial class BHoMAdapter | ||
{ | ||
/******************************************************/ | ||
/**** Public Adapter Methods "Adapter ACTIONS" *****/ | ||
/******************************************************/ | ||
/* These methods represent Actions that the Adapter can complete. | ||
They are publicly available in the UI as individual components, e.g. in Grasshopper, under BHoM/Adapters tab. */ | ||
|
||
// Used to send specific commands to the external software, if it supports it. It should be implemented (overridden) at the Toolkit level. | ||
public virtual bool Execute(string command, Dictionary<string, object> parameters = null, Dictionary<string, object> config = null) | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* This file is part of the Buildings and Habitats object Model (BHoM) | ||
* Copyright (c) 2015 - 2018, the respective contributors. All rights reserved. | ||
* | ||
* Each contributor holds copyright over their respective contributions. | ||
* The project versioning (Git) records all such contribution source information. | ||
* | ||
* | ||
* The BHoM is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3.0 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The BHoM is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||
*/ | ||
|
||
using BH.oM.Base; | ||
using BH.Engine.Base; | ||
using BH.oM.Data.Requests; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace BH.Adapter | ||
{ | ||
public abstract partial class BHoMAdapter | ||
{ | ||
/******************************************************/ | ||
/**** Public Adapter Methods "Adapter ACTIONS" *****/ | ||
/******************************************************/ | ||
/* These methods represent Actions that the Adapter can complete. | ||
They are publicly available in the UI as individual components, e.g. in Grasshopper, under BHoM/Adapters tab. */ | ||
|
||
// Performs a Pull and then a Push. Useful to move data between two different software without passing it through the UI. | ||
public virtual bool Move(BHoMAdapter to, IRequest request, Dictionary<string, object> pullConfig = null, Dictionary<string, object> pushConfig = null) | ||
{ | ||
string tag = ""; | ||
if (request is FilterRequest) | ||
tag = (request as FilterRequest).Tag; | ||
|
||
IEnumerable<object> objects = Pull(request, pullConfig); | ||
int count = objects.Count(); | ||
return to.Push(objects.Cast<IObject>(), tag, pushConfig).Count() == count; | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* This file is part of the Buildings and Habitats object Model (BHoM) | ||
* Copyright (c) 2015 - 2018, the respective contributors. All rights reserved. | ||
* | ||
* Each contributor holds copyright over their respective contributions. | ||
* The project versioning (Git) records all such contribution source information. | ||
* | ||
* | ||
* The BHoM is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3.0 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The BHoM is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||
*/ | ||
|
||
using BH.oM.Base; | ||
using BH.Engine.Base; | ||
using BH.oM.Data.Requests; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace BH.Adapter | ||
{ | ||
public abstract partial class BHoMAdapter | ||
{ | ||
/******************************************************/ | ||
/**** Public Adapter Methods "Adapter ACTIONS" *****/ | ||
/******************************************************/ | ||
/* These methods represent Actions that the Adapter can complete. | ||
They are publicly available in the UI as individual components, e.g. in Grasshopper, under BHoM/Adapters tab. */ | ||
|
||
// Calls the appropriate basic CRUD/Read method. | ||
public virtual IEnumerable<object> Pull(IRequest request, Dictionary<string, object> config = null) | ||
{ | ||
// --------------------------------------------------------------------------------- // | ||
// *** Temporary retrocompatibility fix *** | ||
// If it's a FilterRequest, check if it should read IResults or Objects with that. | ||
// This should be replaced by an appropriate IResultRequest. | ||
FilterRequest filterReq = request as FilterRequest; | ||
if (filterReq != null) | ||
if (typeof(BH.oM.Common.IResult).IsAssignableFrom(filterReq.Type)) | ||
return ReadResults(filterReq); | ||
// --------------------------------------------------------------------------------- // | ||
|
||
if (request is IResultRequest) | ||
return ReadResults(request as dynamic); | ||
|
||
if (request is IRequest) | ||
return Read(request as dynamic); | ||
|
||
return new List<object>(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* This file is part of the Buildings and Habitats object Model (BHoM) | ||
* Copyright (c) 2015 - 2018, the respective contributors. All rights reserved. | ||
* | ||
* Each contributor holds copyright over their respective contributions. | ||
* The project versioning (Git) records all such contribution source information. | ||
* | ||
* | ||
* The BHoM is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3.0 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The BHoM is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||
*/ | ||
|
||
using BH.oM.Base; | ||
using BH.Engine.Base; | ||
using BH.oM.Data.Requests; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace BH.Adapter | ||
{ | ||
public abstract partial class BHoMAdapter | ||
{ | ||
/******************************************************/ | ||
/**** Public Adapter Methods "Adapter ACTIONS" *****/ | ||
/******************************************************/ | ||
/* These methods represent Actions that the Adapter can complete. | ||
They are publicly available in the UI as individual components, e.g. in Grasshopper, under BHoM/Adapters tab. */ | ||
|
||
// Performs the full CRUD if implemented, or calls the appropriate basic CRUD/Create method. | ||
public virtual List<IObject> Push(IEnumerable<IObject> objects, string tag = "", Dictionary<string, object> pushConfig = null) | ||
{ | ||
bool success = true; | ||
|
||
// Get the Push Type from the pushConfig. | ||
string pushType; | ||
object ptObj; | ||
if (pushConfig != null && pushConfig.TryGetValue("PushType", out ptObj)) | ||
pushType = ptObj.ToString(); | ||
else | ||
pushType = "Replace"; | ||
|
||
// Wrap non-BHoM objects into a Custom BHoMObject to make them work as BHoMObjects. | ||
List<IObject> objectsToPush = Modify.WrapNonBHoMObjects(objects, Config, tag, pushConfig).ToList(); | ||
|
||
// Clone the objects for immutability in the UI. CloneBeforePush should always be true, except for very specific cases. | ||
objectsToPush = Config.CloneBeforePush ? objectsToPush.Select(x => x.DeepClone()).ToList() : objects.ToList(); | ||
|
||
// Perform the actual Push. | ||
Type iBHoMObjectType = typeof(IBHoMObject); | ||
MethodInfo miToList = typeof(Enumerable).GetMethod("Cast"); | ||
foreach (var typeGroup in objectsToPush.GroupBy(x => x.GetType())) | ||
{ | ||
MethodInfo miListObject = miToList.MakeGenericMethod(new[] { typeGroup.Key }); | ||
|
||
var list = miListObject.Invoke(typeGroup, new object[] { typeGroup }); | ||
|
||
if (iBHoMObjectType.IsAssignableFrom(typeGroup.Key)) | ||
{ | ||
if (pushType == "Replace") | ||
success &= CRUD(list as dynamic, tag); | ||
else if (pushType == "UpdateOnly") | ||
{ | ||
success &= UpdateOnly(list as dynamic, tag); | ||
} | ||
} | ||
} | ||
|
||
return success ? objectsToPush : new List<IObject>(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* This file is part of the Buildings and Habitats object Model (BHoM) | ||
* Copyright (c) 2015 - 2018, the respective contributors. All rights reserved. | ||
* | ||
* Each contributor holds copyright over their respective contributions. | ||
* The project versioning (Git) records all such contribution source information. | ||
* | ||
* | ||
* The BHoM is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3.0 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The BHoM is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||
*/ | ||
|
||
using BH.oM.Base; | ||
using BH.Engine.Base; | ||
using BH.oM.Data.Requests; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace BH.Adapter | ||
{ | ||
public abstract partial class BHoMAdapter | ||
{ | ||
/******************************************************/ | ||
/**** Public Adapter Methods "Adapter ACTIONS" *****/ | ||
/******************************************************/ | ||
/* These methods represent Actions that the Adapter can complete. | ||
They are publicly available in the UI as individual components, e.g. in Grasshopper, under BHoM/Adapters tab. */ | ||
|
||
// To be renamed to "Remove" or something different from the CRUD method "Delete". | ||
// Calls the basic CRUD/Delete method. | ||
public virtual int Delete(IRequest request, Dictionary<string, object> config = null) | ||
{ | ||
// If the provided request is a FilterRequest, the specific wrapper method for FilterRequest is called. | ||
// For all other cases, Toolkits should implement specific IRequests and the related CRUD Wrapper method(s). | ||
return Delete(request as dynamic); | ||
} | ||
} | ||
} |
Oops, something went wrong.