Skip to content
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

7.1 Deployment #60

Merged
merged 18 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion Excel_Adapter/AdapterActions/Pull.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -58,3 +58,4 @@ public override IEnumerable<object> Pull(IRequest request = null, PullType pullO




104 changes: 74 additions & 30 deletions Excel_Adapter/AdapterActions/Push.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -64,7 +64,7 @@ public override List<object> Push(IEnumerable<object> objects, string tag = "",

// Cast action config to ExcelPushConfig, create new if null.
ExcelPushConfig config = actionConfig as ExcelPushConfig;
if (config == null)
if (config == null && !(objects.FirstOrDefault() is PushItem))
{
BH.Engine.Base.Compute.RecordNote($"{nameof(ExcelPushConfig)} has not been provided, default config is used.");
config = new ExcelPushConfig();
Expand Down Expand Up @@ -93,6 +93,74 @@ public override List<object> Push(IEnumerable<object> objects, string tag = "",
return new List<object>();
}

// Push the objects
List<object> pushedObjects = new List<object>();
if (objects.FirstOrDefault() is PushItem)
{
foreach (PushItem item in objects.OfType<PushItem>())
{
if (PushObjects(workbook, item.Objects, item.Config, pushType))
pushedObjects.AddRange(item.Objects);
}
}
else
{
if (PushObjects(workbook, objects.ToList(), config, pushType))
pushedObjects = objects.ToList();
}

// Try to update the workbook properties and then save it.
try
{
if (config != null)
Update(workbook, config.WorkbookProperties);

if (m_FileSettings != null)
workbook.SaveAs(m_FileSettings.GetFullFileName());
else if (m_OutputStream != null)
{
workbook.SaveAs(m_OutputStream);
m_OutputStream.Position = 0;
}
else
{
BH.Engine.Base.Compute.RecordError("Output stream has not been provided. The workbook cannot be saved.");
return new List<object>();
}

return pushedObjects;
}
catch (Exception e)
{
BH.Engine.Base.Compute.RecordError($"Finalisation and saving of the workbook failed with the following error: {e.Message}");
return new List<object>();
}
}

/***************************************************/
/**** Private Methods ****/
/***************************************************/

private bool PushObjects(XLWorkbook workbook, List<object> objects, ExcelPushConfig config, PushType pushType = PushType.AdapterDefault)
{
// Makwe sure the config is defined
if (config == null)
{
BH.Engine.Base.Compute.RecordNote($"{nameof(ExcelPushConfig)} has not been provided, default config is used.");
config = new ExcelPushConfig();
}

// Make sure that a single type of objects are pushed
List<Type> objectTypes = objects.Select(x => x.GetType()).Distinct().ToList();
if (objectTypes.Count != 1)
{
string message = "The Excel adapter only allows to push objects of a single type per table."
+ "\nRight now you are providing objects of the following types: "
+ objectTypes.Select(x => x.ToString()).Aggregate((a, b) => a + ", " + b);
Engine.Base.Compute.RecordError(message);
return false;
}

// Split the tables into collections to delete, create and update.
bool success = true;
string sheetName = config.Worksheet;
Expand Down Expand Up @@ -134,39 +202,14 @@ public override List<object> Push(IEnumerable<object> objects, string tag = "",
default:
{
BH.Engine.Base.Compute.RecordError($"Currently Excel adapter does not supports {nameof(PushType)} equal to {pushType}");
return new List<object>();
return false;
}
}

// Try to update the workbook properties and then save it.
try
{
Update(workbook, config.WorkbookProperties);

if (m_FileSettings != null)
workbook.SaveAs(m_FileSettings.GetFullFileName());
else if (m_OutputStream != null)
{
workbook.SaveAs(m_OutputStream);
m_OutputStream.Position = 0;
}
else
{
BH.Engine.Base.Compute.RecordError("Output stream has not been provided. The workbook cannot be saved.");
return new List<object>();
}

return success ? objects.ToList() : new List<object>();
}
catch (Exception e)
{
BH.Engine.Base.Compute.RecordError($"Finalisation and saving of the workbook failed with the following error: {e.Message}");
return new List<object>();
}
return success;
}

/***************************************************/
/**** Private Methods ****/

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

private XLWorkbook CreateWorkbookFromFile(string fileName, PushType pushType)
Expand Down Expand Up @@ -312,3 +355,4 @@ private static void GetPropertyDictionary(ref Dictionary<string, object> dict, o




3 changes: 2 additions & 1 deletion Excel_Adapter/CRUD/Create/Create.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -68,3 +68,4 @@ private bool Create(IXLWorkbook workbook, string sheetName, List<TableRow> data,
/***************************************************/
}
}

3 changes: 2 additions & 1 deletion Excel_Adapter/CRUD/Delete/Delete.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -53,3 +53,4 @@ private bool Delete(IXLWorkbook workbook, string sheetName)




3 changes: 2 additions & 1 deletion Excel_Adapter/CRUD/Read/Read.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -250,23 +250,23 @@
List<string> customProperties = typeof(CustomObject).GetProperties().Select(x => x.Name).ToList();
List<string> keys = rows.First().Content.Select(x => x.ToString()).ToList();

return rows.Skip(1).Select(row =>
{
CustomObject result = new CustomObject();

Dictionary<string, object> item = new Dictionary<string, object>();
for (int i = 0; i < Math.Min((int)keys.Count(), (int)row.Content?.Count()); i ++)
{
if (customProperties.Contains(keys[i]))
result.SetPropertyValue(keys[i], row.Content[i]);
else
item[keys[i]] = row.Content[i];
}

result.CustomData = item;
return result;

}).ToList<IBHoMObject>();

Check warning on line 269 in Excel_Adapter/CRUD/Read/Read.cs

View check run for this annotation

BHoMBot-CI / beta-code-compliance

Excel_Adapter/CRUD/Read/Read.cs#L253-L269

The use of CustomData within the code is discouraged except in circumstances where volatile data is being used. - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsUsingCustomData
}

/***************************************************/
Expand Down Expand Up @@ -314,3 +314,4 @@




3 changes: 2 additions & 1 deletion Excel_Adapter/CRUD/Update/Update.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -70,3 +70,4 @@ public bool Update(IXLWorkbook workbook, string sheetName, List<TableRow> data,




3 changes: 2 additions & 1 deletion Excel_Adapter/CRUD/Update/UpdateWorkbookProperties.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -66,3 +66,4 @@ public void Update(IXLWorkbook workbook, WorkbookProperties properties)




13 changes: 7 additions & 6 deletions Excel_Adapter/Convert/FromExcel/CellContents.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -44,14 +44,14 @@ public static CellContents FromExcel(this IXLCell xLCell)

return new CellContents()
{
Comment = xLCell.HasComment ? xLCell.Comment.Text : "",
Comment = xLCell.HasComment ? xLCell.GetComment().Text : "",
Value = xLCell.CellValueOrCachedValue(),
Address = BH.Engine.Excel.Create.CellAddress(xLCell.Address.ToString()),
DataType = xLCell.DataType.SystemType(),
FormulaA1 = xLCell.FormulaA1,
FormulaR1C1 = xLCell.FormulaR1C1,
HyperLink = xLCell.HasHyperlink ? xLCell.Hyperlink.ExternalAddress.ToString() : "",
RichText = xLCell.HasRichText ? xLCell.RichText.Text : ""
HyperLink = xLCell.HasHyperlink ? xLCell.GetHyperlink().ExternalAddress.ToString() : "",
RichText = xLCell.HasRichText ? xLCell.GetRichText().Text : ""
};


Expand All @@ -62,10 +62,10 @@ public static CellContents FromExcel(this IXLCell xLCell)
[Description("Gets the value of the cell, or cached value if the TryGetValue method fails. Raises a warning if the cached value is used, and ClosedXML beleives the cell needs to be recalculated.")]
[Input("xLCell", "IXLCell to get the (cached) value from.")]
[Input("value", "Value or cached value of the cell.")]
public static object CellValueOrCachedValue(this IXLCell xLCell)
public static object CellValueOrCachedValue(this IXLCell xLCell)
{
object value;
if (!xLCell.TryGetValue(out value))
if (!xLCell.TryGetValue(out value))
{
//If not able to just get the value, then get the cached value
//If cell is flagged as needing recalculation, raise warning.
Expand Down Expand Up @@ -105,3 +105,4 @@ private static Type SystemType(this XLDataType dataType)
}



3 changes: 2 additions & 1 deletion Excel_Adapter/ExcelAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -68,7 +68,7 @@
[Description("Adapter to create a new Excel file based on an existing template.")]
[Input("inputStream", "Defines the content of the input Excel file. This content will not be modified.")]
[Output("outputStream", "Defines the content of the new Excel file. This will be generated on a push and is not required for a pull.")]
public ExcelAdapter(Stream inputStream, Stream outputStream = null)

Check warning on line 71 in Excel_Adapter/ExcelAdapter.cs

View check run for this annotation

BHoMBot-CI / beta-documentation-compliance

Excel_Adapter/ExcelAdapter.cs#L71

Input parameter requires a matching Input attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsInputAttributePresent
{
if (inputStream == null)
{
Expand Down Expand Up @@ -149,3 +149,4 @@
}
}


20 changes: 14 additions & 6 deletions Excel_Adapter/Excel_Adapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Authors>BHoM</Authors>
<Copyright>Copyright © https://github.com/BHoM</Copyright>
<RootNamespace>BH.Adapter.Excel</RootNamespace>
<FileVersion>7.0.0.0</FileVersion>
<FileVersion>7.1.0.0</FileVersion>
<Configurations>Debug;Release;ZeroCodeTool</Configurations>
<OutputPath>..\Build\</OutputPath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
Expand All @@ -23,7 +23,7 @@
</PropertyGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
<Exec Command="xcopy &quot;$(TargetPath)&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /C /Y&#xD;&#xA;xcopy &quot;$(TargetDir)ClosedXML.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;xcopy &quot;$(TargetDir)DocumentFormat.OpenXml.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y" />
<Exec Command="xcopy &quot;$(TargetPath)&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /C /Y&#xD;&#xA;xcopy &quot;$(TargetDir)ClosedXML.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;xcopy &quot;$(TargetDir)ExcelNumberFormat.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;xcopy &quot;$(TargetDir)DocumentFormat.OpenXml.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;xcopy &quot;$(TargetDir)SixLabors.Fonts.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;xcopy &quot;$(TargetDir)System.IO.Packaging.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y" />
</Target>

<ItemGroup>
Expand Down Expand Up @@ -82,14 +82,22 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.95.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
<PackageReference Include="ClosedXML" Version="0.102.2" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.16.0" />
<PackageReference Include="ExcelNumberFormat" Version="1.1.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.Security.Permissions" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0" />
<PackageReference Include="System.IO.Packaging" Version="6.0.0" />
<PackageReference Include="System.Security.AccessControl" Version="6.0.2-mauipre.1.22102.15" />
<PackageReference Include="System.Security.Permissions" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.0.1" />
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)'=='ZeroCodeTool'">
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion Excel_Adapter/Validation/Enums/WorksheetValidation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -34,3 +34,4 @@ public enum WorksheetValidation
}
}


