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

6.2 Deployment #32

Merged
merged 26 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1f18005
Upgrade AssemblyFileVersion to 6.2.0.0
BHoMBot Mar 28, 2023
a9ea092
Fix issue with reading from synced file in a sharepoint folder
IsakNaslundBh Apr 3, 2023
4349929
Upgrade to NetStandard2.0 for ZeroCodeTool deployments
Apr 24, 2023
9ebab51
Add compilation support between Net472 and NetStandard2.0
Apr 24, 2023
06f8540
Update nugets accordingly for NS2.0 and NF472
Apr 24, 2023
cc2cb63
Remove unnecessary UI reference
Apr 24, 2023
b906f5f
Update project compliance
BHoMBot Apr 24, 2023
8a9fd63
Update postbuild following discussion with @adecler
Apr 25, 2023
eedb265
Update csproj
Apr 25, 2023
070b0f4
Add method for getting out value or cached value and use it for when …
IsakNaslundBh Apr 19, 2023
bea3089
Add descriptions
IsakNaslundBh Apr 19, 2023
7816c33
Apply suggestions from code review
IsakNaslundBh May 4, 2023
5201f66
Add WorksheetsRequest object #27
Jun 8, 2023
f8738b1
Add Worksheet object to return from pull #27
Jun 8, 2023
f7172d6
Add read/pull commands to the Adapter for pulling worksheet names #27
Jun 8, 2023
159e041
Add ability to filter worksheet names
Jun 8, 2023
930094f
Remove unnecessary using
Jun 8, 2023
88e8b04
Tidy up object file
Jun 8, 2023
9d67b08
Updated Cell Range to Accept Numerical Only and Letter Only Inputs
desaiwangBH Jun 8, 2023
89310b8
Update Excel_Engine/Query/IsValid.cs
Jun 8, 2023
6421ca4
Update Excel_Engine/Query/IsValid.cs
Jun 8, 2023
0748500
Update to row or column selection filtering.
Jun 8, 2023
3ea0fe9
Tidy up usings
Jun 8, 2023
66d4b6e
Give credit where credit is due
Jun 8, 2023
36c67eb
Created ExcelToolkitWiki.cs
desaiwangBH Jun 9, 2023
b6c9fa6
Update Excel_Engine/Query/ExcelToolkitWiki.cs
Jun 9, 2023
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
75 changes: 73 additions & 2 deletions Excel_Adapter/CRUD/Read/Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected override IEnumerable<IBHoMObject> Read(IRequest request, ActionConfig
XLWorkbook workbook = null;
try
{
FileStream fileStream = new FileStream(m_FileSettings.GetFullFileName(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
FileStream fileStream = new FileStream(m_FileSettings.GetFullFileName(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
workbook = new XLWorkbook(fileStream);
fileStream.Close();
}
Expand All @@ -74,6 +74,8 @@ protected override IEnumerable<IBHoMObject> Read(IRequest request, ActionConfig
}
else if (request is CellContentsRequest)
return ReadExcel(workbook, ((CellContentsRequest)request).Worksheet, ((CellContentsRequest)request).Range, false);
else if (request is WorksheetsRequest)
return ReadExcel(workbook, ((WorksheetsRequest)request));
else
{
BH.Engine.Base.Compute.RecordError($"Requests of type {request?.GetType()} are not supported by the Excel adapter.");
Expand All @@ -86,11 +88,42 @@ protected override IEnumerable<IBHoMObject> Read(IRequest request, ActionConfig
/**** Private Methods ****/
/***************************************************/

private List<IBHoMObject> ReadExcel(XLWorkbook workbook, WorksheetsRequest request)
{
var worksheets = Worksheets(workbook, null);

List<BH.oM.Adapters.Excel.Worksheet> sheets = worksheets.Select(x =>
{
var sheet = new BH.oM.Adapters.Excel.Worksheet();
sheet.Name = x.Name;
return sheet;
}).ToList();

if (!string.IsNullOrEmpty(request.NameContains))
sheets = sheets.Where(x => x.Name.ToLower().Contains(request.NameContains.ToLower())).ToList();

return sheets.ToList<IBHoMObject>();
}

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

private List<IBHoMObject> ReadExcel(XLWorkbook workbook, string worksheet, CellRange range, bool valuesOnly)
{
string rangeString = "";
if (range != null)
{
if (string.IsNullOrEmpty(range.From.Column))
range.From.Column = "A";

if(range.From.Row == -1)
range.From.Row = 1;

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

if(range.To.Row == -1)
range.To.Row = MaximumRowNumber(workbook, worksheet);

rangeString = range.ToExcel();
if (string.IsNullOrWhiteSpace(rangeString))
return new List<IBHoMObject>();
Expand Down Expand Up @@ -126,7 +159,7 @@ private List<IBHoMObject> ReadExcel(XLWorkbook workbook, string worksheet, strin
foreach (IXLRangeColumn column in ixlRange.Columns())
{
if (valuesOnly)
dataRow.Add(ixlWorksheet.Cell(row.RowNumber(), column.ColumnNumber()).GetValue<object>());
dataRow.Add(ixlWorksheet.Cell(row.RowNumber(), column.ColumnNumber()).CellValueOrCachedValue());
else
dataRow.Add((ixlWorksheet.Cell(row.RowNumber(), column.ColumnNumber())).FromExcel());
}
Expand Down Expand Up @@ -231,8 +264,46 @@ private List<IBHoMObject> CreateCustomObjects(List<TableRow> rows)
}).ToList<IBHoMObject>();
}

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

private string MaximumColumnName(IXLWorkbook workbook, string worksheet)
{
var sheet = Worksheets(workbook, worksheet).FirstOrDefault();
if (sheet == null)
return "XFD"; //Maximum Excel Column name

var columnNumber = sheet.LastColumnUsed().ColumnNumber();
return ConvertToColumnName(columnNumber);
}

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

private int MaximumRowNumber(IXLWorkbook workbook, string worksheet)
{
var sheet = Worksheets(workbook, worksheet).FirstOrDefault();
if (sheet == null)
return 1048576; //Maximum Excel Row number

return sheet.LastRowUsed().RowNumber();
}

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

private string ConvertToColumnName(int number)
{
//Taken from https://frasergreenroyd.com/convert-a-number-to-an-excel-column-heading/
int mod = 0;
string columnHeading = "";

while (number > 0)
{
mod = (number - 1) % 26;
columnHeading = System.Convert.ToChar(65 + mod).ToString() + columnHeading;
number = (int)((number - mod) / 26);
}

return columnHeading;
}
}
}

Expand Down
23 changes: 22 additions & 1 deletion Excel_Adapter/Convert/FromExcel/CellContents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,37 @@ public static CellContents FromExcel(this IXLCell xLCell)
return new CellContents()
{
Comment = xLCell.HasComment ? xLCell.Comment.Text : "",
Value = xLCell.Value,
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 : ""
};


}

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

[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)
{
object 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.
if (xLCell.NeedsRecalculation)
BH.Engine.Base.Compute.RecordWarning($"Cell {xLCell?.Address?.ToString() ?? "unknown"} is flagged as needing to be recalculated, but this is not able to be done. The cached value for this cell is returned, which for most cases is correct, but please check the validity of the value.");

value = xLCell.CachedValue;
}
return value;
}

/*******************************************/
/**** Private Methods ****/
Expand Down
7 changes: 6 additions & 1 deletion Excel_Adapter/ExcelAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ public override bool SetupPullRequest(object request, out IRequest actualRequest
private void VerifySecurityEvidenceForIsolatedStorage(Assembly assembly)
{
var isEvidenceFound = true;
#if ZCTDEPLOY
var initialAppDomainEvidence = new Evidence();
#else
var initialAppDomainEvidence = System.Threading.Thread.GetDomain().Evidence;
#endif

try
{
// this will fail when the current AppDomain Evidence is instantiated via COM or in PowerShell
Expand All @@ -108,7 +113,7 @@ private void VerifySecurityEvidenceForIsolatedStorage(Assembly assembly)
var securityIdentityField = currentAppDomain.GetType().GetField("_SecurityIdentity", BindingFlags.Instance | BindingFlags.NonPublic);
securityIdentityField.SetValue(currentAppDomain, initialAppDomainEvidence);

var latestAppDomainEvidence = System.Threading.Thread.GetDomain().Evidence; // setting a breakpoint here will let you inspect the current app domain evidence
//var latestAppDomainEvidence = System.Threading.Thread.GetDomain().Evidence; // setting a breakpoint here will let you inspect the current app domain evidence
}
}

Expand Down
140 changes: 55 additions & 85 deletions Excel_Adapter/Excel_Adapter.csproj
Original file line number Diff line number Diff line change
@@ -1,93 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{79D1BABE-DF98-4635-A605-AA396FF58915}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Excel_Adapter</RootNamespace>
<AssemblyName>Excel_Adapter</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<Description>https://github.com/BHoM/Excel_Toolkit</Description>
<Version>5.0.0</Version>
<Authors>BHoM</Authors>
<Copyright>Copyright © https://github.com/BHoM</Copyright>
<RootNamespace>BH.Adapter.Excel</RootNamespace>
<FileVersion>6.2.0.0</FileVersion>
<Configurations>Debug;Release;ZeroCodeTool</Configurations>
<OutputPath>..\Build\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\Build\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>

<PropertyGroup Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
<TargetFramework>net472</TargetFramework>
<DefineConstants>INSTALLERDEPLOY</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='ZeroCodeTool'">
<TargetFramework>netstandard2.0</TargetFramework>
<DefineConstants>ZCTDEPLOY</DefineConstants>
</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)ExcelNumberFormat.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;xcopy &quot;$(TargetDir)DocumentFormat.OpenXml.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y" />
</Target>

<ItemGroup>
<Reference Include="Adapter_Engine">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\ProgramData\BHoM\Assemblies\Adapter_Engine.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\Adapter_Engine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Adapter_oM">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\ProgramData\BHoM\Assemblies\Adapter_oM.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\Adapter_oM.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BHoM">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\ProgramData\BHoM\Assemblies\BHoM.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BHoM_Adapter">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
<HintPath>C:\ProgramData\BHoM\Assemblies\BHoM_Adapter.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM_Adapter.dll</HintPath>
</Reference>
<Reference Include="BHoM_Engine">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\ProgramData\BHoM\Assemblies\BHoM_Engine.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM_Engine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ClosedXML, Version=0.95.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ClosedXML.0.95.0\lib\net46\ClosedXML.dll</HintPath>
</Reference>
<Reference Include="Data_Engine">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
<HintPath>C:\ProgramData\BHoM\Assemblies\Data_Engine.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\Data_Engine.dll</HintPath>
</Reference>
<Reference Include="Data_oM">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
<HintPath>C:\ProgramData\BHoM\Assemblies\Data_oM.dll</HintPath>
</Reference>
<Reference Include="DocumentFormat.OpenXml, Version=2.7.2.0, Culture=neutral, PublicKeyToken=8fb06cb64d019a17, processorArchitecture=MSIL">
<HintPath>..\packages\DocumentFormat.OpenXml.2.7.2\lib\net46\DocumentFormat.OpenXml.dll</HintPath>
</Reference>
<Reference Include="ExcelNumberFormat, Version=1.0.10.0, Culture=neutral, PublicKeyToken=23c6f5d73be07eca, processorArchitecture=MSIL">
<HintPath>..\packages\ExcelNumberFormat.1.0.10\lib\net20\ExcelNumberFormat.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\Data_oM.dll</HintPath>
</Reference>
<Reference Include="Reflection_Engine">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
<HintPath>C:\ProgramData\BHoM\Assemblies\Reflection_Engine.dll</HintPath>
<HintPath>$(ProgramData)\BHoM\Assemblies\Reflection_Engine.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.FileSystem.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.FileSystem.Primitives.4.0.1\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.IO.Packaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Packaging.4.0.0\lib\net46\System.IO.Packaging.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -96,42 +80,28 @@
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>

<ItemGroup>
<Compile Include="AdapterActions\Pull.cs" />
<Compile Include="AdapterActions\Push.cs" />
<Compile Include="Convert\FromExcel\CellContents.cs" />
<Compile Include="CRUD\Create\Create.cs" />
<Compile Include="CRUD\Delete\Delete.cs" />
<Compile Include="CRUD\Read\Read.cs" />
<Compile Include="CRUD\Update\Update.cs" />
<Compile Include="CRUD\Update\UpdateWorkbookProperties.cs" />
<Compile Include="ExcelAdapter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Validation\WorksheetName.cs" />
<Compile Include="Validation\Enums\WorksheetValidation.cs" />
<PackageReference Include="ClosedXML" Version="0.95.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.7.2" />
<PackageReference Include="ExcelNumberFormat" Version="1.0.10" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.IO.Packaging" Version="4.0.0" />
<PackageReference Include="System.Security.AccessControl" Version="6.0.2-mauipre.1.22102.15" />
<PackageReference Include="System.Security.Permissions" Version="8.0.0-preview.2.23128.3" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

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

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

<ItemGroup>
<ProjectReference Include="..\Excel_Engine\Excel_Engine.csproj">
<Project>{a6884466-297e-4aaa-a232-abbec42168d3}</Project>
<Name>Excel_Engine</Name>
</ProjectReference>
<ProjectReference Include="..\Excel_oM\Excel_oM.csproj">
<Project>{79fac4b0-77ec-4257-bcbe-cff37fff537c}</Project>
<Name>Excel_oM</Name>
</ProjectReference>
<ProjectReference Include="..\Excel_Engine\Excel_Engine.csproj" />
<ProjectReference Include="..\Excel_oM\Excel_oM.csproj" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
xcopy "$(TargetPath)" "C:\ProgramData\BHoM\Assemblies" /C /Y
xcopy "$(TargetDir)ClosedXML.dll" "C:\ProgramData\BHoM\Assemblies" /Y
xcopy "$(TargetDir)ExcelNumberFormat.dll" "C:\ProgramData\BHoM\Assemblies" /Y
xcopy "$(TargetDir)DocumentFormat.OpenXml.dll" "C:\ProgramData\BHoM\Assemblies" /Y

</PostBuildEvent>
</PropertyGroup>
</Project>

</Project>
Loading