Skip to content

Commit d5f33f6

Browse files
author
Fraser Greenroyd
authored
7.1 Deployment (#60)
2 parents 32f7b99 + fb1caf3 commit d5f33f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+212
-88
lines changed

Excel_Adapter/AdapterActions/Pull.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -58,3 +58,4 @@ public override IEnumerable<object> Pull(IRequest request = null, PullType pullO
5858

5959

6060

61+

Excel_Adapter/AdapterActions/Push.cs

Lines changed: 74 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -64,7 +64,7 @@ public override List<object> Push(IEnumerable<object> objects, string tag = "",
6464

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

96+
// Push the objects
97+
List<object> pushedObjects = new List<object>();
98+
if (objects.FirstOrDefault() is PushItem)
99+
{
100+
foreach (PushItem item in objects.OfType<PushItem>())
101+
{
102+
if (PushObjects(workbook, item.Objects, item.Config, pushType))
103+
pushedObjects.AddRange(item.Objects);
104+
}
105+
}
106+
else
107+
{
108+
if (PushObjects(workbook, objects.ToList(), config, pushType))
109+
pushedObjects = objects.ToList();
110+
}
111+
112+
// Try to update the workbook properties and then save it.
113+
try
114+
{
115+
if (config != null)
116+
Update(workbook, config.WorkbookProperties);
117+
118+
if (m_FileSettings != null)
119+
workbook.SaveAs(m_FileSettings.GetFullFileName());
120+
else if (m_OutputStream != null)
121+
{
122+
workbook.SaveAs(m_OutputStream);
123+
m_OutputStream.Position = 0;
124+
}
125+
else
126+
{
127+
BH.Engine.Base.Compute.RecordError("Output stream has not been provided. The workbook cannot be saved.");
128+
return new List<object>();
129+
}
130+
131+
return pushedObjects;
132+
}
133+
catch (Exception e)
134+
{
135+
BH.Engine.Base.Compute.RecordError($"Finalisation and saving of the workbook failed with the following error: {e.Message}");
136+
return new List<object>();
137+
}
138+
}
139+
140+
/***************************************************/
141+
/**** Private Methods ****/
142+
/***************************************************/
143+
144+
private bool PushObjects(XLWorkbook workbook, List<object> objects, ExcelPushConfig config, PushType pushType = PushType.AdapterDefault)
145+
{
146+
// Makwe sure the config is defined
147+
if (config == null)
148+
{
149+
BH.Engine.Base.Compute.RecordNote($"{nameof(ExcelPushConfig)} has not been provided, default config is used.");
150+
config = new ExcelPushConfig();
151+
}
152+
153+
// Make sure that a single type of objects are pushed
154+
List<Type> objectTypes = objects.Select(x => x.GetType()).Distinct().ToList();
155+
if (objectTypes.Count != 1)
156+
{
157+
string message = "The Excel adapter only allows to push objects of a single type per table."
158+
+ "\nRight now you are providing objects of the following types: "
159+
+ objectTypes.Select(x => x.ToString()).Aggregate((a, b) => a + ", " + b);
160+
Engine.Base.Compute.RecordError(message);
161+
return false;
162+
}
163+
96164
// Split the tables into collections to delete, create and update.
97165
bool success = true;
98166
string sheetName = config.Worksheet;
@@ -134,39 +202,14 @@ public override List<object> Push(IEnumerable<object> objects, string tag = "",
134202
default:
135203
{
136204
BH.Engine.Base.Compute.RecordError($"Currently Excel adapter does not supports {nameof(PushType)} equal to {pushType}");
137-
return new List<object>();
205+
return false;
138206
}
139207
}
140208

141-
// Try to update the workbook properties and then save it.
142-
try
143-
{
144-
Update(workbook, config.WorkbookProperties);
145-
146-
if (m_FileSettings != null)
147-
workbook.SaveAs(m_FileSettings.GetFullFileName());
148-
else if (m_OutputStream != null)
149-
{
150-
workbook.SaveAs(m_OutputStream);
151-
m_OutputStream.Position = 0;
152-
}
153-
else
154-
{
155-
BH.Engine.Base.Compute.RecordError("Output stream has not been provided. The workbook cannot be saved.");
156-
return new List<object>();
157-
}
158-
159-
return success ? objects.ToList() : new List<object>();
160-
}
161-
catch (Exception e)
162-
{
163-
BH.Engine.Base.Compute.RecordError($"Finalisation and saving of the workbook failed with the following error: {e.Message}");
164-
return new List<object>();
165-
}
209+
return success;
166210
}
167211

168-
/***************************************************/
169-
/**** Private Methods ****/
212+
170213
/***************************************************/
171214

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

313356

314357

358+

Excel_Adapter/CRUD/Create/Create.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -68,3 +68,4 @@ private bool Create(IXLWorkbook workbook, string sheetName, List<TableRow> data,
6868
/***************************************************/
6969
}
7070
}
71+

Excel_Adapter/CRUD/Delete/Delete.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -53,3 +53,4 @@ private bool Delete(IXLWorkbook workbook, string sheetName)
5353

5454

5555

56+

Excel_Adapter/CRUD/Read/Read.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -314,3 +314,4 @@ private string ConvertToColumnName(int number)
314314

315315

316316

317+

Excel_Adapter/CRUD/Update/Update.cs

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

7171

7272

73+

Excel_Adapter/CRUD/Update/UpdateWorkbookProperties.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -66,3 +66,4 @@ public void Update(IXLWorkbook workbook, WorkbookProperties properties)
6666

6767

6868

69+

Excel_Adapter/Convert/FromExcel/CellContents.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -44,14 +44,14 @@ public static CellContents FromExcel(this IXLCell xLCell)
4444

4545
return new CellContents()
4646
{
47-
Comment = xLCell.HasComment ? xLCell.Comment.Text : "",
47+
Comment = xLCell.HasComment ? xLCell.GetComment().Text : "",
4848
Value = xLCell.CellValueOrCachedValue(),
4949
Address = BH.Engine.Excel.Create.CellAddress(xLCell.Address.ToString()),
5050
DataType = xLCell.DataType.SystemType(),
5151
FormulaA1 = xLCell.FormulaA1,
5252
FormulaR1C1 = xLCell.FormulaR1C1,
53-
HyperLink = xLCell.HasHyperlink ? xLCell.Hyperlink.ExternalAddress.ToString() : "",
54-
RichText = xLCell.HasRichText ? xLCell.RichText.Text : ""
53+
HyperLink = xLCell.HasHyperlink ? xLCell.GetHyperlink().ExternalAddress.ToString() : "",
54+
RichText = xLCell.HasRichText ? xLCell.GetRichText().Text : ""
5555
};
5656

5757

@@ -62,10 +62,10 @@ public static CellContents FromExcel(this IXLCell xLCell)
6262
[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.")]
6363
[Input("xLCell", "IXLCell to get the (cached) value from.")]
6464
[Input("value", "Value or cached value of the cell.")]
65-
public static object CellValueOrCachedValue(this IXLCell xLCell)
65+
public static object CellValueOrCachedValue(this IXLCell xLCell)
6666
{
6767
object value;
68-
if (!xLCell.TryGetValue(out value))
68+
if (!xLCell.TryGetValue(out value))
6969
{
7070
//If not able to just get the value, then get the cached value
7171
//If cell is flagged as needing recalculation, raise warning.
@@ -105,3 +105,4 @@ private static Type SystemType(this XLDataType dataType)
105105
}
106106

107107

108+

Excel_Adapter/ExcelAdapter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -149,3 +149,4 @@ private void VerifySecurityEvidenceForIsolatedStorage(Assembly assembly)
149149
}
150150
}
151151

152+

Excel_Adapter/Excel_Adapter.csproj

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Authors>BHoM</Authors>
88
<Copyright>Copyright © https://github.com/BHoM</Copyright>
99
<RootNamespace>BH.Adapter.Excel</RootNamespace>
10-
<FileVersion>7.0.0.0</FileVersion>
10+
<FileVersion>7.1.0.0</FileVersion>
1111
<Configurations>Debug;Release;ZeroCodeTool</Configurations>
1212
<OutputPath>..\Build\</OutputPath>
1313
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
@@ -23,7 +23,7 @@
2323
</PropertyGroup>
2424

2525
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
26-
<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" />
26+
<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" />
2727
</Target>
2828

2929
<ItemGroup>
@@ -82,14 +82,22 @@
8282
</ItemGroup>
8383

8484
<ItemGroup>
85-
<PackageReference Include="ClosedXML" Version="0.95.0" />
86-
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
85+
<PackageReference Include="ClosedXML" Version="0.102.2" />
86+
<PackageReference Include="DocumentFormat.OpenXml" Version="2.16.0" />
87+
<PackageReference Include="ExcelNumberFormat" Version="1.1.0" />
8788
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
88-
<PackageReference Include="System.Security.Permissions" Version="8.0.0-rc.2.23479.6" />
89+
<PackageReference Include="SixLabors.Fonts" Version="1.0.0" />
90+
<PackageReference Include="System.IO.Packaging" Version="6.0.0" />
91+
<PackageReference Include="System.Security.AccessControl" Version="6.0.2-mauipre.1.22102.15" />
92+
<PackageReference Include="System.Security.Permissions" Version="8.0.0" />
8993
</ItemGroup>
9094

9195
<ItemGroup Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
92-
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.0.1" />
96+
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
97+
</ItemGroup>
98+
99+
<ItemGroup Condition="'$(Configuration)'=='ZeroCodeTool'">
100+
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
93101
</ItemGroup>
94102

95103
<ItemGroup>

Excel_Adapter/Validation/Enums/WorksheetValidation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -34,3 +34,4 @@ public enum WorksheetValidation
3434
}
3535
}
3636

