Skip to content

Upgrade net6 #8

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,6 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# Rider
.idea/
60 changes: 4 additions & 56 deletions AtlasStarter/AtlasStarter.csproj
Original file line number Diff line number Diff line change
@@ -1,71 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">anycpu</Platform>
<ProjectGuid>{AF9123AE-E6AF-44F6-BBE6-D8A633C4FDDE}</ProjectGuid>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<RootNamespace>AtlasStarter</RootNamespace>
<AssemblyName>AtlasStarter</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|anycpu' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|anycpu' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Crc32C.NET">
<HintPath>packages\Crc32C.NET.1.0.5.0\lib\net20\Crc32C.NET.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Bson">
<HintPath>packages\MongoDB.Bson.2.10.4\lib\net452\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Libmongocrypt">
<HintPath>packages\MongoDB.Libmongocrypt.1.0.0\lib\net452\MongoDB.Libmongocrypt.dll</HintPath>
</Reference>
<Reference Include="SharpCompress">
<HintPath>packages\SharpCompress.0.23.0\lib\net45\SharpCompress.dll</HintPath>
</Reference>
<Reference Include="Snappy.NET">
<HintPath>packages\Snappy.NET.1.1.1.8\lib\net45\Snappy.NET.dll</HintPath>
</Reference>
<Reference Include="System.Buffers">
<HintPath>packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="DnsClient">
<HintPath>packages\DnsClient.1.3.1\lib\net471\DnsClient.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.InteropServices.RuntimeInformation">
<HintPath>packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver.Core">
<HintPath>packages\MongoDB.Driver.Core.2.10.4\lib\net452\MongoDB.Driver.Core.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver">
<HintPath>packages\MongoDB.Driver.2.10.4\lib\net452\MongoDB.Driver.dll</HintPath>
</Reference>
<PackageReference Include="MongoDB.Driver" Version="2.21.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="packages\MongoDB.Libmongocrypt.1.0.0\build\MongoDB.Libmongocrypt.targets" Condition="Exists('packages\MongoDB.Libmongocrypt.1.0.0\build\MongoDB.Libmongocrypt.targets')" />
</Project>
41 changes: 41 additions & 0 deletions AtlasStarter/Models/Recipe.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using MongoDB.Bson.Serialization.Attributes;

namespace AtlasStarter.Models;

/// <summary>
/// This Recipe class provides formal C# code structure to the data
/// that is stored in MongoDB. Using strongly-typed classes makes
/// serialization & deserializaton of your data much easier.
/// </summary>

[BsonIgnoreExtraElements]
public class Recipe
{
public string Name { get; set; }
public List<string> Ingredients { get; set; }
public int PrepTimeInMinutes { get; set; }

public Recipe(string name, List<string> ingredients, int prepTime)
{
Name = name;
Ingredients = ingredients;
PrepTimeInMinutes = prepTime;
}

/// <summary>
/// This static method is just here so we have a convenient way
/// to generate sample recipe data.
/// </summary>
/// <returns>A list of Recipes</returns>
public static List<Recipe> GetRecipes()
{
return new List<Recipe>
{
new("elotes", new List<string>(){"corn", "mayonnaise", "cotija cheese", "sour cream", "lime" }, 35),
new("loco moco", new List<string>(){"ground beef", "butter", "onion", "egg", "bread bun", "mushrooms" }, 54),
new("patatas bravas", new List<string>(){"potato", "tomato", "olive oil", "onion", "garlic", "paprika" }, 80),
new("fried rice", new List<string>(){"rice", "soy sauce", "egg", "onion", "pea", "carrot", "sesame oil" }, 40),
};
}
}
64 changes: 17 additions & 47 deletions AtlasStarter/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using AtlasStarter.Models;
using MongoDB.Driver;

