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

Upgrade to Mongo version 2.18 #145

Merged
merged 12 commits into from
Nov 24, 2022
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
1 change: 0 additions & 1 deletion File_Adapter/AdapterActions/Execute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down
1 change: 0 additions & 1 deletion File_Adapter/AdapterActions/Pull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down
1 change: 0 additions & 1 deletion File_Adapter/AdapterActions/Push.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down
1 change: 0 additions & 1 deletion File_Adapter/AdapterActions/Remove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down
1 change: 0 additions & 1 deletion File_Adapter/CRUD/Create/CreateDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

using BH.oM.Base;
using MongoDB.Bson.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down
47 changes: 0 additions & 47 deletions File_Adapter/CRUD/Create/CreateJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

using BH.oM.Base;
using MongoDB.Bson.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -30,7 +29,6 @@
using BH.oM.Adapter;
using BH.Engine.Adapters.File;
using BH.oM.Adapters.File;
using System.Text.Json;
using BH.Engine.Diffing;
using BH.oM.Diffing;
using BH.oM.Data.Library;
Expand Down Expand Up @@ -76,18 +74,6 @@ public FSFile CreateJson(FSFile file, PushType pushType, PushConfig pushConfig)
allLines.AddRange(file.Content.Where(c => c != null).Select(obj => obj.ToJson()));
json = String.Join(Environment.NewLine, allLines);
}

if (pushConfig.BeautifyJson)
{
try
{
json = BeautifyJson(json);
}
catch (Exception e)
{
BH.Engine.Base.Compute.RecordWarning($"Beautify json failed. File will be created with non-beautified json. Error:\n{e.Message}");
}
}
}

bool filecreated = true;
Expand Down Expand Up @@ -276,39 +262,6 @@ public static void WriteJsonFile(string fullPath, string json, bool replaceConte
}
}
}

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

private static string BeautifyJson(string jsonString)
{
if (string.IsNullOrWhiteSpace(jsonString))
return jsonString;

JsonDocument doc = JsonDocument.Parse(
jsonString,
new JsonDocumentOptions
{
AllowTrailingCommas = true
}
);
MemoryStream memoryStream = new MemoryStream();
using (
var utf8JsonWriter = new Utf8JsonWriter(
memoryStream,
new JsonWriterOptions
{
Indented = true
}
)
)
{
doc.WriteTo(utf8JsonWriter);
}
return new System.Text.UTF8Encoding()
.GetString(memoryStream.ToArray());
}
}
}

Expand Down
40 changes: 2 additions & 38 deletions File_Adapter/CRUD/Read/ReadFileContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

using BH.oM.Adapter;
using BH.oM.Base;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.IO;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -155,41 +152,8 @@ public static IEnumerable<object> RetrieveJsonContent(string fileFullPath)

