2025-02-20 16:10:09 +03:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2025-02-05 18:04:35 +03:00
|
|
|
using Example.Shared;
|
2025-02-07 16:53:12 +03:00
|
|
|
using mROA.Implementation.Attributes;
|
2025-02-05 18:04:35 +03:00
|
|
|
|
2025-02-20 16:10:09 +03:00
|
|
|
namespace Example.Backend
|
2025-02-05 18:04:35 +03:00
|
|
|
{
|
2025-02-20 16:10:09 +03:00
|
|
|
[SharedObjectSingleton]
|
|
|
|
|
public class PrinterFactory : IPrinterFactory
|
2025-02-05 18:04:35 +03:00
|
|
|
{
|
2025-02-20 16:10:09 +03:00
|
|
|
private List<IPrinter> _printers = new List<IPrinter>();
|
2025-02-13 19:38:54 +03:00
|
|
|
|
2025-03-01 16:53:00 +03:00
|
|
|
public IPrinter Create(string printerName)
|
2025-02-20 16:10:09 +03:00
|
|
|
{
|
|
|
|
|
Console.WriteLine("Creating printer");
|
|
|
|
|
return new Printer { Name = printerName };
|
|
|
|
|
}
|
2025-02-13 19:38:54 +03:00
|
|
|
|
2025-03-01 16:53:00 +03:00
|
|
|
public void Register(IPrinter printer)
|
2025-02-20 16:10:09 +03:00
|
|
|
{
|
2025-03-01 16:53:00 +03:00
|
|
|
_printers.Add(printer);
|
2025-02-20 16:10:09 +03:00
|
|
|
Console.WriteLine("Registered printer");
|
|
|
|
|
}
|
2025-02-14 22:26:55 +03:00
|
|
|
|
2025-03-01 16:53:00 +03:00
|
|
|
public IPrinter GetPrinterByName(string printerName)
|
2025-02-20 16:10:09 +03:00
|
|
|
{
|
|
|
|
|
Console.WriteLine("Getting printer");
|
2025-03-01 16:53:00 +03:00
|
|
|
return (_printers.Find(i => i.GetName() == printerName)!);
|
2025-02-20 16:10:09 +03:00
|
|
|
}
|
2025-02-18 12:14:51 +03:00
|
|
|
|
2025-03-01 16:53:00 +03:00
|
|
|
public IPrinter GetFirstPrinter()
|
2025-02-20 16:10:09 +03:00
|
|
|
{
|
2025-03-01 16:53:00 +03:00
|
|
|
return _printers.First();
|
2025-02-20 16:10:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string[] CollectAllNames()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Collecting all printers");
|
|
|
|
|
return _printers.Select(i => i.GetName()).ToArray();
|
|
|
|
|
}
|
2025-02-14 22:26:55 +03:00
|
|
|
}
|
2025-02-05 18:04:35 +03:00
|
|
|
}
|