You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.3 KiB

  1. using System;
  2. using System.Drawing;
  3. using System.Runtime.Remoting;
  4. using System.Security.Permissions;
  5. namespace RenderHookAPI.Interface
  6. {
  7. [Serializable]
  8. public class ScreenshotRequest: MarshalByRefObject, IDisposable
  9. {
  10. public Guid RequestId { get; set; }
  11. public Rectangle RegionToCapture { get; set; }
  12. public Size? Resize { get; set; }
  13. public ImageFormat Format { get; set; }
  14. public ScreenshotRequest(Rectangle region, Size resize)
  15. : this(Guid.NewGuid(), region, resize)
  16. {
  17. }
  18. public ScreenshotRequest(Rectangle region)
  19. : this(Guid.NewGuid(), region, null)
  20. {
  21. }
  22. public ScreenshotRequest(Guid requestId, Rectangle region)
  23. : this(requestId, region, null)
  24. {
  25. }
  26. public ScreenshotRequest(Guid requestId, Rectangle region, Size? resize)
  27. {
  28. RequestId = requestId;
  29. RegionToCapture = region;
  30. Resize = resize;
  31. }
  32. public ScreenshotRequest Clone()
  33. {
  34. return new ScreenshotRequest(RequestId, RegionToCapture, Resize)
  35. {
  36. Format = Format
  37. };
  38. }
  39. ~ScreenshotRequest()
  40. {
  41. Dispose(false);
  42. }
  43. private bool _disposed;
  44. public void Dispose()
  45. {
  46. Dispose(true);
  47. GC.SuppressFinalize(this);
  48. }
  49. protected virtual void Dispose(bool disposing)
  50. {
  51. if (!_disposed)
  52. {
  53. if (disposing)
  54. {
  55. Disconnect();
  56. }
  57. _disposed = true;
  58. }
  59. }
  60. /// <summary>
  61. /// Disconnects the remoting channel(s) of this object and all nested objects.
  62. /// </summary>
  63. private void Disconnect()
  64. {
  65. RemotingServices.Disconnect(this);
  66. }
  67. [SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.Infrastructure)]
  68. public override object InitializeLifetimeService()
  69. {
  70. // Returning null designates an infinite non-expiring lease.
  71. // We must therefore ensure that RemotingServices.Disconnect() is called when
  72. // it's no longer needed otherwise there will be a memory leak.
  73. return null;
  74. }
  75. }
  76. }