diff --git a/samples/datasync-server/.gitignore b/samples/datasync-server/.gitignore new file mode 100644 index 0000000..a348e8f --- /dev/null +++ b/samples/datasync-server/.gitignore @@ -0,0 +1,633 @@ +# Created by https://www.toptal.com/developers/gitignore/api/visualstudio,rider,visualstudiocode,dotnetcore,aspnetcore +# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudio,rider,visualstudiocode,dotnetcore,aspnetcore + +### Azure Developer CLI ### +.azure/ + +### ASPNETCore ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/ + +### DotnetCore ### +# .NET Core build folders +bin/ +obj/ + +# Common node modules locations +/node_modules +/wwwroot/node_modules + +### Rider ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +### VisualStudio ### +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser + +# User-specific files (MonoDevelop/Xamarin Studio) + +# Mono auto generated files +mono_crash.* + +# Build results +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +# Uncomment if you have tasks that create the project's static files in wwwroot + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results + +# NUnit +nunit-*.xml + +# Build Results of an ATL Project + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_h.h +*.iobj +*.ipdb +*_wpftmp.csproj +*.tlog + +# Chutzpah Test files + +# Visual C++ cache files + +# Visual Studio profiler + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace + +# Guidance Automation Toolkit + +# ReSharper is a .NET coding add-in + +# TeamCity is a build add-in + +# DotCover is a Code Coverage Tool + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results + +# NCrunch + +# MightyMoose + +# Web workbench (sass) + +# Installshield output folder + +# DocProject is a documentation generator add-in + +# Click-Once directory + +# Publish Web Output +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted + +# NuGet Packages +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files + +# Microsoft Azure Build Output + +# Microsoft Azure Emulator + +# Windows Store app package directories and files +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) + +# RIA/Silverlight projects + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.ndf + +# Business Intelligence projects +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes + +# GhostDoc plugin setting file + +# Node.js Tools for Visual Studio + +# Visual Studio 6 build log + +# Visual Studio 6 workspace options file + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files + +# Visual Studio LightSwitch build output + +# Paket dependency manager + +# FAKE - F# Make + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +*.code-workspace + +# Local History for Visual Studio Code + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider + +### VisualStudio Patch ### +# Additional files built by Visual Studio + +# End of https://www.toptal.com/developers/gitignore/api/visualstudio,rider,visualstudiocode,dotnetcore,aspnetcore \ No newline at end of file diff --git a/samples/datasync-server/Sample.Datasync.Server.sln b/samples/datasync-server/Sample.Datasync.Server.sln new file mode 100644 index 0000000..11ceb1d --- /dev/null +++ b/samples/datasync-server/Sample.Datasync.Server.sln @@ -0,0 +1,50 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4B8E4DD5-C2CA-4729-A10B-8A3C993018EC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Datasync.Server", "src\Sample.Datasync.Server\Sample.Datasync.Server.csproj", "{67A76156-0033-4085-86BE-558DC28688A6}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "library", "library", "{95358590-6440-469A-8A6A-6ACC47F52966}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Datasync.Server", "..\..\..\..\CommunityToolkit\Datasync\src\CommunityToolkit.Datasync.Server\CommunityToolkit.Datasync.Server.csproj", "{D42DBA41-28AA-4B6D-83A4-A5B839EC8B25}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Datasync.Server.Abstractions", "..\..\..\..\CommunityToolkit\Datasync\src\CommunityToolkit.Datasync.Server.Abstractions\CommunityToolkit.Datasync.Server.Abstractions.csproj", "{CECB1B21-46C7-4197-B8D2-EC54D0AF8145}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Datasync.Server.EntityFrameworkCore", "..\..\..\..\CommunityToolkit\Datasync\src\CommunityToolkit.Datasync.Server.EntityFrameworkCore\CommunityToolkit.Datasync.Server.EntityFrameworkCore.csproj", "{8CDD3736-4B8D-43F5-8F9A-222210D73DAC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {67A76156-0033-4085-86BE-558DC28688A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {67A76156-0033-4085-86BE-558DC28688A6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {67A76156-0033-4085-86BE-558DC28688A6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {67A76156-0033-4085-86BE-558DC28688A6}.Release|Any CPU.Build.0 = Release|Any CPU + {D42DBA41-28AA-4B6D-83A4-A5B839EC8B25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D42DBA41-28AA-4B6D-83A4-A5B839EC8B25}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D42DBA41-28AA-4B6D-83A4-A5B839EC8B25}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D42DBA41-28AA-4B6D-83A4-A5B839EC8B25}.Release|Any CPU.Build.0 = Release|Any CPU + {CECB1B21-46C7-4197-B8D2-EC54D0AF8145}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CECB1B21-46C7-4197-B8D2-EC54D0AF8145}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CECB1B21-46C7-4197-B8D2-EC54D0AF8145}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CECB1B21-46C7-4197-B8D2-EC54D0AF8145}.Release|Any CPU.Build.0 = Release|Any CPU + {8CDD3736-4B8D-43F5-8F9A-222210D73DAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8CDD3736-4B8D-43F5-8F9A-222210D73DAC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8CDD3736-4B8D-43F5-8F9A-222210D73DAC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8CDD3736-4B8D-43F5-8F9A-222210D73DAC}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {67A76156-0033-4085-86BE-558DC28688A6} = {4B8E4DD5-C2CA-4729-A10B-8A3C993018EC} + {D42DBA41-28AA-4B6D-83A4-A5B839EC8B25} = {95358590-6440-469A-8A6A-6ACC47F52966} + {CECB1B21-46C7-4197-B8D2-EC54D0AF8145} = {95358590-6440-469A-8A6A-6ACC47F52966} + {8CDD3736-4B8D-43F5-8F9A-222210D73DAC} = {95358590-6440-469A-8A6A-6ACC47F52966} + EndGlobalSection +EndGlobal diff --git a/samples/datasync-server/azure.yaml b/samples/datasync-server/azure.yaml new file mode 100644 index 0000000..c7419d0 --- /dev/null +++ b/samples/datasync-server/azure.yaml @@ -0,0 +1,17 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json + +name: community-toolkit-datasync-server +metadata: + template: community-toolkit-datasync-server@8.0.0 + +workflows: + up: + steps: + - azd: provision + - azd: deploy --all + +services: + backend: + project: ./src/Sample.Datasync.Server + language: csharp + host: appservice \ No newline at end of file diff --git a/samples/datasync-server/infra/main.bicep b/samples/datasync-server/infra/main.bicep new file mode 100644 index 0000000..404ee69 --- /dev/null +++ b/samples/datasync-server/infra/main.bicep @@ -0,0 +1,63 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +targetScope = 'subscription' + +@minLength(1) +@maxLength(64) +@description('Name of the the environment which is used to generate a short unique hash used in all resources.') +param environmentName string + +@minLength(1) +@description('Primary location for all resources') +param location string + +@description('Optional - the name of the App Service to create. If not provided, a unique name will be generated.') +param appServiceName string = '' + +@description('Optional - the name of the App Service Plan to create. If not provided, a unique name will be generated.') +param appServicePlanName string = '' + +@description('Optional - the name of the Resource Group to create. If not provided, a unique name will be generated.') +param resourceGroupName string = '' + +@description('Optional - the name of the SQL Server to create. If not provided, a unique name will be generated.') +param sqlServerName string = '' + +@description('Optional - the name of the SQL Database to create. If not provided, a unique name will be generated.') +param sqlDatabaseName string = '' + +@description('Optional - the SQL Server administrator password. If not provided, the username will be \'appadmin\'.') +param sqlAdminUsername string = 'appadmin' + +@secure() +@description('Optional - SQL Server administrator password. If not provided, a random password will be generated.') +param sqlAdminPassword string = newGuid() + +var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) +var tags = { 'azd-env-name': environmentName } + +resource resourceGroup 'Microsoft.Resources/resourceGroups@2022-09-01' = { + name: !empty(resourceGroupName) ? resourceGroupName : 'rg-${environmentName}' + location: location + tags: tags +} + +module resources './resources.bicep' = { + name: 'resources' + scope: resourceGroup + params: { + location: location + tags: tags + appServiceName: !empty(appServiceName) ? appServiceName : 'app-${resourceToken}' + appServicePlanName: !empty(appServicePlanName) ? appServicePlanName : 'asp-${resourceToken}' + sqlServerName: !empty(sqlServerName) ? sqlServerName : 'sql-${resourceToken}' + sqlDatabaseName: !empty(sqlDatabaseName) ? sqlDatabaseName : 'TodoDb' + sqlAdminUsername: !empty(sqlAdminUsername) ? sqlAdminUsername : 'appadmin' + sqlAdminPassword: sqlAdminPassword + } +} + +output SERVICE_ENDPOINT string = resources.outputs.SERVICE_ENDPOINT + diff --git a/samples/datasync-server/infra/main.parameters.json b/samples/datasync-server/infra/main.parameters.json new file mode 100644 index 0000000..7d7d8f9 --- /dev/null +++ b/samples/datasync-server/infra/main.parameters.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "environmentName": { + "value": "${AZURE_ENV_NAME}" + }, + "location": { + "value": "${AZURE_LOCATION}" + }, + "principalId": { + "value": "${AZURE_PRINCIPAL_ID}" + }, + "sqlAdminUsername": { + "value": "appadmin" + }, + "sqlAdminPassword": { + "value": "$(secretOrRandomPassword)" + } + } +} \ No newline at end of file diff --git a/samples/datasync-server/infra/resources.bicep b/samples/datasync-server/infra/resources.bicep new file mode 100644 index 0000000..c64fe3b --- /dev/null +++ b/samples/datasync-server/infra/resources.bicep @@ -0,0 +1,111 @@ +targetScope = 'resourceGroup' + +@minLength(1) +@description('Primary location for all resources') +param location string + +@description('The name of the App Service to create.') +param appServiceName string + +@description('The name of the App Service Plan to create.') +param appServicePlanName string + +@description('The name of the SQL Server to create.') +param sqlServerName string + +@description('The name of the SQL Database to create.') +param sqlDatabaseName string + +@description('The SQL Server administrator password.') +param sqlAdminUsername string + +@secure() +@description('The SQL Server administrator password.') +param sqlAdminPassword string + +@description('The list of tags to apply to all resources.') +param tags object = {} + +resource sqlServer 'Microsoft.Sql/servers@2021-11-01' = { + name: sqlServerName + location: location + tags: tags + properties: { + version: '12.0' + minimalTlsVersion: '1.2' + publicNetworkAccess: 'Enabled' + administratorLogin: sqlAdminUsername + administratorLoginPassword: sqlAdminPassword + } + + resource firewall 'firewallRules' = { + name: 'AllowAllAzureServices' + properties: { + startIpAddress: '0.0.0.0' + endIpAddress: '0.0.0.0' + } + } +} + +resource sqlDatabase 'Microsoft.Sql/servers/databases@2021-11-01' = { + name: sqlDatabaseName + parent: sqlServer + location: location + tags: tags + sku: { + name: 'Basic' + } + properties: { + collation: 'SQL_Latin1_General_CP1_CI_AS' + maxSizeBytes: 1073741824 + } +} + +resource appServicePlan 'Microsoft.Web/serverfarms@2022-09-01' = { + name: appServicePlanName + location: location + tags: tags + sku: { + name: 'B1' + capacity: 1 + } +} + +resource appService 'Microsoft.Web/sites@2022-09-01' = { + name: appServiceName + location: location + tags: union(tags, { + 'azd-service-name': 'backend' + 'hidden-related:${appServicePlan.id}': 'empty' + }) + properties: { + httpsOnly: true + serverFarmId: appServicePlan.id + siteConfig: { + ftpsState: 'Disabled' + minTlsVersion: '1.2' + } + } + + resource configLogs 'config' = { + name: 'logs' + properties: { + applicationLogs: { fileSystem: { level: 'Verbose' } } + detailedErrorMessages: { enabled: true } + failedRequestsTracing: { enabled: true } + httpLogs: { fileSystem: { retentionInMb: 35, retentionInDays: 3, enabled: true } } + } + } + + resource connectionStrings 'config' = { + name: 'connectionstrings' + properties: { + DefaultConnection: { + value: 'Data Source=tcp:${sqlServer.properties.fullyQualifiedDomainName},1433;Initial Catalog=${sqlDatabase.name};User Id=${sqlServer.properties.administratorLogin};Password=${sqlAdminPassword};' + type: 'SQLAzure' + } + } + } +} + +output SERVICE_ENDPOINT string = 'https://${appService.properties.defaultHostName}' diff --git a/samples/datasync-server/src/Sample.Datasync.Server/Controllers/TodoItemController.cs b/samples/datasync-server/src/Sample.Datasync.Server/Controllers/TodoItemController.cs new file mode 100644 index 0000000..2543b2d --- /dev/null +++ b/samples/datasync-server/src/Sample.Datasync.Server/Controllers/TodoItemController.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using CommunityToolkit.Datasync.Server; +using CommunityToolkit.Datasync.Server.EntityFrameworkCore; +using Microsoft.AspNetCore.Mvc; +using Sample.Datasync.Server.Db; + +namespace Sample.Datasync.Server.Controllers; + +[Route("tables/[controller]")] +public class TodoItemController : TableController +{ + public TodoItemController(AppDbContext context) + : base(new EntityTableRepository(context)) + { + } +} \ No newline at end of file diff --git a/samples/datasync-server/src/Sample.Datasync.Server/Db/AppDbContext.cs b/samples/datasync-server/src/Sample.Datasync.Server/Db/AppDbContext.cs new file mode 100644 index 0000000..3a81c19 --- /dev/null +++ b/samples/datasync-server/src/Sample.Datasync.Server/Db/AppDbContext.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.EntityFrameworkCore; + +namespace Sample.Datasync.Server.Db; + +public class AppDbContext : DbContext +{ + public AppDbContext(DbContextOptions options) : base(options) + { + + } + + public DbSet TodoItems => Set(); + + public async Task InitializeDatabaseAsync() + { + await Database.EnsureCreatedAsync(); + } +} diff --git a/samples/datasync-server/src/Sample.Datasync.Server/Db/TodoItem.cs b/samples/datasync-server/src/Sample.Datasync.Server/Db/TodoItem.cs new file mode 100644 index 0000000..afd02d6 --- /dev/null +++ b/samples/datasync-server/src/Sample.Datasync.Server/Db/TodoItem.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using CommunityToolkit.Datasync.Server.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; + +namespace Sample.Datasync.Server.Db; + +public class TodoItem : EntityTableData +{ + [Required, MinLength(1)] + public string Text { get; set; } = string.Empty; + + public bool IsComplete { get; set; } +} diff --git a/samples/datasync-server/src/Sample.Datasync.Server/Program.cs b/samples/datasync-server/src/Sample.Datasync.Server/Program.cs new file mode 100644 index 0000000..1f0c8c3 --- /dev/null +++ b/samples/datasync-server/src/Sample.Datasync.Server/Program.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using CommunityToolkit.Datasync.Server; +using Microsoft.EntityFrameworkCore; +using Sample.Datasync.Server.Db; + +WebApplicationBuilder builder = WebApplication.CreateBuilder(args); + +string connectionString = builder.Configuration.GetConnectionString("DefaultConnection") + ?? throw new ApplicationException("DefaultConnection is not set"); + +builder.Services.AddDbContext(options => options.UseSqlServer(connectionString)); +builder.Services.AddDatasyncServices(); +builder.Services.AddControllers(); + +WebApplication app = builder.Build(); + +// Initialize the database +using (IServiceScope scope = app.Services.CreateScope()) +{ + AppDbContext context = scope.ServiceProvider.GetRequiredService(); + await context.InitializeDatabaseAsync(); +} + +app.UseHttpsRedirection(); +app.UseAuthorization(); +app.MapControllers(); + +app.Run(); diff --git a/samples/datasync-server/src/Sample.Datasync.Server/Properties/.gitignore b/samples/datasync-server/src/Sample.Datasync.Server/Properties/.gitignore new file mode 100644 index 0000000..894598d --- /dev/null +++ b/samples/datasync-server/src/Sample.Datasync.Server/Properties/.gitignore @@ -0,0 +1,4 @@ +# These files are used during the Publish process from VS +PublishProfiles/ +ServiceDependencies/ +serviceDependencies.* \ No newline at end of file diff --git a/samples/datasync-server/src/Sample.Datasync.Server/Properties/launchSettings.json b/samples/datasync-server/src/Sample.Datasync.Server/Properties/launchSettings.json new file mode 100644 index 0000000..d11ca61 --- /dev/null +++ b/samples/datasync-server/src/Sample.Datasync.Server/Properties/launchSettings.json @@ -0,0 +1,33 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:48768", + "sslPort": 44300 + } + }, + "profiles": { + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "https://localhost:5001/tables/todoitem", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sqlDebugging": true + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "https://localhost:44300/tables/todoitem", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sqlDebugging": true + } + } +} diff --git a/samples/datasync-server/src/Sample.Datasync.Server/Sample.Datasync.Server.csproj b/samples/datasync-server/src/Sample.Datasync.Server/Sample.Datasync.Server.csproj new file mode 100644 index 0000000..5d9fbd5 --- /dev/null +++ b/samples/datasync-server/src/Sample.Datasync.Server/Sample.Datasync.Server.csproj @@ -0,0 +1,30 @@ + + + net8.0 + enable + enable + 2fc55b72-4090-46ad-ae44-8b6a415339b8 + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + diff --git a/samples/datasync-server/src/Sample.Datasync.Server/appsettings.Development.json b/samples/datasync-server/src/Sample.Datasync.Server/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/samples/datasync-server/src/Sample.Datasync.Server/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/samples/datasync-server/src/Sample.Datasync.Server/appsettings.json b/samples/datasync-server/src/Sample.Datasync.Server/appsettings.json new file mode 100644 index 0000000..6991581 --- /dev/null +++ b/samples/datasync-server/src/Sample.Datasync.Server/appsettings.json @@ -0,0 +1,12 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=TodoApp;Trusted_Connection=True" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}