diff --git a/src/Application/Interfaces/ISearchDeviceService.cs b/src/Application/Interfaces/ISearchDeviceService.cs index ff016a6..2e5f5bd 100644 --- a/src/Application/Interfaces/ISearchDeviceService.cs +++ b/src/Application/Interfaces/ISearchDeviceService.cs @@ -8,6 +8,6 @@ namespace ProgGym.PrinterMonitor.Application.Interfaces { public interface ISearchDeviceService { - public Task> GetPrinters(); + public List GetPrinters(); } } diff --git a/src/Domain-Win/Interfaces/IAuthDomain.cs b/src/Domain-Win/Interfaces/IAuthDomain.cs new file mode 100644 index 0000000..230f253 --- /dev/null +++ b/src/Domain-Win/Interfaces/IAuthDomain.cs @@ -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); + } +} diff --git a/src/Domain-Win/Services/SearchDeviceService.cs b/src/Domain-Win/Services/SearchDeviceService.cs index 26bd483..84c6b80 100644 --- a/src/Domain-Win/Services/SearchDeviceService.cs +++ b/src/Domain-Win/Services/SearchDeviceService.cs @@ -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 printers = new List(); + + public SearchDeviceService(MonitorSettings monitorSettings, IAuthDomain authDomain) { - _monitorSettings = monitorSettings; + this.monitorSettings = monitorSettings; + this.authDomain = authDomain; } - public async Task > GetPrinters() + public List GetPrinters() { - List printers = new List(); - 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()) diff --git a/src/Domain-Win/Services/authDevice.cs b/src/Domain-Win/Services/authDevice.cs new file mode 100644 index 0000000..d755311 --- /dev/null +++ b/src/Domain-Win/Services/authDevice.cs @@ -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; + } + + + } +}