From e4f7cb3f5f46092c55eab778b9532528e6618d8c Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 28 Nov 2023 22:15:45 +0500 Subject: [PATCH] =?UTF-8?q?DEV-1=20fix/refactore=20=D0=A0=D0=B5=D1=84?= =?UTF-8?q?=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Изменил метод GetEntry интерфейса IAuthDomain на поле Root и его реализациях. --- src/Domain-Win/Interfaces/IAuthDomain.cs | 2 +- src/Domain-Win/Services/SearchDeviceService.cs | 8 ++------ src/Domain-Win/Services/authDevice.cs | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Domain-Win/Interfaces/IAuthDomain.cs b/src/Domain-Win/Interfaces/IAuthDomain.cs index 230f253..3188e06 100644 --- a/src/Domain-Win/Interfaces/IAuthDomain.cs +++ b/src/Domain-Win/Interfaces/IAuthDomain.cs @@ -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; } } } diff --git a/src/Domain-Win/Services/SearchDeviceService.cs b/src/Domain-Win/Services/SearchDeviceService.cs index 84c6b80..d474e57 100644 --- a/src/Domain-Win/Services/SearchDeviceService.cs +++ b/src/Domain-Win/Services/SearchDeviceService.cs @@ -15,21 +15,17 @@ namespace ProgGym.PrinterMonitor.Domain_Win.Services { public class SearchDeviceService : ISearchDeviceService { - private readonly MonitorSettings monitorSettings; private readonly IAuthDomain authDomain; private List printers = new List(); - public SearchDeviceService(MonitorSettings monitorSettings, IAuthDomain authDomain) + public SearchDeviceService(IAuthDomain authDomain) { - this.monitorSettings = monitorSettings; this.authDomain = authDomain; } public List 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()) diff --git a/src/Domain-Win/Services/authDevice.cs b/src/Domain-Win/Services/authDevice.cs index d755311..5c996f1 100644 --- a/src/Domain-Win/Services/authDevice.cs +++ b/src/Domain-Win/Services/authDevice.cs @@ -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; @@ -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); + } } }