GeneralConfig_t.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace IACommService4CSharp
  7. {
  8. public class GeneralConfig_t : IDisposable
  9. {
  10. private IGeneralConfig4CSharp m_config;
  11. private bool m_disposed;
  12. public GeneralConfig_t()
  13. {
  14. m_config = GeneralConfigFactory4CSharp.Create();
  15. if (null == m_config)
  16. throw new IACommServiceException(ErrorCode.InternalError);
  17. m_disposed = false;
  18. }
  19. ~GeneralConfig_t()
  20. {
  21. Dispose(false);
  22. }
  23. public uint SetParameter(string name, string value)
  24. {
  25. if (null == m_config)
  26. return ErrorCode.InvalidState;
  27. if (null == name || null == value)
  28. return ErrorCode.InvalidArgument;
  29. return m_config.SetParameter(name, value);
  30. }
  31. public string GetParameter(string name)
  32. {
  33. if (null == m_config || null == name)
  34. {
  35. return null;
  36. }
  37. return m_config.GetParameter(name);
  38. }
  39. public uint RemoveParameter(string name)
  40. {
  41. if (null == m_config)
  42. return ErrorCode.InvalidState;
  43. if (null == name)
  44. return ErrorCode.InvalidArgument;
  45. return m_config.RemoveParameter(name);
  46. }
  47. public void RemoveAll()
  48. {
  49. if (null != m_config)
  50. {
  51. m_config.RemoveAll();
  52. }
  53. }
  54. public void Dispose()
  55. {
  56. Dispose(true);
  57. GC.SuppressFinalize(this);
  58. }
  59. protected virtual void Dispose(bool disposeManaged)
  60. {
  61. if (!m_disposed)
  62. {
  63. if (disposeManaged)
  64. {
  65. //do nothing
  66. }
  67. GeneralConfigFactory4CSharp.Destroy(m_config);
  68. m_config = null;
  69. m_disposed = true;
  70. }
  71. }
  72. //Internal use
  73. public IGeneralConfig4CSharp Internal
  74. {
  75. get
  76. {
  77. return m_config;
  78. }
  79. }
  80. }
  81. }