MessageShow.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* ==============================================================================
  2. * 功能描述:MessageShow
  3. * 创 建 者:SAGACLOUD
  4. * 创建日期:2017/8/25 9:49:58
  5. * ==============================================================================*/
  6. using System;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Autodesk.Revit.UI;
  10. using SAGA.DotNetUtils;
  11. using SAGA.DotNetUtils.Others;
  12. using SAGA.RevitUtils.ErrorSupports;
  13. using SAGA.RevitUtils.Extends;
  14. using SAGA.RevitUtils.Log;
  15. using SAGA.RevitUtils.WinForm;
  16. namespace SAGA.RevitUtils
  17. {
  18. /// <summary>
  19. /// MessageShow
  20. /// </summary>
  21. public class MessageShow : MessageShowBase
  22. {
  23. public static TaskDialogResult Infomation(string strMessage)
  24. {
  25. if (strMessage.Length < 80)
  26. {
  27. if (!strMessage.Contains(Environment.NewLine))
  28. {
  29. StringBuilder builder = new StringBuilder();
  30. for (int i = 0; i < strMessage.Length; i++)
  31. {
  32. builder.Append(strMessage[i]);
  33. if ((i % 0x25) == 0x24)
  34. {
  35. builder.Append(Environment.NewLine);
  36. }
  37. }
  38. strMessage = builder.ToString();
  39. }
  40. string title = "上格云技术";
  41. TaskDialog dialog = new TaskDialog(title)
  42. {
  43. TitleAutoPrefix = false,
  44. MainContent = strMessage
  45. };
  46. return dialog.Show();
  47. }
  48. Win32WindowImpl owner = new Win32WindowImpl(RevitProcess.GetMainWindowHandle());
  49. TErrorSupport support = new TErrorSupport(ErrorGrades.Information, strMessage, null);
  50. if (support.ShowDialog(owner) == DialogResult.OK)
  51. {
  52. return TaskDialogResult.Ok;
  53. }
  54. return TaskDialogResult.Cancel;
  55. }
  56. public static bool Question(string strText)
  57. {
  58. return MessageShowBase.Question(strText);
  59. }
  60. public static TaskDialogResult Show(Exception ex, bool blnDebug = false, string strMessage = "")
  61. {
  62. if (blnDebug)
  63. {
  64. Write(ex);
  65. return TaskDialogResult.Ok;
  66. }
  67. if (ex is ShowInfoStringException)
  68. {
  69. return Infomation(ex.Message);
  70. }
  71. Win32WindowImpl owner = new Win32WindowImpl(RevitProcess.GetMainWindowHandle());
  72. TErrorSupport support = new TErrorSupport(strMessage, ex);
  73. if (support.ShowDialog(owner) == DialogResult.OK)
  74. {
  75. return TaskDialogResult.Ok;
  76. }
  77. return TaskDialogResult.Cancel;
  78. }
  79. public static void Write(Exception ex)
  80. {
  81. if (ex != null)
  82. {
  83. LogHelper.WriterAsyn(PubMethod.CreateGuidKey() + Environment.NewLine + ex.ToString() + Environment.NewLine);
  84. }
  85. }
  86. }
  87. }