Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV-1 init Авторизации приложения в домен для доступа к информации о принтерах в веб-приложении #2

Merged
merged 10 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ jobs:
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
#- name: Test
# run: dotnet test --no-build --verbosity normal
34 changes: 25 additions & 9 deletions PrinterMonitor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASP", "src\PresentationASP\
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentations", "Presentations", "{923E7B9C-EDE6-4BC4-A561-4FDB159A2DDC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "src\Application\Application.csproj", "{39C3BCBB-94F9-4954-B9DE-2B82DDFC5F77}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "src\Application\Application.csproj", "{39C3BCBB-94F9-4954-B9DE-2B82DDFC5F77}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "src\Domain\Domain.csproj", "{73940C84-32D9-4548-B5D8-0790BD271F63}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure", "src\Infrastructure\Infrastructure.csproj", "{B15824D0-C294-46BD-BFDD-FD75439F36EF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "src\Infrastructure\Infrastructure.csproj", "{B15824D0-C294-46BD-BFDD-FD75439F36EF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cross-Cutting", "src\Cross-Cutting\Cross-Cutting.csproj", "{2869E815-7ABF-422F-B59D-DA47C73C1D62}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cross_Cutting", "src\Cross-Cutting\Cross_Cutting.csproj", "{2869E815-7ABF-422F-B59D-DA47C73C1D62}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Элементы решения", "Элементы решения", "{0EE2584E-067F-45AB-A957-3C0FC2A66887}"
ProjectSection(SolutionItems) = preProject
README.MD = README.MD
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{9C52CF31-4A61-46ED-91DE-C73B07D9EE9F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTest", "tests\UnitTest\UnitTest.csproj", "{CA325FB5-C970-4E48-B29B-A2C5631A6AD4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Domain_Win", "src\Domain-Win\Domain_Win.csproj", "{1DF9A4AE-4B7F-4335-B802-9A32A3BD8C55}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTest", "tests\IntegrationTest\IntegrationTest.csproj", "{C7686106-F90B-42E6-A648-55DB253882B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -34,10 +40,6 @@ Global
{39C3BCBB-94F9-4954-B9DE-2B82DDFC5F77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39C3BCBB-94F9-4954-B9DE-2B82DDFC5F77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39C3BCBB-94F9-4954-B9DE-2B82DDFC5F77}.Release|Any CPU.Build.0 = Release|Any CPU
{73940C84-32D9-4548-B5D8-0790BD271F63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73940C84-32D9-4548-B5D8-0790BD271F63}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73940C84-32D9-4548-B5D8-0790BD271F63}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73940C84-32D9-4548-B5D8-0790BD271F63}.Release|Any CPU.Build.0 = Release|Any CPU
{B15824D0-C294-46BD-BFDD-FD75439F36EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B15824D0-C294-46BD-BFDD-FD75439F36EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B15824D0-C294-46BD-BFDD-FD75439F36EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -46,12 +48,26 @@ Global
{2869E815-7ABF-422F-B59D-DA47C73C1D62}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2869E815-7ABF-422F-B59D-DA47C73C1D62}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2869E815-7ABF-422F-B59D-DA47C73C1D62}.Release|Any CPU.Build.0 = Release|Any CPU
{CA325FB5-C970-4E48-B29B-A2C5631A6AD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA325FB5-C970-4E48-B29B-A2C5631A6AD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA325FB5-C970-4E48-B29B-A2C5631A6AD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA325FB5-C970-4E48-B29B-A2C5631A6AD4}.Release|Any CPU.Build.0 = Release|Any CPU
{1DF9A4AE-4B7F-4335-B802-9A32A3BD8C55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1DF9A4AE-4B7F-4335-B802-9A32A3BD8C55}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DF9A4AE-4B7F-4335-B802-9A32A3BD8C55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DF9A4AE-4B7F-4335-B802-9A32A3BD8C55}.Release|Any CPU.Build.0 = Release|Any CPU
{C7686106-F90B-42E6-A648-55DB253882B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7686106-F90B-42E6-A648-55DB253882B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7686106-F90B-42E6-A648-55DB253882B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7686106-F90B-42E6-A648-55DB253882B8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F7F053B0-8E7F-41C8-A60F-790061386B0D} = {923E7B9C-EDE6-4BC4-A561-4FDB159A2DDC}
{CA325FB5-C970-4E48-B29B-A2C5631A6AD4} = {9C52CF31-4A61-46ED-91DE-C73B07D9EE9F}
{C7686106-F90B-42E6-A648-55DB253882B8} = {9C52CF31-4A61-46ED-91DE-C73B07D9EE9F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8AC27A90-8AD6-4D17-9B63-91E4D30A9DE1}
Expand Down
4 changes: 4 additions & 0 deletions src/Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
<RootNamespace>ProgGym.PrinterMonitor.Application</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Application/Interfaces/ISearchDeviceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace ProgGym.PrinterMonitor.Application.Interfaces
{
public interface ISearchDeviceService
{

public List<string?> GetPrinters();

Choose a reason for hiding this comment

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

При получении коллекция должна быть не мутабельна, рекомендуется использовать readonly коллекциии

}
}
7 changes: 6 additions & 1 deletion src/Application/MonitorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace ProgGym.PrinterMonitor.Application
{
public class MonitorSettings
{
public string? Subnet { get; set; }
public string? DomainPath { get; set; }

public string? DomainUserName { get; set; }

public string? DomainPassword { get; set; }

}
}
104 changes: 0 additions & 104 deletions src/Application/Services/SearchDeviceService.cs

This file was deleted.

10 changes: 0 additions & 10 deletions src/Cross-Cutting/Cross-Cutting.csproj

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>ProgGym.PrinterMonitor.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>ProgGym.PrinterMonitor.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
</PropertyGroup>

</Project>
18 changes: 18 additions & 0 deletions src/Domain-Win/Domain_Win.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>ProgGym.PrinterMonitor.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.DirectoryServices" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Application\Application.csproj" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions src/Domain-Win/Interfaces/IAuthDomain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProgGym.PrinterMonitor.Domain_Win.Interfaces
{
public interface IAuthDomain
{
public DirectoryEntry Root { get; }
}
}
39 changes: 39 additions & 0 deletions src/Domain-Win/Services/SearchDeviceService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using ProgGym.PrinterMonitor.Application.Interfaces;
using System.DirectoryServices;
using ProgGym.PrinterMonitor.Application;
using ProgGym.PrinterMonitor.Domain_Win.Interfaces;

namespace ProgGym.PrinterMonitor.Domain_Win.Services
{
public class SearchDeviceService : ISearchDeviceService
{
private readonly IAuthDomain authDomain;
private List<string?> printers = new List<string?>();

public SearchDeviceService(IAuthDomain authDomain)
{
this.authDomain = authDomain;
}

//TODO: Создать модель-класс для получения нескольких данных о принтере
public List<string?> GetPrinters()
{
DirectorySearcher searcher = new DirectorySearcher(this.authDomain.Root);
searcher.Filter = "(objectClass=printQueue)";
searcher.PropertiesToLoad.Add("cn");
foreach (SearchResult result in searcher.FindAll())
{
printers.Add(result.Properties["cn"][0].ToString());
}
return printers;
}
}
}
28 changes: 28 additions & 0 deletions src/Domain-Win/Services/authDevice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using ProgGym.PrinterMonitor.Application;
using ProgGym.PrinterMonitor.Domain_Win.Interfaces;
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProgGym.PrinterMonitor.Domain_Win.Services
{
public class AuthDevice: IAuthDomain
{
private readonly MonitorSettings _monitorSettings;

public DirectoryEntry Root { get; private set; }

public AuthDevice(MonitorSettings monitorSettings)
{
_monitorSettings = monitorSettings;

Root = new DirectoryEntry(_monitorSettings.DomainPath,
_monitorSettings.DomainUserName,
_monitorSettings.DomainPassword);
}

}
}
7 changes: 0 additions & 7 deletions src/Domain/Class1.cs

This file was deleted.

4 changes: 3 additions & 1 deletion src/PresentationASP/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"Microsoft.AspNetCore": "Warning"
}
},
"Subnet": "",
"DomainPath": "",
"DomainUserName": "",
"DomainPassword": "",
"AllowedHosts": "*"
}
1 change: 1 addition & 0 deletions tests/IntegrationTest/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using NUnit.Framework;
26 changes: 26 additions & 0 deletions tests/IntegrationTest/IntegrationTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>ProgGym.PrinterMonitor.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Domain-Win\Domain_Win.csproj" />
</ItemGroup>

</Project>
Loading