namespace AtlasStarter
{
class MainClassNoPrompt
static class MainClassNoPrompt
{
public static void Main(string[] args)
{
Expand Down Expand Up @@ -55,8 +56,9 @@ public static void Main(string[] args)
var dbName = "myDatabase";
var collectionName = "recipes";

collection = client.GetDatabase(dbName)
.GetCollection<Recipe>(collectionName);
collection = client
.GetDatabase(dbName)
.GetCollection<Recipe>(collectionName);

/* *** INSERT DOCUMENTS ***
*
Expand Down Expand Up @@ -88,10 +90,11 @@ public static void Main(string[] args)
* filters, and is used here to show its most basic use.
*/

var allDocs = collection.Find(Builders<Recipe>.Filter.Empty)
var allDocs = collection
.Find(Builders<Recipe>.Filter.Empty)
.ToList();

foreach (Recipe recipe in allDocs)
foreach (var recipe in allDocs)
{
Console.WriteLine($"{recipe.Name} has {recipe.Ingredients.Count} ingredients " +
$"and takes {recipe.PrepTimeInMinutes} minutes to make");
Expand All @@ -103,11 +106,12 @@ public static void Main(string[] args)
// use the Builders class to create the filter, and a LINQ
// statement to define the property and value we're after:

var findFilter = Builders<Recipe>
.Filter.AnyEq(t => t.Ingredients,
"potato");
var findFilter = Builders<Recipe>.Filter
.AnyEq(t => t.Ingredients, "potato");

var findResult = collection.Find(findFilter).FirstOrDefault();
var findResult = collection
.Find(findFilter)
.FirstOrDefault();

if (findResult == null)
{
Expand All @@ -128,7 +132,8 @@ public static void Main(string[] args)
* just found.
*/

var updateFilter = Builders<Recipe>.Update.Set(t => t.PrepTimeInMinutes, 72);
var updateFilter = Builders<Recipe>.Update
.Set(t => t.PrepTimeInMinutes, 72);

// The following FindOneAndUpdateOptions specify that we want the *updated* document
// to be returned to us. By default, we get the document as it was *before*
Expand All @@ -147,6 +152,7 @@ public static void Main(string[] args)
Console.WriteLine("Here's the updated document:");
Console.WriteLine(updatedDocument.ToString());
Console.WriteLine();

/* *** DELETE DOCUMENTS ***
*
* As with other CRUD methods, you can delete a single document
Expand All @@ -157,49 +163,13 @@ public static void Main(string[] args)
*/

var deleteResult = collection
.DeleteMany(Builders<Recipe>.Filter.In(r => r.Name, new string[] { "elotes", "fried rice" }));
.DeleteMany(Builders<Recipe>.Filter.In(r => r.Name, new[] { "elotes", "fried rice" }));

Console.WriteLine($"I deleted {deleteResult.DeletedCount} records.");

Console.Read();
}
}

/// <summary>
/// This Recipe class provides formal C# code structure to the data
/// that is stored in MongoDB. Using strongly-typed classes makes
/// serialization & deserializaton of your data much easier.
/// </summary>

public class Recipe
{
public string Name { get; set; }
public List<string> Ingredients { get; set; }
public int PrepTimeInMinutes { get; set; }

public Recipe(string name, List<string> ingredients, int prepTime)
{
this.Name = name;
this.Ingredients = ingredients;
this.PrepTimeInMinutes = prepTime;
}

/// <summary>
/// This static method is just here so we have a convenient way
/// to generate sample recipe data.
/// </summary>
/// <returns>A list of Recipes</returns>
public static List<Recipe> GetRecipes()
{
return new List<Recipe>()
{
new Recipe("elotes", new List<string>(){"corn", "mayonnaise", "cotija cheese", "sour cream", "lime" }, 35),
new Recipe("loco moco", new List<string>(){"ground beef", "butter", "onion", "egg", "bread bun", "mushrooms" }, 54),
new Recipe("patatas bravas", new List<string>(){"potato", "tomato", "olive oil", "onion", "garlic", "paprika" }, 80),
new Recipe("fried rice", new List<string>(){"rice", "soy sauce", "egg", "onion", "pea", "carrot", "sesame oil" }, 40),
};
}
}
}


2 changes: 1 addition & 1 deletion AtlasStarter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
13 changes: 0 additions & 13 deletions AtlasStarter/packages.config

This file was deleted.