Skip to content

Commit 361dbe6

Browse files
authored
8.1 Deployment (#91)
2 parents 8e38fd4 + 9f7b295 commit 361dbe6

Some content is hidden

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

41 files changed

+141
-174
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 - 2024, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2025, 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.
@@ -59,3 +59,4 @@ public override IEnumerable<object> Pull(IRequest request = null, PullType pullO
5959

6060

6161

62+

Excel_Adapter/AdapterActions/Push.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 - 2024, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2025, 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.
@@ -359,3 +359,4 @@ private static void GetPropertyDictionary(ref Dictionary<string, object> dict, o
359359

360360

361361

362+

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 - 2024, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2025, 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.
@@ -69,3 +69,4 @@ private bool Create(IXLWorkbook workbook, string sheetName, List<TableRow> data,
6969
}
7070
}
7171

72+

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 - 2024, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2025, 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.
@@ -54,3 +54,4 @@ private bool Delete(IXLWorkbook workbook, string sheetName)
5454

5555

5656

57+

Excel_Adapter/CRUD/Read/Read.cs

Lines changed: 23 additions & 15 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 - 2024, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2025, 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.
@@ -26,12 +26,10 @@
2626
using BH.oM.Adapter;
2727
using BH.oM.Adapters.Excel;
2828
using BH.oM.Base;
29-
using BH.oM.Data.Collections;
3029
using BH.oM.Data.Requests;
3130
using ClosedXML.Excel;
3231
using System;
3332
using System.Collections.Generic;
34-
using System.Data;
3533
using System.IO;
3634
using System.Linq;
3735

@@ -68,6 +66,16 @@ protected override IEnumerable<IBHoMObject> Read(IRequest request, ActionConfig
6866
return new List<IBHoMObject>();
6967
}
7068

69+
return ReadExcel(workbook, request, actionConfig);
70+
}
71+
72+
73+
/***************************************************/
74+
/**** Private Methods ****/
75+
/***************************************************/
76+
77+
private List<IBHoMObject> ReadExcel(XLWorkbook workbook, IRequest request, ActionConfig actionConfig)
78+
{
7179
if (request is ObjectRequest)
7280
{
7381
List<TableRow> result = ReadExcel(workbook, ((ObjectRequest)request).Worksheet, ((ObjectRequest)request).Range, true).OfType<TableRow>().ToList();
@@ -81,25 +89,24 @@ protected override IEnumerable<IBHoMObject> Read(IRequest request, ActionConfig
8189
return ReadExcel(workbook, ((CellContentsRequest)request).Worksheet, ((CellContentsRequest)request).Range, false);
8290
else if (request is WorksheetsRequest)
8391
return ReadExcel(workbook, ((WorksheetsRequest)request));
92+
else if (request is BatchRequest batchRequest)
93+
return batchRequest.Requests.Select(x => new ResultItem { Objects = ReadExcel(workbook, x, actionConfig), OriginalRequest = x }).ToList<IBHoMObject>();
8494
else
8595
{
8696
BH.Engine.Base.Compute.RecordError($"Requests of type {request?.GetType()} are not supported by the Excel adapter.");
8797
return new List<IBHoMObject>();
8898
}
8999
}
90100

91-
92-
/***************************************************/
93-
/**** Private Methods ****/
94101
/***************************************************/
95102

96103
private List<IBHoMObject> ReadExcel(XLWorkbook workbook, WorksheetsRequest request)
97104
{
98-
var worksheets = Worksheets(workbook, null);
105+
IEnumerable<IXLWorksheet> worksheets = Worksheets(workbook, null);
99106

100107
List<BH.oM.Adapters.Excel.Worksheet> sheets = worksheets.Select(x =>
101108
{
102-
var sheet = new BH.oM.Adapters.Excel.Worksheet();
109+
Worksheet sheet = new BH.oM.Adapters.Excel.Worksheet();
103110
sheet.Name = x.Name;
104111
return sheet;
105112
}).ToList();
@@ -120,13 +127,13 @@ private List<IBHoMObject> ReadExcel(XLWorkbook workbook, string worksheet, CellR
120127
if (string.IsNullOrEmpty(range.From.Column))
121128
range.From.Column = "A";
122129

123-
if(range.From.Row == -1)
130+
if (range.From.Row == -1)
124131
range.From.Row = 1;
125132

126133
if (string.IsNullOrEmpty(range.To.Column))
127134
range.To.Column = MaximumColumnName(workbook, worksheet);
128135

129-
if(range.To.Row == -1)
136+
if (range.To.Row == -1)
130137
range.To.Row = MaximumRowNumber(workbook, worksheet);
131138

132139
rangeString = range.ToExcel();
@@ -255,7 +262,7 @@ private List<IBHoMObject> CreateCustomObjects(List<TableRow> rows)
255262
CustomObject result = new CustomObject();
256263

257264
Dictionary<string, object> item = new Dictionary<string, object>();
258-
for (int i = 0; i < Math.Min((int)keys.Count(), (int)row.Content?.Count()); i ++)
265+
for (int i = 0; i < Math.Min((int)keys.Count(), (int)row.Content?.Count()); i++)
259266
{
260267
if (customProperties.Contains(keys[i]))
261268
result.SetPropertyValue(keys[i], row.Content[i]);
@@ -273,19 +280,19 @@ private List<IBHoMObject> CreateCustomObjects(List<TableRow> rows)
273280

274281
private string MaximumColumnName(IXLWorkbook workbook, string worksheet)
275282
{
276-
var sheet = Worksheets(workbook, worksheet).FirstOrDefault();
283+
IXLWorksheet sheet = Worksheets(workbook, worksheet).FirstOrDefault();
277284
if (sheet == null)
278285
return "XFD"; //Maximum Excel Column name
279286

280-
var columnNumber = sheet.LastColumnUsed().ColumnNumber();
281-
return ConvertToColumnName(columnNumber);
287+
int columnNumber = sheet.LastColumnUsed().ColumnNumber();
288+
return ConvertToColumnName(columnNumber);
282289
}
283290

284291
/***************************************************/
285292

286293
private int MaximumRowNumber(IXLWorkbook workbook, string worksheet)
287294
{
288-
var sheet = Worksheets(workbook, worksheet).FirstOrDefault();
295+
IXLWorksheet sheet = Worksheets(workbook, worksheet).FirstOrDefault();
289296
if (sheet == null)
290297
return 1048576; //Maximum Excel Row number
291298

@@ -315,3 +322,4 @@ private string ConvertToColumnName(int number)
315322

316323

317324

325+

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 - 2024, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2025, 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.
@@ -71,3 +71,4 @@ public bool Update(IXLWorkbook workbook, string sheetName, List<TableRow> data,
7171

7272

7373

74+

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 - 2024, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2025, 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.
@@ -67,3 +67,4 @@ public void Update(IXLWorkbook workbook, WorkbookProperties properties)
6767

6868

6969

70+

Excel_Adapter/Convert/FromExcel/CellContents.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 - 2024, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2025, 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.
@@ -129,3 +129,4 @@ private static object ExtractValue(XLCellValue xCellValue)
129129

130130

131131

132+

Excel_Adapter/ExcelAdapter.cs

Lines changed: 5 additions & 46 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 - 2024, the respective contributors. All rights reserved.
3+
* Copyright (c) 2015 - 2025, 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.
@@ -24,11 +24,11 @@
2424
using BH.oM.Adapters.Excel;
2525
using BH.oM.Base.Attributes;
2626
using BH.oM.Data.Requests;
27+
using System;
2728
using System.ComponentModel;
2829
using System.IO;
30+
using System.Linq;
2931
using System.Reflection;
30-
using System.Security;
31-
using System.Security.Policy;
3232
using System.Threading;
3333

3434
namespace BH.Adapter.Excel
@@ -57,10 +57,6 @@ public ExcelAdapter(BH.oM.Adapter.FileSettings fileSettings = null)
5757
}
5858

5959
m_FileSettings = fileSettings;
60-
61-
// This is needed because of save action of large files being made with an isolated storage
62-
// Fox taken from http://rekiwi.blogspot.com/2008/12/unable-to-determine-identity-of-domain.html
63-
VerifySecurityEvidenceForIsolatedStorage(this.GetType().Assembly);
6460
}
6561

6662
/***************************************************/
@@ -80,6 +76,7 @@ public ExcelAdapter(Stream inputStream, Stream outputStream = null)
8076
m_OutputStream = outputStream;
8177
}
8278

79+
8380
/***************************************************/
8481
/**** Override Methods ****/
8582
/***************************************************/
@@ -96,45 +93,6 @@ public override bool SetupPullRequest(object request, out IRequest actualRequest
9693
}
9794

9895

99-
/***************************************************/
100-
/**** Private Methods ****/
101-
/***************************************************/
102-
103-
private void VerifySecurityEvidenceForIsolatedStorage(Assembly assembly)
104-
{
105-
var isEvidenceFound = true;
106-
#if ZCTDEPLOY
107-
var initialAppDomainEvidence = new Evidence();
108-
#else
109-
var initialAppDomainEvidence = System.Threading.Thread.GetDomain().Evidence;
110-
#endif
111-
112-
try
113-
{
114-
// this will fail when the current AppDomain Evidence is instantiated via COM or in PowerShell
115-
using (var usfdAttempt1 = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForDomain())
116-
{
117-
}
118-
}
119-
catch (System.IO.IsolatedStorage.IsolatedStorageException e)
120-
{
121-
isEvidenceFound = false;
122-
}
123-
124-
if (!isEvidenceFound)
125-
{
126-
initialAppDomainEvidence.AddHostEvidence(new Url(assembly.Location));
127-
initialAppDomainEvidence.AddHostEvidence(new Zone(SecurityZone.MyComputer));
128-
129-
var currentAppDomain = Thread.GetDomain();
130-
var securityIdentityField = currentAppDomain.GetType().GetField("_SecurityIdentity", BindingFlags.Instance | BindingFlags.NonPublic);
131-
securityIdentityField.SetValue(currentAppDomain, initialAppDomainEvidence);
132-
133-
//var latestAppDomainEvidence = System.Threading.Thread.GetDomain().Evidence; // setting a breakpoint here will let you inspect the current app domain evidence
134-
}
135-
}
136-
137-
13896
/***************************************************/
13997
/**** Private Fields ****/
14098
/***************************************************/
@@ -150,3 +108,4 @@ private void VerifySecurityEvidenceForIsolatedStorage(Assembly assembly)
150108
}
151109

152110

111+

Excel_Adapter/Excel_Adapter.csproj

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
45
<AssemblyVersion>8.0.0.0</AssemblyVersion>
56
<Description>https://github.com/BHoM/Excel_Toolkit</Description>
67
<Version>5.0.0</Version>
78
<Authors>BHoM</Authors>
89
<Copyright>Copyright © https://github.com/BHoM</Copyright>
910
<RootNamespace>BH.Adapter.Excel</RootNamespace>
10-
<FileVersion>8.0.0.0</FileVersion>
11+
<FileVersion>8.1.0.0</FileVersion>
1112
<Configurations>Debug;Release;ZeroCodeTool</Configurations>
1213
<OutputPath>..\Build\</OutputPath>
1314
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1415
</PropertyGroup>
1516

16-
<PropertyGroup Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
17-
<TargetFramework>net472</TargetFramework>
18-
<DefineConstants>INSTALLERDEPLOY</DefineConstants>
19-
</PropertyGroup>
20-
<PropertyGroup Condition="'$(Configuration)'=='ZeroCodeTool'">
21-
<TargetFramework>netstandard2.0</TargetFramework>
22-
<DefineConstants>ZCTDEPLOY</DefineConstants>
23-
</PropertyGroup>
17+
2418

2519
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
2620
<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&#xD;&#xA;xcopy &quot;$(TargetDir)Irony.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;xcopy &quot;$(TargetDir)XLParser.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y" />
@@ -68,35 +62,15 @@
6862
<HintPath>$(ProgramData)\BHoM\Assemblies\Reflection_Engine.dll</HintPath>
6963
</Reference>
7064
</ItemGroup>
71-
72-
<ItemGroup Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
73-
<Reference Include="System" />
74-
<Reference Include="System.Core" />
75-
<Reference Include="System.Xml.Linq" />
76-
<Reference Include="System.Data.DataSetExtensions" />
77-
<Reference Include="Microsoft.CSharp" />
78-
<Reference Include="System.Data" />
79-
<Reference Include="System.Net.Http" />
80-
<Reference Include="System.Xml" />
81-
<Reference Include="WindowsBase" />
82-
</ItemGroup>
8365

8466
<ItemGroup>
67+
<Reference Include="Microsoft.CSharp" />
8568
<PackageReference Include="ClosedXML" Version="0.102.2" />
8669
<PackageReference Include="DocumentFormat.OpenXml" Version="2.16.0" />
8770
<PackageReference Include="ExcelNumberFormat" Version="1.1.0" />
8871
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
8972
<PackageReference Include="SixLabors.Fonts" Version="1.0.0" />
9073
<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" />
93-
</ItemGroup>
94-
95-
<ItemGroup Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
96-
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
97-
</ItemGroup>
98-
99-
<ItemGroup Condition="'$(Configuration)'=='ZeroCodeTool'">
10074
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
10175
</ItemGroup>
10276

0 commit comments

Comments
 (0)