diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3e759b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,330 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# 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/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# 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 + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.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 + +# Visual Studio Trace Files +*.e2e + +# 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 + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# 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 +# Note: 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 +**/[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 +*.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 +*.appx + +# 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 +orleans.codegen.cs + +# 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) +#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 +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# 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/** +# !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/ diff --git a/Windows-party/CodeMaid.config b/Windows-party/CodeMaid.config new file mode 100644 index 0000000..8116e53 --- /dev/null +++ b/Windows-party/CodeMaid.config @@ -0,0 +1,22 @@ + + + + +
+ + + + + + 120 + + + True + + + False + + + + \ No newline at end of file diff --git a/Windows-party/Directory.Build.props b/Windows-party/Directory.Build.props new file mode 100644 index 0000000..fc70c68 --- /dev/null +++ b/Windows-party/Directory.Build.props @@ -0,0 +1,10 @@ + + + + $(SolutionDir)\StyleCop.Analyzers.ruleset + + + + + + \ No newline at end of file diff --git a/Windows-party/StyleCop.Analyzers.ruleset b/Windows-party/StyleCop.Analyzers.ruleset new file mode 100644 index 0000000..8da42c6 --- /dev/null +++ b/Windows-party/StyleCop.Analyzers.ruleset @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Windows-party/Windows-party.sln b/Windows-party/Windows-party.sln new file mode 100644 index 0000000..ecb84c5 --- /dev/null +++ b/Windows-party/Windows-party.sln @@ -0,0 +1,61 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29920.165 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WindowsParty.Ui", "WindowsParty.Ui\WindowsParty.Ui.csproj", "{121FEBA6-9793-4872-BDA9-2E62468CE76A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WindowsParty.Domain", "WindowsParty.Domain\WindowsParty.Domain.csproj", "{FEDE26CA-9BF5-4405-9F11-1FCA2098899C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsParty.Authentication.Tesonet", "WindowsParty.Authentication.Tesonet\WindowsParty.Authentication.Tesonet.csproj", "{F7D4D9AD-A4AE-4BA9-A299-76B9913D3F14}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsParty.Repository.Tesonet", "WindowsParty.Repository.Tesonet\WindowsParty.Repository.Tesonet.csproj", "{21B3A566-257A-4F95-96EC-F4E7B11F4E95}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{13B8F404-19C8-4AF6-B62C-2AC490644BC3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsParty.Authentication.Tesonet.UnitTests", "WindowsParty.Authentication.Tesonet.UnitTests\WindowsParty.Authentication.Tesonet.UnitTests.csproj", "{78CE8304-A6AF-4312-85ED-5BF5307B49C3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsParty.Repository.Tesonet.UnitTests", "WindowsParty.Repository.Tesonet.UnitTests\WindowsParty.Repository.Tesonet.UnitTests.csproj", "{C8AE1055-F4C1-40D1-BCE6-5118B2B8D8DB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {121FEBA6-9793-4872-BDA9-2E62468CE76A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {121FEBA6-9793-4872-BDA9-2E62468CE76A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {121FEBA6-9793-4872-BDA9-2E62468CE76A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {121FEBA6-9793-4872-BDA9-2E62468CE76A}.Release|Any CPU.Build.0 = Release|Any CPU + {FEDE26CA-9BF5-4405-9F11-1FCA2098899C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FEDE26CA-9BF5-4405-9F11-1FCA2098899C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FEDE26CA-9BF5-4405-9F11-1FCA2098899C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FEDE26CA-9BF5-4405-9F11-1FCA2098899C}.Release|Any CPU.Build.0 = Release|Any CPU + {F7D4D9AD-A4AE-4BA9-A299-76B9913D3F14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7D4D9AD-A4AE-4BA9-A299-76B9913D3F14}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7D4D9AD-A4AE-4BA9-A299-76B9913D3F14}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7D4D9AD-A4AE-4BA9-A299-76B9913D3F14}.Release|Any CPU.Build.0 = Release|Any CPU + {21B3A566-257A-4F95-96EC-F4E7B11F4E95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {21B3A566-257A-4F95-96EC-F4E7B11F4E95}.Debug|Any CPU.Build.0 = Debug|Any CPU + {21B3A566-257A-4F95-96EC-F4E7B11F4E95}.Release|Any CPU.ActiveCfg = Release|Any CPU + {21B3A566-257A-4F95-96EC-F4E7B11F4E95}.Release|Any CPU.Build.0 = Release|Any CPU + {78CE8304-A6AF-4312-85ED-5BF5307B49C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {78CE8304-A6AF-4312-85ED-5BF5307B49C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {78CE8304-A6AF-4312-85ED-5BF5307B49C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {78CE8304-A6AF-4312-85ED-5BF5307B49C3}.Release|Any CPU.Build.0 = Release|Any CPU + {C8AE1055-F4C1-40D1-BCE6-5118B2B8D8DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C8AE1055-F4C1-40D1-BCE6-5118B2B8D8DB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C8AE1055-F4C1-40D1-BCE6-5118B2B8D8DB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C8AE1055-F4C1-40D1-BCE6-5118B2B8D8DB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {78CE8304-A6AF-4312-85ED-5BF5307B49C3} = {13B8F404-19C8-4AF6-B62C-2AC490644BC3} + {C8AE1055-F4C1-40D1-BCE6-5118B2B8D8DB} = {13B8F404-19C8-4AF6-B62C-2AC490644BC3} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {67F56276-10EA-4EE6-B071-345D69F2D16E} + EndGlobalSection +EndGlobal diff --git a/Windows-party/Windows-party.sln.DotSettings b/Windows-party/Windows-party.sln.DotSettings new file mode 100644 index 0000000..9e40da4 --- /dev/null +++ b/Windows-party/Windows-party.sln.DotSettings @@ -0,0 +1,450 @@ + + True + False + True + <?xml version="1.0" encoding="utf-16"?><Profile name="Compliance Cleanup"><CSReorderTypeMembers>True</CSReorderTypeMembers><JsInsertSemicolon>True</JsInsertSemicolon><FormatAttributeQuoteDescriptor>True</FormatAttributeQuoteDescriptor><CorrectVariableKindsDescriptor>True</CorrectVariableKindsDescriptor><VariablesToInnerScopesDescriptor>True</VariablesToInnerScopesDescriptor><StringToTemplatesDescriptor>True</StringToTemplatesDescriptor><JsReformatCode>True</JsReformatCode><JsFormatDocComments>True</JsFormatDocComments><RemoveRedundantQualifiersTs>True</RemoveRedundantQualifiersTs><OptimizeImportsTs>True</OptimizeImportsTs><OptimizeReferenceCommentsTs>True</OptimizeReferenceCommentsTs><PublicModifierStyleTs>True</PublicModifierStyleTs><ExplicitAnyTs>True</ExplicitAnyTs><TypeAnnotationStyleTs>True</TypeAnnotationStyleTs><RelativePathStyleTs>True</RelativePathStyleTs><AsInsteadOfCastTs>True</AsInsteadOfCastTs><HtmlReformatCode>True</HtmlReformatCode><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><XMLReformatCode>True</XMLReformatCode><CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="True" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="True" ArrangeArgumentsStyle="True" ArrangeCodeBodyStyle="True" ArrangeVarStyle="True" /><RemoveCodeRedundanciesVB>True</RemoveCodeRedundanciesVB><CssAlphabetizeProperties>True</CssAlphabetizeProperties><VBOptimizeImports>True</VBOptimizeImports><VBShortenReferences>True</VBShortenReferences><RemoveCodeRedundancies>True</RemoveCodeRedundancies><CSUseAutoProperty>True</CSUseAutoProperty><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSMakeAutoPropertyGetOnly>True</CSMakeAutoPropertyGetOnly><CSArrangeQualifiers>True</CSArrangeQualifiers><CSFixBuiltinTypeReferences>True</CSFixBuiltinTypeReferences><CssReformatCode>True</CssReformatCode><VBReformatCode>True</VBReformatCode><VBFormatDocComments>True</VBFormatDocComments><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode></Profile> + <?xml version="1.0" encoding="utf-16"?><Profile name="StyleCop"><CSUpdateFileHeader>False</CSUpdateFileHeader><CSArrangeQualifiers>True</CSArrangeQualifiers><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSReformatCode>True</CSReformatCode><CSReorderTypeMembers>True</CSReorderTypeMembers><CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="True" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="True" ArrangeArgumentsStyle="False" ArrangeCodeBodyStyle="False" ArrangeVarStyle="True" /><CSUseAutoProperty>True</CSUseAutoProperty><CSFixBuiltinTypeReferences>True</CSFixBuiltinTypeReferences></Profile> + Compliance Cleanup + Required + Required + Required + Required + Arithmetic, Shift, Bitwise, Conditional, Lowest + None + False + False + False + False + False + False + + False + False + False + NEXT_LINE + 1 + 1 + 0 + 1 + 0 + 1 + 1 + + + 1 + 0 + NEXT_LINE + NO_INDENT + NEXT_LINE + 1 + 1 + False + False + False + True + False + True + True + True + NEVER + NEVER + + True + NEVER + NEVER + False + True + True + False + True + False + True + True + CHOP_IF_LONG + CHOP_IF_LONG + True + True + CHOP_IF_LONG + CHOP_IF_LONG + CHOP_IF_LONG + 120 + CHOP_IF_LONG + <?xml version="1.0" encoding="utf-16"?> +<Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns"> + <TypePattern DisplayName="COM interfaces or structs"> + <TypePattern.Match> + <Or> + <And> + <Kind Is="Interface" /> + <Or> + <HasAttribute Name="System.Runtime.InteropServices.InterfaceTypeAttribute" /> + <HasAttribute Name="System.Runtime.InteropServices.ComImport" /> + </Or> + </And> + <Kind Is="Struct" /> + </Or> + </TypePattern.Match> + </TypePattern> + <TypePattern DisplayName="P/Invoke classes called 'NativeMethods' (StyleCop)"> + <TypePattern.Match> + <And> + <Kind Is="Class" /> + <Name Is=".*NativeMethods" /> + </And> + </TypePattern.Match> + </TypePattern> + <TypePattern DisplayName="DataMember serialisation classes (StyleCop)"> + <TypePattern.Match> + <And> + <Or> + <Kind Is="Field" /> + <Kind Is="Property" /> + </Or> + <HasAttribute Name="System.Runtime.Serialization.DataMemberAttribute" /> + </And> + </TypePattern.Match> + </TypePattern> + <TypePattern DisplayName="Default Pattern (StyleCop)" RemoveRegions="All"> + <Entry DisplayName="Constants"> + <Entry.Match> + <Kind Is="Constant" /> + </Entry.Match> + <Entry.SortBy> + <Access /> + <Kind Is="Member" /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Static fields"> + <Entry.Match> + <And> + <Kind Is="Field" /> + <Static /> + </And> + </Entry.Match> + <Entry.SortBy> + <Access /> + <Readonly /> + <Kind Is="Member" /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Fields"> + <Entry.Match> + <Kind Is="Field" /> + </Entry.Match> + <Entry.SortBy> + <Access /> + <Readonly /> + <Kind Is="Member" /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Constructors and Destructors" Priority="200"> + <Entry.Match> + <Or> + <Kind Is="Constructor" /> + <Kind Is="Destructor" /> + </Or> + </Entry.Match> + <Entry.SortBy> + <Static /> + <Kind Order="Constructor Destructor" /> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Delegates"> + <Entry.Match> + <Kind Is="Delegate" /> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Static /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Public events"> + <Entry.Match> + <And> + <Kind Is="Event" /> + <Access Is="Public" /> + </And> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public" /> + <Static /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Interface events"> + <Entry.Match> + <And> + <Kind Is="Event" /> + <ImplementsInterface /> + </And> + </Entry.Match> + <Entry.SortBy> + <ImplementsInterface Immediate="True" /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Other events"> + <Entry.Match> + <Kind Is="Event" /> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Static /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Enums"> + <Entry.Match> + <Kind Is="Enum" /> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Interfaces"> + <Entry.Match> + <Kind Is="Interface" /> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Key properties"> + <Entry.Match> + <And> + <Kind Is="Property" /> + <Access Is="Public" /> + <HasAttribute Name="Key" /> + </And> + </Entry.Match> + <Entry.SortBy> + <Static /> + <Kind Is="Member" /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Public properties"> + <Entry.Match> + <And> + <Kind Is="Property" /> + <Access Is="Public" /> + </And> + </Entry.Match> + <Entry.SortBy> + <Static /> + <Kind Is="Member" /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Interface properties"> + <Entry.Match> + <And> + <Kind Is="Property" /> + <ImplementsInterface /> + </And> + </Entry.Match> + <Entry.SortBy> + <ImplementsInterface /> + <Kind Is="Member" /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Other properties"> + <Entry.Match> + <Kind Is="Property" /> + </Entry.Match> + <Entry.SortBy> + <Access /> + <Static /> + <Kind Is="Member" /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Public indexers" Priority="1000"> + <Entry.Match> + <And> + <Kind Is="Indexer" /> + <Access Is="Public" /> + </And> + </Entry.Match> + <Entry.SortBy> + <Static /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Interface indexers" Priority="1000"> + <Entry.Match> + <And> + <Kind Is="Indexer" /> + <ImplementsInterface /> + </And> + </Entry.Match> + <Entry.SortBy> + <ImplementsInterface Immediate="True" /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Other indexers" Priority="1000"> + <Entry.Match> + <Kind Is="Indexer" /> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Static /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="SetUp methods"> + <Entry.Match> + <And> + <Or> + <HasAttribute Name="SetUp" /> + <HasAttribute Name="OneTimeSetUp" /> + <HasAttribute Name="BeforeScenario" /> + <HasAttribute Name="BeforeTestRun" /> + </Or> + <Kind Is="Method" /> + </And> + </Entry.Match> + </Entry> + <Entry DisplayName="TearDown methods"> + <Entry.Match> + <And> + <Or> + <HasAttribute Name="TearDown" /> + <HasAttribute Name="OneTimeTearDown" /> + <HasAttribute Name="AfterScenario" /> + <HasAttribute Name="AfterTestRun" /> + </Or> + <Kind Is="Method" /> + </And> + </Entry.Match> + </Entry> + <Entry DisplayName="Public methods and operators"> + <Entry.Match> + <And> + <Or> + <Kind Is="Method" /> + <Kind Is="Operator" /> + </Or> + <Access Is="Public" /> + </And> + </Entry.Match> + <Entry.SortBy> + <Static /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Interface methods"> + <Entry.Match> + <And> + <Kind Is="Method" /> + <ImplementsInterface /> + </And> + </Entry.Match> + <Entry.SortBy> + <ImplementsInterface Immediate="True" /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Other methods"> + <Entry.Match> + <Kind Is="Method" /> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Static /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Operators"> + <Entry.Match> + <Kind Is="Operator" /> + </Entry.Match> + <Entry.SortBy> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Static /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Nested structs" Priority="600"> + <Entry.Match> + <Kind Is="Struct" /> + </Entry.Match> + <Entry.SortBy> + <Static /> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="Nested classes" Priority="700"> + <Entry.Match> + <Kind Is="Class" /> + </Entry.Match> + <Entry.SortBy> + <Static /> + <Access Order="Public Internal ProtectedInternal Protected Private" /> + <Name /> + </Entry.SortBy> + </Entry> + <Entry DisplayName="All other members" /> + </TypePattern> +</Patterns> + True + True + AD + + XY + <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> + LIVE_MONITOR + LIVE_MONITOR + DO_NOTHING + LIVE_MONITOR + LIVE_MONITOR + LIVE_MONITOR + LIVE_MONITOR + LIVE_MONITOR + LIVE_MONITOR + LIVE_MONITOR + LIVE_MONITOR + DO_NOTHING + LIVE_MONITOR + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True \ No newline at end of file diff --git a/Windows-party/WindowsParty.Authentication.Tesonet.UnitTests/Services/AuthenticationServiceTests.cs b/Windows-party/WindowsParty.Authentication.Tesonet.UnitTests/Services/AuthenticationServiceTests.cs new file mode 100644 index 0000000..b32b76c --- /dev/null +++ b/Windows-party/WindowsParty.Authentication.Tesonet.UnitTests/Services/AuthenticationServiceTests.cs @@ -0,0 +1,187 @@ +namespace WindowsParty.Authentication.Tesonet.UnitTests.Services +{ + using System; + using System.Net; + using System.Net.Http; + using System.Threading; + using System.Threading.Tasks; + using FluentAssertions; + using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.Logging; + using Moq; + using Moq.Protected; + using Newtonsoft.Json; + using Newtonsoft.Json.Serialization; + using NUnit.Framework; + using WindowsParty.Authentication.Tesonet.Services; + using WindowsParty.Domain.Models; + + public class AuthenticationServiceTests + { + private Mock _httpFactoryMock; + private Mock _httpHandlerMock; + private AuthenticationService _sut; + + [SetUp] + public void Setup() + { + _httpFactoryMock = new Mock(); + _httpHandlerMock = new Mock(); + var httpClient = new HttpClient(_httpHandlerMock.Object); + + _httpFactoryMock.Setup(s => s.CreateClient(It.IsAny())).Returns(httpClient); + var configurationMock = new Mock(); + var configurationSectionMock = new Mock(); + configurationSectionMock.Setup(s => s.Value).Returns("http://localhost/token"); + configurationMock.Setup(s => s.GetSection("AuthenticationEndpoint")) + .Returns(configurationSectionMock.Object); + + _sut = new AuthenticationService( + _httpFactoryMock.Object, + configurationMock.Object, + Mock.Of>()); + } + + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public async Task LogInAsync_NoPassword_ReturnsEmptyToken(string password) + { + var credentials = new Credentials + { + Username = "someUsername", + Password = password + }; + HttpRequestMessage request = null; + _httpHandlerMock.Protected() + .Setup>( + "SendAsync", + ItExpr.IsAny(), + ItExpr.IsAny()) + .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.BadRequest)) + .Callback((HttpRequestMessage r, CancellationToken ct) => request = r); + + var result = await _sut.LogInAsync(credentials); + + result.IsSuccess.Should().BeFalse(); + result.Token.Should().BeNullOrEmpty(); + request.Should().BeNull(); + } + + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public async Task LogInAsync_NoUsername_ReturnsEmptyToken(string username) + { + var credentials = new Credentials + { + Username = username, + Password = "somePassword" + }; + HttpRequestMessage request = null; + _httpHandlerMock.Protected() + .Setup>( + "SendAsync", + ItExpr.IsAny(), + ItExpr.IsAny()) + .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.BadRequest)) + .Callback((HttpRequestMessage r, CancellationToken ct) => request = r); + + var result = await _sut.LogInAsync(credentials); + + result.IsSuccess.Should().BeFalse(); + result.Token.Should().BeNullOrEmpty(); + request.Should().BeNull(); + } + + [Test] + public async Task LogInAsync_PostReturnsNotSuccess_ReturnsEmptyToken() + { + var credentials = new Credentials + { + Username = "someUsername", + Password = "somePassword" + }; + HttpRequestMessage request = null; + _httpHandlerMock.Protected() + .Setup>( + "SendAsync", + ItExpr.IsAny(), + ItExpr.IsAny()) + .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.BadRequest)) + .Callback((HttpRequestMessage r, CancellationToken ct) => request = r); + + var result = await _sut.LogInAsync(credentials); + + result.IsSuccess.Should().BeFalse(); + result.Token.Should().BeNullOrEmpty(); + await AssertRequestAsync(request, credentials); + } + + [Test] + public async Task LogInAsync_PostReturnsOK_ReturnsToken() + { + var credentials = new Credentials + { + Username = "someUsername", + Password = "somePassword" + }; + HttpRequestMessage request = null; + _httpHandlerMock.Protected() + .Setup>( + "SendAsync", + ItExpr.IsAny(), + ItExpr.IsAny()) + .ReturnsAsync( + new HttpResponseMessage(HttpStatusCode.OK) + { Content = new StringContent("{ \"token\": \"received\" }") }) + .Callback((HttpRequestMessage r, CancellationToken ct) => request = r); + + var result = await _sut.LogInAsync(credentials); + + result.IsSuccess.Should().BeTrue(); + result.Token.Should().Be("received"); + await AssertRequestAsync(request, credentials); + } + + [Test] + public async Task LogInAsync_PostThrows_ReturnsEmptyToken() + { + var credentials = new Credentials + { + Username = "someUsername", + Password = "somePassword" + }; + HttpRequestMessage request = null; + _httpHandlerMock.Protected() + .Setup>( + "SendAsync", + ItExpr.IsAny(), + ItExpr.IsAny()) + .ThrowsAsync(new Exception()) + .Callback((HttpRequestMessage r, CancellationToken ct) => request = r); + + var result = await _sut.LogInAsync(credentials); + + result.IsSuccess.Should().BeFalse(); + result.Token.Should().BeNullOrEmpty(); + await AssertRequestAsync(request, credentials); + } + + private async Task AssertRequestAsync(HttpRequestMessage request, Credentials credentials) + { + request.Should().NotBeNull(); + request.Method.Should().Be(HttpMethod.Post); + request.RequestUri.OriginalString.Should().Be("http://localhost/token"); + var requestJson = await request.Content.ReadAsStringAsync(); + requestJson.Should() + .Be( + JsonConvert.SerializeObject( + credentials, + new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + })); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Authentication.Tesonet.UnitTests/WindowsParty.Authentication.Tesonet.UnitTests.csproj b/Windows-party/WindowsParty.Authentication.Tesonet.UnitTests/WindowsParty.Authentication.Tesonet.UnitTests.csproj new file mode 100644 index 0000000..0843f6d --- /dev/null +++ b/Windows-party/WindowsParty.Authentication.Tesonet.UnitTests/WindowsParty.Authentication.Tesonet.UnitTests.csproj @@ -0,0 +1,30 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/Windows-party/WindowsParty.Authentication.Tesonet/Assembly.cs b/Windows-party/WindowsParty.Authentication.Tesonet/Assembly.cs new file mode 100644 index 0000000..1298ee5 --- /dev/null +++ b/Windows-party/WindowsParty.Authentication.Tesonet/Assembly.cs @@ -0,0 +1,4 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("WindowsParty.Authentication.Tesonet.UnitTests")] +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] \ No newline at end of file diff --git a/Windows-party/WindowsParty.Authentication.Tesonet/AuthenticationModule.cs b/Windows-party/WindowsParty.Authentication.Tesonet/AuthenticationModule.cs new file mode 100644 index 0000000..365aa53 --- /dev/null +++ b/Windows-party/WindowsParty.Authentication.Tesonet/AuthenticationModule.cs @@ -0,0 +1,15 @@ +namespace WindowsParty.Authentication.Tesonet +{ + using Microsoft.Extensions.DependencyInjection; + using WindowsParty.Authentication.Tesonet.Services; + using WindowsParty.Domain.Contracts; + + public static class AuthenticationModule + { + public static void AddTesonetAuthentication(this IServiceCollection service) + { + service.AddHttpClient(); + service.AddTransient(); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Authentication.Tesonet/Services/AuthenticationService.cs b/Windows-party/WindowsParty.Authentication.Tesonet/Services/AuthenticationService.cs new file mode 100644 index 0000000..22b27a2 --- /dev/null +++ b/Windows-party/WindowsParty.Authentication.Tesonet/Services/AuthenticationService.cs @@ -0,0 +1,77 @@ +namespace WindowsParty.Authentication.Tesonet.Services +{ + using System; + using System.Net.Http; + using System.Net.Mime; + using System.Text; + using System.Threading.Tasks; + using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.Logging; + using Newtonsoft.Json; + using Newtonsoft.Json.Serialization; + using WindowsParty.Domain.Contracts; + using WindowsParty.Domain.Models; + + internal class AuthenticationService : IAuthenticationService + { + private readonly string _endpoint; + private readonly HttpClient _httpClient; + private readonly JsonSerializerSettings _jsonConverterSettings; + private readonly ILogger _logger; + + public AuthenticationService( + IHttpClientFactory httpClientFactory, + IConfiguration configuration, + ILogger logger) + { + _logger = logger; + _httpClient = httpClientFactory.CreateClient(); + _endpoint = configuration.GetSection("AuthenticationEndpoint").Value; + + _jsonConverterSettings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + }; + } + + public async Task LogInAsync(Credentials credentials) + { + try + { + if (UsernameShouldBeSpecified(credentials) || PasswordShouldBeSpecified(credentials)) + { + return new TokenResult(); + } + + var jsonCredentials = JsonConvert.SerializeObject(credentials, _jsonConverterSettings); + var content = new StringContent(jsonCredentials, Encoding.UTF8, MediaTypeNames.Application.Json); + var response = await _httpClient.PostAsync(_endpoint, content); + var responseString = await response.Content.ReadAsStringAsync(); + + if (!response.IsSuccessStatusCode) + { + _logger.Log(LogLevel.Information, $"Log in failed: {responseString}."); + return new TokenResult(); + } + + return JsonConvert.DeserializeObject(responseString, _jsonConverterSettings); + } + catch (Exception ex) + { + _logger.Log(LogLevel.Error, ex, "Unexpected error occured."); + + return new TokenResult(); + } + } + + private static bool PasswordShouldBeSpecified(Credentials credentials) + { + return string.IsNullOrWhiteSpace(credentials.Password); + } + + private static bool UsernameShouldBeSpecified(Credentials credentials) + { + return string.IsNullOrWhiteSpace(credentials.Username); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Authentication.Tesonet/WindowsParty.Authentication.Tesonet.csproj b/Windows-party/WindowsParty.Authentication.Tesonet/WindowsParty.Authentication.Tesonet.csproj new file mode 100644 index 0000000..73a0270 --- /dev/null +++ b/Windows-party/WindowsParty.Authentication.Tesonet/WindowsParty.Authentication.Tesonet.csproj @@ -0,0 +1,21 @@ + + + + netstandard2.1 + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/Windows-party/WindowsParty.Domain/Contracts/IAuthenticationService.cs b/Windows-party/WindowsParty.Domain/Contracts/IAuthenticationService.cs new file mode 100644 index 0000000..1a8118d --- /dev/null +++ b/Windows-party/WindowsParty.Domain/Contracts/IAuthenticationService.cs @@ -0,0 +1,10 @@ +namespace WindowsParty.Domain.Contracts +{ + using System.Threading.Tasks; + using WindowsParty.Domain.Models; + + public interface IAuthenticationService + { + Task LogInAsync(Credentials credentials); + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Domain/Contracts/IServerQueryService.cs b/Windows-party/WindowsParty.Domain/Contracts/IServerQueryService.cs new file mode 100644 index 0000000..eb5f972 --- /dev/null +++ b/Windows-party/WindowsParty.Domain/Contracts/IServerQueryService.cs @@ -0,0 +1,12 @@ +namespace WindowsParty.Domain.Contracts +{ + using System.Collections.Generic; + using System.Threading.Tasks; + using WindowsParty.Domain.Entities; + using WindowsParty.Domain.Models; + + public interface IServerQueryService + { + Task> GetAsync(TokenResult token); + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Domain/Entities/Server.cs b/Windows-party/WindowsParty.Domain/Entities/Server.cs new file mode 100644 index 0000000..4d3bd88 --- /dev/null +++ b/Windows-party/WindowsParty.Domain/Entities/Server.cs @@ -0,0 +1,9 @@ +namespace WindowsParty.Domain.Entities +{ + public class Server + { + public string Name { get; set; } + + public int Distance { get; set; } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Domain/Models/Credentials.cs b/Windows-party/WindowsParty.Domain/Models/Credentials.cs new file mode 100644 index 0000000..b16d57f --- /dev/null +++ b/Windows-party/WindowsParty.Domain/Models/Credentials.cs @@ -0,0 +1,9 @@ +namespace WindowsParty.Domain.Models +{ + public class Credentials + { + public string Username { get; set; } + + public string Password { get; set; } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Domain/Models/TokenResult.cs b/Windows-party/WindowsParty.Domain/Models/TokenResult.cs new file mode 100644 index 0000000..db77198 --- /dev/null +++ b/Windows-party/WindowsParty.Domain/Models/TokenResult.cs @@ -0,0 +1,9 @@ +namespace WindowsParty.Domain.Models +{ + public class TokenResult + { + public bool IsSuccess => !string.IsNullOrWhiteSpace(Token); + + public string Token { get; set; } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Domain/WindowsParty.Domain.csproj b/Windows-party/WindowsParty.Domain/WindowsParty.Domain.csproj new file mode 100644 index 0000000..4ff2a36 --- /dev/null +++ b/Windows-party/WindowsParty.Domain/WindowsParty.Domain.csproj @@ -0,0 +1,14 @@ + + + + netstandard2.1 + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/Windows-party/WindowsParty.Repository.Tesonet.UnitTests/Services/ServersQueryServiceTests.cs b/Windows-party/WindowsParty.Repository.Tesonet.UnitTests/Services/ServersQueryServiceTests.cs new file mode 100644 index 0000000..f99bee8 --- /dev/null +++ b/Windows-party/WindowsParty.Repository.Tesonet.UnitTests/Services/ServersQueryServiceTests.cs @@ -0,0 +1,149 @@ +namespace WindowsParty.Repository.Tesonet.UnitTests.Services +{ + using System; + using System.Net; + using System.Net.Http; + using System.Net.Http.Headers; + using System.Threading; + using System.Threading.Tasks; + using FluentAssertions; + using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.Logging; + using Moq; + using Moq.Protected; + using NUnit.Framework; + using WindowsParty.Domain.Models; + using WindowsParty.Repository.Tesonet.Services; + + public class ServersQueryServiceTests + { + private Mock _httpFactoryMock; + private Mock _httpHandlerMock; + private ServersQueryService _sut; + + [SetUp] + public void Setup() + { + _httpFactoryMock = new Mock(); + _httpHandlerMock = new Mock(); + var httpClient = new HttpClient(_httpHandlerMock.Object); + + _httpFactoryMock.Setup(s => s.CreateClient(It.IsAny())).Returns(httpClient); + var configurationMock = new Mock(); + var configurationSectionMock = new Mock(); + configurationSectionMock.Setup(s => s.Value).Returns("http://localhost/servers"); + configurationMock.Setup(s => s.GetSection("ServersEndpoint")) + .Returns(configurationSectionMock.Object); + + _sut = new ServersQueryService( + _httpFactoryMock.Object, + configurationMock.Object, + Mock.Of>()); + } + + [Test] + public async Task GetAsync_GetReturnsNotSuccess_ReturnsEmptyList() + { + var tokenResult = new TokenResult + { + Token = "super-token" + }; + HttpRequestMessage request = null; + _httpHandlerMock.Protected() + .Setup>( + "SendAsync", + ItExpr.IsAny(), + ItExpr.IsAny()) + .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.NotFound)) + .Callback((HttpRequestMessage r, CancellationToken ct) => request = r); + + var result = await _sut.GetAsync(tokenResult); + + result.Should().BeEmpty(); + AssertRequest(request, tokenResult); + } + + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public async Task GetAsync_NoToken_ReturnsEmptyToken(string token) + { + var tokenResult = new TokenResult + { + Token = token + }; + HttpRequestMessage request = null; + _httpHandlerMock.Protected() + .Setup>( + "SendAsync", + ItExpr.IsAny(), + ItExpr.IsAny()) + .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.BadRequest)) + .Callback((HttpRequestMessage r, CancellationToken ct) => request = r); + + var result = await _sut.GetAsync(tokenResult); + + result.Should().BeEmpty(); + request.Should().BeNull(); + } + + [Test] + public async Task GetAsync_PostReturnsOK_ReturnsToken() + { + var tokenResult = new TokenResult + { + Token = "super-token" + }; + HttpRequestMessage request = null; + _httpHandlerMock.Protected() + .Setup>( + "SendAsync", + ItExpr.IsAny(), + ItExpr.IsAny()) + .ReturnsAsync( + new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent( + "[{ \"name\": \"N1\", \"distance\": 333 }, { \"name\": \"N2\", \"distance\": 446 }]") + }) + .Callback((HttpRequestMessage r, CancellationToken ct) => request = r); + + var result = await _sut.GetAsync(tokenResult); + + result.Should().HaveCount(2); + result.Should().Contain(s => (s.Name == "N1") && (s.Distance == 333)); + result.Should().Contain(s => (s.Name == "N2") && (s.Distance == 446)); + AssertRequest(request, tokenResult); + } + + [Test] + public async Task GetAsync_PostThrows_ReturnsEmptyToken() + { + var token = new TokenResult + { + Token = "super-token" + }; + HttpRequestMessage request = null; + _httpHandlerMock.Protected() + .Setup>( + "SendAsync", + ItExpr.IsAny(), + ItExpr.IsAny()) + .ThrowsAsync(new Exception()) + .Callback((HttpRequestMessage r, CancellationToken ct) => request = r); + + var result = await _sut.GetAsync(token); + + result.Should().BeEmpty(); + AssertRequest(request, token); + } + + private void AssertRequest(HttpRequestMessage request, TokenResult token) + { + request.Should().NotBeNull(); + request.Method.Should().Be(HttpMethod.Get); + request.RequestUri.OriginalString.Should().Be("http://localhost/servers"); + request.Headers.Authorization.Should().BeEquivalentTo(new AuthenticationHeaderValue("Bearer", token.Token)); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Repository.Tesonet.UnitTests/WindowsParty.Repository.Tesonet.UnitTests.csproj b/Windows-party/WindowsParty.Repository.Tesonet.UnitTests/WindowsParty.Repository.Tesonet.UnitTests.csproj new file mode 100644 index 0000000..7f02536 --- /dev/null +++ b/Windows-party/WindowsParty.Repository.Tesonet.UnitTests/WindowsParty.Repository.Tesonet.UnitTests.csproj @@ -0,0 +1,29 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/Windows-party/WindowsParty.Repository.Tesonet/Assembly.cs b/Windows-party/WindowsParty.Repository.Tesonet/Assembly.cs new file mode 100644 index 0000000..c1ac057 --- /dev/null +++ b/Windows-party/WindowsParty.Repository.Tesonet/Assembly.cs @@ -0,0 +1,4 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("WindowsParty.Repository.Tesonet.UnitTests")] +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] \ No newline at end of file diff --git a/Windows-party/WindowsParty.Repository.Tesonet/RepositoryModule.cs b/Windows-party/WindowsParty.Repository.Tesonet/RepositoryModule.cs new file mode 100644 index 0000000..07753c8 --- /dev/null +++ b/Windows-party/WindowsParty.Repository.Tesonet/RepositoryModule.cs @@ -0,0 +1,15 @@ +namespace WindowsParty.Repository.Tesonet +{ + using Microsoft.Extensions.DependencyInjection; + using WindowsParty.Domain.Contracts; + using WindowsParty.Repository.Tesonet.Services; + + public static class RepositoryModule + { + public static void AddTesonetRepository(this IServiceCollection service) + { + service.AddHttpClient(); + service.AddTransient(); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Repository.Tesonet/Services/ServersQueryService.cs b/Windows-party/WindowsParty.Repository.Tesonet/Services/ServersQueryService.cs new file mode 100644 index 0000000..5e9828e --- /dev/null +++ b/Windows-party/WindowsParty.Repository.Tesonet/Services/ServersQueryService.cs @@ -0,0 +1,73 @@ +namespace WindowsParty.Repository.Tesonet.Services +{ + using System; + using System.Collections.Generic; + using System.Net.Http; + using System.Net.Http.Headers; + using System.Threading.Tasks; + using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.Logging; + using Newtonsoft.Json; + using Newtonsoft.Json.Serialization; + using WindowsParty.Domain.Contracts; + using WindowsParty.Domain.Entities; + using WindowsParty.Domain.Models; + + public class ServersQueryService : IServerQueryService + { + private readonly string _endpoint; + private readonly HttpClient _httpClient; + private readonly JsonSerializerSettings _jsonConverterSettings; + private readonly ILogger _logger; + + public ServersQueryService( + IHttpClientFactory httpClientFactory, + IConfiguration configuration, + ILogger logger) + { + _logger = logger; + + _httpClient = httpClientFactory.CreateClient(); + _endpoint = configuration.GetSection("ServersEndpoint").Value; + + _jsonConverterSettings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + }; + } + + public async Task> GetAsync(TokenResult token) + { + try + { + if (TokenShouldBeProvided(token)) + { + return new List(); + } + + _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Token); + var response = await _httpClient.GetAsync(_endpoint); + var responseString = await response.Content.ReadAsStringAsync(); + + if (!response.IsSuccessStatusCode) + { + _logger.Log(LogLevel.Information, $"Get servers failed: {responseString}."); + return new List(); + } + + return JsonConvert.DeserializeObject>(responseString, _jsonConverterSettings); + } + catch (Exception ex) + { + _logger.Log(LogLevel.Error, ex, "Unexpected error occured."); + + return new List(); + } + } + + private static bool TokenShouldBeProvided(TokenResult token) + { + return string.IsNullOrWhiteSpace(token.Token); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Repository.Tesonet/WindowsParty.Repository.Tesonet.csproj b/Windows-party/WindowsParty.Repository.Tesonet/WindowsParty.Repository.Tesonet.csproj new file mode 100644 index 0000000..73a0270 --- /dev/null +++ b/Windows-party/WindowsParty.Repository.Tesonet/WindowsParty.Repository.Tesonet.csproj @@ -0,0 +1,21 @@ + + + + netstandard2.1 + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/Windows-party/WindowsParty.Ui/App.xaml b/Windows-party/WindowsParty.Ui/App.xaml new file mode 100644 index 0000000..b8887fe --- /dev/null +++ b/Windows-party/WindowsParty.Ui/App.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/App.xaml.cs b/Windows-party/WindowsParty.Ui/App.xaml.cs new file mode 100644 index 0000000..67db1ad --- /dev/null +++ b/Windows-party/WindowsParty.Ui/App.xaml.cs @@ -0,0 +1,68 @@ +namespace WindowsParty.Ui +{ + using System; + using System.Windows; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Hosting; + using Microsoft.Extensions.Logging; + using WindowsParty.Authentication.Tesonet; + using WindowsParty.Repository.Tesonet; + using WindowsParty.Ui.Services; + using WindowsParty.Ui.Views; + + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + private readonly IHost _host; + + public App() + { + _host = Host.CreateDefaultBuilder() + .ConfigureServices(ConfigureServices) + .ConfigureLogging( + logging => + { + logging.AddConsole(); + + // Add other loggers... + }) + .Build(); + + ServiceProvider = _host.Services; + } + + public static IServiceProvider ServiceProvider { get; private set; } + + protected override async void OnExit(ExitEventArgs e) + { + using (_host) + { + await _host.StopAsync(TimeSpan.FromSeconds(5)); + } + + base.OnExit(e); + } + + protected override async void OnStartup(StartupEventArgs e) + { + await _host.StartAsync(); + + var mainView = ServiceProvider.GetRequiredService(); + mainView.Show(); + + var pageNavigationService = ServiceProvider.GetRequiredService(); + pageNavigationService.NavigateTo(); + + base.OnStartup(e); + } + + private void ConfigureServices(IServiceCollection services) + { + services.AddTesonetAuthentication(); + services.AddTesonetRepository(); + services.AddUiModule(); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/AssemblyInfo.cs b/Windows-party/WindowsParty.Ui/AssemblyInfo.cs new file mode 100644 index 0000000..76af59d --- /dev/null +++ b/Windows-party/WindowsParty.Ui/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using System.Windows; + +[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)] diff --git a/Windows-party/WindowsParty.Ui/Assets/bg_login.png b/Windows-party/WindowsParty.Ui/Assets/bg_login.png new file mode 100644 index 0000000..bff717f Binary files /dev/null and b/Windows-party/WindowsParty.Ui/Assets/bg_login.png differ diff --git a/Windows-party/WindowsParty.Ui/Assets/bg_servers.png b/Windows-party/WindowsParty.Ui/Assets/bg_servers.png new file mode 100644 index 0000000..2376175 Binary files /dev/null and b/Windows-party/WindowsParty.Ui/Assets/bg_servers.png differ diff --git a/Windows-party/WindowsParty.Ui/Assets/logo_dark.png b/Windows-party/WindowsParty.Ui/Assets/logo_dark.png new file mode 100644 index 0000000..193e517 Binary files /dev/null and b/Windows-party/WindowsParty.Ui/Assets/logo_dark.png differ diff --git a/Windows-party/WindowsParty.Ui/Assets/logo_pass.png b/Windows-party/WindowsParty.Ui/Assets/logo_pass.png new file mode 100644 index 0000000..f790176 Binary files /dev/null and b/Windows-party/WindowsParty.Ui/Assets/logo_pass.png differ diff --git a/Windows-party/WindowsParty.Ui/Assets/logo_user.png b/Windows-party/WindowsParty.Ui/Assets/logo_user.png new file mode 100644 index 0000000..0bd0a2c Binary files /dev/null and b/Windows-party/WindowsParty.Ui/Assets/logo_user.png differ diff --git a/Windows-party/WindowsParty.Ui/Assets/logo_white.png b/Windows-party/WindowsParty.Ui/Assets/logo_white.png new file mode 100644 index 0000000..566345a Binary files /dev/null and b/Windows-party/WindowsParty.Ui/Assets/logo_white.png differ diff --git a/Windows-party/WindowsParty.Ui/Assets/logo_white_sm.png b/Windows-party/WindowsParty.Ui/Assets/logo_white_sm.png new file mode 100644 index 0000000..cc44570 Binary files /dev/null and b/Windows-party/WindowsParty.Ui/Assets/logo_white_sm.png differ diff --git a/Windows-party/WindowsParty.Ui/Assets/logoff_icon.png b/Windows-party/WindowsParty.Ui/Assets/logoff_icon.png new file mode 100644 index 0000000..467c639 Binary files /dev/null and b/Windows-party/WindowsParty.Ui/Assets/logoff_icon.png differ diff --git a/Windows-party/WindowsParty.Ui/Converters/DistanceToKilometersConverter.cs b/Windows-party/WindowsParty.Ui/Converters/DistanceToKilometersConverter.cs new file mode 100644 index 0000000..a3ae32d --- /dev/null +++ b/Windows-party/WindowsParty.Ui/Converters/DistanceToKilometersConverter.cs @@ -0,0 +1,41 @@ +namespace WindowsParty.Ui.Converters +{ + using System; + using System.Globalization; + using System.Windows; + using System.Windows.Data; + + public class DistanceToKilometersConverter : IValueConverter + { + /// + /// Converts a value. + /// + /// A converted value. If the method returns null, the valid null value is used. + /// The value produced by the binding source. + /// The type of the binding target property. + /// The converter parameter to use. + /// The culture to use in the converter. + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if ((value == null) || (value == DependencyProperty.UnsetValue)) + { + return string.Empty; + } + + return $"{value} km"; + } + + /// + /// Converts a value. + /// + /// A converted value. If the method returns null, the valid null value is used. + /// The value that is produced by the binding target. + /// The type to convert to. + /// The converter parameter to use. + /// The culture to use in the converter. + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/Converters/StringToVisibilityConverter.cs b/Windows-party/WindowsParty.Ui/Converters/StringToVisibilityConverter.cs new file mode 100644 index 0000000..5ed147b --- /dev/null +++ b/Windows-party/WindowsParty.Ui/Converters/StringToVisibilityConverter.cs @@ -0,0 +1,47 @@ +namespace WindowsParty.Ui.Converters +{ + using System; + using System.Globalization; + using System.Windows; + using System.Windows.Data; + + /// + /// Converts string to visibility based on contents + /// + public class StringToVisibilityConverter : IValueConverter + { + /// + /// Converts string to visibility. + /// + /// + /// Returns if received string is empty or null, otherwise + /// + /// The value produced by the binding source. + /// The type of the binding target property. + /// The converter parameter to use. + /// The culture to use in the converter. + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if ((value == null) || (value == DependencyProperty.UnsetValue)) + { + return Visibility.Hidden; + } + + return string.IsNullOrEmpty((string)value) ? Visibility.Collapsed : Visibility.Visible; + } + + /// + /// Converts a value. + /// + /// A converted value. If the method returns null, the valid null value is used. + /// The value that is produced by the binding target. + /// The type to convert to. + /// The converter parameter to use. + /// The culture to use in the converter. + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/Extensions/StringExtensions.cs b/Windows-party/WindowsParty.Ui/Extensions/StringExtensions.cs new file mode 100644 index 0000000..22c66e9 --- /dev/null +++ b/Windows-party/WindowsParty.Ui/Extensions/StringExtensions.cs @@ -0,0 +1,10 @@ +namespace WindowsParty.Ui.Extensions +{ + public static class StringExtensions + { + public static bool IsEmpty(this string value) + { + return string.IsNullOrEmpty(value); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/Services/IPageNavigationService.cs b/Windows-party/WindowsParty.Ui/Services/IPageNavigationService.cs new file mode 100644 index 0000000..f7254d5 --- /dev/null +++ b/Windows-party/WindowsParty.Ui/Services/IPageNavigationService.cs @@ -0,0 +1,11 @@ +namespace WindowsParty.Ui.Services +{ + using System.Windows.Controls; + + public interface IPageNavigationService + { + object Parameter { get; } + + void NavigateTo(object parameter = null) where T : Page; + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/Services/PageNavigationService.cs b/Windows-party/WindowsParty.Ui/Services/PageNavigationService.cs new file mode 100644 index 0000000..3a465d8 --- /dev/null +++ b/Windows-party/WindowsParty.Ui/Services/PageNavigationService.cs @@ -0,0 +1,84 @@ +namespace WindowsParty.Ui.Services +{ + using System; + using System.ComponentModel; + using System.Runtime.CompilerServices; + using System.Threading.Tasks; + using System.Windows; + using System.Windows.Controls; + using System.Windows.Media; + + internal class PageNavigationService : IPageNavigationService + { + private readonly string _frameName = "MainFrame"; + private string _currentPageKey; + + public event PropertyChangedEventHandler PropertyChanged; + + public string CurrentPageKey + { + get => _currentPageKey; + private set + { + if (_currentPageKey != value) + { + _currentPageKey = value; + NotifyPropertyChanged(); + } + } + } + + public object Parameter { get; private set; } + + public void NavigateTo(object parameter = null) where T : Page + { + var pageKey = typeof(T).Name; + + if (pageKey != CurrentPageKey) + { + if (GetDescendantFromName(Application.Current.MainWindow, _frameName) is Frame frame) + { + frame.Source = new Uri($"../Views/{pageKey}.xaml", UriKind.Relative); + } + + Parameter = parameter; + CurrentPageKey = pageKey; + } + } + + private static FrameworkElement GetDescendantFromName(DependencyObject parent, string name) + { + var count = VisualTreeHelper.GetChildrenCount(parent); + + if (count < 1) + { + return null; + } + + for (var i = 0; i < count; i++) + { + if (VisualTreeHelper.GetChild(parent, i) is FrameworkElement frameworkElement) + { + if (frameworkElement.Name == name) + { + return frameworkElement; + } + + frameworkElement = GetDescendantFromName(frameworkElement, name); + + if (frameworkElement != null) + { + return frameworkElement; + } + } + } + + return null; + } + + private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/Theme/scrollbar.xaml b/Windows-party/WindowsParty.Ui/Theme/scrollbar.xaml new file mode 100644 index 0000000..299932f --- /dev/null +++ b/Windows-party/WindowsParty.Ui/Theme/scrollbar.xaml @@ -0,0 +1,134 @@ + + + + \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/Theme/styles.xaml b/Windows-party/WindowsParty.Ui/Theme/styles.xaml new file mode 100644 index 0000000..af5ccae --- /dev/null +++ b/Windows-party/WindowsParty.Ui/Theme/styles.xaml @@ -0,0 +1,243 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/UiModule.cs b/Windows-party/WindowsParty.Ui/UiModule.cs new file mode 100644 index 0000000..e3b3bd2 --- /dev/null +++ b/Windows-party/WindowsParty.Ui/UiModule.cs @@ -0,0 +1,25 @@ +namespace WindowsParty.Ui +{ + using Microsoft.Extensions.DependencyInjection; + using WindowsParty.Ui.Services; + using WindowsParty.Ui.ViewModels; + using WindowsParty.Ui.Views; + + public static class UiModule + { + public static void AddUiModule(this IServiceCollection services) + { + // Register all ViewModels. + services.AddSingleton(); + services.AddSingleton(); + services.AddTransient(); + + // Register all the Windows of the applications. + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddSingleton(); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/UserControls/Password.xaml b/Windows-party/WindowsParty.Ui/UserControls/Password.xaml new file mode 100644 index 0000000..85766df --- /dev/null +++ b/Windows-party/WindowsParty.Ui/UserControls/Password.xaml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Windows-party/WindowsParty.Ui/UserControls/Password.xaml.cs b/Windows-party/WindowsParty.Ui/UserControls/Password.xaml.cs new file mode 100644 index 0000000..7d1cb1d --- /dev/null +++ b/Windows-party/WindowsParty.Ui/UserControls/Password.xaml.cs @@ -0,0 +1,37 @@ +namespace WindowsParty.Ui.UserControls +{ + using System.Windows; + using System.Windows.Controls; + + /// + /// Interaction logic for Password.xaml + /// + public partial class Password : UserControl + { + public static readonly DependencyProperty PasswordTextProperty = DependencyProperty.Register( + "PasswordText", + typeof(string), + typeof(Password), + new FrameworkPropertyMetadata(null) + { + BindsTwoWayByDefault = true + }); + + public Password() + { + InitializeComponent(); + } + + public string PasswordText + { + get => (string)GetValue(PasswordTextProperty); + + set => SetValue(PasswordTextProperty, value); + } + + private void PasswordTextBox_OnPasswordChanged(object sender, RoutedEventArgs e) + { + PasswordText = PasswordTextBox.Password; + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/UserControls/PasswordBoxMonitoring.cs b/Windows-party/WindowsParty.Ui/UserControls/PasswordBoxMonitoring.cs new file mode 100644 index 0000000..ca48471 --- /dev/null +++ b/Windows-party/WindowsParty.Ui/UserControls/PasswordBoxMonitoring.cs @@ -0,0 +1,73 @@ +namespace WindowsParty.Ui.UserControls +{ + using System.Windows; + using System.Windows.Controls; + + public class PasswordBoxMonitor : DependencyObject + { + public static readonly DependencyProperty IsMonitoringProperty = + DependencyProperty.RegisterAttached( + "IsMonitoring", + typeof(bool), + typeof(PasswordBoxMonitor), + new UIPropertyMetadata(false, OnIsMonitoringChanged)); + + public static readonly DependencyProperty PasswordLengthProperty = + DependencyProperty.RegisterAttached( + "PasswordLength", + typeof(int), + typeof(PasswordBoxMonitor), + new UIPropertyMetadata(0)); + + public static bool GetIsMonitoring(DependencyObject obj) + { + return (bool)obj.GetValue(IsMonitoringProperty); + } + + public static int GetPasswordLength(DependencyObject obj) + { + return (int)obj.GetValue(PasswordLengthProperty); + } + + public static void SetIsMonitoring(DependencyObject obj, bool value) + { + obj.SetValue(IsMonitoringProperty, value); + } + + public static void SetPasswordLength(DependencyObject obj, int value) + { + obj.SetValue(PasswordLengthProperty, value); + } + + private static void OnIsMonitoringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var pb = d as PasswordBox; + + if (pb == null) + { + return; + } + + if ((bool)e.NewValue) + { + pb.PasswordChanged += PasswordChanged; + } + else + { + pb.PasswordChanged -= PasswordChanged; + } + } + + private static void PasswordChanged(object sender, RoutedEventArgs e) + { + var pb = sender as PasswordBox; + + if (pb == null) + { + return; + } + + SetPasswordLength(pb, pb.Password.Length); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/UserControls/Username.xaml b/Windows-party/WindowsParty.Ui/UserControls/Username.xaml new file mode 100644 index 0000000..88f3bdc --- /dev/null +++ b/Windows-party/WindowsParty.Ui/UserControls/Username.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/UserControls/Username.xaml.cs b/Windows-party/WindowsParty.Ui/UserControls/Username.xaml.cs new file mode 100644 index 0000000..ccb3935 --- /dev/null +++ b/Windows-party/WindowsParty.Ui/UserControls/Username.xaml.cs @@ -0,0 +1,32 @@ +namespace WindowsParty.Ui.UserControls +{ + using System.Windows; + using System.Windows.Controls; + + /// + /// Interaction logic for Username.xaml + /// + public partial class Username : UserControl + { + public static readonly DependencyProperty EditableTextProperty = DependencyProperty.Register( + "EditableText", + typeof(string), + typeof(Username), + new FrameworkPropertyMetadata(null) + { + BindsTwoWayByDefault = true + }); + + public Username() + { + InitializeComponent(); + } + + public string EditableText + { + get => (string)GetValue(EditableTextProperty); + + set => SetValue(EditableTextProperty, value); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/ViewModels/IViewModel.cs b/Windows-party/WindowsParty.Ui/ViewModels/IViewModel.cs new file mode 100644 index 0000000..c787630 --- /dev/null +++ b/Windows-party/WindowsParty.Ui/ViewModels/IViewModel.cs @@ -0,0 +1,9 @@ +namespace WindowsParty.Ui.ViewModels +{ + using System.Threading.Tasks; + + public interface IViewModel + { + Task ActivateAsync(object parameter); + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/ViewModels/LogInViewModel.cs b/Windows-party/WindowsParty.Ui/ViewModels/LogInViewModel.cs new file mode 100644 index 0000000..9ba877b --- /dev/null +++ b/Windows-party/WindowsParty.Ui/ViewModels/LogInViewModel.cs @@ -0,0 +1,96 @@ +namespace WindowsParty.Ui.ViewModels +{ + using System.Threading.Tasks; + using GalaSoft.MvvmLight; + using GalaSoft.MvvmLight.Command; + using WindowsParty.Domain.Contracts; + using WindowsParty.Domain.Models; + using WindowsParty.Ui.Services; + using WindowsParty.Ui.Views; + + public class LogInViewModel : ViewModelBase, IViewModel + { + private readonly IAuthenticationService _authenticationService; + private readonly IPageNavigationService _pageNavigationService; + private readonly IServerQueryService _serverQueryService; + private string _password; + private string _userName; + private string _errorMessage; + + public LogInViewModel( + IAuthenticationService authenticationService, + IPageNavigationService pageNavigationService, + IServerQueryService serverQueryService) + { + _authenticationService = authenticationService; + _pageNavigationService = pageNavigationService; + _serverQueryService = serverQueryService; + LogInCommand = new RelayCommand(async () => await LogIn(), CanExecuteLogin); + } + + public RelayCommand LogInCommand { get; } + + public string Password + { + get => _password; + set + { + Set(ref _password, value); + LogInCommand.RaiseCanExecuteChanged(); + ErrorMessage = string.Empty; + } + } + + public string UserName + { + get => _userName; + set + { + Set(ref _userName, value); + LogInCommand.RaiseCanExecuteChanged(); + ErrorMessage = string.Empty; + } + } + + public string ErrorMessage + { + get => _errorMessage; + set + { + Set(ref _errorMessage, value); + LogInCommand.RaiseCanExecuteChanged(); + } + } + + public Task ActivateAsync(object parameter) + { + return Task.CompletedTask; + } + + private bool CanExecuteLogin() + { + return !(string.IsNullOrWhiteSpace(_userName) && string.IsNullOrWhiteSpace(_password)); + } + + private async Task LogIn() + { + UiServices.SetBusyState(); + var result = await _authenticationService.LogInAsync( + new Credentials + { + Password = _password, + Username = _userName + }); + + if (result.IsSuccess) + { + var servers = await _serverQueryService.GetAsync(result); + _pageNavigationService.NavigateTo(servers); + } + else + { + ErrorMessage = "Wrong credentials"; + } + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/ViewModels/MainViewModel.cs b/Windows-party/WindowsParty.Ui/ViewModels/MainViewModel.cs new file mode 100644 index 0000000..e9ee569 --- /dev/null +++ b/Windows-party/WindowsParty.Ui/ViewModels/MainViewModel.cs @@ -0,0 +1,37 @@ +namespace WindowsParty.Ui.ViewModels +{ + using System.Threading.Tasks; + using GalaSoft.MvvmLight; + using GalaSoft.MvvmLight.Command; + using WindowsParty.Ui.Services; + using WindowsParty.Ui.Views; + + public class MainViewModel : ViewModelBase, IViewModel + { + private RelayCommand _loadedCommand; + private IPageNavigationService _navigationService; + + public MainViewModel(IPageNavigationService navigationService) + { + _navigationService = navigationService; + } + + public RelayCommand LoadedCommand + { + get + { + return _loadedCommand + ?? (_loadedCommand = new RelayCommand( + () => + { + _navigationService.NavigateTo(); + })); + } + } + + public Task ActivateAsync(object parameter) + { + return Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/ViewModels/ServersViewModel.cs b/Windows-party/WindowsParty.Ui/ViewModels/ServersViewModel.cs new file mode 100644 index 0000000..7001d2c --- /dev/null +++ b/Windows-party/WindowsParty.Ui/ViewModels/ServersViewModel.cs @@ -0,0 +1,45 @@ +namespace WindowsParty.Ui.ViewModels +{ + using System.Collections.Generic; + using System.ComponentModel; + using System.Threading.Tasks; + using GalaSoft.MvvmLight; + using GalaSoft.MvvmLight.Command; + using WindowsParty.Domain.Entities; + using WindowsParty.Ui.Services; + using WindowsParty.Ui.Views; + + public class ServersViewModel : ViewModelBase, IViewModel + { + private readonly IPageNavigationService _navigationService; + + public ServersViewModel(IPageNavigationService navigationService) + { + _navigationService = navigationService; + LogOffCommand = new RelayCommand(LogOff); + + if (navigationService.Parameter is IList servers) + { + Servers = new BindingList(servers); + } + else + { + Servers = new BindingList(); + } + } + + public RelayCommand LogOffCommand { get; } + + public BindingList Servers { get; } + + public Task ActivateAsync(object parameter) + { + return Task.CompletedTask; + } + + private void LogOff() + { + _navigationService.NavigateTo(); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/ViewModels/UiServices.cs b/Windows-party/WindowsParty.Ui/ViewModels/UiServices.cs new file mode 100644 index 0000000..e5f9ff7 --- /dev/null +++ b/Windows-party/WindowsParty.Ui/ViewModels/UiServices.cs @@ -0,0 +1,61 @@ +namespace WindowsParty.Ui.ViewModels +{ + using System; + using System.Windows; + using System.Windows.Input; + using System.Windows.Threading; + + public static class UiServices + { + /// + /// A value indicating whether the UI is currently busy + /// + private static bool _isBusy; + + /// + /// Sets the busystate as busy. + /// + public static void SetBusyState() + { + SetBusyState(true); + } + + /// + /// Handles the Tick event of the dispatcherTimer control. + /// + /// The source of the event. + /// The instance containing the event data. + private static void DispatcherTimerTick(object sender, EventArgs e) + { + if (sender is DispatcherTimer dispatcherTimer) + { + SetBusyState(false); + dispatcherTimer.Stop(); + } + } + + /// + /// Sets the busystate to busy or not busy. + /// + /// if set to true the application is now busy. + private static void SetBusyState(bool busy) + { + if (busy == _isBusy) + { + return; + } + + _isBusy = busy; + Mouse.OverrideCursor = busy ? Cursors.Wait : null; + + if (_isBusy) + { + new DispatcherTimer( + TimeSpan.FromSeconds(0), + DispatcherPriority.ApplicationIdle, + DispatcherTimerTick, + Application.Current.Dispatcher); + } + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/ViewModels/ViewModelLocator.cs b/Windows-party/WindowsParty.Ui/ViewModels/ViewModelLocator.cs new file mode 100644 index 0000000..6b1edc2 --- /dev/null +++ b/Windows-party/WindowsParty.Ui/ViewModels/ViewModelLocator.cs @@ -0,0 +1,13 @@ +namespace WindowsParty.Ui.ViewModels +{ + using Microsoft.Extensions.DependencyInjection; + + public class ViewModelLocator + { + public LogInViewModel LogInViewModel => App.ServiceProvider.GetRequiredService(); + + public ServersViewModel ServersViewModel => App.ServiceProvider.GetRequiredService(); + + public MainViewModel MainViewModel => App.ServiceProvider.GetRequiredService(); + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/Views/LogInView.xaml b/Windows-party/WindowsParty.Ui/Views/LogInView.xaml new file mode 100644 index 0000000..93637f5 --- /dev/null +++ b/Windows-party/WindowsParty.Ui/Views/LogInView.xaml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/Views/LogInView.xaml.cs b/Windows-party/WindowsParty.Ui/Views/LogInView.xaml.cs new file mode 100644 index 0000000..567f6a5 --- /dev/null +++ b/Windows-party/WindowsParty.Ui/Views/LogInView.xaml.cs @@ -0,0 +1,15 @@ +namespace WindowsParty.Ui.Views +{ + using System.Windows.Controls; + + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class LogInView : Page + { + public LogInView() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/Views/MainView.xaml b/Windows-party/WindowsParty.Ui/Views/MainView.xaml new file mode 100644 index 0000000..d67abea --- /dev/null +++ b/Windows-party/WindowsParty.Ui/Views/MainView.xaml @@ -0,0 +1,22 @@ + + + + + + diff --git a/Windows-party/WindowsParty.Ui/Views/MainView.xaml.cs b/Windows-party/WindowsParty.Ui/Views/MainView.xaml.cs new file mode 100644 index 0000000..3fd7719 --- /dev/null +++ b/Windows-party/WindowsParty.Ui/Views/MainView.xaml.cs @@ -0,0 +1,15 @@ +namespace WindowsParty.Ui.Views +{ + using System.Windows; + + /// + /// Interaction logic for MainView.xaml + /// + public partial class MainView : Window + { + public MainView() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/Windows-party/WindowsParty.Ui/Views/ServersView.xaml b/Windows-party/WindowsParty.Ui/Views/ServersView.xaml new file mode 100644 index 0000000..eae4a40 --- /dev/null +++ b/Windows-party/WindowsParty.Ui/Views/ServersView.xaml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + +