├── Chapter01 ├── global.json ├── dummyapi31 │ ├── dummyapi31.csproj │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── WeatherForecast.cs │ ├── Program.cs │ └── Properties │ │ └── launchSettings.json ├── myscapp │ ├── myscapp.csproj │ └── Program.cs ├── dummyapi50 │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── dummyapi50.csproj │ ├── WeatherForecast.cs │ ├── Program.cs │ └── Properties │ │ └── launchSettings.json └── Benchmarks │ ├── Benchmarks.csproj │ ├── Program.cs │ ├── Program4.csx │ ├── Program3.csx │ ├── Program5.csx │ └── Program2.csx ├── Chapter05 ├── net5 │ └── BookApp │ │ ├── BookApp.Web.V2 │ │ ├── Views │ │ │ ├── _ViewStart.cshtml │ │ │ ├── Shared │ │ │ │ ├── _ViewStart.cshtml │ │ │ │ ├── _ValidationScriptsPartial.cshtml │ │ │ │ └── Error.cshtml │ │ │ ├── _ViewImports.cshtml │ │ │ ├── Home │ │ │ │ └── Index.cshtml │ │ │ ├── BookReviews │ │ │ │ └── Delete.cshtml │ │ │ └── Books │ │ │ │ ├── Details.cshtml │ │ │ │ └── Index.cshtml │ │ ├── appsettings.Development.json │ │ ├── Models │ │ │ └── ErrorViewModel.cs │ │ ├── appsettings.json │ │ ├── Properties │ │ │ └── launchSettings.json │ │ ├── Program.cs │ │ ├── BookApp.Web.csproj │ │ └── Controllers │ │ │ └── HomeController.cs │ │ ├── Models │ │ ├── App.config │ │ ├── BookApp.Models.csproj │ │ ├── BookReview.cs │ │ └── Book.cs │ │ ├── AdminDesktop │ │ ├── appsettings.json │ │ ├── Properties │ │ │ ├── Settings.settings │ │ │ └── Settings.Designer.cs │ │ ├── App.xaml │ │ ├── App.config │ │ ├── BookApp.AdminDesktop.csproj │ │ └── ImageConverter.cs │ │ └── BookApp.DAL │ │ ├── Resources │ │ ├── learnpowerapps.png │ │ └── pythonmachinelearning.png │ │ ├── DI │ │ └── BookAppDBModule.cs │ │ ├── BookApp.DAL.csproj │ │ └── Utilities.cs └── netframework472 │ └── BookApp │ ├── Models │ ├── App.config │ ├── packages.config │ ├── BookReview.cs │ ├── Book.cs │ └── Properties │ │ └── AssemblyInfo.cs │ ├── BookApp.Web │ ├── Views │ │ ├── _ViewStart.cshtml │ │ ├── Shared │ │ │ └── Error.cshtml │ │ ├── Home │ │ │ └── Index.cshtml │ │ ├── BookReviews │ │ │ └── Delete.cshtml │ │ └── Books │ │ │ ├── Details.cshtml │ │ │ └── Index.cshtml │ ├── Global.asax │ ├── favicon.ico │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 │ ├── App_Start │ │ ├── FilterConfig.cs │ │ ├── RouteConfig.cs │ │ └── BundleConfig.cs │ ├── Content │ │ └── Site.css │ ├── Controllers │ │ └── HomeController.cs │ ├── Web.Debug.config │ ├── Global.asax.cs │ ├── Web.Release.config │ └── Properties │ │ └── AssemblyInfo.cs │ ├── BookApp.DAL │ ├── Resources │ │ ├── learnpowerapps.png │ │ └── pythonmachinelearning.png │ ├── app.config │ ├── DI │ │ └── BookAppDBModule.cs │ ├── BooksDBContext.cs │ ├── packages.config │ ├── Utilities.cs │ └── Properties │ │ └── AssemblyInfo.cs │ └── AdminDesktop │ ├── Properties │ ├── Settings.settings │ └── Settings.Designer.cs │ ├── App.xaml │ ├── packages.config │ ├── App.config │ ├── App.xaml.cs │ └── ImageConverter.cs ├── Chapter06 ├── azure │ └── BookApp │ │ ├── BookApp.Web.V2 │ │ ├── Views │ │ │ ├── _ViewStart.cshtml │ │ │ ├── Shared │ │ │ │ ├── _ViewStart.cshtml │ │ │ │ ├── _ValidationScriptsPartial.cshtml │ │ │ │ └── Error.cshtml │ │ │ ├── _ViewImports.cshtml │ │ │ ├── Home │ │ │ │ └── Index.cshtml │ │ │ ├── BookReviews │ │ │ │ ├── Delete.cshtml │ │ │ │ └── _GetSentiment.cshtml │ │ │ └── Books │ │ │ │ ├── Details.cshtml │ │ │ │ └── Index.cshtml │ │ ├── .config │ │ │ └── dotnet-tools.json │ │ ├── appsettings.Development.json │ │ ├── Models │ │ │ ├── ErrorViewModel.cs │ │ │ └── SentimentAnalysisServiceSettings.cs │ │ ├── appsettings.json │ │ ├── Program.cs │ │ ├── Dockerfile │ │ ├── Properties │ │ │ ├── launchSettings.json │ │ │ └── PublishProfiles │ │ │ │ ├── bookapp2020.pubxml │ │ │ │ ├── bookApp2020 - FTP.pubxml │ │ │ │ ├── bookApp2020 - ReadOnly - FTP.pubxml │ │ │ │ └── bookApp2020 - Web Deploy.pubxml │ │ ├── Controllers │ │ │ └── HomeController.cs │ │ └── BookApp.Web.csproj │ │ ├── Models │ │ ├── App.config │ │ ├── BookApp.Models.csproj │ │ ├── BookReview.cs │ │ └── Book.cs │ │ ├── AdminDesktop │ │ ├── appsettings.json │ │ ├── Properties │ │ │ ├── Settings.settings │ │ │ └── Settings.Designer.cs │ │ ├── App.xaml │ │ ├── App.config │ │ ├── BookApp.AdminDesktop.csproj │ │ └── ImageConverter.cs │ │ ├── docker-compose.yml │ │ ├── BookApp.SentimentAnalysisFunction │ │ ├── Sentiment.cs │ │ ├── ISentimentAnaysisService.cs │ │ ├── Properties │ │ │ ├── serviceDependencies.json │ │ │ └── serviceDependencies.local.json │ │ ├── host.json │ │ ├── Startup.cs │ │ ├── BookApp.SentimentAnalysisFunction.csproj │ │ └── SentimentFunction.cs │ │ ├── BookApp.DAL │ │ ├── Resources │ │ │ ├── learnpowerapps.png │ │ │ └── pythonmachinelearning.png │ │ ├── DI │ │ │ └── BookAppDBModule.cs │ │ ├── BookApp.DAL.csproj │ │ └── Utilities.cs │ │ ├── docker-compose.override.yml │ │ ├── .dockerignore │ │ └── docker-compose.dcproj ├── onprem │ └── BookApp │ │ ├── Models │ │ ├── App.config │ │ ├── BookApp.Models.csproj │ │ ├── BookReview.cs │ │ └── Book.cs │ │ ├── BookApp.Web.V2 │ │ ├── Views │ │ │ ├── _ViewStart.cshtml │ │ │ ├── Shared │ │ │ │ ├── _ViewStart.cshtml │ │ │ │ ├── _ValidationScriptsPartial.cshtml │ │ │ │ └── Error.cshtml │ │ │ ├── _ViewImports.cshtml │ │ │ ├── Home │ │ │ │ └── Index.cshtml │ │ │ ├── BookReviews │ │ │ │ └── Delete.cshtml │ │ │ └── Books │ │ │ │ ├── Details.cshtml │ │ │ │ └── Index.cshtml │ │ ├── appsettings.Development.json │ │ ├── Models │ │ │ └── ErrorViewModel.cs │ │ ├── appsettings.json │ │ ├── Properties │ │ │ └── launchSettings.json │ │ ├── Program.cs │ │ ├── BookApp.Web.csproj │ │ └── Controllers │ │ │ └── HomeController.cs │ │ ├── AdminDesktop │ │ ├── appsettings.json │ │ ├── Properties │ │ │ ├── Settings.settings │ │ │ └── Settings.Designer.cs │ │ ├── App.xaml │ │ ├── App.config │ │ ├── BookApp.AdminDesktop.csproj │ │ └── ImageConverter.cs │ │ └── BookApp.DAL │ │ ├── Resources │ │ ├── learnpowerapps.png │ │ └── pythonmachinelearning.png │ │ ├── DI │ │ └── BookAppDBModule.cs │ │ ├── BookApp.DAL.csproj │ │ └── Utilities.cs └── cli scripts │ ├── cleaning up resources.txt │ ├── azure function scripts.txt │ ├── azure container instance scripts.txt │ └── sql migration scripts.txt ├── Chapter03 ├── whatisdi │ ├── ISomeUsecase.cs │ ├── IDependencyOne.cs │ ├── IDependencyTwo.cs │ ├── whatisdi.csproj │ ├── Program.cs │ ├── DependencyOne.cs │ └── DependentClass.cs └── tinyrp │ ├── Student.cs │ ├── tinyrp.csproj │ ├── Program.cs │ ├── IStudentRepository.cs │ └── SQLStudentRepository.cs ├── Chapter02 ├── top-level-programs │ ├── hello-world │ │ ├── Program.cs │ │ └── top-level-program.csproj │ ├── hello-world-with-method │ │ ├── Program.cs │ │ └── top-level-program.csproj │ └── hello-world-with-classes │ │ ├── top-level-program.csproj │ │ └── Program.cs ├── module-intializer │ ├── module-intializer.csproj │ └── Program.cs ├── snippets │ ├── hello-world.linq │ ├── new-method-param.linq │ ├── records-positional-parameters.linq │ ├── init-only-properties.linq │ ├── type-inference-from-shared-base.linq │ ├── new-multiple-initializations.linq │ ├── records-equality.linq │ ├── records-with.linq │ ├── discard-lambdas.linq │ ├── records-equality-inheritance.linq │ ├── records-inheritance.linq │ └── switch-on-type.linq ├── cs9-player-value-calculator │ ├── BrandSize.cs │ ├── cs9-player-value-calculator.csproj │ ├── TennisStats.cs │ ├── SoccerStats.cs │ ├── CricketStats.cs │ ├── Program.cs │ └── cs9-player-value-calculator.sln └── cs9-performance │ ├── Program.cs │ ├── cs9-performance.csproj │ └── cs9-performance.sln ├── nuget.config ├── Chapter04 └── microservicesapp │ ├── primecalculator │ ├── Messaging │ │ ├── IMQClient.cs │ │ └── IMessageQueueSender.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── Properties │ │ └── launchSettings.json │ ├── Protos │ │ └── prime.proto │ ├── primecalculator.csproj │ ├── Program.cs │ └── Extensions │ │ └── RabbitMQServiceCollectionExtensions.cs │ ├── primeclienta │ ├── appsettings.json │ ├── appsettings.Development.json │ ├── Properties │ │ └── launchSettings.json │ ├── primeclienta.csproj │ └── Program.cs │ ├── primeclientb │ ├── appsettings.json │ ├── appsettings.Development.json │ ├── Properties │ │ └── launchSettings.json │ ├── primeclientb.csproj │ └── Program.cs │ ├── primeclientc │ ├── appsettings.json │ ├── appsettings.Development.json │ ├── Properties │ │ └── launchSettings.json │ ├── primeclientc.csproj │ └── Program.cs │ ├── primeqconsumer │ ├── appsettings.json │ ├── appsettings.Development.json │ ├── Properties │ │ └── launchSettings.json │ ├── primeqconsumer.csproj │ └── Program.cs │ ├── redis.yaml │ ├── tye.yaml │ ├── tye_rabbit_unnamedbinding.yaml │ ├── tye_rabbit_namedbinding.yaml │ └── rabbitmq.yaml ├── Chapter07 ├── SentimentAnalysis │ ├── BookApp.SentimentAnalysisFunction │ │ ├── Sentiment.cs │ │ ├── ISentimentAnaysisService.cs │ │ ├── host.json │ │ ├── SentimentAnaysisService.cs │ │ ├── BookApp.SentimentAnalysisFunction.csproj │ │ └── SentimentFunction.cs │ ├── ModelBuilderApp │ │ ├── ModelOutput │ │ │ └── sentiment_analysis_model.zip │ │ ├── Program.cs │ │ └── ModelBuilderApp.csproj │ └── SentimentAnalysis.Models │ │ ├── SentimentAnalysis.Models.csproj │ │ ├── SentimentOutput.cs │ │ └── SentimentInput.cs └── SpendScorePredictor │ ├── SpendScorePredictorML.Model │ ├── MLModel.zip │ ├── ModelOutput.cs │ ├── SpendScorePredictorML.Model.csproj │ ├── ModelInput.cs │ └── ConsumeModel.cs │ ├── SpendScorePredictor │ ├── Program.cs │ └── SpendScorePredictor.csproj │ └── SpendScorePredictorML.ConsoleApp │ ├── SpendScorePredictorML.ConsoleApp.csproj │ └── Program.cs └── LICENSE /Chapter01/global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "3.1.402" 4 | } 5 | } -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/Models/App.config: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/Models/App.config: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/Models/App.config: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Chapter03/whatisdi/ISomeUsecase.cs: -------------------------------------------------------------------------------- 1 | public interface ISomeUsecase 2 | { 3 | void IDoSomeActivity(); 4 | } -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/Models/App.config: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Chapter02/top-level-programs/hello-world/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | Console.WriteLine("Hello World from C# 9"); 4 | -------------------------------------------------------------------------------- /Chapter03/whatisdi/IDependencyOne.cs: -------------------------------------------------------------------------------- 1 | public interface IDependencyOne 2 | { 3 | void DoSomething(string something); 4 | } -------------------------------------------------------------------------------- /Chapter03/whatisdi/IDependencyTwo.cs: -------------------------------------------------------------------------------- 1 | public interface IDependencyTwo 2 | { 3 | void DoSomethingToo(string something); 4 | } -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/Views/Shared/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": {} 5 | } -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Views/Shared/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/Views/Shared/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter06/cli scripts/cleaning up resources.txt: -------------------------------------------------------------------------------- 1 | resourcegroupname=bookAppResourceGroup 2 | az group delete --name $resourcegroupname 3 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="BookApp.Web.MvcApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /Chapter03/tinyrp/Student.cs: -------------------------------------------------------------------------------- 1 | public class Student 2 | { 3 | public int Id { get; set; } 4 | public string Name { get; set; } 5 | public string Email { get; set; } 6 | } 7 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using BookApp.Web.V3 2 | @using BookApp.Web.V3.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using BookApp.Web.V3 2 | @using BookApp.Web.V3.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using BookApp.Web.V3 2 | @using BookApp.Web.V3.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/AdminDesktop/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "BooksDB": "Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=BookApp;Integrated Security=True;" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/Models/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter01/dummyapi31/dummyapi31.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/AdminDesktop/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "BooksDB": "Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=BookApp;Integrated Security=True;" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/AdminDesktop/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "BooksDB": "Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=BookApp;Integrated Security=True;" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Chapter02/top-level-programs/hello-world-with-method/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | Console.WriteLine(SayHello("John")); 4 | 5 | string SayHello(string name) 6 | { 7 | return $"Hello {name}"; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Chapter01/myscapp/myscapp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter03/tinyrp/tinyrp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.4' 2 | 3 | services: 4 | bookapp.web: 5 | image: ${DOCKER_REGISTRY-}bookappweb 6 | build: 7 | context: . 8 | dockerfile: BookApp.Web.V2/Dockerfile 9 | -------------------------------------------------------------------------------- /Chapter03/whatisdi/whatisdi.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter05/netframework472/BookApp/BookApp.Web/favicon.ico -------------------------------------------------------------------------------- /Chapter02/module-intializer/module-intializer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.SentimentAnalysisFunction/Sentiment.cs: -------------------------------------------------------------------------------- 1 | namespace BookApp.SentimentAnalysisFunction 2 | { 3 | public enum Sentiment 4 | { 5 | Negative=-1, 6 | Neutral=0, 7 | Positive=1 8 | } 9 | } -------------------------------------------------------------------------------- /nuget.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primecalculator/Messaging/IMQClient.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | 3 | namespace primecalculator.Messaging 4 | { 5 | public interface IMQClient 6 | { 7 | IModel CreateChannel(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.DAL/Resources/learnpowerapps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter05/net5/BookApp/BookApp.DAL/Resources/learnpowerapps.png -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.DAL/Resources/learnpowerapps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter06/azure/BookApp/BookApp.DAL/Resources/learnpowerapps.png -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.DAL/Resources/learnpowerapps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter06/onprem/BookApp/BookApp.DAL/Resources/learnpowerapps.png -------------------------------------------------------------------------------- /Chapter07/SentimentAnalysis/BookApp.SentimentAnalysisFunction/Sentiment.cs: -------------------------------------------------------------------------------- 1 | namespace BookApp.SentimentAnalysisFunction 2 | { 3 | public enum Sentiment 4 | { 5 | Negative=-1, 6 | Neutral=0, 7 | Positive=1 8 | } 9 | } -------------------------------------------------------------------------------- /Chapter01/dummyapi31/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter01/dummyapi50/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primecalculator/Messaging/IMessageQueueSender.cs: -------------------------------------------------------------------------------- 1 | namespace primecalculator.Messaging 2 | { 3 | public interface IMessageQueueSender 4 | { 5 | public void Send(string queueName, string message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Chapter01/myscapp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace myscapp 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter02/top-level-programs/hello-world/top-level-program.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter03/tinyrp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace tinyrp 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclienta/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclientb/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclientc/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeqconsumer/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.DAL/Resources/pythonmachinelearning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter05/net5/BookApp/BookApp.DAL/Resources/pythonmachinelearning.png -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.SentimentAnalysisFunction/ISentimentAnaysisService.cs: -------------------------------------------------------------------------------- 1 | namespace BookApp.SentimentAnalysisFunction 2 | { 3 | public interface ISentimentAnaysisService 4 | { 5 | Sentiment GetSentiment(string text); 6 | } 7 | } -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Chapter07/SentimentAnalysis/BookApp.SentimentAnalysisFunction/ISentimentAnaysisService.cs: -------------------------------------------------------------------------------- 1 | namespace BookApp.SentimentAnalysisFunction 2 | { 3 | public interface ISentimentAnaysisService 4 | { 5 | Sentiment GetSentiment(string text); 6 | } 7 | } -------------------------------------------------------------------------------- /Chapter07/SpendScorePredictor/SpendScorePredictorML.Model/MLModel.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter07/SpendScorePredictor/SpendScorePredictorML.Model/MLModel.zip -------------------------------------------------------------------------------- /Chapter03/whatisdi/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace whatisdi 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.DAL/Resources/pythonmachinelearning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter06/azure/BookApp/BookApp.DAL/Resources/pythonmachinelearning.png -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.DAL/Resources/pythonmachinelearning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter06/onprem/BookApp/BookApp.DAL/Resources/pythonmachinelearning.png -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/dummyapi31/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /Chapter01/dummyapi50/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /Chapter02/top-level-programs/hello-world-with-classes/top-level-program.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter02/top-level-programs/hello-world-with-method/top-level-program.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclienta/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclientb/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclientc/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.DAL/Resources/learnpowerapps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter05/netframework472/BookApp/BookApp.DAL/Resources/learnpowerapps.png -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeqconsumer/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/AdminDesktop/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/AdminDesktop/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/AdminDesktop/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter02/snippets/hello-world.linq: -------------------------------------------------------------------------------- 1 | 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | List greetings= new() {"Hello","World!"}; // C#9 Feature 8 | Console.WriteLine(String.Join(" ",greetings)); 9 | } 10 | } -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primecalculator/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Grpc": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.DAL/Resources/pythonmachinelearning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter05/netframework472/BookApp/BookApp.DAL/Resources/pythonmachinelearning.png -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/AdminDesktop/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter05/netframework472/BookApp/BookApp.Web/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter05/netframework472/BookApp/BookApp.Web/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter05/netframework472/BookApp/BookApp.Web/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /Chapter07/SentimentAnalysis/ModelBuilderApp/ModelOutput/sentiment_analysis_model.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter07/SentimentAnalysis/ModelBuilderApp/ModelOutput/sentiment_analysis_model.zip -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Adopting-.NET-5--Architecture-Migration-Best-Practices-and-New-Features/HEAD/Chapter05/netframework472/BookApp/BookApp.Web/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/docker-compose.override.yml: -------------------------------------------------------------------------------- 1 | version: '3.4' 2 | 3 | services: 4 | bookapp.web: 5 | environment: 6 | - ASPNETCORE_ENVIRONMENT=Development 7 | ports: 8 | - "80" 9 | volumes: 10 | - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro -------------------------------------------------------------------------------- /Chapter07/SpendScorePredictor/SpendScorePredictor/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SpendScorePredictor 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.SentimentAnalysisFunction/Properties/serviceDependencies.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "appInsights1": { 4 | "type": "appInsights" 5 | }, 6 | "storage1": { 7 | "type": "storage", 8 | "connectionId": "AzureWebJobsStorage" 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /Chapter01/dummyapi50/dummyapi50.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter03/tinyrp/IStudentRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | public interface IStudentRepository 4 | { 5 | IEnumerable GetAllStudents(); 6 | Student Get(int Id); 7 | Student Add(Student student); 8 | Student Update(Student changedStudent); 9 | Student Delete(int Id); 10 | } -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclienta/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "primeclienta": { 4 | "commandName": "Project", 5 | "dotnetRunMessages": "true", 6 | "environmentVariables": { 7 | "DOTNET_ENVIRONMENT": "Development" 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclientb/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "primeclientb": { 4 | "commandName": "Project", 5 | "dotnetRunMessages": "true", 6 | "environmentVariables": { 7 | "DOTNET_ENVIRONMENT": "Development" 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclientc/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "primeclientc": { 4 | "commandName": "Project", 5 | "dotnetRunMessages": "true", 6 | "environmentVariables": { 7 | "DOTNET_ENVIRONMENT": "Development" 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeqconsumer/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "primeqconsumer": { 4 | "commandName": "Project", 5 | "dotnetRunMessages": "true", 6 | "environmentVariables": { 7 | "DOTNET_ENVIRONMENT": "Development" 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BookApp.Web.V3.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BookApp.Web.V3.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BookApp.Web.V3.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter02/cs9-player-value-calculator/BrandSize.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace IntroducingNet5.Chapter3.CS9PlayerValueCalculator 8 | { 9 | public enum BrandSize { Small, Medium, Large } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.SentimentAnalysisFunction/Properties/serviceDependencies.local.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "appInsights1": { 4 | "type": "appInsights.sdk" 5 | }, 6 | "storage1": { 7 | "type": "storage.emulator", 8 | "connectionId": "AzureWebJobsStorage" 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.SentimentAnalysisFunction/host.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "logging": { 4 | "applicationInsights": { 5 | "samplingExcludedTypes": "Request", 6 | "samplingSettings": { 7 | "isEnabled": true 8 | } 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /Chapter07/SentimentAnalysis/BookApp.SentimentAnalysisFunction/host.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "logging": { 4 | "applicationInsights": { 5 | "samplingExcludedTypes": "Request", 6 | "samplingSettings": { 7 | "isEnabled": true 8 | } 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /Chapter02/top-level-programs/hello-world-with-classes/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | for (int i=0;i<10;i++) 4 | Console.WriteLine(GreetingsProvider.SayHello("John")); 5 | 6 | internal class GreetingsProvider 7 | { 8 | public static string SayHello(string name) 9 | { 10 | return $"Hello {name}"; 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter07/SpendScorePredictor/SpendScorePredictorML.Model/ModelOutput.cs: -------------------------------------------------------------------------------- 1 | // This file was auto-generated by ML.NET Model Builder. 2 | 3 | using System; 4 | using Microsoft.ML.Data; 5 | 6 | namespace SpendScorePredictorML.Model 7 | { 8 | public class ModelOutput 9 | { 10 | public float Score { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter02/cs9-performance/Program.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Running; 2 | using System; 3 | 4 | namespace IntroducingNet5.Chapter3.CS9Performance 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | var summary = BenchmarkRunner.Run(); 11 | 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter02/cs9-player-value-calculator/cs9-player-value-calculator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | IntroducingNet5.Chapter3.CS9PlayerValueCalculator 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter07/SentimentAnalysis/SentimentAnalysis.Models/SentimentAnalysis.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter02/snippets/new-method-param.linq: -------------------------------------------------------------------------------- 1 | 2 | 3 | void Main() 4 | { 5 | Person CloneThisPerson(Person person) 6 | { 7 | return new Person(person.FirstName,person.LastName); 8 | } 9 | 10 | 11 | Console.WriteLine( CloneThisPerson(new ("FirstName","LastName"))); 12 | } 13 | 14 | public record Person(string FirstName, string LastName); 15 | -------------------------------------------------------------------------------- /Chapter07/SentimentAnalysis/SentimentAnalysis.Models/SentimentOutput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.ML.Data; 3 | 4 | namespace SentimentAnalysis.Models 5 | { 6 | public class SentimentOutput 7 | { 8 | [ColumnName("PredictedLabel")] 9 | public String Prediction { get; set; } 10 | public float[] Score { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter02/cs9-player-value-calculator/TennisStats.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace IntroducingNet5.Chapter3.CS9PlayerValueCalculator 8 | { 9 | public class TennisStats 10 | { 11 | public int SetsWon { get; set; } 12 | } 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter03/whatisdi/DependencyOne.cs: -------------------------------------------------------------------------------- 1 | public class DependencyOne : IDependencyOne 2 | { 3 | private IDependencyTwo dependencyTwo; 4 | public DependencyOne(IDependencyTwo dependencyTwo) 5 | { 6 | this.dependencyTwo = dependencyTwo; 7 | } 8 | public void DoSomething(string something) 9 | { 10 | //Use dependencyTwo and DoSomething 11 | } 12 | } -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Error 6 | 7 | 8 |
9 |

Error.

10 |

An error occurred while processing your request.

11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Error 6 | 7 | 8 |
9 |

Error.

10 |

An error occurred while processing your request.

11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Error 6 | 7 | 8 |
9 |

Error.

10 |

An error occurred while processing your request.

11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primecalculator/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*", 10 | "Kestrel": { 11 | "EndpointDefaults": { 12 | "Protocols": "Http2" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Error 6 | 7 | 8 |
9 |

Error.

10 |

An error occurred while processing your request.

11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/App_Start/FilterConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Mvc; 3 | 4 | namespace BookApp.Web 5 | { 6 | public class FilterConfig 7 | { 8 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 9 | { 10 | filters.Add(new HandleErrorAttribute()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter01/dummyapi31/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace dummyapi31 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter01/dummyapi50/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace dummyapi50 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter02/snippets/records-positional-parameters.linq: -------------------------------------------------------------------------------- 1 | 2 | 3 | void Main() 4 | { 5 | var player = new Player("John", "Citizen"); // both properties will initialize 6 | 7 | var (name1,name2) = player; // name1 = John, name2= Citizen 8 | 9 | Console.WriteLine(name1); 10 | Console.WriteLine(name2); 11 | } 12 | 13 | public record Player(string FirstName, string LastName); 14 | 15 | -------------------------------------------------------------------------------- /Chapter03/whatisdi/DependentClass.cs: -------------------------------------------------------------------------------- 1 | public class DependentClass : ISomeUsecase 2 | { 3 | private IDependencyOne dependencyOne; 4 | public DependentClass(IDependencyOne dependencyOne) 5 | { 6 | this.dependencyOne = dependencyOne; 7 | } 8 | public void IDoSomeActivity() //From the interface ISomeUsecase 9 | { 10 | //I do some activity using dependencyOne 11 | } 12 | } -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Models/SentimentAnalysisServiceSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace BookApp.Web.Models 7 | { 8 | public class SentimentAnalysisServiceSettings 9 | { 10 | public string URL { get; set; } 11 | public string Code { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter07/SpendScorePredictor/SpendScorePredictor/SpendScorePredictor.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "BooksDB": "Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=BookApp;Integrated Security=True;" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Information", 8 | "Microsoft": "Warning", 9 | "Microsoft.Hosting.Lifetime": "Information" 10 | } 11 | }, 12 | "AllowedHosts": "*" 13 | } 14 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "BooksDB": "Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=BookApp;Integrated Security=True;" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Information", 8 | "Microsoft": "Warning", 9 | "Microsoft.Hosting.Lifetime": "Information" 10 | } 11 | }, 12 | "AllowedHosts": "*" 13 | } 14 | -------------------------------------------------------------------------------- /Chapter02/cs9-player-value-calculator/SoccerStats.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace IntroducingNet5.Chapter3.CS9PlayerValueCalculator 8 | { 9 | public class SoccerStats 10 | { 11 | public int GoalsScored { get; set; } 12 | public bool HasPlayedWorldCup { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter02/snippets/init-only-properties.linq: -------------------------------------------------------------------------------- 1 | 2 | 3 | void Main() 4 | { 5 | var p1 = new Player { PlayerId = 10,FirstName= "John" }; 6 | Console.WriteLine (p1.FirstName); 7 | } 8 | 9 | public class Player 10 | { 11 | public int PlayerId { get; init; } 12 | public string FirstName { get; set; } 13 | public string LastName { get; set; } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter07/SentimentAnalysis/ModelBuilderApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ModelBuilderApp 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | ModelBuilder.CreateModel(); 10 | Console.WriteLine("=============== Model created successfully, hit any key to finish ==============="); 11 | Console.ReadKey(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter02/cs9-performance/cs9-performance.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | IntroducingNet5.Chapter3.CS9Performance 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primecalculator/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "primecalculator": { 4 | "commandName": "Project", 5 | "dotnetRunMessages": "true", 6 | "launchBrowser": false, 7 | "applicationUrl": "http://localhost:5050;https://localhost:5051", 8 | "environmentVariables": { 9 | "ASPNETCORE_ENVIRONMENT": "Development" 10 | } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter02/snippets/type-inference-from-shared-base.linq: -------------------------------------------------------------------------------- 1 | 2 | 3 | void Main() 4 | { 5 | Animal animal=null; 6 | Tiger tiger=null; 7 | Animal someAnimal = animal ?? tiger; // Both share Animal type 8 | 9 | var items = new List{"Item1","Item2","Item3"}; 10 | items.ForEach(_ => Console.WriteLine("Another item processed")); 11 | 12 | } 13 | 14 | public class Animal{}; 15 | public class Tiger:Animal{}; 16 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/AdminDesktop/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/Models/BookApp.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 12.0.2 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/AdminDesktop/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/AdminDesktop/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/Models/BookApp.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 12.0.3 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/AdminDesktop/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/Models/BookApp.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 12.0.2 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/.dockerignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.dockerignore 3 | **/.env 4 | **/.git 5 | **/.gitignore 6 | **/.project 7 | **/.settings 8 | **/.toolstarget 9 | **/.vs 10 | **/.vscode 11 | **/*.*proj.user 12 | **/*.dbmdl 13 | **/*.jfm 14 | **/azds.yaml 15 | **/bin 16 | **/charts 17 | **/docker-compose* 18 | **/Dockerfile* 19 | **/node_modules 20 | **/npm-debug.log 21 | **/obj 22 | **/secrets.dev.yaml 23 | **/values.dev.yaml 24 | LICENSE 25 | README.md -------------------------------------------------------------------------------- /Chapter02/cs9-player-value-calculator/CricketStats.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace IntroducingNet5.Chapter3.CS9PlayerValueCalculator 8 | { 9 | public class CricketStats 10 | { 11 | public int RunsScored { get; set; } 12 | public int WicketsTaken { get; set; } 13 | public int MatchesPlayed { get; set; } 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter02/snippets/new-multiple-initializations.linq: -------------------------------------------------------------------------------- 1 | 2 | 3 | void Main() 4 | { 5 | Dictionary < string,List > citiesInCountries = new() 6 | { 7 | { "USA", new() { "New York", "Los Angeles", "Chicago", "Houston" } }, 8 | {"Australia", new() { "Sydney", "Melbourne", "Brisbane"} }, 9 | { "Canada", new() { "Ottawa","Toronto","Edmonton" } } 10 | }; 11 | 12 | Console.WriteLine(citiesInCountries["USA"][0]); 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter07/SentimentAnalysis/SentimentAnalysis.Models/SentimentInput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.ML.Data; 5 | 6 | namespace SentimentAnalysis.Models 7 | { 8 | public class SentimentInput 9 | { 10 | [ColumnName("text"), LoadColumn(0)] 11 | public string Text { get; set; } 12 | 13 | [ColumnName("sentiment"), LoadColumn(1)] 14 | public string Sentiment { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.DAL/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter02/snippets/records-equality.linq: -------------------------------------------------------------------------------- 1 | 2 | 3 | void Main() 4 | { 5 | 6 | var p1 = new Player ("John", "Citizen"); 7 | var p2 = new Player ("John", "Citizen"); 8 | 9 | Console.WriteLine(p1.Equals(p2)); // true, same values 10 | Console.WriteLine(p1 == p2); // true, == operator is generated to compare on same values 11 | Console.WriteLine(ReferenceEquals(p1,p2)); // false 12 | 13 | } 14 | 15 | public record Player(string FirstName, string LastName); 16 | 17 | 18 | -------------------------------------------------------------------------------- /Chapter02/snippets/records-with.linq: -------------------------------------------------------------------------------- 1 | 2 | 3 | void Main() 4 | { 5 | var player = new Player { PlayerId =10,FirstName = "John", LastName = "Citizen" }; 6 | 7 | var player2= player with { FirstName = "Ron" }; 8 | 9 | Console.WriteLine(player2.LastName); 10 | } 11 | 12 | public record Player 13 | { 14 | public int PlayerId { get; init; } 15 | public string FirstName { get; init; } 16 | public string LastName { get; init; } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeqconsumer/primeqconsumer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | dotnet-primeqconsumer-0FF6CEBD-3C61-4924-A77C-6177131284FD 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Chapter02/snippets/discard-lambdas.linq: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | void Main() 5 | { 6 | void MakeHttpCall(string url, out long timeTook) => 7 | timeTook = 100; 8 | 9 | void MakeCallToPackt() 10 | { 11 | MakeHttpCall("www.packt.com",out _); 12 | } 13 | 14 | MakeCallToPackt(); 15 | var items = new List{"Item1","Item2","Item3"}; 16 | items.ForEach(_ => Console.WriteLine("Another item processed")); 17 | } 18 | 19 | // You can define other methods, fields, classes and namespaces here 20 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primecalculator/Protos/prime.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option csharp_namespace = "microservicesapp"; 4 | 5 | package prime; 6 | 7 | //Service definition for the microservice: PrimeCalculator 8 | service PrimeCalculator { 9 | //Sends a true false if the number is prime or not 10 | rpc IsItPrime (PrimeRequest) returns (PrimeReply); 11 | } 12 | 13 | //Request message 14 | message PrimeRequest { 15 | int64 number = 1; 16 | } 17 | 18 | //Response message containing the result 19 | message PrimeReply { 20 | bool isPrime = 1; 21 | } 22 | -------------------------------------------------------------------------------- /Chapter02/snippets/records-equality-inheritance.linq: -------------------------------------------------------------------------------- 1 | 2 | 3 | void Main() 4 | { 5 | 6 | 7 | Player tennisPlayer1 = new TennisPlayer { age=39,FirstName="Roger",LastName="Federrer" }; 8 | Player player2 = new Player { FirstName = "Roger", LastName = "Federrer" }; 9 | 10 | Console.WriteLine(tennisPlayer1.Equals(player2) ); // false 11 | Console.WriteLine(player2.Equals(tennisPlayer1)); // false 12 | 13 | } 14 | 15 | public record Player {public string FirstName; public string LastName;}; 16 | 17 | public record TennisPlayer : Player { public int age; } 18 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/Models/BookReview.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace BookApp.Models 9 | { 10 | public class BookReview 11 | { 12 | public int Id { get; set; } 13 | public Book Book { get; set; } 14 | [Range(0, 5)] 15 | public int? Rating { get; set; } 16 | public string Review { get; set; } 17 | [Required] 18 | public string Title { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/Models/BookReview.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace BookApp.Models 9 | { 10 | public class BookReview 11 | { 12 | public int Id { get; set; } 13 | public Book Book { get; set; } 14 | [Range(0, 5)] 15 | public int? Rating { get; set; } 16 | public string Review { get; set; } 17 | [Required] 18 | public string Title { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter02/snippets/records-inheritance.linq: -------------------------------------------------------------------------------- 1 | 2 | 3 | void Main() 4 | { 5 | 6 | 7 | Player tennisPlayer1 = new TennisPlayer { age=39,FirstName="Roger",LastName="Federrer" }; 8 | Console.WriteLine((tennisPlayer1 as TennisPlayer).age); // 39 9 | 10 | Player tennisPlayer2 = tennisPlayer1 with { FirstName="Rafael", LastName = "Nadal" }; 11 | Console.WriteLine((tennisPlayer2 as TennisPlayer).age); // 39 12 | 13 | } 14 | 15 | public record Player {public string FirstName; public string LastName;}; 16 | 17 | public record TennisPlayer : Player { public int age; } 18 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/Models/BookReview.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace BookApp.Models 9 | { 10 | public class BookReview 11 | { 12 | public int Id { get; set; } 13 | public Book Book { get; set; } 14 | [Range(0, 5)] 15 | public int? Rating { get; set; } 16 | public string Review { get; set; } 17 | [Required] 18 | public string Title { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/Models/BookReview.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace BookApp.Models 9 | { 10 | public class BookReview 11 | { 12 | public int Id { get; set; } 13 | public Book Book { get; set; } 14 | [Range(0, 5)] 15 | public int? Rating { get; set; } 16 | public string Review { get; set; } 17 | [Required] 18 | public string Title { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter02/module-intializer/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace Preview 7 | { 8 | class Program 9 | { 10 | public static string ConnectionString; 11 | static void Main(string[] args) 12 | { 13 | Console.WriteLine($"ConnectionString = {ConnectionString}"); 14 | } 15 | 16 | 17 | [ModuleInitializer] 18 | public static void Initialize() 19 | { 20 | ConnectionString = "DB Connection String"; 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewBag.Title = "Home Page"; 3 | } 4 | 5 |
6 |

Book App .NET

7 |

8 | This sample app showcases migration of code from .NET Framework to .NET 5. 9 |

10 |
11 |
12 |
13 |

About the book

14 |

This sample application is part of the Packt book "Introducing .NET 5"

15 |

Check out the Packt Publishing books

16 |
17 |
-------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewBag.Title = "Home Page"; 3 | } 4 | 5 |
6 |

Book App .NET

7 |

8 | This sample app showcases migration of code from .NET Framework to .NET 5. 9 |

10 |
11 |
12 |
13 |

About the book

14 |

This sample application is part of the Packt book "Introducing .NET 5"

15 |

Check out the Packt Publishing books

16 |
17 |
-------------------------------------------------------------------------------- /Chapter01/Benchmarks/Benchmarks.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0;netcoreapp3.1;net48 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewBag.Title = "Home Page"; 3 | } 4 | 5 |
6 |

Book App .NET

7 |

8 | This sample app showcases migration of code from .NET Framework to .NET 5. 9 |

10 |
11 |
12 |
13 |

About the book

14 |

This sample application is part of the Packt book "Introducing .NET 5"

15 |

Check out the Packt Publishing books

16 |
17 |
-------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewBag.Title = "Home Page"; 3 | } 4 | 5 |
6 |

Book App .NET

7 |

8 | This sample app showcases migration of code from .NET Framework to .NET 5. 9 |

10 |
11 |
12 |
13 |

About the book

14 |

This sample application is part of the Packt book "Introducing .NET 5"

15 |

Check out the Packt Publishing books

16 |
17 |
-------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/Content/Site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | padding-bottom: 20px; 4 | } 5 | 6 | /* Set padding to keep content from hitting the edges */ 7 | .body-content { 8 | padding-left: 15px; 9 | padding-right: 15px; 10 | } 11 | 12 | /* Override the default bootstrap behavior where horizontal description lists 13 | will truncate terms that are too long to fit in the left column 14 | */ 15 | .dl-horizontal dt { 16 | white-space: normal; 17 | } 18 | 19 | /* Set width on the form input elements since they're 100% wide by default */ 20 | input, 21 | select, 22 | textarea { 23 | max-width: 280px; 24 | } 25 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeqconsumer/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using Microsoft.Extensions.Hosting; 3 | 4 | namespace primeqconsumer 5 | { 6 | public class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | CreateHostBuilder(args).Build().Run(); 11 | } 12 | 13 | public static IHostBuilder CreateHostBuilder(string[] args) => 14 | Host.CreateDefaultBuilder(args) 15 | .ConfigureServices((hostContext, services) => 16 | { 17 | services.AddHostedService(); 18 | }); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.SentimentAnalysisFunction/Startup.cs: -------------------------------------------------------------------------------- 1 | using BookApp.SentimentAnalysisFunction; 2 | using Microsoft.Azure.Functions.Extensions.DependencyInjection; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | [assembly: FunctionsStartup(typeof(Startup))] 9 | namespace BookApp.SentimentAnalysisFunction 10 | { 11 | public class Startup : FunctionsStartup 12 | { 13 | public override void Configure(IFunctionsHostBuilder builder) 14 | { 15 | builder.Services.AddSingleton(); 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "BooksDB": "Server=tcp:BookAppSQLServer2020.database.windows.net,1433;Database=BookApp;User ID=sqlserveradmin;Password=ASampleP@ssw0rd!;Encrypt=true;Connection Timeout=30" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Information", 8 | "Microsoft": "Warning", 9 | "Microsoft.Hosting.Lifetime": "Information" 10 | } 11 | }, 12 | "AllowedHosts": "*", 13 | "SentimentAnalysisService": { 14 | "URL": "https://sentimentanalysis2020.azurewebsites.net/api/GetSentiment", 15 | "Code": "1jCLHNSdZCTT2sXxB5XyJhScfObpnY1BdApeAs0nNrdRXMzZFPvzuQ==" 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter01/Benchmarks/Program.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using BenchmarkDotNet.Diagnosers; 3 | using BenchmarkDotNet.Running; 4 | using System; 5 | using System.Text; 6 | 7 | //Run with 8 | //dotnet run -c Release -f net48 --runtimes net48 netcoreapp3.1 netcoreapp5.0 --filter *Program* 9 | 10 | [MemoryDiagnoser] 11 | public class Program 12 | { 13 | static void Main(string[] args) => BenchmarkSwitcher.FromAssemblies(new[] { typeof(Program).Assembly }).Run(args); 14 | 15 | private byte[] _arr = Encoding.UTF8.GetBytes("Test to see improvements to IndexOfAny.. how are they?"); 16 | [Benchmark] public int IndexOf() => new Span(_arr).IndexOfAny((byte)'.', (byte)'?'); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.DAL/DI/BookAppDBModule.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace BookApp.DAL.DI 9 | { 10 | 11 | 12 | public class BookAppDBModule : Module 13 | { 14 | 15 | protected override void Load(ContainerBuilder builder) 16 | { 17 | builder 18 | .RegisterType().AsSelf() 19 | .InstancePerLifetimeScope(); 20 | 21 | builder.RegisterType().AsImplementedInterfaces().InstancePerLifetimeScope(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primecalculator/primecalculator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Chapter07/SpendScorePredictor/SpendScorePredictorML.Model/SpendScorePredictorML.Model.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | PreserveNewest 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace BookApp.Web 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter07/SpendScorePredictor/SpendScorePredictorML.ConsoleApp/SpendScorePredictorML.ConsoleApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Chapter03/tinyrp/SQLStudentRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | public class SQLStudentRepository : IStudentRepository 4 | { 5 | public Student Add(Student student) 6 | { 7 | throw new System.NotImplementedException(); 8 | } 9 | public Student Delete(int Id) 10 | { 11 | throw new System.NotImplementedException(); 12 | } 13 | public Student Get(int Id) 14 | { 15 | throw new System.NotImplementedException(); 16 | } 17 | public IEnumerable GetAllStudents() 18 | { 19 | throw new System.NotImplementedException(); 20 | } 21 | public Student Update(Student changedStudent) 22 | { 23 | throw new System.NotImplementedException(); 24 | } 25 | } -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.DAL/BooksDBContext.cs: -------------------------------------------------------------------------------- 1 | using BookApp.Models; 2 | using System.Data.Entity; 3 | using System.Data.Entity.ModelConfiguration.Conventions; 4 | 5 | namespace BookApp.DAL 6 | { 7 | public class BooksDBContext:DbContext 8 | { 9 | public BooksDBContext():base("BooksDB") 10 | { 11 | Database.SetInitializer(new BooksDBInitialiser()); 12 | } 13 | public DbSet Books { get; set; } 14 | public DbSet BookReviews { get; set; } 15 | 16 | protected override void OnModelCreating(DbModelBuilder modelBuilder) 17 | { 18 | modelBuilder.Conventions.Remove(); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | 7 | namespace BookApp.Web.Controllers 8 | { 9 | public class HomeController : Controller 10 | { 11 | public ActionResult Index() 12 | { 13 | return View(); 14 | } 15 | 16 | public ActionResult About() 17 | { 18 | ViewBag.Message = "Your application description page."; 19 | 20 | return View(); 21 | } 22 | 23 | public ActionResult Contact() 24 | { 25 | ViewBag.Message = "Your contact page."; 26 | 27 | return View(); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Chapter06/cli scripts/azure function scripts.txt: -------------------------------------------------------------------------------- 1 | # Creating the storage account 2 | resourcegroupname=bookAppResourceGroup 3 | locationname=australiaeast 4 | storageaccountname=bookappstorageaccount 5 | az storage account create -n $storageaccountname -g $resourcegroupname -l $locationname --sku Standard_LRS 6 | 7 | # Creating Function App 8 | functionappname=sentimentanalysis2020 9 | az functionapp create --consumption-plan-location $locationname --name $functionappname --os-type Windows --resource-group $resourcegroupname --runtime dotnet --storage-account $storageaccountname --functions-version 3 10 | 11 | # Obtaining function keys 12 | functionname=GetSentiment 13 | az functionapp function keys list -g $resourcegroupname -n $functionappname --function-name $functionname 14 | 15 | -------------------------------------------------------------------------------- /Chapter06/cli scripts/azure container instance scripts.txt: -------------------------------------------------------------------------------- 1 | # Creating the storage account 2 | resourcegroupname=bookAppResourceGroup 3 | locationname=australiaeast 4 | storageaccountname=bookappstorageaccount 5 | az storage account create -n $storageaccountname -g $resourcegroupname -l $locationname --sku Standard_LRS 6 | 7 | # Creating Function App 8 | functionappname=sentimentanalysis2020 9 | az functionapp create --consumption-plan-location $locationname --name $functionappname --os-type Windows --resource-group $resourcegroupname --runtime dotnet --storage-account $storageaccountname --functions-version 3 10 | 11 | # Obtaining function keys 12 | functionname=GetSentiment 13 | az functionapp function keys list -g $resourcegroupname -n $functionappname --function-name $functionname 14 | 15 | -------------------------------------------------------------------------------- /Chapter01/dummyapi31/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace dummyapi31 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter01/dummyapi50/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace dummyapi50 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/docker-compose.dcproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 2.1 5 | Linux 6 | 338356db-540b-4b21-ab62-7127c93fde64 7 | LaunchBrowser 8 | {Scheme}://localhost:{ServicePort} 9 | bookapp.web 10 | 11 | 12 | 13 | docker-compose.yml 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/Models/Book.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Diagnostics; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace BookApp.Models 11 | { 12 | public class Book 13 | { 14 | public int Id { get; set; } 15 | [Required] 16 | public string Title { get; set; } 17 | [Required] 18 | public string SubTitle { get; set; } 19 | public DateTime DatePublished { get; set; } = DateTime.Now; 20 | [JsonIgnore] 21 | public byte[] CoverImage { get; set; } 22 | [Required] 23 | public string Author { get; set; } 24 | public ICollection Reviews { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/Models/Book.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Diagnostics; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace BookApp.Models 11 | { 12 | public class Book 13 | { 14 | public int Id { get; set; } 15 | [Required] 16 | public string Title { get; set; } 17 | [Required] 18 | public string SubTitle { get; set; } 19 | public DateTime DatePublished { get; set; } = DateTime.Now; 20 | [JsonIgnore] 21 | public byte[] CoverImage { get; set; } 22 | [Required] 23 | public string Author { get; set; } 24 | public ICollection Reviews { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:62729", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "BookApp.Web.V3": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/Models/Book.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Diagnostics; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace BookApp.Models 11 | { 12 | public class Book 13 | { 14 | public int Id { get; set; } 15 | [Required] 16 | public string Title { get; set; } 17 | [Required] 18 | public string SubTitle { get; set; } 19 | public DateTime DatePublished { get; set; } = DateTime.Now; 20 | [JsonIgnore] 21 | public byte[] CoverImage { get; set; } 22 | [Required] 23 | public string Author { get; set; } 24 | public ICollection Reviews { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter07/SpendScorePredictor/SpendScorePredictorML.Model/ModelInput.cs: -------------------------------------------------------------------------------- 1 | // This file was auto-generated by ML.NET Model Builder. 2 | 3 | using Microsoft.ML.Data; 4 | 5 | namespace SpendScorePredictorML.Model 6 | { 7 | public class ModelInput 8 | { 9 | [ColumnName("CustomerID"), LoadColumn(0)] 10 | public float CustomerID { get; set; } 11 | 12 | 13 | [ColumnName("Gender"), LoadColumn(1)] 14 | public string Gender { get; set; } 15 | 16 | 17 | [ColumnName("Age"), LoadColumn(2)] 18 | public float Age { get; set; } 19 | 20 | 21 | [ColumnName("AnnualIncome"), LoadColumn(3)] 22 | public float AnnualIncome { get; set; } 23 | 24 | 25 | [ColumnName("SpendingScore"), LoadColumn(4)] 26 | public float SpendingScore { get; set; } 27 | 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/Models/Book.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Diagnostics; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace BookApp.Models 11 | { 12 | public class Book 13 | { 14 | public int Id { get; set; } 15 | [Required] 16 | public string Title { get; set; } 17 | [Required] 18 | public string SubTitle { get; set; } 19 | public DateTime DatePublished { get; set; } = DateTime.Now; 20 | [JsonIgnore] 21 | public byte[] CoverImage { get; set; } 22 | [Required] 23 | public string Author { get; set; } 24 | public ICollection Reviews { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:62729", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "BookApp.Web.V3": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.Hosting; 4 | using Microsoft.Extensions.Logging; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace BookApp.Web.V3 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.Hosting; 4 | using Microsoft.Extensions.Logging; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace BookApp.Web.V3 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.Hosting; 4 | using Microsoft.Extensions.Logging; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace BookApp.Web.V3 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.SentimentAnalysisFunction/BookApp.SentimentAnalysisFunction.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netcoreapp3.1 4 | v3 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | PreserveNewest 13 | 14 | 15 | PreserveNewest 16 | Never 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primecalculator/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Extensions.Hosting; 3 | 4 | namespace primecalculator 5 | { 6 | public class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | CreateHostBuilder(args).Build().Run(); 11 | } 12 | 13 | // Additional configuration is required to successfully run gRPC on macOS. 14 | // For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682 15 | public static IHostBuilder CreateHostBuilder(string[] args) => 16 | Host.CreateDefaultBuilder(args) 17 | .ConfigureWebHostDefaults(webBuilder => 18 | { 19 | webBuilder.UseStartup(); 20 | }); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.DAL/DI/BookAppDBModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace BookApp.DAL.DI 10 | { 11 | 12 | 13 | public static class BookAppDBDIModule 14 | { 15 | 16 | public static IServiceCollection AddBookAppDB(this IServiceCollection services,string sqlConnection) 17 | { 18 | 19 | var dbOptions = new DbContextOptionsBuilder(); 20 | dbOptions.UseSqlServer(sqlConnection); 21 | services.AddSingleton(x => dbOptions.Options); 22 | services.AddScoped(); 23 | 24 | return services; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.DAL/DI/BookAppDBModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace BookApp.DAL.DI 10 | { 11 | 12 | 13 | public static class BookAppDBDIModule 14 | { 15 | 16 | public static IServiceCollection AddBookAppDB(this IServiceCollection services,string sqlConnection) 17 | { 18 | 19 | var dbOptions = new DbContextOptionsBuilder(); 20 | dbOptions.UseSqlServer(sqlConnection); 21 | services.AddSingleton(x => dbOptions.Options); 22 | services.AddScoped(); 23 | 24 | return services; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.DAL/DI/BookAppDBModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace BookApp.DAL.DI 10 | { 11 | 12 | 13 | public static class BookAppDBDIModule 14 | { 15 | 16 | public static IServiceCollection AddBookAppDB(this IServiceCollection services,string sqlConnection) 17 | { 18 | 19 | var dbOptions = new DbContextOptionsBuilder(); 20 | dbOptions.UseSqlServer(sqlConnection); 21 | services.AddSingleton(x => dbOptions.Options); 22 | services.AddScoped(); 23 | 24 | return services; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Dockerfile: -------------------------------------------------------------------------------- 1 | #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. 2 | 3 | FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base 4 | WORKDIR /app 5 | EXPOSE 80 6 | 7 | FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build 8 | WORKDIR /src 9 | COPY ["BookApp.Web.V2/BookApp.Web.csproj", "BookApp.Web.V2/"] 10 | COPY ["BookApp.DAL/BookApp.DAL.csproj", "BookApp.DAL/"] 11 | COPY ["Models/BookApp.Models.csproj", "Models/"] 12 | RUN dotnet restore "BookApp.Web.V2/BookApp.Web.csproj" 13 | COPY . . 14 | WORKDIR "/src/BookApp.Web.V2" 15 | RUN dotnet build "BookApp.Web.csproj" -c Release -o /app/build 16 | 17 | FROM build AS publish 18 | RUN dotnet publish "BookApp.Web.csproj" -c Release -o /app/publish 19 | 20 | FROM base AS final 21 | WORKDIR /app 22 | COPY --from=publish /app/publish . 23 | ENTRYPOINT ["dotnet", "BookApp.Web.dll"] 24 | -------------------------------------------------------------------------------- /Chapter01/dummyapi31/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:62971", 8 | "sslPort": 44359 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "weatherforecast", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "dummyapi31": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "weatherforecast", 24 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.DAL/BookApp.DAL.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | BookApp.Models 15 | 16 | 17 | 18 | 19 | 20 | 21 | 2.10.0 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.DAL/BookApp.DAL.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | BookApp.Models 15 | 16 | 17 | 18 | 19 | 20 | 21 | 2.10.0 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.DAL/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.DAL/BookApp.DAL.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | BookApp.Models 15 | 16 | 17 | 18 | 19 | 20 | 21 | 2.10.1-dev-01249 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter01/dummyapi50/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:34377", 8 | "sslPort": 44387 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "dummyapi50": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": "true", 23 | "launchBrowser": true, 24 | "launchUrl": "swagger", 25 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:62729", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "BookApp.Web.V3": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "dotnetRunMessages": "true", 25 | "applicationUrl": "http://localhost:5000" 26 | }, 27 | "Docker": { 28 | "commandName": "Docker", 29 | "launchBrowser": true, 30 | "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", 31 | "publishAllPorts": true 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Chapter04/microservicesapp/redis.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: redis 5 | labels: 6 | app.kubernetes.io/name: redis 7 | app.kubernetes.io/part-of: microservicesapp 8 | spec: 9 | selector: 10 | matchLabels: 11 | app.kubernetes.io/name: redis 12 | replicas: 1 13 | template: 14 | metadata: 15 | labels: 16 | app.kubernetes.io/name: redis 17 | app.kubernetes.io/part-of: microservicesapp 18 | spec: 19 | containers: 20 | - name: redis 21 | image: redis 22 | resources: 23 | requests: 24 | cpu: 100m 25 | memory: 100Mi 26 | ports: 27 | - containerPort: 6379 28 | 29 | --- 30 | apiVersion: v1 31 | kind: Service 32 | metadata: 33 | name: redis 34 | labels: 35 | app.kubernetes.io/name: redis 36 | app.kubernetes.io/part-of: microservicesapp 37 | spec: 38 | ports: 39 | - port: 6379 40 | targetPort: 6379 41 | selector: 42 | app.kubernetes.io/name: redis 43 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/AdminDesktop/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter02/snippets/switch-on-type.linq: -------------------------------------------------------------------------------- 1 | 2 | false 3 | 4 | 5 | void Main() 6 | { 7 | cs9samples.CS7TypeSwitch.Run(); 8 | } 9 | 10 | namespace cs9samples 11 | { 12 | public interface Shape{ } 13 | 14 | public class Square : Shape { } 15 | public class Circle : Shape { } 16 | public class Rectangle : Shape { } 17 | public class Triangle : Shape { } 18 | 19 | public static class CS7TypeSwitch 20 | { 21 | public static bool HasFourSides(this T shape) where T :Shape 22 | { 23 | switch (shape) 24 | { 25 | case Square: return true; 26 | case Circle: return false; 27 | case Rectangle: return true; 28 | default: throw new ApplicationException("Unknown Shape Type"); 29 | } 30 | } 31 | 32 | public static void Run() 33 | { 34 | Console.WriteLine(new Square().HasFourSides()); 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/BookApp.Web.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | true 15 | PreserveNewest 16 | 17 | 18 | true 19 | PreserveNewest 20 | 21 | 22 | true 23 | PreserveNewest 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/BookApp.Web.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | true 15 | PreserveNewest 16 | 17 | 18 | true 19 | PreserveNewest 20 | 21 | 22 | true 23 | PreserveNewest 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Chapter02/cs9-player-value-calculator/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IntroducingNet5.Chapter3.CS9PlayerValueCalculator 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | var service = new PlayerValueCalculatorService(); 10 | 11 | var value1 = service.GetPlayerValue_1( 12 | new CricketStats {RunsScored=100 } 13 | ); 14 | 15 | Console.WriteLine(value1); 16 | 17 | var value2 = service.GetPlayerValue_2( 18 | new SoccerStats { GoalsScored = 100,HasPlayedWorldCup=true } 19 | ); 20 | 21 | Console.WriteLine(value2); 22 | 23 | var value3 = service.GetPlayerValue_3( 24 | new CricketStats { MatchesPlayed=110,RunsScored=200 } 25 | ); 26 | 27 | Console.WriteLine(value3); 28 | 29 | var value4 = service.GetPlayerValue_4( 30 | new TennisStats { SetsWon=200 },BrandSize.Large 31 | ); 32 | 33 | Console.WriteLine(value4); 34 | 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using BookApp.Web.V3.Models; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.Extensions.Logging; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Diagnostics; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace BookApp.Web.V3.Controllers 11 | { 12 | public class HomeController : Controller 13 | { 14 | private readonly ILogger _logger; 15 | 16 | public HomeController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | public ActionResult Index() 22 | { 23 | return View(); 24 | } 25 | 26 | public ActionResult About() 27 | { 28 | ViewBag.Message = "Your application description page."; 29 | 30 | return View(); 31 | } 32 | 33 | public ActionResult Contact() 34 | { 35 | ViewBag.Message = "Your contact page."; 36 | 37 | return View(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using BookApp.Web.V3.Models; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.Extensions.Logging; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Diagnostics; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace BookApp.Web.V3.Controllers 11 | { 12 | public class HomeController : Controller 13 | { 14 | private readonly ILogger _logger; 15 | 16 | public HomeController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | public ActionResult Index() 22 | { 23 | return View(); 24 | } 25 | 26 | public ActionResult About() 27 | { 28 | ViewBag.Message = "Your application description page."; 29 | 30 | return View(); 31 | } 32 | 33 | public ActionResult Contact() 34 | { 35 | ViewBag.Message = "Your contact page."; 36 | 37 | return View(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using BookApp.Web.V3.Models; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.Extensions.Logging; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Diagnostics; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace BookApp.Web.V3.Controllers 11 | { 12 | public class HomeController : Controller 13 | { 14 | private readonly ILogger _logger; 15 | 16 | public HomeController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | public ActionResult Index() 22 | { 23 | return View(); 24 | } 25 | 26 | public ActionResult About() 27 | { 28 | ViewBag.Message = "Your application description page."; 29 | 30 | return View(); 31 | } 32 | 33 | public ActionResult Contact() 34 | { 35 | ViewBag.Message = "Your contact page."; 36 | 37 | return View(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Chapter01/Benchmarks/Program4.csx: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using BenchmarkDotNet.Diagnosers; 3 | using BenchmarkDotNet.Running; 4 | using System; 5 | using System.Buffers.Text; 6 | using System.Collections; 7 | using System.Collections.Concurrent; 8 | using System.Collections.Generic; 9 | using System.Collections.Immutable; 10 | using System.IO; 11 | using System.Linq; 12 | using System.Net; 13 | using System.Net.Http; 14 | using System.Net.Security; 15 | using System.Net.Sockets; 16 | using System.Runtime.CompilerServices; 17 | using System.Threading; 18 | using System.Threading.Tasks; 19 | using System.Text; 20 | using System.Text.Json; 21 | using System.Text.RegularExpressions; 22 | 23 | //Run with 24 | //dotnet run -c Release -f net48 --runtimes net48 netcoreapp3.1 netcoreapp5.0 --filter *Program* 25 | 26 | [MemoryDiagnoser] 27 | public class Program 28 | { 29 | static void Main(string[] args) => BenchmarkSwitcher.FromAssemblies(new[] { typeof(Program).Assembly }).Run(args); 30 | 31 | private int[] _arr = Enumerable.Range(0, 256).ToArray(); 32 | 33 | [Benchmark] 34 | public void Reverse() => Array.Reverse(_arr); 35 | } 36 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.DAL/Utilities.cs: -------------------------------------------------------------------------------- 1 | using Serilog; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace BookApp.DAL 10 | { 11 | public static class Utilities 12 | { 13 | 14 | public static byte[] ExtractImage(String fileName) 15 | { 16 | System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); 17 | Stream resFilestream = assembly.GetManifestResourceStream(assembly.GetName().Name + ".Resources." + fileName); 18 | if (resFilestream != null) 19 | { 20 | BinaryReader br = new BinaryReader(resFilestream); 21 | byte[] ba = new byte[resFilestream.Length]; 22 | resFilestream.Read(ba, 0, ba.Length); 23 | br.Close(); 24 | return ba; 25 | } 26 | else 27 | { 28 | Log.Warning("Embedded Resource with name {fileName} not found", fileName); 29 | return null; 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.DAL/Utilities.cs: -------------------------------------------------------------------------------- 1 | using Serilog; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace BookApp.DAL 10 | { 11 | public static class Utilities 12 | { 13 | 14 | public static byte[] ExtractImage(String fileName) 15 | { 16 | System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); 17 | Stream resFilestream = assembly.GetManifestResourceStream(assembly.GetName().Name + ".Resources." + fileName); 18 | if (resFilestream != null) 19 | { 20 | BinaryReader br = new BinaryReader(resFilestream); 21 | byte[] ba = new byte[resFilestream.Length]; 22 | resFilestream.Read(ba, 0, ba.Length); 23 | br.Close(); 24 | return ba; 25 | } 26 | else 27 | { 28 | Log.Warning("Embedded Resource with name {fileName} not found", fileName); 29 | return null; 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.DAL/Utilities.cs: -------------------------------------------------------------------------------- 1 | using Serilog; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace BookApp.DAL 10 | { 11 | public static class Utilities 12 | { 13 | 14 | public static byte[] ExtractImage(String fileName) 15 | { 16 | System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); 17 | Stream resFilestream = assembly.GetManifestResourceStream(assembly.GetName().Name + ".Resources." + fileName); 18 | if (resFilestream != null) 19 | { 20 | BinaryReader br = new BinaryReader(resFilestream); 21 | byte[] ba = new byte[resFilestream.Length]; 22 | resFilestream.Read(ba, 0, ba.Length); 23 | br.Close(); 24 | return ba; 25 | } 26 | else 27 | { 28 | Log.Warning("Embedded Resource with name {fileName} not found", fileName); 29 | return null; 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.DAL/Utilities.cs: -------------------------------------------------------------------------------- 1 | using Serilog; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace BookApp.DAL 10 | { 11 | public static class Utilities 12 | { 13 | 14 | public static byte[] ExtractImage(String fileName) 15 | { 16 | System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); 17 | Stream resFilestream = assembly.GetManifestResourceStream(assembly.GetName().Name + ".Resources." + fileName); 18 | if (resFilestream != null) 19 | { 20 | BinaryReader br = new BinaryReader(resFilestream); 21 | byte[] ba = new byte[resFilestream.Length]; 22 | resFilestream.Read(ba, 0, ba.Length); 23 | br.Close(); 24 | return ba; 25 | } 26 | else 27 | { 28 | Log.Warning("Embedded Resource with name {fileName} not found", fileName); 29 | return null; 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclientb/primeclientb.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | dotnet-primeclientb-BD7AB3F1-910C-43CA-BF9A-BDDAFA38FE9E 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | runtime; build; native; contentfiles; analyzers; buildtransitive 14 | all 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Protos\prime.proto 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclientc/primeclientc.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | dotnet-primeclientc-5F9982B4-2225-4466-9836-3BAC7BDD3A03 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | runtime; build; native; contentfiles; analyzers; buildtransitive 14 | all 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Protos\prime.proto 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter01/Benchmarks/Program3.csx: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using BenchmarkDotNet.Diagnosers; 3 | using BenchmarkDotNet.Running; 4 | using System; 5 | using System.Buffers.Text; 6 | using System.Collections; 7 | using System.Collections.Concurrent; 8 | using System.Collections.Generic; 9 | using System.Collections.Immutable; 10 | using System.IO; 11 | using System.Linq; 12 | using System.Net; 13 | using System.Net.Http; 14 | using System.Net.Security; 15 | using System.Net.Sockets; 16 | using System.Runtime.CompilerServices; 17 | using System.Threading; 18 | using System.Threading.Tasks; 19 | using System.Text; 20 | using System.Text.Json; 21 | using System.Text.RegularExpressions; 22 | 23 | //Run with 24 | //dotnet run -c Release -f net48 --runtimes net48 netcoreapp3.1 netcoreapp5.0 --filter *Program* 25 | 26 | [MemoryDiagnoser] 27 | public class Program 28 | { 29 | static void Main(string[] args) => BenchmarkSwitcher.FromAssemblies(new[] { typeof(Program).Assembly }).Run(args); 30 | 31 | private string _src = "This is a source string that needs to be capitalized."; 32 | private char[] _dst = new char[1024]; 33 | [Benchmark] public int ToUpperInvariant() => _src.AsSpan().ToUpperInvariant(_dst); 34 | } 35 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/AdminDesktop/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace BookApp.AdminDesktop.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/AdminDesktop/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace BookApp.AdminDesktop.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter02/cs9-performance/cs9-performance.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30404.54 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "cs9-performance", "cs9-performance.csproj", "{F611BD71-DF9F-4F4B-B173-2099720E7F0F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {F611BD71-DF9F-4F4B-B173-2099720E7F0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {F611BD71-DF9F-4F4B-B173-2099720E7F0F}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {F611BD71-DF9F-4F4B-B173-2099720E7F0F}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {F611BD71-DF9F-4F4B-B173-2099720E7F0F}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {A315D90A-DEA7-4CB8-BF4D-F0865F0857A3} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/AdminDesktop/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace BookApp.AdminDesktop.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/AdminDesktop/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace AdminDesktop.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclienta/primeclienta.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | dotnet-primeclienta-4C1BF1C9-7DA3-459E-8DD8-15B12C0AD17C 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | runtime; build; native; contentfiles; analyzers; buildtransitive 14 | all 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | Protos\prime.proto 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter02/cs9-player-value-calculator/cs9-player-value-calculator.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30404.54 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "cs9-player-value-calculator", "cs9-player-value-calculator.csproj", "{F611BD71-DF9F-4F4B-B173-2099720E7F0F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {F611BD71-DF9F-4F4B-B173-2099720E7F0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {F611BD71-DF9F-4F4B-B173-2099720E7F0F}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {F611BD71-DF9F-4F4B-B173-2099720E7F0F}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {F611BD71-DF9F-4F4B-B173-2099720E7F0F}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {A315D90A-DEA7-4CB8-BF4D-F0865F0857A3} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primecalculator/Extensions/RabbitMQServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using primecalculator.Messaging; 3 | using System; 4 | 5 | namespace primecalculator.Extensions 6 | { 7 | /// 8 | /// Extension methods for setting up IMQClient services in an . 9 | /// 10 | public static class RabbitMQServiceCollectionExtensions 11 | { 12 | /// 13 | /// Adds Rabbit Message Queuing services to the specified . 14 | /// 15 | /// The to add services to. 16 | /// The so that additional calls can be chained. 17 | public static IServiceCollection AddRabbitMQ(this IServiceCollection services) 18 | { 19 | if (services == null) 20 | { 21 | throw new ArgumentNullException(nameof(services)); 22 | } 23 | 24 | services.Add(ServiceDescriptor.Singleton()); 25 | services.Add(ServiceDescriptor.Singleton()); 26 | 27 | return services; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/AdminDesktop/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/Views/BookReviews/Delete.cshtml: -------------------------------------------------------------------------------- 1 | @model BookApp.Models.BookReview 2 | 3 | @{ 4 | ViewBag.Title = "Delete"; 5 | } 6 | 7 |

Delete

8 | 9 |

Are you sure you want to delete this?

10 |
11 |

Book Review For - @Model.Book.Title

12 |
13 |
14 |
15 | @Html.DisplayNameFor(model => model.Rating) 16 |
17 | 18 |
19 | @Html.DisplayFor(model => model.Rating) 20 |
21 | 22 |
23 | @Html.DisplayNameFor(model => model.Review) 24 |
25 | 26 |
27 | @Html.DisplayFor(model => model.Review) 28 |
29 | 30 |
31 | @Html.DisplayNameFor(model => model.Title) 32 |
33 | 34 |
35 | @Html.DisplayFor(model => model.Title) 36 |
37 | 38 |
39 | 40 | @using (Html.BeginForm()) 41 | { 42 | @Html.AntiForgeryToken() 43 | 44 |
45 | @Html.Hidden("bookId", Model.Book.Id, new { @Id = "bookId" }) 46 | | 47 | @Html.ActionLink("Back to List", "Index", "Books", new { id = Model.Id }, null) 48 |
49 | } 50 |
51 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/AdminDesktop/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Properties/PublishProfiles/bookapp2020.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | Custom 9 | true 10 | /subscriptions/0e257083-102e-48d2-807d-0421f0b04ab6/resourceGroups/bookAppResourceGroup/providers/Microsoft.ContainerRegistry/registries/bookapp2020 11 | bookapp2020 12 | bookAppResourceGroup 13 | Free Trial 14 | https://bookapp2020.azurecr.io 15 | 16 | latest 17 | ContainerRegistry 18 | Release 19 | Any CPU 20 | 2c2181b3-a12d-4d27-826c-4dc9f63b7415 21 | 22 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Views/BookReviews/Delete.cshtml: -------------------------------------------------------------------------------- 1 | @model BookApp.Models.BookReview 2 | 3 | @{ 4 | ViewBag.Title = "Delete"; 5 | } 6 | 7 |

Delete

8 | 9 |

Are you sure you want to delete this?

10 |
11 |

Book Review For - @Model.Book.Title

12 |
13 |
14 |
15 | @Html.DisplayNameFor(model => model.Rating) 16 |
17 | 18 |
19 | @Html.DisplayFor(model => model.Rating) 20 |
21 | 22 |
23 | @Html.DisplayNameFor(model => model.Review) 24 |
25 | 26 |
27 | @Html.DisplayFor(model => model.Review) 28 |
29 | 30 |
31 | @Html.DisplayNameFor(model => model.Title) 32 |
33 | 34 |
35 | @Html.DisplayFor(model => model.Title) 36 |
37 | 38 |
39 | 40 | @using (Html.BeginForm()) 41 | { 42 | @Html.AntiForgeryToken() 43 | 44 |
45 | @Html.Hidden("bookId", Model.Book.Id, new { @Id = "bookId" }) 46 | | 47 | @Html.ActionLink("Back to List", "Index", "Books", new { id = Model.Id }, null) 48 |
49 | } 50 |
51 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/AdminDesktop/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Chapter01/Benchmarks/Program5.csx: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using BenchmarkDotNet.Diagnosers; 3 | using BenchmarkDotNet.Running; 4 | using System; 5 | using System.Buffers.Text; 6 | using System.Collections; 7 | using System.Collections.Concurrent; 8 | using System.Collections.Generic; 9 | using System.Collections.Immutable; 10 | using System.IO; 11 | using System.Linq; 12 | using System.Net; 13 | using System.Net.Http; 14 | using System.Net.Security; 15 | using System.Net.Sockets; 16 | using System.Runtime.CompilerServices; 17 | using System.Threading; 18 | using System.Threading.Tasks; 19 | using System.Text; 20 | //using System.Text.Json; 21 | using System.Text.RegularExpressions; 22 | 23 | //Run with 24 | //dotnet run -c Release -f net48 --runtimes net48 netcoreapp3.1 netcoreapp5.0 --filter *Program* 25 | 26 | [MemoryDiagnoser] 27 | public class Program 28 | { 29 | static void Main(string[] args) => BenchmarkSwitcher.FromAssemblies(new[] { typeof(Program).Assembly }).Run(args); 30 | 31 | private static byte[] ArrayProp { get; } = new byte[] { 1, 2, 3 }; 32 | 33 | [Benchmark(Baseline = true)] 34 | public ReadOnlySpan GetArrayProp() => ArrayProp; 35 | 36 | private static ReadOnlySpan SpanProp => new byte[] { 1, 2, 3 }; 37 | 38 | [Benchmark] 39 | public ReadOnlySpan GetSpanProp() => SpanProp; 40 | } 41 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/Views/BookReviews/Delete.cshtml: -------------------------------------------------------------------------------- 1 | @model BookApp.Models.BookReview 2 | 3 | @{ 4 | ViewBag.Title = "Delete"; 5 | } 6 | 7 |

Delete

8 | 9 |

Are you sure you want to delete this?

10 |
11 |

Book Review For - @Model.Book.Title

12 |
13 |
14 |
15 | @Html.DisplayNameFor(model => model.Rating) 16 |
17 | 18 |
19 | @Html.DisplayFor(model => model.Rating) 20 |
21 | 22 |
23 | @Html.DisplayNameFor(model => model.Review) 24 |
25 | 26 |
27 | @Html.DisplayFor(model => model.Review) 28 |
29 | 30 |
31 | @Html.DisplayNameFor(model => model.Title) 32 |
33 | 34 |
35 | @Html.DisplayFor(model => model.Title) 36 |
37 | 38 |
39 | 40 | @using (Html.BeginForm()) 41 | { 42 | @Html.AntiForgeryToken() 43 | 44 |
45 | @Html.HiddenFor(m => m.Book.Id, new { Name = "bookId" }) 46 | | 47 | @Html.ActionLink("Back to List", "Index", "Books", new { id = Model.Id }, null) 48 |
49 | } 50 |
51 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/Views/BookReviews/Delete.cshtml: -------------------------------------------------------------------------------- 1 | @model BookApp.Models.BookReview 2 | 3 | @{ 4 | ViewBag.Title = "Delete"; 5 | } 6 | 7 |

Delete

8 | 9 |

Are you sure you want to delete this?

10 |
11 |

Book Review For - @Model.Book.Title

12 |
13 |
14 |
15 | @Html.DisplayNameFor(model => model.Rating) 16 |
17 | 18 |
19 | @Html.DisplayFor(model => model.Rating) 20 |
21 | 22 |
23 | @Html.DisplayNameFor(model => model.Review) 24 |
25 | 26 |
27 | @Html.DisplayFor(model => model.Review) 28 |
29 | 30 |
31 | @Html.DisplayNameFor(model => model.Title) 32 |
33 | 34 |
35 | @Html.DisplayFor(model => model.Title) 36 |
37 | 38 |
39 | 40 | @using (Html.BeginForm()) 41 | { 42 | @Html.AntiForgeryToken() 43 | 44 |
45 | @Html.Hidden("bookId", Model.Book.Id, new { @Id = "bookId" }) 46 | | 47 | @Html.ActionLink("Back to List", "Index", "Books", new { id = Model.Id }, null) 48 |
49 | } 50 |
51 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclienta/Program.cs: -------------------------------------------------------------------------------- 1 | using microservicesapp; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Microsoft.Extensions.Hosting; 5 | using System; 6 | 7 | namespace primeclienta 8 | { 9 | public class Program 10 | { 11 | private static readonly Uri MANUAL_DEBUGTIME_URI = new Uri("https://localhost:5051"); //From launchSettings of the primecalculator 12 | 13 | public static void Main(string[] args) 14 | { 15 | CreateHostBuilder(args).Build().Run(); 16 | } 17 | 18 | public static IHostBuilder CreateHostBuilder(string[] args) => 19 | Host.CreateDefaultBuilder(args) 20 | .ConfigureServices((hostContext, services) => 21 | { 22 | var configurationFromHostBuilderContext = hostContext.Configuration; 23 | 24 | services.AddHostedService(); 25 | 26 | services.AddGrpcClient(o => 27 | { 28 | //primecalculator will be inject to configuration via Tye 29 | o.Address = configurationFromHostBuilderContext.GetServiceUri("primecalculator") ?? MANUAL_DEBUGTIME_URI; 30 | }); 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclientb/Program.cs: -------------------------------------------------------------------------------- 1 | using microservicesapp; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Microsoft.Extensions.Hosting; 5 | using System; 6 | 7 | namespace primeclientb 8 | { 9 | public class Program 10 | { 11 | private static readonly Uri MANUAL_DEBUGTIME_URI = new Uri("https://localhost:5051"); //From launchSettings of the primecalculator 12 | 13 | public static void Main(string[] args) 14 | { 15 | CreateHostBuilder(args).Build().Run(); 16 | } 17 | 18 | public static IHostBuilder CreateHostBuilder(string[] args) => 19 | Host.CreateDefaultBuilder(args) 20 | .ConfigureServices((hostContext, services) => 21 | { 22 | var configurationFromHostBuilderContext = hostContext.Configuration; 23 | 24 | services.AddHostedService(); 25 | 26 | services.AddGrpcClient(o => 27 | { 28 | //primecalculator will be inject to configuration via Tye 29 | o.Address = configurationFromHostBuilderContext.GetServiceUri("primecalculator") ?? MANUAL_DEBUGTIME_URI; 30 | }); 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/primeclientc/Program.cs: -------------------------------------------------------------------------------- 1 | using microservicesapp; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Microsoft.Extensions.Hosting; 5 | using System; 6 | 7 | namespace primeclientc 8 | { 9 | public class Program 10 | { 11 | private static readonly Uri MANUAL_DEBUGTIME_URI = new Uri("https://localhost:5051"); //From launchSettings of the primecalculator 12 | 13 | public static void Main(string[] args) 14 | { 15 | CreateHostBuilder(args).Build().Run(); 16 | } 17 | 18 | public static IHostBuilder CreateHostBuilder(string[] args) => 19 | Host.CreateDefaultBuilder(args) 20 | .ConfigureServices((hostContext, services) => 21 | { 22 | var configurationFromHostBuilderContext = hostContext.Configuration; 23 | 24 | services.AddHostedService(); 25 | 26 | services.AddGrpcClient(o => 27 | { 28 | //primecalculator will be inject to configuration via Tye 29 | o.Address = configurationFromHostBuilderContext.GetServiceUri("primecalculator") ?? MANUAL_DEBUGTIME_URI; 30 | }); 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/AdminDesktop/BookApp.AdminDesktop.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | WinExe 6 | true 7 | 8 | 9 | 10 | 11 | BookApp.DAL 12 | 13 | 14 | BookApp.Models 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 12.0.2 23 | 24 | 25 | 2.10.0 26 | 27 | 28 | 29 | 30 | PreserveNewest 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/App_Start/BundleConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Optimization; 3 | 4 | namespace BookApp.Web 5 | { 6 | public class BundleConfig 7 | { 8 | // For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862 9 | public static void RegisterBundles(BundleCollection bundles) 10 | { 11 | bundles.Add(new ScriptBundle("~/bundles/jquery").Include( 12 | "~/Scripts/jquery-{version}.js")); 13 | 14 | bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( 15 | "~/Scripts/jquery.validate*")); 16 | 17 | // Use the development version of Modernizr to develop with and learn from. Then, when you're 18 | // ready for production, use the build tool at https://modernizr.com to pick only the tests you need. 19 | bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( 20 | "~/Scripts/modernizr-*")); 21 | 22 | bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( 23 | "~/Scripts/bootstrap.js")); 24 | 25 | bundles.Add(new StyleBundle("~/Content/css").Include( 26 | "~/Content/bootstrap.css", 27 | "~/Content/site.css")); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Properties/PublishProfiles/bookApp2020 - FTP.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | FTP 9 | AzureWebSite 10 | Release 11 | Any CPU 12 | http://bookapp2020.azurewebsites.net 13 | True 14 | False 15 | 2c2181b3-a12d-4d27-826c-4dc9f63b7415 16 | ftp://waws-prod-sy3-023.ftp.azurewebsites.windows.net 17 | False 18 | True 19 | site/wwwroot 20 | bookApp2020\$bookApp2020 21 | <_SavePWD>True 22 | 23 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/AdminDesktop/BookApp.AdminDesktop.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | WinExe 6 | true 7 | 8 | 9 | 10 | 11 | BookApp.DAL 12 | 13 | 14 | BookApp.Models 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 12.0.2 23 | 24 | 25 | 2.10.0 26 | 27 | 28 | 29 | 30 | PreserveNewest 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Chapter07/SentimentAnalysis/BookApp.SentimentAnalysisFunction/SentimentAnaysisService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.Extensions.ML; 3 | using SentimentAnalysis.Models; 4 | using System.Linq; 5 | using System.Security.Cryptography.X509Certificates; 6 | 7 | namespace BookApp.SentimentAnalysisFunction 8 | { 9 | public class SentimentAnaysisService : ISentimentAnaysisService 10 | { 11 | private readonly PredictionEnginePool predictionEnginePool; 12 | 13 | public SentimentAnaysisService(PredictionEnginePool predictionEnginePool) 14 | { 15 | this.predictionEnginePool = predictionEnginePool; 16 | } 17 | 18 | public Sentiment GetSentiment(string text) 19 | { 20 | var input = new SentimentInput 21 | { 22 | Text = text 23 | }; 24 | 25 | var prediction = predictionEnginePool.Predict(modelName: "SentimentAnalysisModel", example: input); 26 | 27 | var confidence = prediction.Prediction == "0" ? prediction.Score[0] : prediction.Score[1]; 28 | if (confidence < 0.7) 29 | return Sentiment.Neutral; 30 | 31 | return (prediction.Prediction=="1") ? Sentiment.Positive : Sentiment.Negative; 32 | 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/AdminDesktop/BookApp.AdminDesktop.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | WinExe 6 | true 7 | 8 | 9 | 10 | 11 | BookApp.DAL 12 | 13 | 14 | BookApp.Models 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 12.0.3 23 | 24 | 25 | 2.10.1-dev-01249 26 | 27 | 28 | 29 | 30 | PreserveNewest 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Properties/PublishProfiles/bookApp2020 - ReadOnly - FTP.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | FTP 9 | AzureWebSite 10 | Release 11 | Any CPU 12 | http://bookapp2020.azurewebsites.net 13 | True 14 | False 15 | 2c2181b3-a12d-4d27-826c-4dc9f63b7415 16 | ftp://waws-prod-sy3-023dr.ftp.azurewebsites.windows.net 17 | False 18 | True 19 | site/wwwroot 20 | bookApp2020\$bookApp2020 21 | <_SavePWD>True 22 | 23 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/tye.yaml: -------------------------------------------------------------------------------- 1 | # tye application configuration file 2 | # read all about it at https://github.com/dotnet/tye 3 | # 4 | # when you've given us a try, we'd love to know what you think: 5 | # https://aka.ms/AA7q20u 6 | # 7 | name: microservicesapp 8 | registry: localhost:5000 9 | services: 10 | - name: primecalculator 11 | tags: 12 | - be 13 | project: primecalculator/primecalculator.csproj 14 | replicas: 3 15 | env: 16 | - RABBIT_USER=guest 17 | - RABBIT_PSWD=guest 18 | - RABBIT_QUEUE=primes 19 | - name: primeclienta 20 | tags: 21 | - cl 22 | project: primeclienta/primeclienta.csproj 23 | replicas: 3 24 | - name: primeclientb 25 | tags: 26 | - cl 27 | project: primeclientb/primeclientb.csproj 28 | replicas: 3 29 | - name: primeclientc 30 | tags: 31 | - cl 32 | project: primeclientc/primeclientc.csproj 33 | replicas: 3 34 | - name: primeqconsumer 35 | tags: 36 | - mw 37 | project: primeqconsumer/primeqconsumer.csproj 38 | replicas: 1 39 | - name: redis 40 | tags: 41 | - be 42 | image: redis 43 | bindings: 44 | - port: 6379 45 | connectionString: "${host}:${port}" 46 | - name: redis-cli 47 | tags: 48 | - be 49 | image: redis 50 | args: "redis-cli -h redis MONITOR" 51 | - name: rabbitmq 52 | tags: 53 | - mw 54 | image: rabbitmq:3-management 55 | bindings: 56 | - port: 5672 57 | protocol: rabbitmq -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/tye_rabbit_unnamedbinding.yaml: -------------------------------------------------------------------------------- 1 | # tye application configuration file 2 | # read all about it at https://github.com/dotnet/tye 3 | # 4 | # when you've given us a try, we'd love to know what you think: 5 | # https://aka.ms/AA7q20u 6 | # 7 | name: microservicesapp 8 | registry: localhost:5000 9 | services: 10 | - name: primecalculator 11 | tags: 12 | - be 13 | project: primecalculator/primecalculator.csproj 14 | replicas: 3 15 | env: 16 | - RABBIT_USER=guest 17 | - RABBIT_PSWD=guest 18 | - RABBIT_QUEUE=primes 19 | - name: primeclienta 20 | tags: 21 | - cl 22 | project: primeclienta/primeclienta.csproj 23 | replicas: 3 24 | - name: primeclientb 25 | tags: 26 | - cl 27 | project: primeclientb/primeclientb.csproj 28 | replicas: 3 29 | - name: primeclientc 30 | tags: 31 | - cl 32 | project: primeclientc/primeclientc.csproj 33 | replicas: 3 34 | - name: primeqconsumer 35 | tags: 36 | - mw 37 | project: primeqconsumer/primeqconsumer.csproj 38 | replicas: 1 39 | - name: redis 40 | tags: 41 | - be 42 | image: redis 43 | bindings: 44 | - port: 6379 45 | connectionString: "${host}:${port}" 46 | - name: redis-cli 47 | tags: 48 | - be 49 | image: redis 50 | args: "redis-cli -h redis MONITOR" 51 | - name: rabbitmq 52 | tags: 53 | - mw 54 | image: rabbitmq:3-management 55 | bindings: 56 | - port: 5672 57 | protocol: rabbitmq -------------------------------------------------------------------------------- /Chapter07/SpendScorePredictor/SpendScorePredictorML.ConsoleApp/Program.cs: -------------------------------------------------------------------------------- 1 | // This file was auto-generated by ML.NET Model Builder. 2 | 3 | using System; 4 | using SpendScorePredictorML.Model; 5 | 6 | namespace SpendScorePredictorML.ConsoleApp 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | // Create single instance of sample data from first line of dataset for model input 13 | ModelInput sampleData = new ModelInput() 14 | { 15 | Gender = @"Male", 16 | Age = 29F, 17 | AnnualIncome = 15F, 18 | }; 19 | 20 | // Make a single prediction on the sample data and print results 21 | var predictionResult = ConsumeModel.Predict(sampleData); 22 | 23 | Console.WriteLine("Using model to make single prediction -- Comparing actual SpendingScore with predicted SpendingScore from sample data...\n\n"); 24 | Console.WriteLine($"Gender: {sampleData.Gender}"); 25 | Console.WriteLine($"Age: {sampleData.Age}"); 26 | Console.WriteLine($"AnnualIncome: {sampleData.AnnualIncome}"); 27 | Console.WriteLine($"\n\nPredicted SpendingScore: {predictionResult.Score}\n\n"); 28 | Console.WriteLine("=============== End of process, hit any key to finish ==============="); 29 | Console.ReadKey(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Integration.Mvc; 3 | using BookApp.DAL.DI; 4 | using Serilog; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Web; 9 | using System.Web.Mvc; 10 | using System.Web.Optimization; 11 | using System.Web.Routing; 12 | 13 | namespace BookApp.Web 14 | { 15 | public class MvcApplication : HttpApplication 16 | { 17 | protected void Application_Start() 18 | { 19 | AreaRegistration.RegisterAllAreas(); 20 | FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 21 | RouteConfig.RegisterRoutes(RouteTable.Routes); 22 | BundleConfig.RegisterBundles(BundleTable.Bundles); 23 | 24 | ConfigureDependencyInjection(); 25 | } 26 | 27 | protected void Application_Error() 28 | { 29 | var ex = Server.GetLastError(); 30 | Log.Error(ex,ex.Message); 31 | } 32 | private void ConfigureDependencyInjection() 33 | { 34 | var builder = new ContainerBuilder(); 35 | 36 | builder.RegisterControllers(typeof(MvcApplication).Assembly); 37 | builder.RegisterModule(new BookAppDBModule()); 38 | 39 | IContainer container = builder.Build(); 40 | DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); 41 | 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/AdminDesktop/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/AdminDesktop/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using BookApp.DAL; 3 | using BookApp.DAL.DI; 4 | using Serilog; 5 | using System; 6 | using System.Windows; 7 | 8 | namespace AdminDesktop 9 | { 10 | /// 11 | /// Interaction logic for App.xaml 12 | /// 13 | public partial class App : Application 14 | { 15 | 16 | private IContainer container; 17 | 18 | public App() 19 | { 20 | InitialiseDI(); 21 | AppDomain currentDomain = AppDomain.CurrentDomain; 22 | currentDomain.UnhandledException += new UnhandledExceptionEventHandler(GlobalExceptionHandler); 23 | } 24 | 25 | private void InitialiseDI() 26 | { 27 | 28 | var builder = new ContainerBuilder(); 29 | builder.RegisterType().AsSelf().SingleInstance(); 30 | builder.RegisterModule(new BookAppDBModule()); 31 | 32 | container = builder.Build(); 33 | } 34 | 35 | 36 | private void OnStartup(object sender, StartupEventArgs e) 37 | { 38 | var mainWindow = container.Resolve(); 39 | mainWindow.Show(); 40 | } 41 | 42 | static void GlobalExceptionHandler(object sender, UnhandledExceptionEventArgs args) 43 | { 44 | Exception e = (Exception)args.ExceptionObject; 45 | Log.Error(e.Message); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Chapter07/SentimentAnalysis/ModelBuilderApp/ModelBuilderApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | PreserveNewest 15 | 16 | 17 | PreserveNewest 18 | 19 | 20 | PreserveNewest 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Chapter01/Benchmarks/Program2.csx: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using BenchmarkDotNet.Diagnosers; 3 | using BenchmarkDotNet.Running; 4 | using System; 5 | using System.Buffers.Text; 6 | using System.Collections; 7 | using System.Collections.Concurrent; 8 | using System.Collections.Generic; 9 | using System.Collections.Immutable; 10 | using System.Globalization; 11 | using System.IO; 12 | using System.Linq; 13 | using System.Net; 14 | using System.Net.Http; 15 | using System.Net.Security; 16 | using System.Net.Sockets; 17 | using System.Runtime.CompilerServices; 18 | using System.Threading; 19 | using System.Threading.Tasks; 20 | using System.Text; 21 | using System.Text.Json; 22 | using System.Text.RegularExpressions; 23 | 24 | //Run with 25 | //dotnet run -c Release -f net48 --runtimes net48 netcoreapp3.1 netcoreapp5.0 --filter *Program* 26 | 27 | [MemoryDiagnoser] 28 | public class Program 29 | { 30 | static void Main(string[] args) => BenchmarkSwitcher.FromAssemblies(new[] { typeof(Program).Assembly }).Run(args); 31 | 32 | private Task _incomplete = new TaskCompletionSource().Task; 33 | 34 | [Benchmark] 35 | public Task OneAlreadyCompleted() => Task.WhenAny(Task.CompletedTask, _incomplete); 36 | 37 | [Benchmark] 38 | public Task AsyncCompletion() 39 | { 40 | AsyncTaskMethodBuilder atmb = default; 41 | Task result = Task.WhenAny(atmb.Task, _incomplete); 42 | atmb.SetResult(); 43 | return result; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Chapter07/SentimentAnalysis/BookApp.SentimentAnalysisFunction/BookApp.SentimentAnalysisFunction.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netcoreapp3.1 4 | v3 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | PreserveNewest 15 | 16 | 17 | PreserveNewest 18 | Never 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | PreserveNewest 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/tye_rabbit_namedbinding.yaml: -------------------------------------------------------------------------------- 1 | # tye application configuration file 2 | # read all about it at https://github.com/dotnet/tye 3 | # 4 | # when you've given us a try, we'd love to know what you think: 5 | # https://aka.ms/AA7q20u 6 | # 7 | name: microservicesapp 8 | registry: localhost:5000 9 | services: 10 | - name: primecalculator 11 | tags: 12 | - be 13 | project: primecalculator/primecalculator.csproj 14 | replicas: 3 15 | env: 16 | - RABBIT_USER=guest 17 | - RABBIT_PSWD=guest 18 | - RABBIT_QUEUE=primes 19 | - name: primeclienta 20 | tags: 21 | - cl 22 | project: primeclienta/primeclienta.csproj 23 | replicas: 3 24 | - name: primeclientb 25 | tags: 26 | - cl 27 | project: primeclientb/primeclientb.csproj 28 | replicas: 3 29 | - name: primeclientc 30 | tags: 31 | - cl 32 | project: primeclientc/primeclientc.csproj 33 | replicas: 3 34 | - name: primeqconsumer 35 | tags: 36 | - mw 37 | project: primeqconsumer/primeqconsumer.csproj 38 | replicas: 1 39 | - name: redis 40 | tags: 41 | - be 42 | image: redis 43 | bindings: 44 | - port: 6379 45 | connectionString: "${host}:${port}" 46 | - name: redis-cli 47 | tags: 48 | - be 49 | image: redis 50 | args: "redis-cli -h redis MONITOR" 51 | - name: rabbitmq 52 | tags: 53 | - mw 54 | image: rabbitmq:3-management 55 | bindings: 56 | - name: mq_binding 57 | port: 5672 58 | protocol: rabbitmq 59 | - name: mui_binding 60 | port: 15672 -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Views/BookReviews/_GetSentiment.cshtml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.SentimentAnalysisFunction/SentimentFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Threading.Tasks; 4 | using Microsoft.AspNetCore.Mvc; 5 | using Microsoft.Azure.WebJobs; 6 | using Microsoft.Azure.WebJobs.Extensions.Http; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.Logging; 9 | using Newtonsoft.Json; 10 | 11 | namespace BookApp.SentimentAnalysisFunction 12 | { 13 | public class SentimentFunction 14 | { 15 | private readonly ISentimentAnaysisService sentimentAnaysisService; 16 | public SentimentFunction(ISentimentAnaysisService sentimentAnaysisService) 17 | { 18 | this.sentimentAnaysisService = sentimentAnaysisService; 19 | } 20 | 21 | [FunctionName("GetSentiment")] 22 | public async Task Run( 23 | [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, 24 | ILogger log) 25 | { 26 | log.LogInformation("C# HTTP trigger function processed a request."); 27 | 28 | string text = req.Query["text"]; 29 | 30 | string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); 31 | dynamic data = JsonConvert.DeserializeObject(requestBody); 32 | text = text ?? data?.text; 33 | 34 | 35 | var result = sentimentAnaysisService.GetSentiment(text); 36 | 37 | return new OkObjectResult(result); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Chapter07/SentimentAnalysis/BookApp.SentimentAnalysisFunction/SentimentFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Threading.Tasks; 4 | using Microsoft.AspNetCore.Mvc; 5 | using Microsoft.Azure.WebJobs; 6 | using Microsoft.Azure.WebJobs.Extensions.Http; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.Logging; 9 | using Newtonsoft.Json; 10 | 11 | namespace BookApp.SentimentAnalysisFunction 12 | { 13 | public class SentimentFunction 14 | { 15 | private readonly ISentimentAnaysisService sentimentAnaysisService; 16 | public SentimentFunction(ISentimentAnaysisService sentimentAnaysisService) 17 | { 18 | this.sentimentAnaysisService = sentimentAnaysisService; 19 | } 20 | 21 | [FunctionName("GetSentiment")] 22 | public async Task Run( 23 | [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, 24 | ILogger log) 25 | { 26 | log.LogInformation("C# HTTP trigger function processed a request."); 27 | 28 | string text = req.Query["text"]; 29 | 30 | string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); 31 | dynamic data = JsonConvert.DeserializeObject(requestBody); 32 | text = text ?? data?.text; 33 | 34 | 35 | var result = sentimentAnaysisService.GetSentiment(text); 36 | 37 | return new OkObjectResult(result); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Chapter06/cli scripts/sql migration scripts.txt: -------------------------------------------------------------------------------- 1 | # Getting the list of available locations 2 | az account list-locations -o table 3 | 4 | 5 | # Creating a resource group 6 | resourceGroupName=bookAppResourceGroup 7 | location=australiaeast 8 | az group create --name $resourceGroupName --location $location 9 | 10 | 11 | # Creating SQL Server in Azure 12 | adminlogin=sqlserveradmin 13 | password=ASampleP@ssw0rd! 14 | serverName=BookAppSQLServer2020 15 | 16 | az sql server create \ 17 | --name $serverName \ 18 | --resource-group $resourceGroupName \ 19 | --location $location \ 20 | --admin-user $adminlogin \ 21 | --admin-password $password 22 | 23 | 24 | #Whitelisting IP Addresses 25 | startip=118.211.162.81 26 | endip=118.211.162.81 27 | az sql server firewall-rule create \ 28 | --resource-group $resourceGroupName \ 29 | --server $serverName \ 30 | -n DeveloperLocalIP \ 31 | --start-ip-address $startip \ 32 | --end-ip-address $endip 33 | az sql server firewall-rule create \ 34 | --resource-group $resourceGroupName \ 35 | --server $serverName \ 36 | -n AzureServices \ 37 | --start-ip-address 0.0.0.0 \ 38 | --end-ip-address 0.0.0.0 39 | 40 | 41 | # Creating SQL database 42 | az sql db create \ 43 | --resource-group $resourceGroupName \ 44 | --server $serverName \ 45 | --name BookApp \ 46 | --service-objective Basic 47 | 48 | # Querying the database 49 | SELECT TOP 10 * FROM [Book] 50 | Inner Join BookReview 51 | ON Book.Id = BookReview.Book_Id 52 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BookApp.Web")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("BookApp.Web")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c75b0c42-ab66-4a4b-a991-265536dc8ca9")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /Chapter04/microservicesapp/rabbitmq.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: rabbitmq 5 | labels: 6 | app.kubernetes.io/name: rabbitmq 7 | app.kubernetes.io/part-of: microservicesapp 8 | spec: 9 | selector: 10 | matchLabels: 11 | app.kubernetes.io/name: rabbitmq 12 | replicas: 1 13 | template: 14 | metadata: 15 | labels: 16 | app.kubernetes.io/name: rabbitmq 17 | app.kubernetes.io/part-of: microservicesapp 18 | spec: 19 | containers: 20 | - name: rabbitmq 21 | image: rabbitmq:3-management 22 | resources: 23 | requests: 24 | cpu: 100m 25 | memory: 100Mi 26 | ports: 27 | - containerPort: 5672 28 | - containerPort: 15672 29 | 30 | --- 31 | apiVersion: v1 32 | kind: Service 33 | metadata: 34 | name: rabbitmq 35 | labels: 36 | app.kubernetes.io/name: rabbitmq 37 | app.kubernetes.io/part-of: microservicesapp 38 | spec: 39 | ports: 40 | - port: 5672 41 | protocol: TCP 42 | targetPort: 5672 43 | selector: 44 | app.kubernetes.io/name: rabbitmq 45 | --- 46 | apiVersion: v1 47 | kind: Service 48 | metadata: 49 | name: rabbitmq-mui 50 | labels: 51 | app.kubernetes.io/name: rabbitmq 52 | app.kubernetes.io/part-of: microservicesapp 53 | spec: 54 | type: NodePort 55 | ports: 56 | - port: 15672 57 | protocol: TCP 58 | targetPort: 15672 59 | nodePort: 30072 60 | selector: 61 | app.kubernetes.io/name: rabbitmq 62 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/Views/Books/Details.cshtml: -------------------------------------------------------------------------------- 1 | @model BookApp.Models.Book 2 | 3 | @{ 4 | ViewBag.Title = "Details"; 5 | } 6 | 7 |

Details

8 | 9 |
10 |

Book

11 |
12 |
13 |
14 | @Html.DisplayNameFor(model => model.Title) 15 |
16 | 17 |
18 | @Html.DisplayFor(model => model.Title) 19 |
20 | 21 |
22 | @Html.DisplayNameFor(model => model.SubTitle) 23 |
24 | 25 |
26 | @Html.DisplayFor(model => model.SubTitle) 27 |
28 | 29 |
30 | @Html.DisplayNameFor(model => model.DatePublished) 31 |
32 | 33 |
34 | Date Published 35 |
36 | 37 |
38 | Cover Image 39 |
40 | 41 |
42 | @if (Model.CoverImage != null) 43 | { 44 | 45 | } 46 | 47 |
48 | 49 |
50 | @Html.DisplayNameFor(model => model.Author) 51 |
52 | 53 |
54 | @Html.DisplayFor(model => model.Author) 55 |
56 | 57 |
58 |
59 |

60 | @Html.ActionLink("Reviews", "Index", "BookReviews", new { id = Model.Id }, null) | 61 | @Html.ActionLink("Back to List", "Index") 62 |

63 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Properties/PublishProfiles/bookApp2020 - Web Deploy.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | MSDeploy 9 | AzureWebSite 10 | Release 11 | Any CPU 12 | http://bookapp2020.azurewebsites.net 13 | True 14 | False 15 | 2c2181b3-a12d-4d27-826c-4dc9f63b7415 16 | bookapp2020.scm.azurewebsites.net:443 17 | bookApp2020 18 | 19 | True 20 | WMSVC 21 | True 22 | $bookApp2020 23 | <_SavePWD>True 24 | <_DestinationType>AzureWebSite 25 | 26 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Views/Books/Details.cshtml: -------------------------------------------------------------------------------- 1 | @model BookApp.Models.Book 2 | 3 | @{ 4 | ViewBag.Title = "Details"; 5 | } 6 | 7 |

Details

8 | 9 |
10 |

Book

11 |
12 |
13 |
14 | @Html.DisplayNameFor(model => model.Title) 15 |
16 | 17 |
18 | @Html.DisplayFor(model => model.Title) 19 |
20 | 21 |
22 | @Html.DisplayNameFor(model => model.SubTitle) 23 |
24 | 25 |
26 | @Html.DisplayFor(model => model.SubTitle) 27 |
28 | 29 |
30 | @Html.DisplayNameFor(model => model.DatePublished) 31 |
32 | 33 |
34 | Date Published 35 |
36 | 37 |
38 | Cover Image 39 |
40 | 41 |
42 | @if (Model.CoverImage != null) 43 | { 44 | 45 | } 46 | 47 |
48 | 49 |
50 | @Html.DisplayNameFor(model => model.Author) 51 |
52 | 53 |
54 | @Html.DisplayFor(model => model.Author) 55 |
56 | 57 |
58 |
59 |

60 | @Html.ActionLink("Reviews", "Index", "BookReviews", new { id = Model.Id }, null) | 61 | @Html.ActionLink("Back to List", "Index") 62 |

63 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/Views/Books/Details.cshtml: -------------------------------------------------------------------------------- 1 | @model BookApp.Models.Book 2 | 3 | @{ 4 | ViewBag.Title = "Details"; 5 | } 6 | 7 |

Details

8 | 9 |
10 |

Book

11 |
12 |
13 |
14 | @Html.DisplayNameFor(model => model.Title) 15 |
16 | 17 |
18 | @Html.DisplayFor(model => model.Title) 19 |
20 | 21 |
22 | @Html.DisplayNameFor(model => model.SubTitle) 23 |
24 | 25 |
26 | @Html.DisplayFor(model => model.SubTitle) 27 |
28 | 29 |
30 | @Html.DisplayNameFor(model => model.DatePublished) 31 |
32 | 33 |
34 | Date Published 35 |
36 | 37 |
38 | Cover Image 39 |
40 | 41 |
42 | @if (Model.CoverImage != null) 43 | { 44 | 45 | } 46 | 47 |
48 | 49 |
50 | @Html.DisplayNameFor(model => model.Author) 51 |
52 | 53 |
54 | @Html.DisplayFor(model => model.Author) 55 |
56 | 57 |
58 |
59 |

60 | @Html.ActionLink("Reviews", "Index", "BookReviews", new { id = Model.Id }, null) | 61 | @Html.ActionLink("Back to List", "Index") 62 |

63 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/Views/Books/Details.cshtml: -------------------------------------------------------------------------------- 1 | @model BookApp.Models.Book 2 | 3 | @{ 4 | ViewBag.Title = "Details"; 5 | } 6 | 7 |

Details

8 | 9 |
10 |

Book

11 |
12 |
13 |
14 | @Html.DisplayNameFor(model => model.Title) 15 |
16 | 17 |
18 | @Html.DisplayFor(model => model.Title) 19 |
20 | 21 |
22 | @Html.DisplayNameFor(model => model.SubTitle) 23 |
24 | 25 |
26 | @Html.DisplayFor(model => model.SubTitle) 27 |
28 | 29 |
30 | @Html.DisplayNameFor(model => model.DatePublished) 31 |
32 | 33 |
34 | Date Published 35 |
36 | 37 |
38 | Cover Image 39 |
40 | 41 |
42 | @if (Model.CoverImage != null) 43 | { 44 | 45 | } 46 | 47 |
48 | 49 |
50 | @Html.DisplayNameFor(model => model.Author) 51 |
52 | 53 |
54 | @Html.DisplayFor(model => model.Author) 55 |
56 | 57 |
58 |
59 |

60 | @Html.ActionLink("Reviews", "Index", "BookReviews", new { id = Model.Id }, null) | 61 | @Html.ActionLink("Back to List", "Index") 62 |

63 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/BookApp.Web.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 5e7819b3-da31-4d5b-8ba9-b100eeed7713 6 | 7 | 8 | 9 | false 10 | ..\docker-compose.dcproj 11 | Linux 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | true 26 | PreserveNewest 27 | 28 | 29 | true 30 | PreserveNewest 31 | 32 | 33 | true 34 | PreserveNewest 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/Models/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BookApp.Models")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Models")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c873adba-e37d-4844-8053-0141ce91ffc4")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/AdminDesktop/ImageConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows.Data; 9 | using System.Windows.Media.Imaging; 10 | 11 | namespace AdminDesktop 12 | { 13 | public class ImageConverter:IValueConverter 14 | { 15 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 16 | { 17 | if (value != null) 18 | { 19 | byte[] byteArray = (byte[])value; 20 | 21 | if (byteArray == null) 22 | return null; 23 | BitmapImage image = new BitmapImage(); 24 | using (MemoryStream imageStream = new MemoryStream()) 25 | { 26 | imageStream.Write(byteArray, 0, byteArray.Length); 27 | imageStream.Seek(0, SeekOrigin.Begin); 28 | image.BeginInit(); 29 | image.CacheOption = BitmapCacheOption.OnLoad; 30 | image.StreamSource = imageStream; 31 | image.EndInit(); 32 | image.Freeze(); 33 | } 34 | return image; 35 | } 36 | return null; 37 | } 38 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 39 | { 40 | throw new NotImplementedException(); 41 | } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.DAL/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BookApp.DAL")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("BookApp.DAL")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("fd3755fa-b71d-43ac-aa15-f7126d676ddb")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/AdminDesktop/ImageConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows.Data; 9 | using System.Windows.Media.Imaging; 10 | 11 | namespace AdminDesktop 12 | { 13 | public class ImageConverter:IValueConverter 14 | { 15 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 16 | { 17 | if (value != null) 18 | { 19 | byte[] byteArray = (byte[])value; 20 | 21 | if (byteArray == null) 22 | return null; 23 | BitmapImage image = new BitmapImage(); 24 | using (MemoryStream imageStream = new MemoryStream()) 25 | { 26 | imageStream.Write(byteArray, 0, byteArray.Length); 27 | imageStream.Seek(0, SeekOrigin.Begin); 28 | image.BeginInit(); 29 | image.CacheOption = BitmapCacheOption.OnLoad; 30 | image.StreamSource = imageStream; 31 | image.EndInit(); 32 | image.Freeze(); 33 | } 34 | return image; 35 | } 36 | return null; 37 | } 38 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 39 | { 40 | throw new NotImplementedException(); 41 | } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/AdminDesktop/ImageConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows.Data; 9 | using System.Windows.Media.Imaging; 10 | 11 | namespace AdminDesktop 12 | { 13 | public class ImageConverter:IValueConverter 14 | { 15 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 16 | { 17 | if (value != null) 18 | { 19 | byte[] byteArray = (byte[])value; 20 | 21 | if (byteArray == null) 22 | return null; 23 | BitmapImage image = new BitmapImage(); 24 | using (MemoryStream imageStream = new MemoryStream()) 25 | { 26 | imageStream.Write(byteArray, 0, byteArray.Length); 27 | imageStream.Seek(0, SeekOrigin.Begin); 28 | image.BeginInit(); 29 | image.CacheOption = BitmapCacheOption.OnLoad; 30 | image.StreamSource = imageStream; 31 | image.EndInit(); 32 | image.Freeze(); 33 | } 34 | return image; 35 | } 36 | return null; 37 | } 38 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 39 | { 40 | throw new NotImplementedException(); 41 | } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/AdminDesktop/ImageConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows.Data; 9 | using System.Windows.Media.Imaging; 10 | 11 | namespace AdminDesktop 12 | { 13 | public class ImageConverter:IValueConverter 14 | { 15 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 16 | { 17 | if (value != null) 18 | { 19 | byte[] byteArray = (byte[])value; 20 | 21 | if (byteArray == null) 22 | return null; 23 | BitmapImage image = new BitmapImage(); 24 | using (MemoryStream imageStream = new MemoryStream()) 25 | { 26 | imageStream.Write(byteArray, 0, byteArray.Length); 27 | imageStream.Seek(0, SeekOrigin.Begin); 28 | image.BeginInit(); 29 | image.CacheOption = BitmapCacheOption.OnLoad; 30 | image.StreamSource = imageStream; 31 | image.EndInit(); 32 | image.Freeze(); 33 | } 34 | return image; 35 | } 36 | return null; 37 | } 38 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 39 | { 40 | throw new NotImplementedException(); 41 | } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Chapter07/SpendScorePredictor/SpendScorePredictorML.Model/ConsumeModel.cs: -------------------------------------------------------------------------------- 1 | // This file was auto-generated by ML.NET Model Builder. 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using Microsoft.ML; 8 | using SpendScorePredictorML.Model; 9 | 10 | namespace SpendScorePredictorML.Model 11 | { 12 | public class ConsumeModel 13 | { 14 | private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); 15 | 16 | // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume 17 | // Method for consuming model in your app 18 | public static ModelOutput Predict(ModelInput input) 19 | { 20 | ModelOutput result = PredictionEngine.Value.Predict(input); 21 | return result; 22 | } 23 | 24 | public static PredictionEngine CreatePredictionEngine() 25 | { 26 | // Create new MLContext 27 | MLContext mlContext = new MLContext(); 28 | 29 | // Load model & create prediction engine 30 | string modelPath = @"C:\Users\Default\AppData\Local\Temp\MLVSTools\SpendScorePredictorML\SpendScorePredictorML.Model\MLModel.zip"; 31 | ITransformer mlModel = mlContext.Model.Load(modelPath, out var modelInputSchema); 32 | var predEngine = mlContext.Model.CreatePredictionEngine(mlModel); 33 | 34 | return predEngine; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter05/net5/BookApp/BookApp.Web.V2/Views/Books/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model IEnumerable 2 | 3 | @{ 4 | ViewBag.Title = "Books List"; 5 | } 6 | 7 |

Books List

8 | 9 | 10 | 11 | 14 | 17 | 20 | 23 | 26 | 27 | 28 | 29 | @foreach (var item in Model) { 30 | 31 | 34 | 37 | 40 | 46 | 49 | 53 | 54 | } 55 | 56 |
12 | @Html.DisplayNameFor(model => model.Title) 13 | 15 | @Html.DisplayNameFor(model => model.SubTitle) 16 | 18 | Date Published 19 | 21 | Cover Image 22 | 24 | @Html.DisplayNameFor(model => model.Author) 25 |
32 | @Html.DisplayFor(modelItem => item.Title) 33 | 35 | @Html.DisplayFor(modelItem => item.SubTitle) 36 | 38 | @item.DatePublished.ToString("d") 39 | 41 | @if (item.CoverImage != null) 42 | { 43 | 44 | } 45 | 47 | @Html.DisplayFor(modelItem => item.Author) 48 | 50 | @Html.ActionLink("Details", "Details", new { id = item.Id }) | 51 | @Html.ActionLink("Reviews", "Index", "BookReviews", new { id = item.Id },null) 52 |
57 | -------------------------------------------------------------------------------- /Chapter06/azure/BookApp/BookApp.Web.V2/Views/Books/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model IEnumerable 2 | 3 | @{ 4 | ViewBag.Title = "Books List"; 5 | } 6 | 7 |

Books List

8 | 9 | 10 | 11 | 14 | 17 | 20 | 23 | 26 | 27 | 28 | 29 | @foreach (var item in Model) { 30 | 31 | 34 | 37 | 40 | 46 | 49 | 53 | 54 | } 55 | 56 |
12 | @Html.DisplayNameFor(model => model.Title) 13 | 15 | @Html.DisplayNameFor(model => model.SubTitle) 16 | 18 | Date Published 19 | 21 | Cover Image 22 | 24 | @Html.DisplayNameFor(model => model.Author) 25 |
32 | @Html.DisplayFor(modelItem => item.Title) 33 | 35 | @Html.DisplayFor(modelItem => item.SubTitle) 36 | 38 | @item.DatePublished.ToString("d") 39 | 41 | @if (item.CoverImage != null) 42 | { 43 | 44 | } 45 | 47 | @Html.DisplayFor(modelItem => item.Author) 48 | 50 | @Html.ActionLink("Details", "Details", new { id = item.Id }) | 51 | @Html.ActionLink("Reviews", "Index", "BookReviews", new { id = item.Id },null) 52 |
57 | -------------------------------------------------------------------------------- /Chapter06/onprem/BookApp/BookApp.Web.V2/Views/Books/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model IEnumerable 2 | 3 | @{ 4 | ViewBag.Title = "Books List"; 5 | } 6 | 7 |

Books List

8 | 9 | 10 | 11 | 14 | 17 | 20 | 23 | 26 | 27 | 28 | 29 | @foreach (var item in Model) { 30 | 31 | 34 | 37 | 40 | 46 | 49 | 53 | 54 | } 55 | 56 |
12 | @Html.DisplayNameFor(model => model.Title) 13 | 15 | @Html.DisplayNameFor(model => model.SubTitle) 16 | 18 | Date Published 19 | 21 | Cover Image 22 | 24 | @Html.DisplayNameFor(model => model.Author) 25 |
32 | @Html.DisplayFor(modelItem => item.Title) 33 | 35 | @Html.DisplayFor(modelItem => item.SubTitle) 36 | 38 | @item.DatePublished.ToString("d") 39 | 41 | @if (item.CoverImage != null) 42 | { 43 | 44 | } 45 | 47 | @Html.DisplayFor(modelItem => item.Author) 48 | 50 | @Html.ActionLink("Details", "Details", new { id = item.Id }) | 51 | @Html.ActionLink("Reviews", "Index", "BookReviews", new { id = item.Id },null) 52 |
57 | -------------------------------------------------------------------------------- /Chapter05/netframework472/BookApp/BookApp.Web/Views/Books/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model IEnumerable 2 | 3 | @{ 4 | ViewBag.Title = "Books List"; 5 | } 6 | 7 |

Books List

8 | 9 | 10 | 11 | 14 | 17 | 20 | 23 | 26 | 27 | 28 | 29 | @foreach (var item in Model) { 30 | 31 | 34 | 37 | 40 | 46 | 49 | 53 | 54 | } 55 | 56 |
12 | @Html.DisplayNameFor(model => model.Title) 13 | 15 | @Html.DisplayNameFor(model => model.SubTitle) 16 | 18 | Date Published 19 | 21 | Cover Image 22 | 24 | @Html.DisplayNameFor(model => model.Author) 25 |
32 | @Html.DisplayFor(modelItem => item.Title) 33 | 35 | @Html.DisplayFor(modelItem => item.SubTitle) 36 | 38 | @item.DatePublished.ToString("d") 39 | 41 | @if (item.CoverImage != null) 42 | { 43 | 44 | } 45 | 47 | @Html.DisplayFor(modelItem => item.Author) 48 | 50 | @Html.ActionLink("Details", "Details", new { id = item.Id }) | 51 | @Html.ActionLink("Reviews", "Index", "BookReviews", new { id = item.Id },null) 52 |
57 | --------------------------------------------------------------------------------