37+

Excel_Adapter/Validation/WorksheetName.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -193,3 +193,4 @@ private static string TrimName(string worksheetName)
193193
}
194194
}
195195

196+

Excel_Adapter/packages.config

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="ClosedXML" version="0.95.0" targetFramework="net461" />
4-
<package id="DocumentFormat.OpenXml" version="2.7.2" targetFramework="net461" />
5-
<package id="ExcelNumberFormat" version="1.0.10" targetFramework="net461" />
3+
<package id="ClosedXML" version="0.102.2" targetFramework="net461" />
4+
<package id="DocumentFormat.OpenXml" version="2.16.0" targetFramework="net461" />
5+
<package id="ExcelNumberFormat" version="1.1.0" targetFramework="net461" />
66
<package id="Microsoft.CSharp" version="4.7.0" targetFramework="net461" />
7-
<package id="System.IO.FileSystem.Primitives" version="4.0.1" targetFramework="net461" />
8-
<package id="System.IO.Packaging" version="4.0.0" targetFramework="net461" />
7+
<package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net461" />
8+
<package id="System.IO.Packaging" version="8.0.0" targetFramework="net461" />
9+
<package id="SixLabors.Fonts" version="1.0.0" targetFramework="net461" />
910
</packages>

Excel_Engine/Compute/ListToText.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -51,3 +51,4 @@ public static string ListToText(List<object> objects, string delimiter=",")
5151
}
5252

5353

54+

Excel_Engine/Convert/ToExcel/CellAddress.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
3-
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
55
* Each contributor holds copyright over their respective contributions.
66
* The project versioning (Git) records all such contribution source information.
@@ -48,3 +48,4 @@ public static string ToExcel(this CellAddress bhomAddress)
4848
}
4949

5050

51+

0 commit comments

Comments
 (0)