3 changes: 2 additions & 1 deletion Excel_Adapter/Validation/WorksheetName.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -193,3 +193,4 @@ private static string TrimName(string worksheetName)
}
}


11 changes: 6 additions & 5 deletions Excel_Adapter/packages.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ClosedXML" version="0.95.0" targetFramework="net461" />
<package id="DocumentFormat.OpenXml" version="2.7.2" targetFramework="net461" />
<package id="ExcelNumberFormat" version="1.0.10" targetFramework="net461" />
<package id="ClosedXML" version="0.102.2" targetFramework="net461" />
<package id="DocumentFormat.OpenXml" version="2.16.0" targetFramework="net461" />
<package id="ExcelNumberFormat" version="1.1.0" targetFramework="net461" />
<package id="Microsoft.CSharp" version="4.7.0" targetFramework="net461" />
<package id="System.IO.FileSystem.Primitives" version="4.0.1" targetFramework="net461" />
<package id="System.IO.Packaging" version="4.0.0" targetFramework="net461" />
<package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net461" />
<package id="System.IO.Packaging" version="8.0.0" targetFramework="net461" />
<package id="SixLabors.Fonts" version="1.0.0" targetFramework="net461" />
</packages>
3 changes: 2 additions & 1 deletion Excel_Engine/Compute/ListToText.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -38,7 +38,7 @@
/**** Public Methods ****/
/*******************************************/

public static string ListToText(List<object> objects, string delimiter=",")

Check warning on line 41 in Excel_Engine/Compute/ListToText.cs

View check run for this annotation

BHoMBot-CI / beta-documentation-compliance

Excel_Engine/Compute/ListToText.cs#L41

Input parameter requires a matching Input attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsInputAttributePresent Input parameter requires a matching Input attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsInputAttributePresent Method must contain an Output or MultiOutput attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/HasOutputAttribute
{
if (objects.Count == 0)
return "";
Expand All @@ -51,3 +51,4 @@
}



3 changes: 2 additions & 1 deletion Excel_Engine/Convert/ToExcel/CellAddress.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -48,3 +48,4 @@ public static string ToExcel(this CellAddress bhomAddress)
}



Loading
Loading