Skip to content

Commit

Permalink
DEV-1 fix/refactore Рефакторинг
Browse files Browse the repository at this point in the history
Изменил метод GetEntry интерфейса IAuthDomain на поле Root и его реализациях.
  • Loading branch information
NotTastyCupcake committed Nov 28, 2023
1 parent 7ba8e36 commit e4f7cb3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Domain-Win/Interfaces/IAuthDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ namespace ProgGym.PrinterMonitor.Domain_Win.Interfaces
{
public interface IAuthDomain
{
public DirectoryEntry GetEntry(string? path, string? username, string? password);
public DirectoryEntry Root { get; }
}
}
8 changes: 2 additions & 6 deletions src/Domain-Win/Services/SearchDeviceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,17 @@ namespace ProgGym.PrinterMonitor.Domain_Win.Services
{
public class SearchDeviceService : ISearchDeviceService
{
private readonly MonitorSettings monitorSettings;
private readonly IAuthDomain authDomain;
private List<string?> printers = new List<string?>();

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

public List<string?> GetPrinters()
{
DirectorySearcher searcher = new DirectorySearcher(this.authDomain.GetEntry(this.monitorSettings.DomainPath,
this.monitorSettings.DomainUserName,
this.monitorSettings.DomainPassword));
DirectorySearcher searcher = new DirectorySearcher(this.authDomain.Root);
searcher.Filter = "(objectClass=printQueue)";
searcher.PropertiesToLoad.Add("cn");
foreach (SearchResult result in searcher.FindAll())
Expand Down
17 changes: 12 additions & 5 deletions src/Domain-Win/Services/authDevice.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ProgGym.PrinterMonitor.Domain_Win.Interfaces;
using ProgGym.PrinterMonitor.Application;
using ProgGym.PrinterMonitor.Domain_Win.Interfaces;
using System;
using System.Collections.Generic;
using System.DirectoryServices;
Expand All @@ -10,12 +11,18 @@ namespace ProgGym.PrinterMonitor.Domain_Win.Services
{
public class AuthDevice: IAuthDomain
{
public DirectoryEntry GetEntry(string? path, string? username, string? password)
private readonly MonitorSettings _monitorSettings;

public DirectoryEntry Root { get; private set; }

public AuthDevice(MonitorSettings monitorSettings)
{
DirectoryEntry root = new DirectoryEntry(path, username, password);
return root;
}
_monitorSettings = monitorSettings;

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

}
}

0 comments on commit e4f7cb3

Please sign in to comment.