/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintSystemExceptions/PrintSystemException.cs

https://github.com/dotnet/wpf · C# · 1294 lines · 696 code · 97 blank · 501 comment · 12 complexity · 514467576ad7b8b4532de9dae252396e MD5 · raw file

  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. /*++
  5. Abstract:
  6. Print System exception objects declaration.
  7. --*/
  8. using System;
  9. using System.Collections;
  10. using System.Runtime.InteropServices;
  11. using System.Text;
  12. using System.Security; //SecurityCritical
  13. using System.Collections.ObjectModel;
  14. using System.Collections.Generic;
  15. using MS.Internal.PrintWin32Thunk.Win32ApiThunk;
  16. namespace System.Printing
  17. {
  18. abstract internal class PrinterHResult
  19. {
  20. ///<summary>
  21. ///
  22. ///</summary>
  23. public static
  24. int
  25. HResultFromWin32(
  26. int win32ErrorCode
  27. )
  28. {
  29. return (win32ErrorCode <= 0) ?
  30. win32ErrorCode :
  31. (int)((win32ErrorCode & unchecked((int)0x80000000)) | ((int)Facility.Win32 << 16) | unchecked((int)0x80000000));
  32. }
  33. ///<summary>
  34. ///
  35. ///</summary>
  36. public static
  37. int
  38. HResultCode(
  39. int errorCode
  40. )
  41. {
  42. return ((errorCode) & 0xFFFF);
  43. }
  44. ///<summary>
  45. ///
  46. ///</summary>
  47. public static
  48. Facility
  49. HResultFacility(
  50. int errorCode
  51. )
  52. {
  53. return (Facility)(((errorCode) >> 16) & 0x1fff);
  54. }
  55. public enum Error
  56. {
  57. PrintSystemGenericError = (int)1801, //ERROR_INVALID_PRINTER_NAME,
  58. PrintingCancelledGenericError = (int)1223, //ERROR_CANCELLED,
  59. };
  60. public enum Facility
  61. {
  62. Win32 = 7,
  63. };
  64. }
  65. /// <summary>
  66. /// Print System exception object.
  67. /// </summary>
  68. /// <ExternalAPI/>
  69. [System.Serializable]
  70. public class PrintSystemException : SystemException
  71. {
  72. /// <summary>
  73. /// PrintSystemException constructor.
  74. /// </summary>
  75. /// <remarks>
  76. /// Default message: Print System exception.
  77. /// Default error code: ERROR_INVALID_PRINTER_NAME.
  78. /// </remarks>
  79. public
  80. PrintSystemException(
  81. ) : base(GetMessageFromResource("PrintSystemException.Generic"))
  82. {
  83. base.HResult = PrinterHResult.HResultFromWin32((int)PrinterHResult.Error.PrintSystemGenericError);
  84. }
  85. /// <summary>
  86. /// PrintSystemException constructor.
  87. /// </summary>
  88. /// <param name="message">
  89. /// Message that describes the current exception. Must be localized.
  90. /// </param>
  91. /// <remarks>
  92. /// Default error code: ERROR_INVALID_PRINTER_NAME.
  93. /// </remarks>
  94. public
  95. PrintSystemException(
  96. String message
  97. ) : base(GetMessageFromResource(PrinterHResult.HResultFromWin32((int)PrinterHResult.Error.PrintSystemGenericError),
  98. message))
  99. {
  100. base.HResult = PrinterHResult.HResultFromWin32((int)PrinterHResult.Error.PrintSystemGenericError);
  101. }
  102. /// <summary>
  103. /// PrintSystemException constructor.
  104. /// </summary>
  105. /// <param name="message">
  106. /// Message that describes the current exception. Must be localized.
  107. /// </param>
  108. /// <param name="innerException">
  109. /// The exception instance that caused the current exception.
  110. /// </param>
  111. /// <remarks>
  112. /// Default error code: ERROR_INVALID_PRINTER_NAME.
  113. /// </remarks>
  114. public
  115. PrintSystemException(
  116. String message,
  117. Exception innerException
  118. ) : base (GetMessageFromResource(PrinterHResult.HResultFromWin32((int)PrinterHResult.Error.PrintSystemGenericError),
  119. message),
  120. innerException)
  121. {
  122. base.HResult = PrinterHResult.HResultFromWin32((int)PrinterHResult.Error.PrintSystemGenericError);
  123. }
  124. /// <summary>
  125. /// Sets the SerializationInfo with information about the exception.
  126. /// </summary>
  127. /// <remarks>
  128. /// Inherited from Exception.
  129. /// </remarks>
  130. /// <param name="info"> Holds the serialized object data about the exception being thrown. </param>
  131. /// <param name="context"> The contextual information about the source or destination. </param>
  132. public override
  133. void
  134. GetObjectData(
  135. System.Runtime.Serialization.SerializationInfo info,
  136. System.Runtime.Serialization.StreamingContext context
  137. )
  138. {
  139. base.GetObjectData(info, context);
  140. }
  141. ///<summary>
  142. ///
  143. ///</summary>
  144. public
  145. PrintSystemException(
  146. int errorCode,
  147. String message
  148. ) : base(GetMessageFromResource(errorCode,message))
  149. {
  150. base.HResult = errorCode;
  151. }
  152. ///<summary>
  153. ///
  154. ///</summary>
  155. public
  156. PrintSystemException(
  157. int errorCode,
  158. String message,
  159. String printerMessage
  160. ) : base(GetMessageFromResource(errorCode,message) + printerMessage)
  161. {
  162. base.HResult = errorCode;
  163. }
  164. ///<summary>
  165. ///
  166. ///</summary>
  167. public
  168. PrintSystemException(
  169. int errorCode,
  170. String message,
  171. Exception innerException
  172. ) : base(GetMessageFromResource(errorCode,message),
  173. innerException)
  174. {
  175. base.HResult = errorCode;
  176. }
  177. /// <summary>
  178. /// Initializes a new instance of the PrintQueueException class with serialized data.
  179. /// </summary>
  180. /// <param name="info"> The object that holds the serialized object data. </param>
  181. /// <param name="context"> The contextual information about the source or destination. </param>
  182. protected
  183. PrintSystemException(
  184. System.Runtime.Serialization.SerializationInfo info,
  185. System.Runtime.Serialization.StreamingContext context
  186. ) : base(info, context)
  187. {
  188. }
  189. /// <summary>
  190. /// Loads the resource string for a given resource key.
  191. /// </summary>
  192. /// <param name="resourceKey"> Resource key. </param>
  193. private static
  194. String
  195. GetMessageFromResource(
  196. String resourceKey
  197. )
  198. {
  199. return printResourceManager.GetString(resourceKey,
  200. System.Threading.Thread.CurrentThread.CurrentUICulture);
  201. }
  202. /// <summary>
  203. /// Loads the resource string for a Win32 error and
  204. /// formats an error message given a resource key.
  205. /// </summary>
  206. /// <param name="errorCode"> Win32 error code. </param>
  207. /// <param name="resourceKey"> Resource key. </param>
  208. private static
  209. String
  210. GetMessageFromResource(
  211. int errorCode,
  212. String resourceKey
  213. )
  214. {
  215. String exceptionMessage = null;
  216. String resourceString = printResourceManager.GetString(resourceKey,
  217. System.Threading.Thread.CurrentThread.CurrentUICulture);
  218. if (PrinterHResult.HResultFacility(errorCode) == PrinterHResult.Facility.Win32)
  219. {
  220. exceptionMessage = String.Format(System.Threading.Thread.CurrentThread.CurrentUICulture,
  221. resourceString,
  222. GetFormattedWin32Error(PrinterHResult.HResultCode(errorCode)));
  223. }
  224. else
  225. {
  226. exceptionMessage = String.Format(System.Threading.Thread.CurrentThread.CurrentUICulture,
  227. resourceString,
  228. errorCode);
  229. }
  230. return exceptionMessage;
  231. }
  232. ///<summary>
  233. ///
  234. ///</summary>
  235. private static
  236. String
  237. GetFormattedWin32Error(
  238. int win32Error
  239. )
  240. {
  241. StringBuilder win32ErrorMessage = new StringBuilder(defaultWin32ErrorMessageLength);
  242. int charCount = NativeMethodsForPrintExceptions.InvokeFormatMessage(FormatMessageFromSystem,
  243. IntPtr.Zero,
  244. win32Error,
  245. 0,
  246. win32ErrorMessage,
  247. win32ErrorMessage.Capacity,
  248. IntPtr.Zero);
  249. if(charCount < 0)
  250. {
  251. win32ErrorMessage.Length = 0;
  252. }
  253. else
  254. {
  255. if(charCount < win32ErrorMessage.Length)
  256. {
  257. win32ErrorMessage.Length = charCount;
  258. }
  259. }
  260. return win32ErrorMessage.ToString();
  261. }
  262. ///<summary>
  263. ///
  264. ///</summary>
  265. static
  266. PrintSystemException(
  267. )
  268. {
  269. printResourceManager = new System.Resources.ResourceManager("System.Printing",
  270. (typeof(PrintSystemException)).Assembly);
  271. }
  272. ///<summary>
  273. ///
  274. ///</summary>
  275. static
  276. System.Resources.ResourceManager printResourceManager;
  277. const
  278. int defaultWin32ErrorMessageLength = 256;
  279. const
  280. int FormatMessageFromSystem = unchecked((int)0x00001000);
  281. };
  282. /// <summary>
  283. /// PrintQueueException exception object.
  284. /// Exceptions of type PrintQueueException are thrown when operating on a
  285. /// <c>PrintQueue</c> object.
  286. /// </summary>
  287. /// <ExternalAPI/>
  288. [System.Serializable]
  289. public class PrintQueueException : PrintSystemException
  290. {
  291. /// <summary>
  292. /// PrintQueueException constructor.
  293. /// </summary>
  294. /// <remarks>
  295. /// Default message: An exception occurred while creating the PrintQueue object. Win32 error: {0}
  296. /// Default error code: ERROR_INVALID_PRINTER_NAME.
  297. /// </remarks>
  298. public
  299. PrintQueueException(
  300. ): base("PrintSystemException.PrintQueue.Generic")
  301. { this.printerName = null;
  302. }
  303. /// <summary>
  304. /// PrintQueueException constructor.
  305. /// </summary>
  306. /// <remarks>
  307. /// Default error code: ERROR_INVALID_PRINTER_NAME.
  308. /// </remarks>
  309. /// <param name="message">
  310. /// Message that describes the current exception. Must be localized.
  311. /// </param>
  312. public
  313. PrintQueueException(
  314. String message
  315. ) : base (message)
  316. {
  317. this.printerName = null;
  318. }
  319. /// <summary>
  320. /// PrintQueueException constructor.
  321. /// </summary>
  322. /// <remarks>
  323. /// Default error code: ERROR_INVALID_PRINTER_NAME.
  324. /// </remarks>
  325. /// <param name="message">
  326. /// Message that describes the current exception. Must be localized.
  327. /// </param>
  328. /// <param name="innerException">
  329. /// The exception instance that caused the current exception.
  330. /// </param>
  331. public
  332. PrintQueueException(
  333. String message,
  334. Exception innerException
  335. ): base(message,
  336. innerException)
  337. {
  338. this.printerName = null;
  339. }
  340. /// <value>
  341. /// Printer name property. The name represents the name identifier of
  342. /// the PrintQueue object that was running the code when the exception was thrown.
  343. /// </value>
  344. public
  345. String PrinterName
  346. {
  347. get
  348. {
  349. return printerName;
  350. }
  351. }
  352. /// <summary>
  353. /// Sets the SerializationInfo with information about the exception.
  354. /// </summary>
  355. /// <remarks>
  356. /// Inherited from Exception.
  357. /// </remarks>
  358. /// <param name="info"> Holds the serialized object data about the exception being thrown. </param>
  359. /// <param name="context"> The contextual information about the source or destination. </param>
  360. public override
  361. void
  362. GetObjectData(
  363. System.Runtime.Serialization.SerializationInfo info,
  364. System.Runtime.Serialization.StreamingContext context
  365. )
  366. {
  367. if (info != null)
  368. {
  369. info.AddValue("PrinterName", printerName);
  370. }
  371. base.GetObjectData(info, context);
  372. }
  373. ///<summary>
  374. ///
  375. ///</summary>
  376. public
  377. PrintQueueException(
  378. int errorCode,
  379. String message,
  380. String printerName
  381. ) : base(errorCode, message)
  382. {
  383. this.printerName = printerName;
  384. base.HResult = errorCode;
  385. }
  386. ///<summary>
  387. ///
  388. ///</summary>
  389. public
  390. PrintQueueException(
  391. int errorCode,
  392. String message,
  393. String printerName,
  394. String printerMessage
  395. ) : base(errorCode, message, printerMessage)
  396. {
  397. this.printerName = printerName;
  398. base.HResult = errorCode;
  399. }
  400. ///<summary>
  401. ///
  402. ///</summary>
  403. public
  404. PrintQueueException(
  405. int errorCode,
  406. String message,
  407. String printerName,
  408. Exception innerException
  409. ) : base(errorCode,
  410. message,
  411. innerException)
  412. {
  413. this.printerName = printerName;
  414. base.HResult = errorCode;
  415. }
  416. /// <summary>
  417. /// Initializes a new instance of the PrintQueueException class with serialized data.
  418. /// </summary>
  419. /// <param name="info"> The object that holds the serialized object data. </param>
  420. /// <param name="context"> The contextual information about the source or destination. </param>
  421. protected
  422. PrintQueueException(
  423. System.Runtime.Serialization.SerializationInfo info,
  424. System.Runtime.Serialization.StreamingContext context
  425. ) : base(info, context)
  426. {
  427. this.printerName = (String)(info.GetValue("PrinterName", typeof(System.String)));
  428. }
  429. private String printerName;
  430. };
  431. /// <summary>
  432. /// PrintServerException constructor.
  433. /// Exceptions of type PrintServerException are thrown when operating on a
  434. /// <c>PrintServer</c> object.
  435. /// </summary>
  436. /// <remarks>
  437. /// Default error code: ERROR_INVALID_PRINTER_NAME.
  438. /// </remarks>
  439. [System.Serializable]
  440. public class PrintServerException : PrintSystemException
  441. {
  442. /// <summary>
  443. /// PrintQueueException constructor.
  444. /// </summary>
  445. /// <remarks>
  446. /// Default message: An exception occurred while creating the PrintServer object. Win32 error is: {0}
  447. /// Default error code: ERROR_INVALID_PRINTER_NAME.
  448. /// </remarks>
  449. public
  450. PrintServerException(
  451. ): base ("PrintSystemException.PrintServer.Generic")
  452. {
  453. this.serverName = null;
  454. }
  455. /// <summary>
  456. /// PrintServerException constructor.
  457. /// </summary>
  458. /// <remarks>
  459. /// Default error code: ERROR_INVALID_PRINTER_NAME.
  460. /// </remarks>
  461. /// <param name="message">
  462. /// Message that describes the current exception. Must be localized.
  463. /// </param>
  464. public
  465. PrintServerException(
  466. String message
  467. ): base(message)
  468. {
  469. this.serverName = null;
  470. }
  471. /// <summary>
  472. /// PrintServerException constructor.
  473. /// </summary>
  474. /// <remarks>
  475. /// Default error code: ERROR_INVALID_PRINTER_NAME.
  476. /// </remarks>
  477. /// <param name="message">
  478. /// Message that describes the current exception. Must be localized.
  479. /// </param>
  480. /// <param name="innerException">
  481. /// The exception instance that caused the current exception.
  482. /// </param>
  483. public
  484. PrintServerException(
  485. String message,
  486. Exception innerException
  487. ): base(message,
  488. innerException)
  489. {
  490. this.serverName = null;
  491. }
  492. /// <value>
  493. /// Server name property. The name represents the name identifier of
  494. /// the PrintServer object that was running the code when the exception was thrown.
  495. /// </value>
  496. public
  497. String ServerName
  498. {
  499. get
  500. {
  501. return serverName;
  502. }
  503. }
  504. /// <summary>
  505. /// Sets the SerializationInfo with information about the exception.
  506. /// </summary>
  507. /// <remarks>
  508. /// Inherited from Exception.
  509. /// </remarks>
  510. /// <param name="info"> Holds the serialized object data about the exception being thrown. </param>
  511. /// <param name="context"> The contextual information about the source or destination. </param>
  512. public override
  513. void
  514. GetObjectData(
  515. System.Runtime.Serialization.SerializationInfo info,
  516. System.Runtime.Serialization.StreamingContext context
  517. )
  518. {
  519. if (info != null)
  520. {
  521. info.AddValue("ServerName", serverName);
  522. }
  523. base.GetObjectData(info, context);
  524. }
  525. ///<summary>
  526. ///
  527. ///</summary>
  528. public
  529. PrintServerException(
  530. int errorCode,
  531. String message,
  532. String serverName
  533. ): base(errorCode, message)
  534. {
  535. this.serverName = serverName;
  536. base.HResult = errorCode;
  537. }
  538. ///<summary>
  539. ///
  540. ///</summary>
  541. public
  542. PrintServerException(
  543. int errorCode,
  544. String message,
  545. String serverName,
  546. Exception innerException
  547. ): base(errorCode,
  548. message,
  549. innerException)
  550. {
  551. this.serverName = serverName;
  552. base.HResult = errorCode;
  553. }
  554. /// <summary>
  555. /// Initializes a new instance of the PrintServerException class with serialized data.
  556. /// </summary>
  557. /// <param name="info"> The object that holds the serialized object data. </param>
  558. /// <param name="context"> The contextual information about the source or destination. </param>
  559. protected
  560. PrintServerException(
  561. System.Runtime.Serialization.SerializationInfo info,
  562. System.Runtime.Serialization.StreamingContext context
  563. ): base(info, context)
  564. {
  565. this.serverName = (String)(info.GetValue("ServerName", typeof(String)));
  566. }
  567. private String serverName;
  568. };
  569. /// <summary>
  570. /// PrintCommitAttributesException constructor.
  571. /// Exceptions of type PrintCommitAttributesException are thrown
  572. /// when Commit method of any of the Print System objects that implement the method.
  573. /// </summary>
  574. /// <remarks>
  575. /// Default error code: ERROR_INVALID_PRINTER_NAME.
  576. /// </remarks>
  577. [System.Serializable]
  578. public class PrintCommitAttributesException : PrintSystemException
  579. {
  580. /// <summary>
  581. /// PrintCommitAttributesException constructor.
  582. /// </summary>
  583. /// <remarks>
  584. /// Default message: Print System exception.
  585. /// Default error code: ERROR_INVALID_PRINTER_NAME.
  586. /// </remarks>
  587. public
  588. PrintCommitAttributesException(
  589. ): base("PrintSystemException.CommitPrintSystemAttributesException")
  590. {
  591. committedAttributes = new Collection<String>();
  592. failedAttributes = new Collection<String>();
  593. printObjectName = null;
  594. }
  595. /// <summary>
  596. /// PrintCommitAttributesException constructor.
  597. /// </summary>
  598. /// <remarks>
  599. /// Default error code: ERROR_INVALID_PRINTER_NAME.
  600. /// </remarks>
  601. /// <param name="message">
  602. /// Message that describes the current exception. Must be localized.
  603. /// </param>
  604. public
  605. PrintCommitAttributesException(
  606. String message
  607. ): base(message)
  608. {
  609. printObjectName = null;
  610. committedAttributes = new Collection<String>();
  611. failedAttributes = new Collection<String>();
  612. }
  613. /// <summary>
  614. /// PrintCommitAttributesException constructor.
  615. /// </summary>
  616. /// <remarks>
  617. /// Default error code: ERROR_INVALID_PRINTER_NAME.
  618. /// </remarks>
  619. public
  620. PrintCommitAttributesException(
  621. String message,
  622. Exception innerException
  623. ): base(message,
  624. innerException)
  625. {
  626. printObjectName = null;
  627. committedAttributes = new Collection<String>();
  628. failedAttributes = new Collection<String>();
  629. }
  630. /// <value>
  631. /// PrintSystemObject name property. The name represents the name identifier of
  632. /// the PrintSystemObject object that was running the code when the exception was thrown.
  633. /// </value>
  634. public
  635. String
  636. PrintObjectName
  637. {
  638. get
  639. {
  640. return printObjectName;
  641. }
  642. }
  643. /// <summary>
  644. /// Sets the SerializationInfo with information about the exception.
  645. /// </summary>
  646. /// <remarks>
  647. /// Inherited from Exception.
  648. /// </remarks>
  649. /// <param name="info"> Holds the serialized object data about the exception being thrown. </param>
  650. /// <param name="context"> The contextual information about the source or destination. </param>
  651. public override
  652. void
  653. GetObjectData(
  654. System.Runtime.Serialization.SerializationInfo info,
  655. System.Runtime.Serialization.StreamingContext context
  656. )
  657. {
  658. if (info != null)
  659. {
  660. info.AddValue("CommittedAttributes", committedAttributes);
  661. info.AddValue("FailedAttributes", failedAttributes);
  662. info.AddValue("ObjectName", printObjectName);
  663. }
  664. base.GetObjectData(info, context);
  665. }
  666. ///<summary>
  667. ///
  668. ///</summary>
  669. public
  670. PrintCommitAttributesException(
  671. int errorCode,
  672. Collection<String> attributesSuccessList,
  673. Collection<String> attributesFailList
  674. ): base(errorCode,
  675. "PrintSystemException.CommitPrintSystemAttributesException")
  676. {
  677. this.committedAttributes = attributesSuccessList;
  678. this.failedAttributes = attributesFailList;
  679. this.printObjectName = null;
  680. }
  681. ///<summary>
  682. ///
  683. ///</summary>
  684. public
  685. PrintCommitAttributesException(
  686. int errorCode,
  687. String message,
  688. Collection<String> attributesSuccessList,
  689. Collection<String> attributesFailList,
  690. String objectName
  691. ) : base(errorCode,message)
  692. {
  693. this.committedAttributes = attributesSuccessList;
  694. this.failedAttributes = attributesFailList;
  695. this.printObjectName = null;
  696. }
  697. ///<summary>
  698. ///
  699. ///</summary>
  700. public
  701. Collection<String> CommittedAttributesCollection
  702. {
  703. get
  704. {
  705. return committedAttributes;
  706. }
  707. }
  708. ///<summary>
  709. ///
  710. ///</summary>
  711. public
  712. Collection<String> FailedAttributesCollection
  713. {
  714. get
  715. {
  716. return failedAttributes;
  717. }
  718. }
  719. /// <summary>
  720. /// Initializes a new instance of the PrintCommitAttributesException class with serialized data.
  721. /// </summary>
  722. /// <param name="info"> The object that holds the serialized object data. </param>
  723. /// <param name="context"> The contextual information about the source or destination. </param>
  724. protected
  725. PrintCommitAttributesException(
  726. System.Runtime.Serialization.SerializationInfo info,
  727. System.Runtime.Serialization.StreamingContext context
  728. ): base(info, context)
  729. {
  730. committedAttributes = (Collection<String>)(info.GetValue("CommittedAttributes", committedAttributes.GetType()));
  731. failedAttributes = (Collection<String>)(info.GetValue("FailedAttributes", failedAttributes.GetType()));
  732. printObjectName = (String)(info.GetValue("ObjectName", printObjectName.GetType()));
  733. }
  734. Collection<String> committedAttributes;
  735. Collection<String> failedAttributes;
  736. String printObjectName;
  737. };
  738. /// <summary>
  739. /// PrintJobException exception object.
  740. /// Exceptions of type PrintJobException submitting a print job to a PrintQueue
  741. /// <c>PrintQueue</c> object.
  742. /// </summary>
  743. /// <ExternalAPI/>
  744. [System.Serializable]
  745. public class PrintJobException : PrintSystemException
  746. {
  747. /// <summary>
  748. /// PrintJobException constructor.
  749. /// </summary>
  750. public
  751. PrintJobException(
  752. )
  753. {
  754. this.jobId = 0;
  755. this.printQueueName = null;
  756. this.jobContainer = null;
  757. }
  758. /// <summary>
  759. /// PrintJobException constructor.
  760. /// </summary>
  761. /// <param name="message">
  762. /// Message that describes the current exception. Must be localized.
  763. /// </param>
  764. public
  765. PrintJobException(
  766. String message
  767. ): base(message)
  768. {
  769. this.jobId = 0;
  770. this.printQueueName = null;
  771. this.jobContainer = null;
  772. }
  773. /// <summary>
  774. /// PrintJobException constructor.
  775. /// </summary>
  776. /// <param name="message">
  777. /// Message that describes the current exception. Must be localized.
  778. /// </param>
  779. /// <param name="innerException">
  780. /// The exception instance that caused the current exception.
  781. /// </param>
  782. public
  783. PrintJobException(
  784. String message,
  785. Exception innerException
  786. ) : base(message,
  787. innerException)
  788. {
  789. this.jobId = 0;
  790. this.printQueueName = null;
  791. this.jobContainer = null;
  792. }
  793. /// <value>
  794. /// Job identifier
  795. /// </value>
  796. public
  797. int
  798. JobId
  799. {
  800. get
  801. {
  802. return jobId;
  803. }
  804. }
  805. /// <value>
  806. /// Job name
  807. /// </value>
  808. public
  809. String
  810. JobName
  811. {
  812. get
  813. {
  814. return jobContainer;
  815. }
  816. }
  817. /// <value>
  818. /// Printer name
  819. /// </value>
  820. public
  821. String
  822. PrintQueueName
  823. {
  824. get
  825. {
  826. return printQueueName;
  827. }
  828. }
  829. /// <summary>
  830. /// Sets the SerializationInfo with information about the exception.
  831. /// </summary>
  832. /// <remarks>
  833. /// Inherited from Exception.
  834. /// </remarks>
  835. /// <param name="info"> Holds the serialized object data about the exception being thrown. </param>
  836. /// <param name="context"> The contextual information about the source or destination. </param>
  837. public override
  838. void
  839. GetObjectData(
  840. System.Runtime.Serialization.SerializationInfo info,
  841. System.Runtime.Serialization.StreamingContext context
  842. )
  843. {
  844. if( info != null )
  845. {
  846. info.AddValue("JobId", jobId );
  847. }
  848. base.GetObjectData(info, context);
  849. }
  850. /// <summary>
  851. /// PrintJobException constructor.
  852. /// </summary>
  853. /// <param name="errorCode">
  854. /// HRESULT error code
  855. /// </param>
  856. /// <param name="message">
  857. /// Message that describes the current exception. Must be localized.
  858. /// </param>
  859. public
  860. PrintJobException(
  861. int errorCode,
  862. String message
  863. ) : base(errorCode, (message))
  864. {
  865. this.jobId = 0;
  866. this.printQueueName = null;
  867. this.jobContainer = null;
  868. }
  869. /// <summary>
  870. /// PrintJobException constructor.
  871. /// </summary>
  872. /// <param name="errorCode">
  873. /// HRESULT error code
  874. /// </param>
  875. /// <param name="message">
  876. /// Message that describes the current exception. Must be localized.
  877. /// </param>
  878. /// <param name="jobId">
  879. /// Job identifier
  880. /// </param>
  881. /// <param name="jobName">
  882. /// Job name
  883. /// </param>
  884. /// <param name="printQueueName">
  885. /// Printer name
  886. /// </param>
  887. public
  888. PrintJobException(
  889. int errorCode,
  890. String message,
  891. String printQueueName,
  892. String jobName,
  893. int jobId
  894. ) : base(errorCode, (message))
  895. {
  896. this.printQueueName = printQueueName;
  897. this.jobContainer = jobName;
  898. this.jobId = jobId;
  899. }
  900. /// <summary>
  901. /// PrintJobException constructor.
  902. /// </summary>
  903. /// <param name="errorCode">
  904. /// HRESULT error code
  905. /// </param>
  906. /// <param name="message">
  907. /// Message that describes the current exception. Must be localized.
  908. /// </param>
  909. /// <param name="jobId">
  910. /// Job identifier
  911. /// </param>
  912. /// <param name="jobName">
  913. /// Job name
  914. /// </param>
  915. /// <param name="printQueueName">
  916. /// Printer name
  917. /// </param>
  918. /// <param name="innerException">
  919. /// The exception instance that caused the current exception.
  920. /// </param>
  921. public
  922. PrintJobException(
  923. int errorCode,
  924. String message,
  925. String printQueueName,
  926. String jobName,
  927. int jobId,
  928. Exception innerException
  929. ) : base(errorCode, (message), innerException)
  930. {
  931. this.printQueueName = printQueueName;
  932. this.jobContainer = jobName;
  933. this.jobId = jobId;
  934. }
  935. /// <summary>
  936. /// PrintJobException constructor.
  937. /// </summary>
  938. /// <param name="errorCode">
  939. /// HRESULT error code
  940. /// </param>
  941. /// <param name="message">
  942. /// Message that describes the current exception. Must be localized.
  943. /// </param>
  944. /// <param name="innerException">
  945. /// The exception instance that caused the current exception.
  946. /// </param>
  947. public
  948. PrintJobException(
  949. int errorCode,
  950. String message,
  951. Exception innerException
  952. ) : base(errorCode, message, innerException)
  953. {
  954. this.jobId = 0;
  955. this.printQueueName = null;
  956. this.jobContainer = null;
  957. }
  958. /// <summary>
  959. /// Initializes a new instance of the PrintSystemException class with serialized data.
  960. /// </summary>
  961. /// <param name="info"> The object that holds the serialized object data. </param>
  962. /// <param name="context"> The contextual information about the source or destination. </param>
  963. protected
  964. PrintJobException(
  965. System.Runtime.Serialization.SerializationInfo info,
  966. System.Runtime.Serialization.StreamingContext context
  967. ) : base(info, context)
  968. {
  969. this.jobId = (int)(info.GetValue("JobId", typeof(int)));
  970. }
  971. int jobId;
  972. String printQueueName;
  973. String jobContainer;
  974. };
  975. /// <summary>
  976. /// PrintingCanceledException exception object.
  977. /// Exceptions of type PrintingCanceledException are thrown when the user cancels
  978. /// a printing operation.
  979. /// </summary>
  980. /// <ExternalAPI/>
  981. [System.Serializable]
  982. public class PrintingCanceledException : PrintJobException
  983. {
  984. /// <summary>
  985. /// PrintingCanceledException constructor.
  986. /// </summary>
  987. /// <remarks>
  988. /// Default message: Printing has been cancelled. Win32 error is {0}
  989. /// Default error code: ERROR_CANCELLED.
  990. /// </remarks>
  991. public
  992. PrintingCanceledException(
  993. ) : base(PrinterHResult.HResultFromWin32((int)PrinterHResult.Error.PrintingCancelledGenericError), "PrintSystemException.PrintingCancelled.Generic")
  994. {
  995. }
  996. /// <summary>
  997. /// PrintingCanceledException constructor.
  998. /// </summary>
  999. /// <param name="message">
  1000. /// Message that describes the current exception. Must be localized.
  1001. /// </param>
  1002. public
  1003. PrintingCanceledException(
  1004. String message
  1005. ) : base(message)
  1006. {
  1007. }
  1008. /// <summary>
  1009. /// PrintingCanceledException constructor.
  1010. /// </summary>
  1011. /// <param name="message">
  1012. /// Message that describes the current exception. Must be localized.
  1013. /// </param>
  1014. /// <param name="innerException">
  1015. /// The exception instance that caused the current exception.
  1016. /// </param>
  1017. public
  1018. PrintingCanceledException(
  1019. String message,
  1020. Exception innerException
  1021. ) : base(message,
  1022. innerException)
  1023. {
  1024. }
  1025. /// <summary>
  1026. /// PrintingCanceledException constructor.
  1027. /// </summary>
  1028. /// <param name="errorCode">
  1029. /// HRESULT error code
  1030. /// </param>
  1031. /// <param name="message">
  1032. /// Message that describes the current exception. Must be localized.
  1033. /// </param>
  1034. public
  1035. PrintingCanceledException(
  1036. int errorCode,
  1037. String message
  1038. ) : base(errorCode, message)
  1039. {
  1040. }
  1041. /// <summary>
  1042. /// PrintingCanceledException constructor.
  1043. /// </summary>
  1044. /// <param name="errorCode">
  1045. /// HRESULT error code
  1046. /// </param>
  1047. /// <param name="message">
  1048. /// Message that describes the current exception. Must be localized.
  1049. /// </param>
  1050. /// <param name="innerException">
  1051. /// The exception instance that caused the current exception.
  1052. /// </param>
  1053. public
  1054. PrintingCanceledException(
  1055. int errorCode,
  1056. String message,
  1057. Exception innerException
  1058. ) : base(errorCode, message, innerException)
  1059. {
  1060. }
  1061. /// <summary>
  1062. /// PrintingCanceledException constructor.
  1063. /// </summary>
  1064. /// <param name="errorCode">
  1065. /// HRESULT error code
  1066. /// </param>
  1067. /// <param name="message">
  1068. /// Message that describes the current exception. Must be localized.
  1069. /// </param>
  1070. /// <param name="printQueueName">
  1071. /// Printer name
  1072. /// </param>
  1073. /// <param name="jobName">
  1074. /// Job name
  1075. /// </param>
  1076. /// <param name="jobId">
  1077. /// Job identifier
  1078. /// </param>
  1079. public
  1080. PrintingCanceledException(
  1081. int errorCode,
  1082. String message,
  1083. String printQueueName,
  1084. String jobName,
  1085. int jobId
  1086. ) : base(errorCode, message, printQueueName, jobName, jobId)
  1087. {
  1088. }
  1089. /// <summary>
  1090. /// PrintingCanceledException constructor.
  1091. /// </summary>
  1092. /// <param name="errorCode">
  1093. /// HRESULT error code
  1094. /// </param>
  1095. /// <param name="message">
  1096. /// Message that describes the current exception. Must be localized.
  1097. /// </param>
  1098. /// <param name="printQueueName">
  1099. /// Printer name
  1100. /// </param>
  1101. /// <param name="jobName">
  1102. /// Job name
  1103. /// </param>
  1104. /// <param name="jobId">
  1105. /// Job identifier
  1106. /// </param>
  1107. /// <param name="innerException">
  1108. /// The exception instance that caused the current exception.
  1109. /// </param>
  1110. public
  1111. PrintingCanceledException(
  1112. int errorCode,
  1113. String message,
  1114. String printQueueName,
  1115. String jobName,
  1116. int jobId,
  1117. Exception innerException
  1118. ) : base(errorCode, message, printQueueName, jobName, jobId, innerException)
  1119. {
  1120. }
  1121. /// <summary>
  1122. /// Initializes a new instance of the PrintingCanceledException class with serialized data.
  1123. /// </summary>
  1124. /// <param name="info"> The object that holds the serialized object data. </param>
  1125. /// <param name="context"> The contextual information about the source or destination. </param>
  1126. protected
  1127. PrintingCanceledException(
  1128. System.Runtime.Serialization.SerializationInfo info,
  1129. System.Runtime.Serialization.StreamingContext context
  1130. ) : base(info, context)
  1131. {
  1132. }
  1133. };
  1134. /// <summary>
  1135. /// Print System exception object.
  1136. /// </summary>
  1137. /// <ExternalAPI/>
  1138. [System.Serializable]
  1139. public class PrintingNotSupportedException : PrintSystemException
  1140. {
  1141. /// <summary>
  1142. /// PrintingNotSupportedException constructor.
  1143. /// </summary>
  1144. public PrintingNotSupportedException()
  1145. {
  1146. }
  1147. /// <summary>
  1148. /// PrintingNotSupportedException constructor.
  1149. /// </summary>
  1150. /// <param name="message">
  1151. /// Message that describes the current exception.
  1152. /// </param>
  1153. public PrintingNotSupportedException(String message) : base("PrintSystemException.Generic")
  1154. {
  1155. }
  1156. /// <summary>
  1157. /// PrintingNotSupportedException constructor.
  1158. /// </summary>
  1159. /// <param name="innerException">
  1160. /// The exception instance that caused the current exception.
  1161. /// </param>
  1162. public PrintingNotSupportedException(string message, Exception innerException)
  1163. : base("PrintSystemException.Generic", innerException)
  1164. {
  1165. }
  1166. /// <summary>
  1167. /// Initializes a new instance of the PrintQueueException class with serialized data.
  1168. /// </summary>
  1169. /// <param name="info"> The object that holds the serialized object data. </param>
  1170. /// <param name="context"> The contextual information about the source or destination. </param>
  1171. protected PrintingNotSupportedException(
  1172. System.Runtime.Serialization.SerializationInfo info,
  1173. System.Runtime.Serialization.StreamingContext context
  1174. )
  1175. : base(info, context)
  1176. {
  1177. }
  1178. /// <summary>
  1179. /// Sets the SerializationInfo with information about the exception.
  1180. /// </summary>
  1181. /// <remarks>
  1182. /// Inherited from Exception.
  1183. /// </remarks>
  1184. /// <param name="info"> Holds the serialized object data about the exception being thrown. </param>
  1185. /// <param name="context"> The contextual information about the source or destination. </param>
  1186. public override void GetObjectData(
  1187. System.Runtime.Serialization.SerializationInfo info,
  1188. System.Runtime.Serialization.StreamingContext context
  1189. )
  1190. {
  1191. base.GetObjectData(info, context);
  1192. }
  1193. };
  1194. }