Entities.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using static PDFMonitor_SVG.Entities;
  8. namespace PDFMonitor_SVG {
  9. internal class Entities {
  10. public const int DEFAULT_DPI = 96;
  11. public const double DEFAULT_RATIO = 25.4;
  12. public static int px2mm(double px) {
  13. return (int)Math.Round(px / DEFAULT_DPI * DEFAULT_RATIO);
  14. }
  15. //仿FixedThreadPool
  16. public class FixedThreadPool {
  17. private readonly BlockingCollection<Action> _taskQueue;
  18. private readonly Thread[] _threads;
  19. public FixedThreadPool(int size) {
  20. _taskQueue = new BlockingCollection<Action>();
  21. _threads = new Thread[size];
  22. for (int i = 0; i < size; i++) {
  23. _threads[i] = new Thread(Worker);
  24. _threads[i].Start();
  25. }
  26. }
  27. public void Execute(Action action) {
  28. _taskQueue.Add(action);
  29. }
  30. private void Worker() {
  31. foreach (var task in _taskQueue.GetConsumingEnumerable()) {
  32. task();
  33. }
  34. }
  35. public void Shutdown() {
  36. _taskQueue.CompleteAdding();
  37. foreach (var thread in _threads) {
  38. thread.Join();
  39. }
  40. }
  41. }
  42. public class SVGTaskInfo {
  43. private string width;
  44. private string height;
  45. private string svgPath;
  46. private string svgFileName;
  47. private long idDesignOrder;
  48. public SVGTaskInfo() {
  49. }
  50. public string SvgPath { get => svgPath; set => svgPath = value; }
  51. public string Height { get => height; set => height = value; }
  52. public string Width { get => width; set => width = value; }
  53. public string SvgFileName { get => svgFileName; set => svgFileName = value; }
  54. public long IdDesignOrder { get => idDesignOrder; set => idDesignOrder = value; }
  55. }
  56. public class PDFCallbackInfo {
  57. private long idDesignOrder;
  58. private string pdfFileName;
  59. public long IdDesignOrder { get => idDesignOrder; set => idDesignOrder = value; }
  60. public string PdfFileName { get => pdfFileName; set => pdfFileName = value; }
  61. }
  62. }
  63. }