Skip to content

Commit

Permalink
7.1 Deployment (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraser Greenroyd authored Mar 27, 2024
2 parents 32f7b99 + fb1caf3 commit d5f33f6
Show file tree
Hide file tree
Showing 42 changed files with 212 additions and 88 deletions.
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 @@ -314,3 +314,4 @@ private string ConvertToColumnName(int number)




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 @@ -149,3 +149,4 @@ private void VerifySecurityEvidenceForIsolatedStorage(Assembly assembly)
}
}


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 @@ -51,3 +51,4 @@ public static string ListToText(List<object> objects, string delimiter=",")
}



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

0 comments on commit d5f33f6

Please sign in to comment.