public static bool FromJson(string json, out object result)
{
result = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes the support for reading Json Arrays.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FromJson method in the Serialiser Engine already takes care of arrays

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, as long as all scripts run fine, I'm ok with this! I will test properly all of them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. If there's any problem with warnings, then we should just keep the check on first character ('[' or '{') but then call the appropriate method in the Engine (FromJson and FromJsonArray) instead of replicated the code that is found there. This removes the direct dependency to the Mongo NuGet package and therefore limits the risk to have incompatible versions between toolkits.


if (json == "")
return false;

if (json.StartsWith("{"))
{
BsonDocument document;
if (BsonDocument.TryParse(json, out document))
{
result = BH.Engine.Serialiser.Convert.FromBson(document);
return true;
}
else
{
return false;
}
}

if (json.StartsWith("["))
{
BsonArray array = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonArray>(json);

try
{
result = array.Select(b => b.IsBsonDocument ? BH.Engine.Serialiser.Convert.FromBson(b.AsBsonDocument) : BH.Engine.Serialiser.Convert.FromJson(b.ToString())).ToList();
return true;
}
catch
{
return false;
}
}

return false;
result = BH.Engine.Serialiser.Convert.FromJson(json);
return result != null;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion File_Adapter/FileAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.IO.Abstractions;
using System.Linq;

namespace BH.Adapter.File
Expand Down
64 changes: 4 additions & 60 deletions File_Adapter/File_Adapter.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?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')" />
<PropertyGroup>
Expand All @@ -20,6 +20,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down Expand Up @@ -70,18 +71,6 @@
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>True</Private>
</Reference>
<Reference Include="MongoDB.Bson, Version=2.7.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.7.2\lib\net45\MongoDB.Bson.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Reflection_Engine">
<HintPath>C:\ProgramData\BHoM\Assemblies\Reflection_Engine.dll</HintPath>
<Private>False</Private>
Expand All @@ -93,47 +82,10 @@
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.IO.Abstractions, Version=2.1.0.256, Culture=neutral, PublicKeyToken=96bf224d23c43e59, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Abstractions.2.1.0.256\lib\net40\System.IO.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Numerics">
<Private>True</Private>
</Reference>
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Text.Encodings.Web, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Encodings.Web.4.7.1\lib\net461\System.Text.Encodings.Web.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Text.Json, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Json.4.7.2\lib\net461\System.Text.Json.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Management.Automation" />
Expand Down Expand Up @@ -163,7 +115,6 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Versioning_40.json" />
</ItemGroup>
<ItemGroup>
Expand All @@ -180,13 +131,6 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy "$(TargetDir)$(TargetFileName)" "C:\ProgramData\BHoM\Assemblies" /Y

xcopy "$(TargetDir)Microsoft.Bcl.AsyncInterfaces.dll" "C:\ProgramData\BHoM\Assemblies" /Y
xcopy "$(TargetDir)System.IO.Abstractions.dll" "C:\ProgramData\BHoM\Assemblies" /Y
xcopy "$(TargetDir)System.Numerics.dll" "C:\ProgramData\BHoM\Assemblies" /Y
xcopy "$(TargetDir)System.Numerics.Vectors.dll" "C:\ProgramData\BHoM\Assemblies" /Y
xcopy "$(TargetDir)System.Text.Encodings.Web.dll" "C:\ProgramData\BHoM\Assemblies" /Y
xcopy "$(TargetDir)System.Text.Json.dll" "C:\ProgramData\BHoM\Assemblies" /Y</PostBuildEvent>
<PostBuildEvent>xcopy "$(TargetDir)$(TargetFileName)" "C:\ProgramData\BHoM\Assemblies" /Y</PostBuildEvent>
</PropertyGroup>
</Project>
</Project>
1 change: 0 additions & 1 deletion File_Adapter/Methods/CreateFSDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using System;
using System.Security.AccessControl;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down
1 change: 0 additions & 1 deletion File_Adapter/Methods/CreateFSFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using System;
using System.Security.AccessControl;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down
4 changes: 0 additions & 4 deletions File_Adapter/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
Expand Down
16 changes: 0 additions & 16 deletions File_Adapter/packages.config

This file was deleted.

1 change: 0 additions & 1 deletion File_Engine/Compute/ReadFromJsonFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
using BH.Engine.Serialiser;
using BH.Engine.Adapters.File;
using BH.oM.Adapters.File;
using MongoDB.Bson;
using System.Collections;
using BH.oM.Adapter;
using System.ComponentModel;
Expand Down
2 changes: 0 additions & 2 deletions File_Engine/Create/FileDirRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
using System;
using System.Security.AccessControl;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down
17 changes: 1 addition & 16 deletions File_Engine/File_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Abstractions, Version=2.1.0.256, Culture=neutral, PublicKeyToken=96bf224d23c43e59, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Abstractions.2.1.0.256\lib\net40\System.IO.Abstractions.dll</HintPath>
</Reference>
<Reference Include="System.IO.Abstractions.TestingHelpers, Version=2.1.0.256, Culture=neutral, PublicKeyToken=96bf224d23c43e59, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Abstractions.TestingHelpers.2.1.0.256\lib\net40\System.IO.Abstractions.TestingHelpers.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Management.Automation" />
Expand Down Expand Up @@ -111,9 +105,6 @@
<Compile Include="Query\Encoding.cs" />
<Compile Include="Query\Contents.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\File_oM\File_oM.csproj">
<Project>{d344dcf0-788d-4e0a-8596-70199a080619}</Project>
Expand All @@ -126,12 +117,6 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
xcopy "$(TargetDir)$(TargetFileName)" "C:\ProgramData\BHoM\Assemblies" /Y

xcopy "$(TargetDir)System.IO.Abstractions.TestingHelpers.dll" "C:\ProgramData\BHoM\Assemblies" /Y

xcopy "$(TargetDir)System.IO.Abstractions.dll" "C:\ProgramData\BHoM\Assemblies" /Y
</PostBuildEvent>
<PostBuildEvent>xcopy "$(TargetDir)$(TargetFileName)" "C:\ProgramData\BHoM\Assemblies" /Y</PostBuildEvent>
</PropertyGroup>
</Project>
6 changes: 0 additions & 6 deletions File_Engine/packages.config

This file was deleted.

1 change: 0 additions & 1 deletion File_oM/Directory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

using BH.oM.Base;
using BH.oM.Humans;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
Loading