Skip to content

Commit

Permalink
DEV-1 feat Рефакторинг
Browse files Browse the repository at this point in the history
Вынес авторизацию в домене в отдельный класс вместе с интерфейсом.
Общие правки по внешнему виду.
  • Loading branch information
SinHole committed Nov 28, 2023
1 parent 2684ded commit 9b49c56
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
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 Task<List<string>> GetPrinters();
public List<string> GetPrinters();
}
}
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 GetEntry(string? path, string? username, string? password);
}
}
23 changes: 12 additions & 11 deletions src/Domain-Win/Services/SearchDeviceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@
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 MonitorSettings _monitorSettings;

public SearchDeviceService(MonitorSettings monitorSettings)
private readonly MonitorSettings monitorSettings;
private readonly IAuthDomain authDomain;
private List<string?> printers = new List<string?>();

public SearchDeviceService(MonitorSettings monitorSettings, IAuthDomain authDomain)
{
_monitorSettings = monitorSettings;
this.monitorSettings = monitorSettings;
this.authDomain = authDomain;
}

public async Task <List<string>> GetPrinters()
public List<string?> GetPrinters()

Check warning on line 28 in src/Domain-Win/Services/SearchDeviceService.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in return type of 'List<string?> SearchDeviceService.GetPrinters()' doesn't match implicitly implemented member 'List<string> ISearchDeviceService.GetPrinters()'.

Check warning on line 28 in src/Domain-Win/Services/SearchDeviceService.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in return type of 'List<string?> SearchDeviceService.GetPrinters()' doesn't match implicitly implemented member 'List<string> ISearchDeviceService.GetPrinters()'.
{
List<string> printers = new List<string>();
DirectoryEntry root = new(_monitorSettings.DomainPath,
_monitorSettings.DomainUserName,
_monitorSettings.DomainPassword);

DirectorySearcher searcher = new DirectorySearcher(root);
DirectorySearcher searcher = new DirectorySearcher(this.authDomain.GetEntry(this.monitorSettings.DomainPath,
this.monitorSettings.DomainUserName,
this.monitorSettings.DomainPassword));
searcher.Filter = "(objectClass=printQueue)";
searcher.PropertiesToLoad.Add("cn");
foreach (SearchResult result in searcher.FindAll())
Expand Down
21 changes: 21 additions & 0 deletions src/Domain-Win/Services/authDevice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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
{
public DirectoryEntry GetEntry(string? path, string? username, string? password)
{
DirectoryEntry root = new DirectoryEntry(path, username, password);
return root;
}


}
}

0 comments on commit 9b49c56

Please sign in to comment.